HR Diagram Component



Properties and Methods


diagramMC.addObject(linkageName, name, depth, layerName, initObj)

This function adds a movieclip (ie. a star) to the HR Diagram. The arguments:

  • linkageName is the library name of the movieclip to attach – if it is null then "HR Diagram Dot" is used. There is another movieclip, "HR Diagram Disc", available in the component's resources folder, and of course you can make your own. See the section on the object movieclip options at the bottom of this page.
  • name is the unique identifier for the object. After the object is attached you can access the movieclip with the reference to diagramMC.name. Use null if you don't need to access the movieclip.
  • depth is the depth of the object's movieclip. Use null if you don't care what depth the movieclip is attached at.
  • If defined, layerName should be the name of a layer that has already been created with addObjectLayer. Use null if you don't want the object to be added to an objects layer.
  • initObject is an optional parameter that can be used to pass properties to the newly attached object, such as the object's position or style properties for the movieclip.

Note that an object will not move up and down in response to distanceModulus unless it is added to a layer whose keepFixed property is false.

An object's position in the HR diagram is defined by an x-coordinate property and a y-coordinate property. Acceptable x-coordinate properties are temp, logTemp, type, and BV. Here type is assumed to be the spectral type expressed as a number – use getSpectralTypeNumber (see below) to convert a standard spectral type string to a number. Acceptable y-coordinate properties are lum, logLum, absBolMag, absVisMag, appBolMag, and appVisMag. Note that logTemp and logLum are automatically calculated when the temp and lum properties change (but not the other way around).

When updateObjects is called it first looks for the properties on the object that are the same as those that define the axis scale. If these properties are not found on the object then the function looks for other properties to convert. For example, if the x-axis is spectral type but only temp (and logTemp) are defined on the object, type is calculated using a conversion function.

Call update or updateObjects after adding objects. The following example adds the sun to the HR Diagram using the default dot:

// define the sun's position and the style for the dot on the
// init object (the sun's position could be defined multiple ways)
var initObj = {};
initObj.type = 42;
initObj.absVisMag = 4.75;
initObj.dotSize = 6;
initObj.dotColor = 0xffcc00;
initObj.outlineAlpha = 100;
initObj.outlineColor = 0xa0a0a0;
diagramMC.addObject(null, "sun", null, null, initObj);
diagramMC.updateObjects();
	

diagramMC.updateObjects(subset)

This function positions objects and should be called after adding objects or changing their definitions. The optional subset parameter can be used to have the component update just a limited subset of the objects. To update all objects on a layer subset should be the layer's name. To update a single object subset should be the object's name. To update a list of objects subset should be an array of object names.

Obscure problem warning: if the object you want to update belongs to a layer whose keepFixed property is false you need to update the entire layer (by name, not by list) or all objects – do not update just that object.


diagramMC.removeObject(name)

This function removes the object with the given name. No update is required after calling it. Consider also removeObjectLayer and removeAllObjects.


diagramMC.removeAllObjects()

This function removes all objects and object layers. No update is required after calling it.


diagramMC.plotStars(groupName, linkageName, initObj)

This function adds a group of stars from one of several built-in lists. The list used is specified by groupName, which can take one of the following four values:

  • "brightStars" - This group consists of the 150 brightest stars (in apparent magnitude) minus the 5 that would also be in the nearby star list (also, one star was removed for being a nova). So this group consists of 144 stars.
  • "nearbyStars" - This group contains the stars from the 100 nearest stellar systems. Sub-stellar objects and white dwarfs are not included in the list, and 5 stars that would in this group have been removed since they would also be in the bright star group. This group has 119 stars.
  • "brightAndNearbyStars" - This group consists of the 5 stars that would be in both the bright star and nearby star groups.
  • "nearbyWhiteDwarfs" - This group consists of the 8 white dwarfs that are found in the 100 nearest systems.

The stars are added to a newly created layer with the same name as groupName. If linkageName is left undefined or is null the stars use the "HR Diagram Dot" movieclip. The initObj contains properties to pass to the stars' movieclips when they are attached. If no initObj is provided the default styles are blue for the bright stars (0x6060ff), green for the nearby stars (0x409040), red for the bright and nearby stars (0xff0000), and black for the white dwarfs (0x000000).

A call to updateObjects or update is necessary after calling plotStars. Example code:

// adding the stars (using custom appearance for the white dwarfs) 
diagramMC.plotStars("brightStars");
diagramMC.plotStars("nearbyStars");
diagramMC.plotStars("brightAndNearbyStars");
diagramMC.plotStars("nearbyWhiteDwarfs", null, {dotSize: 3, dotColor: 0x8080ff});

// position and show the objects
diagramMC.updateObjects();

// toggling the visibility of a group
diagramMC.nearbyWhiteDwarfs._visible = false;

