Skip to content
Snippets Groups Projects
Commit 8809dedd authored by xo30xoqa's avatar xo30xoqa
Browse files

Added backstep function and population plots

Still not functional, waiting on feedback to https://github.com/JuliaGraphics/QML.jl/issues/183
parent a7bccfa3
No related branches found
No related tags found
No related merge requests found
......@@ -31,20 +31,37 @@ end
function nextstep()
global model
stepsimulation!(model)
date[] = model.date
progress[] = (model.date-@param(core.startdate)) / (@param(core.enddate)-model.date)
println("Updated model: $(model.date-Day(1))")
if date[] < model.date
# If we've "scrolled back" in time, step forward again without
# having to resimulate (see `previousstep()`)
date[] += Day(1)
else
# If we're already displaying the newest model update, we need to
# keep simulating
stepsimulation!(model)
date[] = model.date
end
progress[] = (date[]-@param(core.startdate)) /
(@param(core.enddate)-@param(core.startdate))
println("Updated model: $(date[]-Day(1))")
end
function runsimulation()
function previousstep()
# Since we store all model output in a dataframe, we can simply
# "scroll back" in time and visualise the state of the model at
# a previous date
global model
while running[] #FIXME how can I interrupt this?
stepsimulation!(model)
date[] = model.date
progress[] = (model.date-@param(core.startdate)) / (@param(core.enddate)-model.date)
date[] -= Day(1)
progress[] = (date[]-@param(core.startdate)) /
(@param(core.enddate)-@param(core.startdate))
println("Backtracked model: $(date[]-Day(1))")
end
function runsimulation()
#XXX is this all I need to interrupt a run?
while running[]
nextstep()
sleep(delay)
println("Updated model: $(model.date-Day(1))")
end
end
......@@ -60,17 +77,22 @@ function togglerunning()
runsimulation()
end
end
#TODO previousstep() - needs adjustments to nextstep() and runsimulation()
function render_map(screen)
global model
figure = visualisemap(model)
figure = visualisemap(model, date[])
display(screen, figure.scene)
end
function render_map(screen)
global model
figure = populationtrends(model)
display(screen, figure.scene)
end
@qmlfunction newsimulation
@qmlfunction nextstep
@qmlfunction previousstep
@qmlfunction togglerunning
@qmlfunction render_map
......@@ -89,8 +111,8 @@ The main function that creates the application.
"""
function launch()
# absolute path in case working dir is overridden
qml_file = joinpath(dirname(@__FILE__), "main.qml")
loadqml(qml_file,
qmlfile = joinpath(dirname(@__FILE__), "main.qml")
loadqml(qmlfile,
vars = JuliaPropertyMap("running" => running,
"date" => date,
"delay" => delay,
......
......@@ -64,41 +64,53 @@ Distributed under the MIT license."
// visualise the model map and the locations of animals
/* MakieViewport { */
/* id: viewport */
/* id: mapviewport */
/* Layout.fillWidth: true */
/* Layout.fillHeight: true */
/* renderFunction: Julia.render_map() //TODO */
/* } */
// the calendar is no longer a single widget, but needs to be
// constructed manually :-(
ColumnLayout {
id: calenderWidget
Layout.alignment: Qt.AlignHCenter
Text {
text: "<b>"+Qt.formatDate(new Date(), "MMM yyyy")+"</b>" //FIXME
}
DayOfWeekRow {
locale: grid.locale
Layout.column: 1
Layout.fillWidth: true
}
MonthGrid {
id: grid
//month: Calendar.December //FIXME
//year: 2015 //FIXME
locale: Qt.locale("en_GB")
Layout.fillWidth: true
Layout.fillHeight: true
delegate: Text {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
opacity: model.month === grid.month ? 1 : 0
text: model.today ? "<b>"+model.day+"</b>" : model.day
font: grid.font
required property var model
anchors.fill: parent
// the calendar is no longer a single widget, but needs to be
// constructed manually :-(
ColumnLayout {
id: calenderWidget
Layout.alignment: Qt.AlignHCenter
Text {
text: "<b>"+Qt.formatDate(new Date(), "MMM yyyy")+"</b>" //FIXME
}
DayOfWeekRow {
locale: grid.locale
Layout.column: 1
Layout.fillWidth: true
}
MonthGrid {
id: grid
//month: Calendar.December //FIXME
//year: 2015 //FIXME
locale: Qt.locale("en_GB")
Layout.fillWidth: true
Layout.fillHeight: true
delegate: Text {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
opacity: model.month === grid.month ? 1 : 0
text: model.today ? "<b>"+model.day+"</b>" : model.day
font: grid.font
required property var model
}
}
}
// plot the population sizes over time
/* MakieViewport { */
/* id: plotviewport */
/* Layout.fillWidth: true */
/* Layout.fillHeight: true */
/* renderFunction: Julia.render_plot() //TODO */
/* } */
}
}
......@@ -117,7 +129,7 @@ Distributed under the MIT license."
text: "<"
ToolTip.text: "Back"
ToolTip.visible: hovered
//onClicked: //TODO
onClicked: { Julia.previousstep() }
}
Button {
id: stepButton
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment