ChartBase.js revision 87a49173dbc22a145cb87e605cca83fd42524377
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * The ChartBase class is an abstract class used to create charts.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @class ChartBase
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @constructor
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippfunction ChartBase() {}
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Reference to the default tooltip available for the chart.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * <p>Contains the following properties:</p>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>node</dt><dd>Reference to the actual dom node</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>showEvent</dt><dd>Event that should trigger the tooltip</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>hideEvent</dt><dd>Event that should trigger the removal of a tooltip (can be an event or an array of events)</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>styles</dt><dd>A hash of style properties that will be applied to the tooltip node</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>show</dt><dd>Indicates whether or not to show the tooltip</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>markerEventHandler</dt><dd>Displays and hides tooltip based on marker events</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>planarEventHandler</dt><dd>Displays and hides tooltip based on planar events</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>markerLabelFunction</dt><dd>Reference to the function used to format a marker event triggered tooltip's text</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>planarLabelFunction</dt><dd>Reference to the function used to format a planar event triggered tooltip's text</dd>
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute tooltip
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Object
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * The key value used for the chart's category axis.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute categoryKey
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type String
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @default category
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Indicates the type of axis to use for the category axis.
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>category</dt><dd>Specifies a <code>CategoryAxis</code>.</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>time</dt><dd>Specifies a <code>TimeAxis</dd>
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute categoryType
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type String
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @default category
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Indicates the the type of interactions that will fire events.
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>marker</dt><dd>Events will be broadcasted when the mouse interacts with individual markers.</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>planar</dt><dd>Events will be broadcasted when the mouse intersects the plane of any markers on the chart.</dd>
87a49173dbc22a145cb87e605cca83fd42524377Tripp * <dt>none</dt><dd>No events will be broadcasted.</dd>
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute interactionType
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type String
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @default marker
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Data used to generate the chart.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute dataProvider
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Array
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * A collection of keys that map to the series axes. If no keys are set,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * they will be generated automatically depending on the data structure passed into
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * the chart.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute seriesKeys
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Array
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Reference to all the axes in the chart.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute axesCollection
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Array
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Reference to graph instance.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute graph
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @type Graph
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @description Default value function for the <code>graph</code> attribute.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Returns a series instance by index or key value.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method getSeries
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param val
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @return CartesianSeries
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var series = null,
f69d245bb21be88752420e834a6b6be37e9b525fTripp * Returns an <code>Axis</code> instance by key reference. If the axis was explicitly set through the <code>axes</code> attribute,
f69d245bb21be88752420e834a6b6be37e9b525fTripp * the key will be the same as the key used in the <code>axes</code> object. For default axes, the key for
f69d245bb21be88752420e834a6b6be37e9b525fTripp * the category axis is the value of the <code>categoryKey</code> (<code>category</code>). For the value axis, the default
f69d245bb21be88752420e834a6b6be37e9b525fTripp * key is <code>values</code>.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method getAxisByKey
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} val Key reference used to look up the axis.
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @return Axis
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Returns the category axis for the chart.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method getCategoryAxis
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @return Axis
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(; i < l; ++i)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._axisClass[t];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp //move the position = absolute logic to a class file
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.get("boundingBox").setStyle("position", "absolute");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.get("contentBox").setStyle("position", "absolute");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp bindUI: function()
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.after("tooltipChange", Y.bind(this._tooltipChangeHandler, this));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.after("dataProviderChange", this._dataProviderChangeHandler);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y.delegate("mouseenter", Y.bind(this._markerEventDispatcher, this), cb, ".yui3-seriesmarker");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y.delegate("mousedown", Y.bind(this._markerEventDispatcher, this), cb, ".yui3-seriesmarker");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y.delegate("mouseup", Y.bind(this._markerEventDispatcher, this), cb, ".yui3-seriesmarker");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y.delegate("mouseleave", Y.bind(this._markerEventDispatcher, this), cb, ".yui3-seriesmarker");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y.delegate("click", Y.bind(this._markerEventDispatcher, this), cb, ".yui3-seriesmarker");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.delegate("mousemove", Y.bind(this._positionTooltip, this), cb, ".yui3-seriesmarker");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._overlay.on("mousemove", Y.bind(this._planarEventDispatcher, this));
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.on(interactionType + "Event:" + hideEvent, this.toggleTooltip);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.on(interactionType + "Event:" + showEvent, tt[interactionType + "EventHandler"]);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp for(; i < len; ++i)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.on(interactionType + "Event:" + hideEvent[i], this.hideTooltip);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.on(interactionType + "Event:" + hideEvent, this.hideTooltip);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Broadcasts when <code>interactionType</code> is set to <code>marker</code> and a series marker has received a mouseover event.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @event markerEvent:mouseover
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @preventable false
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {EventFacade} e Event facade with the following additional
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * properties:
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>categoryItem</dt><dd>Hash containing information about the category <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>valueItem</dt><dd>Hash containing information about the value <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>node</dt><dd>The dom node of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>x</dt><dd>The x-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>y</dt><dd>The y-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>series</dt><dd>Reference to the series of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>index</dt><dd>Index of the marker in the series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>seriesIndex</dt><dd>The <code>order</code> of the marker's series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Broadcasts when <code>interactionType</code> is set to <code>marker</code> and a series marker has received a mouseout event.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @event markerEvent:mouseout
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @preventable false
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {EventFacade} e Event facade with the following additional
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * properties:
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>categoryItem</dt><dd>Hash containing information about the category <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>valueItem</dt><dd>Hash containing information about the value <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>node</dt><dd>The dom node of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>x</dt><dd>The x-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>y</dt><dd>The y-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>series</dt><dd>Reference to the series of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>index</dt><dd>Index of the marker in the series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>seriesIndex</dt><dd>The <code>order</code> of the marker's series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Broadcasts when <code>interactionType</code> is set to <code>marker</code> and a series marker has received a mousedown event.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @event markerEvent:mousedown
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @preventable false
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {EventFacade} e Event facade with the following additional
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * properties:
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>categoryItem</dt><dd>Hash containing information about the category <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>valueItem</dt><dd>Hash containing information about the value <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>node</dt><dd>The dom node of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>x</dt><dd>The x-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>y</dt><dd>The y-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>series</dt><dd>Reference to the series of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>index</dt><dd>Index of the marker in the series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>seriesIndex</dt><dd>The <code>order</code> of the marker's series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Broadcasts when <code>interactionType</code> is set to <code>marker</code> and a series marker has received a mouseup event.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @event markerEvent:mouseup
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @preventable false
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {EventFacade} e Event facade with the following additional
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * properties:
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>categoryItem</dt><dd>Hash containing information about the category <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>valueItem</dt><dd>Hash containing information about the value <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>node</dt><dd>The dom node of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>x</dt><dd>The x-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>y</dt><dd>The y-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>series</dt><dd>Reference to the series of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>index</dt><dd>Index of the marker in the series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>seriesIndex</dt><dd>The <code>order</code> of the marker's series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Broadcasts when <code>interactionType</code> is set to <code>marker</code> and a series marker has received a click event.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @event markerEvent:click
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @preventable false
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {EventFacade} e Event facade with the following additional
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * properties:
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>categoryItem</dt><dd>Hash containing information about the category <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>valueItem</dt><dd>Hash containing information about the value <code>Axis</code>.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>node</dt><dd>The dom node of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>x</dt><dd>The x-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>y</dt><dd>The y-coordinate of the mouse in relation to the Chart.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>series</dt><dd>Reference to the series of the marker.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>index</dt><dd>Index of the marker in the series.</dd>
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * <dt>seriesIndex</dt><dd>The <code>order</code> of the marker's series.</dd>
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.fire("markerEvent:" + type, {categoryItem:items.category, valueItem:items.value, node:markerNode, x:x, y:y, series:series, index:index, seriesIndex:seriesIndex});
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Event listener for toggling the tooltip. If a tooltip is visible, hide it. If not, it
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * will create and show a tooltip based on the event object.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method toggleTooltip
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Hides the default tooltip
16178708ecddc36b034aea99e129ceffa009ac05Tripp msg = tt.markerLabelFunction.apply(this, [e.categoryItem, e.valueItem, e.index, e.series, e.seriesIndex]);
16178708ecddc36b034aea99e129ceffa009ac05Tripp msg = tt.planarLabelFunction.apply(this, [categoryAxis, e.valueItem, e.index, e.items, e.seriesIndex]);
16178708ecddc36b034aea99e129ceffa009ac05Tripp _planarLabelFunction: function(categoryAxis, valueItems, index, seriesArray, seriesIndex)
16178708ecddc36b034aea99e129ceffa009ac05Tripp msg += categoryAxis.get("labelFunction").apply(this, [categoryAxis.getKeyValueAt(this.get("categoryKey"), index), categoryAxis.get("labelFormat")]);
16178708ecddc36b034aea99e129ceffa009ac05Tripp for(; i < len; ++i)
16178708ecddc36b034aea99e129ceffa009ac05Tripp msg += "<br/><span>" + valueItem.displayName + ": " + axis.get("labelFunction").apply(this, [axis.getKeyValueAt(valueItem.key, index), axis.get("labelFormat")]) + "</span>";
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _tooltipLabelFunction: function(categoryItem, valueItem, itemIndex, series, seriesIndex)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ": " + categoryItem.axis.get("labelFunction").apply(this, [categoryItem.value, categoryItem.axis.get("labelFormat")]) +