Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Overview

TODO idea: Use js to manipulate svg


Creating a Configuration File

Example KViZ File
image "Lights.svg"

load "some-js-library"
load "some-other-js-library"
 
init
'
// javascript global variable initialization
// and function definition
// e.g. var hugo = "hugo"
'

handle showLight
in "#theRect"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.fill = status === 0 ? "red" : status === 1 ? "yellow" : "green"
'

handle showLight
in "#theRedOne"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.opacity = status === 1 || status === 2 ? 0 : 1
'

handle showLight
in "#theRedOne"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.opacity = status === 0 || status === 2 ? 0 : 1
'

handle showLight
in "#theRedOne"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.opacity = status === 0 || status === 1 ? 0 : 1
'


Simulation Interaction

Interaction example
image "Lights.svg"
 
handle showLight
in "#theRect"
with (elem, status, datapool) // datapool can always be added to have access to every value in the datapool
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.fill = status === 0 ? "red" : status === 1 ? "yellow" : "green"
'

event "click" 
on "#theRect"
step simulation // executes an actual simulation step
set showLight
'
if (showLight != 1) {
    return 1 // this sets showLight to 1
}
'

// Only set this boolean variable in this tick
event "click"
on "#theRedOne"
signal thisIsABoolean

Scripts that are not associated to a specific value

Scripts can always be associated to a value instead. However it makes clear that is the case:

Script example
image "Lights.svg"

script (datapool)
'
// You are able to write to inputs of the model via the datapool.
datapool.onInput = true
'
  • No labels