// removing a group
diagramMC.removeObjectLayer("brightStars");
	

diagramMC.addObjectLayer(layerName, keepFixed, depth, objectsList, linkageName)

An objects layer makes it easy to add, remove, and toggle the visibility of a group of objects. An objects layer is also the best way to add stars that will move up and down when distanceModulus changes. The arguments:

  • layerName specifies the name of the layer, which allows it to be accessed and referred to.
  • keepFixed is an optional parameter which, if false (the default), allows stars added to this layer to move up and down when the distanceModulus property changes. Note that it makes sense for this property to be false only if the stars on the layer are defined by their apparent magnitudes.
  • depth is an optional parameter to specify the depth of the layer. Layer depths are distinct from object depths – objects added to a layer will appear behind objects not added to a layer as well as objects added to another layer with a higher depth. Use null to have the component determine the depth.
  • objectsList is an optional list of objects to add to this layer after it has been created. This list should consist of the initObj objects that you would pass for each star if you were using addObject function. It is not possible to give a name to or control the depth of objects added through this method.
  • linkageName is the name of the movieclip to use for the objects added from the objectsList. The default is "HR Diagram Dot".

If you add objects through this method you will need to call updateObjects or update afterwards. Example code:

// a list of stars to add to the layer (if you wanted to set
// style properties as well this is where you would do it)
hyadesList = [	{appVisMag: 7.4, BV: 0.566},
		{appVisMag: 7.39, BV: 0.56},
		{appVisMag: 7.4, BV: 0.57}, etc.

// create a layer and add the list of stars at the same time,
// note that since keepFixed is false this layer will move
// up and down when distanceModulus changes
diagramMC.addObjectLayer("hyades", false, null, hyadesList);

// call updateObjects since we've added objects
diagramMC.updateObjects();

// hide the layer
diagramMC.hyades._visible = false;

// remove the layer
diagramMC.removeObjectLayer("hyades");
	

diagramMC.removeObjectLayer(layerName)

This function removes the layer and all objects on it. No update is required.


diagramMC.distanceModulus

This property shifts the apparent magnitude system up and down. This means that the apparent magnitude scales move, objects defined by apparent magnitudes move, and objects on a layer where keepFixed is false move. The distance modulus is defined as the difference between apparent and absolute magnitude scales: m - M. No update is required after changing this property if the only objects defined by apparent magnitude are on object layers. Otherwise you will need to call updateObjects or update.


diagramMC.update()

This universal update function updates every aspect of the HR Diagram. Since the component is somewhat CPU intensive you should usually call only the necessary minimum of the partial update functions, which are updateObjects, updateScales, updateIsoradiusLines, and updateLuminosityClassLines.


diagramMC.setXAxisType(type, min, max)

This function sets the x-coordinate system of the diagram. Valid options for type are "logTemp", "type", and "BV". The axis type specifies how object positions are calculated, not which scales are shown at the top and bottom of the plot (see showScale for that).

The optional min and max properties can be used to specify the horizontal range. These values are expected to be in the units of the axis type. For reference, the default ranges used are [0, 70] for "type", [-0.322, 2.160] for "BV", and [3.359, 4.701] for "logTemp".

Call update after calling this function.


diagramMC.setYAxisType(type, min, max)

This function sets the y-coordinate system of the diagram. Valid options for type are "logLum", "absBolMag", and "absVisMag". The optional min and max properties can be used to define the vertical range. The default ranges are [-5, 6] for "logLum" and [-10.321, 17.309] for the magnitude scales. The axis type specifies how object positions are calculated, not which scales are shown at the left and right of the plot (see showScale). Call update after calling this function.


diagramMC.showScale(type, side)

Use this function to set which scales appear along the sides of the plot. side can be one of "top", "bottom", "left", or "right" depending on whether the scale type specified is a horizontal or vertical one. Horizontal scale types are "logTemp", "type", and "BV", while vertical scale types are "logLum", "absBolMag", "absVisMag", "appBolMag", and "appVisMag". If type is anything other than one of these options then no scale will be shown on the given side (assuming side is valid). Therefore you can use null for type if you want to remove a scale. Call updateScales or update after calling this function.

See the notes at the bottom of this page to learn how to control the appearance of a scale.


diagramMC.updateScales()

updateScales redraws the scales shown around the sides of the plot. Call it after calling the showScale function.


diagramMC.showIsoradiusLines

This property toggles the visibility of the isoradius lines. The effect is immediate – no update is required.


diagramMC.isoradiusLinesList, diagramMC.isoradiusMin, diagramMC.isoradiusMax

These properties control which isoradius lines appear, whether they are labelled, and what the labelled text is. If isoradiusLinesList does not exist then labelled isoradius lines are displayed for every power of ten of the radius within the range defined by isoradiusMin (default 0.0001) and isoradiusMax (default 1000). This is the default situation.

However, if the isoradiusLinesList array exists then only those lines specified in it will be shown. Each entry in the array should be an object with a radius property. Additionally, you can use the optional properties hideLabel and labelText (which allow for the sup, sub and sol tags).

Call updateIsoradiusLines or update after changing any of these properties. An example:

diagramMC.isoradiusLinesList = [{radius: 0.1},
                                {radius: 1, labelText: "1 R<sol>"},
                                {radius: 10, hideLabel: true},
                                {radius: 200, labelText: "210<sup>2</sup> R<sol>"}];
diagramMC.updateIsoradiusLines();
	

diagramMC.isoradiusCurvesColor, diagramMC.isoradiusCurvesAlpha, diagramMC.isoradiusCurvesLineThickness, diagramMC.isoradiusLabelMargin, diagramMC.isoradiusLabelBackgroundAlpha, diagramMC.isoradiusLabelTextFormat

These are the properties that control the appearance of an isoradius line. isoradiusCurvesColor (default 0x669933) sets the color of the curves and labels, and isoradiusCurvesAlpha (default 100) sets the alpha of curves and labels. isoradiusCurvesLineThickness (default 1) sets the thickness of the curves.

isoradiusLabelMargin (default 5) controls how close the labels are to the edge of the plot. isoradiusLabelBackgroundAlpha (default 80) controls how opaque the fill behind the labels appears. Finally, isoradiusLabelTextFormat (the default is determined from the fonts movieclip in the resources folder) specifies the text format used for the labels.

Call updateIsoradiusLines or update after changing these properties.


diagramMC.updateIsoradiusLines()

Call this function to redraw the isoradius lines (needed after changing the isoradiusLinesList, for example).


diagramMC.setShownLuminosityClasses(arg)

Use this function to select which luminosity classes are shown. Either updateLuminosityClassLines or update must be called to see the changes. How the argument is interpreted:

  • If arg is "all" then all luminosity classes will be shown.
  • If arg is one of the strings "I", "II", "III", "IV", or "V", then the indicated luminosity class line will be shown (along with any lines that were already visible).
  • If arg is an array of strings then only the indicated lines will be shown, e.g. arg = ["V", "I"] would show only the main sequence (V) and supergiant (I) classes, even if others were previously visible.
  • Passing a value of "none" has the same effect as setting showLuminosityClassLines to false (but unlike doing that you will need to call an update function).

diagramMC.luminosityClassCurvesColor, diagramMC.luminosityClassCurvesLineThickness, diagramMC.luminosityClassCurvesAlpha

These are the properties that control the appearance of the luminosity class lines. luminosityClassCurvesColor (default 0xff6666) sets their color, luminosityClassCurvesLineThickness (default 1) set the line thickness, and luminosityClassCurvesAlpha (default 100) sets the transparency. Call updateLuminosityClassLines or update after changing these properties.


diagramMC.showLuminosityClassLines

This property toggles the visibility of all the luminosity classes at once. Even if set to true only those luminosity class lines chosen with setShownLuminosityClass will be shown. The change is immediate – no update required.


diagramMC.updateLuminosityClassLines()

This function redraws the luminosity class lines.


diagramMC.getPlotCoordinates(screenPoint)

This function returns an object with all of the x and y coordinate properties defined on it, as well as the bolometric correction. The argument screenPoint should be an object with x and y properties, which are the screen coordinates relative to the diagram's origin (lower left corner, with negative y values going up).

Specifically, the returned object will have the following properties defined on it: temp, logTemp, BV, type, BC, lum, logLum, absVisMag, absBolMag, appVisMag, and appBolMag.


diagramMC.getAFromB(value, [BC]), diagramMC.getBCFromLogTemp(logTemp)

There are many conversion functions on the component that you may want to take advantage of. These functions take the form getAFromB, where A and B stand for the various properties that can be used for an axis. For horizontal axis conversions A and B can be any of "LogTemp", "BV", and "Type". For vertical axis conversions A and B can be any of "LogLum", "AbsBolMag", "AbsVisMag", "AppBolMag", and "AppVisMag". For conversions between bolometric and visual systems (e.g. getLogLumFromAppVisMag) the second argument is expected to be the bolometric correction, which can be calculated with the function getBCFromLogTemp. Note the capitalization in the strings.


diagramMC.getSpectralTypeNumber(typeStr)

This function returns the spectral type number associated with a spectral type expressed as a string. For example, if typeStr is "G2" the function returns 42. This function is provided to assist in assigning the type property of objects, which the component assumes to be a number. See getLogLumFromLogTempAndClass below for an example.


diagramMC.getLogLumFromLogTempAndClass(logTemp, class)

This function calculates the luminosity of a star given its temperature and luminosity class. class should be a number, not a string (e.g. 5 for class V). Here's an example showing how to plot a G7 main sequence star (also demonstrating the getSpectralTypeNumber function):

var type = diagramMC.getSpectralTypeNumber("G7");
var logTemp = diagramMC.getLogTempFromType(type);
var logLum = diagramMC.getLogLumFromLogTempAndClass(logTemp, 5);
var initObj = {};
initObj.logTemp = logTemp;
initObj.logLum = logLum;
diagramMC.addObject(null, null, null, null, initObj);
	

diagramMC.setDimensions(width, height)

Sets the dimensions of the plot window. Call update after changing.


diagramMC.backgroundColor, diagramMC.backgroundAlpha, diagramMC.borderAndScalesLineThickness, diagramMC.borderAndScalesColor, diagramMC.borderAndScalesAlpha

These properties affect the appearance of the plot. backgroundColor (default 0xffffff) and backgroundAlpha (default 100) control the appearance of the plot area. borderAndScalesColor (default 0x000000) sets the color of the border and scales, while borderAndScalesLineThickness (default 1) and borderAndScalesAlpha (default 100) control line thickness and transparency of the border and scale tickmarks.



Axis Scale Style Settings

The following sections explain how to control the appearance of the scales. Call updateScales or update after changing any of the properties described below.

The text styles used for all scales are determined by axisLabelTextFormat, and tickmarkLabelTextFormat. The defaults for these formats are acquired from the fonts movieclip in the component's resources folder at initialization (assuming they have not been provided in an init object), but can be changed at any time after that.


Temperature Axis Settings

The string used to label this axis is defined by logTempAxisLabel. The default is "Temperature (K)". The placement of the label is controlled by the logTempAxisLabelSpacing property, whose default is 25.

The optional logTempLabelsList property can be used to specify what temperature values should have a tickmark and label. This array should be a list of a strings which are numbers (that is, they can be correctly converted to numbers by the parseFloat function).


B-V Axis Settings

The string used to label this axis is defined by BVAxisLabel. The default is "B-V Color Index". The placement of the label is controlled by the BVAxisLabelSpacing property, whose default is 25.

Several optional properties can be used to control the appearance of this axis. The property BVLabelsList can be used to specify which values should be labeled. This array should be a list of a strings which are numbers (that is, they can be correctly converted to numbers by the parseFloat function).

The BVMinorStep specifies the spacing between tickmarks. The default is 0.1. The BVMajorMultiple property specifies which tickmarks are major tickmarks. The default is 5. Therefore, by default there are tickmarks at ... -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.50, 0.6, ... where the ones in bold would be major tickmarks.


Spectral Type Axis Settings

The string used to label this axis is defined by typeAxisLabel. The default is "Spectral Type". The placement of the label is controlled by the typeAxisLabelSpacing property, whose default is 22.

typeNumTickmarks (default 1) is the the number of tickmarks to use for each lettered spectral type and can be any of the numbers 0 through 5, or 10. The typeLabelSpacing property (default 4) determines the spacing of the spectral type letters from the axis. The typeTickmarkLengths array (default [5, 3, 4]) controls the lengths of the various major and minor tickmarks depending on the the number of tickmarks shown. typeShowLabels determines whether labels are shown.


Vertical Axis Settings

Each of the five types of vertical axis is controlled by properties of the form typeAxisLabel, typeAxisLabelSpacing, typeLabelSpacing, and typeLabelMultiple, where type is one of the following strings: "logLum", "absBolMag", "absVisMag", "appBolMag", and "appVisMag". The axis label is the label used for the axis, the axis label spacing controls how far this label is placed from the edge of the plot, the label spacing controls the placement of the tickmarks labels, and the label multiple controls which major tickmarks get labels. For the luminosity scale the defaults of the last three properties are 47, 10, and 1 (meaning that the axis label is 47 pixels from the edge of the plot, the axis labels are 10 pixels from the edge, and labels are shown for each power of ten tickmark). For the magnitude scales the defaults are 40, 10, and 2.



Object Movieclip Options

The following sections explain how to customize the appearance of the dot and disc object movieclips provided with the component.


HR Diagram Dot

The HR Diagram Dot (the default object movieclip) properties and defaults are: dotColor (0x808080), dotAlpha (100), dotSize (2), outlineThickness (0), outlineColor (0x606060), and outlineAlpha (0). These can all be set via the initObj when adding the object. If the properties change later call the update function on the dot movieclip.


HR Diagram Disc

The HR Diagram Disc properties and defaults are: labelText (""), labelColor (0xffffff), discColor (0xff0000), discAlpha (100), discRadius (8), outlineThickness (0), outlineColor (0x909090), and outlineAlpha (0). These can all be set through the initObj when adding the object. If you change one of the properties later you will need to call an update function on the disc movieclip. Call updateLabel after changing the first two properties and updateDisc after changing any of the last six properties (or call update to call both of these functions).