TabLayout is a tab-based layout for showing a simulation, graph, and controls.
TabLayout implements specific ways to present the application on the web page, in this
case with a tab-based layout. TabLayout creates and manages various layout elements
(LabCanvas, div for controls, Terminal, etc.). It also defines regular expressions
for easy Terminal scripting of these objects using short names such as terminal,
simCanvas, graphCanvas.
TabLayout constructor takes an argument that specifies the names of the HTML
elements to look for in the HTML document; these elements are where the user
interface of the simulation is created. This allows for having two separate instances
of the same simulation running concurrently on a single page.
These are the names expected to be in the element IDs object:
The set of layout tabs is contained in a UL list. Each tab has a className property
which identifies the name of the tab. Clicking on a tab will change the layout.
The selected tab also has the class 'selected', for example 'sim selected' would be the
className of the sim tab when it is selected.
The layout tabs are expected to be:
sim: selects the 'sim' layout
graph: selects the 'sim+graph' layout
time_graph: selects the 'sim+time_graph' layout
multi_graph: selects the 'sim+multi_graph' layout
Note that each graph tab corresponds to two different layouts: with or without the sim
view.
The 'show sim' checkbox is visible in the graph views. Clicking the 'show sim' checkbox
will change the layout to pick the appropriate version of the current layout, for
example either 'sim+graph' or 'graph'. The method showSim can be used
from JavaScript to accomplish the same result.
The default state of the 'show sim' checkbox is set inside the application's HTML file
by the presence or absence of the word checked in a line like this:
There are three 'levels' which affect how the Simulation, Graph and TimeGraph appear:
There are Parameters for SIM_WIDTH, GRAPH_WIDTH, TIME_GRAPH_WIDTH. These stretch
or shrink the canvas, without changing the resolution of the canvas (the canvas screen
rectangle remains the same). These set the width of the
surrounding the
LabCanvas's to that fraction of the window width, and the canvas stretches or shrinks
to fit into the
. These Parameters only apply when a single canvas (Sim, Graph, or
TimeGraph) is shown alone without another canvas alongside. When there are two or more
canvases then we always use 49% width to fit two canvases side-by-side.
LabCanvas Parameters for WIDTH, HEIGHT: These set the pixel density (resolution)
and shape (ratio of width to height) of the canvas. These determine the ScreenRect that
is passed to the LabViews. The size of the Simulation LabCanvas is set according to
arguments passed to the TabLayout constructor. In contrast, the Graph and TimeGraph
LabCanvas are always square shaped. Their size is the bigger of the Sim LabCanvas width
or height. The size of any LabCanvas can be changed after construction if desired.
SimView Parameters for WIDTH, HEIGHT, CENTER_X, CENTER_Y, VERTICAL_ALIGN, etc.
These affect only the SimRect, which determines simulation coordinates. Pan and zoom of
the image can be done by changing these Parameters.
We use CSS style display: inline-block on the controls div, so that it naturally flows
to right of the canvas if there is enough room, otherwise it flows below the canvas. The
method alignCanvasControls() attempts to set the controls to have 2 columns when the
controls are below the canvas.
We set the canvases to 'float: left' so that the 'show sim' and 'show terminal' controls
will flow under the controls div.
The individual controls have display: block and are styled with CSS.
Adds the given Observer to this Subject's list of Observers, so that the Observer
will be notified of changes in this Subject. An Observer may call Subject.addObserver
during its observe method.
Positions the controls in relation to the canvas. We use CSS style display: inline-block on the controls div, so that it naturally flows to right of the
canvas if there is enough room, otherwise it flows below the canvas. This
method attempts to set the controls to have 2 columns when the controls are
below the canvas.
Parameters
canvas: HTMLElement
the div containing the canvas element
controls: HTMLElement
the div containing the controls
Optionalcanvas2: HTMLElement
Returns void
broadcast
broadcast(evt): void
Notifies all Observers that this Subject has changed by calling
observe on each Observer.
Sets whether this Subject will broadcast events, typically used to temporarily
disable broadcasting. Intended to be used in situations where a subclass overrides a
method that broadcasts an event. This allows the subclass to prevent the superclass
broadcasting that event, so that the subclass can broadcast the event when the method is
completed.
Parameters
value: boolean
whether this Subject should broadcast events
Returns boolean
the previous value
PrivatesetDisplaySize
setDisplaySize(max_width, graph_div): void
Sets the size of the SimCanvas and a graph. This limits the SimCanvas so that it
fits in the window.
Parameters
max_width: number
size of SimCanvas, as fraction of screen width, from 0 to 1
graph_div: HTMLElement
Returns void
setGraphWidth
setGraphWidth(value): void
Sets the width of the graph LabCanvas, as fraction of available width.
Parameters
value: number
width of the graph LabCanvas, as fraction of available width
Returns void
setLayout
setLayout(layout): void
Sets current layout.
Parameters
layout: string
name of layout
Returns void
setLayoutFromTab
setLayoutFromTab(layout): void
Sets current layout based on which tab was clicked
Parameters
layout: string
class name of tab that was clicked
Returns void
PrivatesetSelectedTab
setSelectedTab(layout): void
Sets selected tab to be the tab with given className
Parameters
layout: string
className of tab
Returns void
setSimWidth
setSimWidth(value): void
Sets the width of the simulation LabCanvas, as fraction of available width.
Parameters
value: number
width of the simulation LabCanvas, as fraction of available width
Returns void
setTimeGraphWidth
setTimeGraphWidth(value): void
Sets the width of the time graph LabCanvas, as fraction of available width.
Parameters
value: number
width of the time graph LabCanvas, as fraction of available width
Returns void
showSim
showSim(visible): void
Change layout to hide or show simulation view.
Parameters
visible: boolean
whether sim view should be visible
Returns void
showTerminal
showTerminal(visible): void
Change layout to hide or show terminal text editor.
Parameters
visible: boolean
whether terminal should be visible
Returns void
toString
toString(): string
Returns string
Inherit Doc
toStringShort
toStringShort(): string
Returns a minimal string representation of this object, usually giving just
identity information like the class name and name of the object.
For an object whose main purpose is to represent another Printable object, it is
recommended to include the result of calling toStringShort on that other object.
For example, calling toStringShort() on a DisplayShape might return something like
this:
TabLayout is a tab-based layout for showing a simulation, graph, and controls. TabLayout implements specific ways to present the application on the web page, in this case with a tab-based layout. TabLayout creates and manages various layout elements (LabCanvas,
div
for controls, Terminal, etc.). It also defines regular expressions for easy Terminal scripting of these objects using short names such as terminal, simCanvas, graphCanvas.Element IDs
TabLayout constructor takes an argument that specifies the names of the HTML elements to look for in the HTML document; these elements are where the user interface of the simulation is created. This allows for having two separate instances of the same simulation running concurrently on a single page.
These are the names expected to be in the element IDs object:
Layouts
There are 7 layouts:
Layout Tabs
The set of layout tabs is contained in a UL list. Each tab has a
className
property which identifies the name of the tab. Clicking on a tab will change the layout.The selected tab also has the class 'selected', for example 'sim selected' would be the
className
of the sim tab when it is selected.The layout tabs are expected to be:
Note that each graph tab corresponds to two different layouts: with or without the sim view.
'Show Sim' Checkbox
The 'show sim' checkbox is visible in the graph views. Clicking the 'show sim' checkbox will change the layout to pick the appropriate version of the current layout, for example either 'sim+graph' or 'graph'. The method showSim can be used from JavaScript to accomplish the same result.
The default state of the 'show sim' checkbox is set inside the application's HTML file by the presence or absence of the word
checked
in a line like this:This is usually determined by a macro in the
macros_tab.html
file.Size of Sim, Graph, TimeGraph
There are three 'levels' which affect how the Simulation, Graph and TimeGraph appear:
There are Parameters for
SIM_WIDTH, GRAPH_WIDTH, TIME_GRAPH_WIDTH
. These stretch or shrink the canvas, without changing the resolution of the canvas (the canvas screen rectangle remains the same). These set the width of theLabCanvas Parameters for
WIDTH, HEIGHT
: These set the pixel density (resolution) and shape (ratio of width to height) of the canvas. These determine the ScreenRect that is passed to the LabViews. The size of the Simulation LabCanvas is set according to arguments passed to the TabLayout constructor. In contrast, the Graph and TimeGraph LabCanvas are always square shaped. Their size is the bigger of the Sim LabCanvas width or height. The size of any LabCanvas can be changed after construction if desired.SimView Parameters for
WIDTH, HEIGHT, CENTER_X, CENTER_Y, VERTICAL_ALIGN
, etc. These affect only the SimRect, which determines simulation coordinates. Pan and zoom of the image can be done by changing these Parameters.Layout Of Controls
We use CSS style
display: inline-block
on the controls div, so that it naturally flows to right of the canvas if there is enough room, otherwise it flows below the canvas. The methodalignCanvasControls()
attempts to set the controls to have 2 columns when the controls are below the canvas.We set the canvases to 'float: left' so that the 'show sim' and 'show terminal' controls will flow under the controls div.
The individual controls have
display: block
and are styled with CSS.Terminal Checkbox
A 'show terminal' checkbox is added to the controls div in all layouts, unless the
opt_terminal
parameter is false.Parameters Created
ParameterNumber named
SIM_WIDTH
, see setSimWidthParameterNumber named
GRAPH_WIDTH
, see setGraphWidthParameterNumber named
TIME_GRAPH_WIDTH
, see setTimeGraphWidthParameterString named
LAYOUT
, see setLayoutParameterBoolean named
SHOW_TERMINAL
, see showTerminalHierarchy (view full)
Implements
Index
Constructors
Properties
Methods
Constructors
constructor
Parameters
elem_ids: ElementIDs
specifies the names of the HTML elements to look for in the HTML document; these elements are where the user interface of the simulation is created.
canvasWidth: number = 800
width of sim canvas in pixels, default 800
canvasHeight: number = 800
height of sim canvas in pixels, default 800
opt_terminal: boolean = true
whether to add the 'show terminal' checkbox, default is true
Returns TabLayout
Properties
debug_ layout
Whether to put dashed borders around elements for debugging layout.
Private
div_div for sim controls
Private
div_div element for Terminal
Private
div_div for time graph controls
Private
graphwidth of graphCanvas, as fraction of available width
Private
layout_name of current layout
Private
show_The 'show sim' checkbox is added to the graph views.
Private
simwidth of simCanvas, as fraction of available width
Private
terminalCan disable terminal with this flag.
Private
timewidth of timeGraphCanvas, as fraction of available width
Methods
add Control
Add the control to the set of simulation controls.
Parameters
control: LabControl
opt_add: boolean = true
whether to also add to SimControls, default is true
Returns LabControl
the control that was passed in
add Observer
Adds the given Observer to this Subject's list of Observers, so that the Observer will be notified of changes in this Subject. An Observer may call
Subject.addObserver
during itsobserve
method.Parameters
observer: Observer
the Observer to add
Returns void
add Parameter
Adds the Parameter to the list of this Subject's available Parameters.
Parameters
parameter: Parameter
the Parameter to add
Returns void
Throws
if a Parameter with the same name already exists.
Private
alignPositions the controls in relation to the canvas. We use CSS style
display: inline-block
on the controls div, so that it naturally flows to right of the canvas if there is enough room, otherwise it flows below the canvas. This method attempts to set the controls to have 2 columns when the controls are below the canvas.Parameters
canvas: HTMLElement
the div containing the canvas element
controls: HTMLElement
the div containing the controls
Optional
canvas2: HTMLElementReturns void
broadcast
Notifies all Observers that this Subject has changed by calling observe on each Observer.
An Observer may call addObserver or removeObserver during its
observe
method.Parameters
evt: SubjectEvent
a SubjectEvent with information relating to the change
Returns void
broadcast Parameter
Notifies all Observers that the Parameter with the given name has changed by calling observe on each Observer.
Parameters
name: string
the language-independent or English name of the Parameter that has changed
Returns void
Throws
if there is no Parameter with the given name
Protected
getReturns whether broadcasting is enabled for this Subject. See setBroadcast.
Returns boolean
whether broadcasting is enabled for this Subject
get Class Name
Returns name of class of this object.
Returns string
name of class of this object.
get Graph Canvas
Returns LabCanvas
Inherit Doc
get Graph Controls
Returns HTMLDivElement
Inherit Doc
get Graph Div
Returns HTMLDivElement
Inherit Doc
get Graph Width
Returns the width of the graph LabCanvas, as fraction of available width
Returns number
width of the graph LabCanvas, as fraction of available width
get Layout
Returns current layout.
Returns string
name of the current layout
get Name
Return the language-independent name of this Subject for scripting purposes.
Returns string
name the language-independent name of this Subject
get Observers
Returns a copy of the list of Observers of this Subject.
Returns Observer[]
a copy of the list of Observers of this Subject.
get Parameter
Returns the Parameter with the given name.
Parameters
name: string
the language-independent or English name of the Parameter
Returns Parameter
the Parameter with the given name
Throws
if there is no Parameter with the given name
get Parameter Boolean
Returns the ParameterBoolean with the given name.
Parameters
name: string
the language-independent or English name of the ParameterBoolean
Returns ParameterBoolean
the ParameterBoolean with the given name
Throws
if there is no ParameterBoolean with the given name
get Parameter Number
Returns the ParameterNumber with the given name.
Parameters
name: string
the language-independent or English name of the ParameterNumber
Returns ParameterNumber
the ParameterNumber with the given name
Throws
if there is no ParameterNumber with the given name
get Parameter String
Returns the ParameterString with the given name.
Parameters
name: string
the language-independent or English name of the ParameterString
Returns ParameterString
the ParameterString with the given name
Throws
if there is no ParameterString with the given name
get Parameters
Returns a copy of the list of this Subject's available Parameters.
Returns Parameter[]
a copy of the list of available Parameters for this Subject
Private
getReturns classname of selected tab
Returns string
classname of selected tab, or empty string if none selected
get Sim Canvas
Returns LabCanvas
Inherit Doc
get Sim Controls
Returns HTMLDivElement
Inherit Doc
get Sim Div
Returns HTMLDivElement
Inherit Doc
get Sim Width
Returns the width of the simulation LabCanvas, as fraction of available width
Returns number
width of the simulation LabCanvas, as fraction of available width
get Subjects
Returns list of Subjects contained in this object, possibly including this object itself.
Returns Subject[]
the Subjects contained in this object
get Terminal
Returns Terminal
Inherit Doc
get Time Graph Canvas
Returns LabCanvas
Inherit Doc
get Time Graph Controls
Returns HTMLDivElement
Inherit Doc
get Time Graph Div
Returns HTMLDivElement
Inherit Doc
get Time Graph Width
Returns the width of the time graph LabCanvas, as fraction of available width
Returns number
width of the time graph LabCanvas, as fraction of available width
Private
redoRedo the current layout, either because the type of layout changed or the size of the view port changed.
Returns void
remove Observer
Removes the Observer from this Subject's list of Observers. An Observer may call
removeObserver
during itsobserve
method.Parameters
observer: Observer
the Observer to detach from list of Observers
Returns void
remove Parameter
Removes the Parameter from the list of this Subject's available Parameters.
Parameters
parameter: Parameter
the Parameter to remove
Returns void
Protected
setSets whether this Subject will broadcast events, typically used to temporarily disable broadcasting. Intended to be used in situations where a subclass overrides a method that broadcasts an event. This allows the subclass to prevent the superclass broadcasting that event, so that the subclass can broadcast the event when the method is completed.
Parameters
value: boolean
whether this Subject should broadcast events
Returns boolean
the previous value
Private
setSets the size of the SimCanvas and a graph. This limits the SimCanvas so that it fits in the window.
Parameters
max_width: number
size of SimCanvas, as fraction of screen width, from 0 to 1
graph_div: HTMLElement
Returns void
set Graph Width
Sets the width of the graph LabCanvas, as fraction of available width.
Parameters
value: number
width of the graph LabCanvas, as fraction of available width
Returns void
set Layout
Sets current layout.
Parameters
layout: string
name of layout
Returns void
set Layout From Tab
Sets current layout based on which tab was clicked
Parameters
layout: string
class name of tab that was clicked
Returns void
Private
setSets selected tab to be the tab with given className
Parameters
layout: string
className of tab
Returns void
set Sim Width
Sets the width of the simulation LabCanvas, as fraction of available width.
Parameters
value: number
width of the simulation LabCanvas, as fraction of available width
Returns void
set Time Graph Width
Sets the width of the time graph LabCanvas, as fraction of available width.
Parameters
value: number
width of the time graph LabCanvas, as fraction of available width
Returns void
show Sim
Change layout to hide or show simulation view.
Parameters
visible: boolean
whether sim view should be visible
Returns void
show Terminal
Change layout to hide or show terminal text editor.
Parameters
visible: boolean
whether terminal should be visible
Returns void
to String
Returns string
Inherit Doc
to String Short
Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.
For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling
toStringShort
on that other object. For example, callingtoStringShort()
on a DisplayShape might return something like this:Returns string
a minimal string representation of this object.
Static
getReturns array containing all possible layout values.
Returns LayoutOptions[]
array containing all possible layout values
Settings
Member Visibility
Theme
On This Page
Generated using TypeDoc