the EnergySystem to display
Private
fontFont ascent in pixels (guesstimate).
Private
fontFont ascent in pixels (guesstimate). TO DO find a way to get this for the current font, similar to the TextMetrics object. http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript http://pomax.nihongoresources.com/pages/Font.js/
The font to use for numbers on the bar chart energy graph, a CSS3 font specification.
Private
graphwhere zero energy is in pixels
Private
lastwhen total energy was last calculated
Color of the potential energy bar, a CSS3 color value
Private
rect_the bounding rectangle, in simulation coords
Color of the rotational energy bar, a CSS3 color value
Color of the translation energy bar, a CSS3 color value
Whether the DisplayObject contains the given world coordinates point.
the point in world coordinates
true
if this DisplayObject contains the given point
Draws this DisplayObject using the given CoordMap.
the canvas's context to draw this object into
the mapping to use for translating between simulation and screen coordinates
Private
drawPrivate
drawPrivate
drawPrivate
formatConvert number to a string, using a format based on how large the value is, and the difference from the previous version shown. Designed to format total energy. When the total energy does not change (for example when sim is paused) then we retain the previous setting for number of digits to show.
the value to be formatted
the previous value that was formatted
Returns the set of MassObjects that this DisplayObject represents. Returns an empty list if this DisplayObject doesn't represent a MassObject.
the set of MassObjects that this DisplayObject represents
Returns the area within which this EnergyBarGraph is drawn, in simulation coordinates.
the area within which this EnergyBarGraph is drawn, in simulation coordinates.
Sets this DisplayObject's position in simulation coordinates of the containing SimView. Each type of DisplayObject has a different policy regarding whether this will have an effect. Generally the policies are:
If the DisplayObject does not represent a SimObject, then the position can be set. Examples are DisplayClock, EnergyBarGraph.
If the SimObject's position is dependent on other objects, then the position cannot be set. Examples are DisplayConnector, DisplayRope, DisplaySpring.
If the SimObject can be moved independently and isDragable
is true
, then the position of the SimObject is modified. Example: DisplayShape.
this DisplayObject's position, in simulation coordinates.
Sets the area within which this EnergyBarGraph is drawn, in simulation coordinates.
the area within which this EnergyBarGraph is drawn, in simulation coordinates.
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:
DisplayShape{polygon:Polygon{'chain3'}}
a minimal string representation of this object.
Static
Private
numberGenerated using TypeDoc
Displays a bar graph of the various forms of energy (potential, kinetic, etc.) in an EnergySystem. The visible area must be set via setVisibleArea in order for EnergyBarGraph to draw.
Display Formats
If the EnergyInfo of the EnergySystem only has data for the potential and translational energy, then the names shown are 'potential' and 'kinetic' (in English, the names are translated for the current locale). Here is the display for a typical situation:
If the EnergyInfo returns a value other than
NaN
for the rotational energy, then the the names shown are 'potential', 'translational', and 'rotational'. Here is the display for a typical situation:When potential energy is positive, all the energy components are on the same line of the graph, as shown above.
When potential energy is negative, the potential energy is shown on a separate line of the bar graph, extending left from the zero position; the kinetic and rotational energy is drawn underneath the potential energy bar starting from the left. Here is a typical situation:
EnergyBarGraph draws with a transparent white rectangle to ensure it is readable against a black background.
Color and Font
Public properties can be set for changing the color of the bars and the font used. See graphFont, potentialColor, translationColor, and rotationColor.
Position and Size
The EnergyBarGraph will only draw after the visible area has been set via setVisibleArea. Usually this is set to be the entire visible area of the SimView containing the EnergyBarGraph. Here is an example script to do that:
The width of the EnergyBarGraph is always the full width of the visible area.
The vertical position of the EnergyBarGraph is initially at the top of the visible area. If the EnergyBarGraph is not moved, then whenever the visible area is changed we continue to align the EnergyBarGraph at the top of the visible area.
Once the EnergyBarGraph is moved via setPosition, we retain that vertical position when the visible area changes, except that we ensure the EnergyBarGraph is entirely within the visible area.
TO DO Create some unit tests for this? It is complex enough that it could benefit. For example, see the kludge about 'energy is zero at startup' which previously resulted in an assertion failing.
TO DO larger fonts (size 14) have formatting problems where the text is overlapping the color key and other pieces of text. (Nov 2012)