Skip to content

Commit

Permalink
Removed Graph dependency from series classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tripp committed Jan 11, 2013
1 parent a013b5b commit 90db190
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/charts/js/Axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ Y.Axis = Y.Base.create("axis", Y.Widget, [Y.AxisBase], {
{
var units,
majorUnit = this.get("styles").majorUnit,
len = this.get("length");
len = this.getLength();
if(majorUnit.determinant === "count")
{
units = majorUnit.count;
Expand Down
3 changes: 1 addition & 2 deletions src/charts/js/BarSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ Y.BarSeries = Y.Base.create("barSeries", Y.MarkerSeries, [Y.Histogram], {
ycoords = this.get("ycoords"),
marker = this._markers[i],
markers,
graph = this.get("graph"),
seriesCollection = graph.seriesTypes[this.get("type")],
seriesCollection = this.get("seriesTypeCollection"),
seriesLen = seriesCollection.length,
seriesStyles,
seriesSize = 0,
Expand Down
60 changes: 48 additions & 12 deletions src/charts/js/CartesianSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,28 @@ Y.CartesianSeries = Y.Base.create("cartesianSeries", Y.Base, [Y.Renderer], {
this._groupMarker.destroy();
this._groupMarker = null;
}
},

/**
* Returns a reference to the parent container to which all chart elements are contained. When the series is bound to a `Chart` instance, the `Chart` instance is
* the reference. If nothing is set as the `chart` attribute, the `_getChart` method will return a reference to the `graphic` attribute.
*
* @method _getChart
* @return {Object}
* @private
*/
_getChart:function() {
var chart,
graph = this.get("graph");
if(graph)
{
chart = graph.get("chart");
}
if(!chart)
{
chart = this.get("graphic");
}
return chart;
}
/**
* Event handle for the x-axis' dataReady event.
Expand Down Expand Up @@ -662,6 +684,14 @@ Y.CartesianSeries = Y.Base.create("cartesianSeries", Y.Base, [Y.Renderer], {
*/
}, {
ATTRS: {
/**
* An array of all series of the same type used within a chart application.
*
* @attribute seriesTypeCollection
* @type Array
*/
seriesTypeCollection: {},

/**
* Name used for for displaying data related to the x-coordinate.
*
Expand Down Expand Up @@ -802,18 +832,22 @@ Y.CartesianSeries = Y.Base.create("cartesianSeries", Y.Base, [Y.Renderer], {
ycoords: {},

/**
* Reference to the `Chart` application.
* Reference to the `Chart` application. If no `Chart` application is present, a reference to the `Graphic` instance that
* the series is drawn into will be returned.
*
* @attribute chart
* @type ChartBase
* @readOnly
*/
chart: {
readOnly: true,

getter: function()
{
return this.get("graph").get("chart");
var chart,
graph = this.get("graph");
if(graph)
{
chart = graph.get("chart");
}
return chart;
}
},

Expand Down Expand Up @@ -1009,14 +1043,16 @@ Y.CartesianSeries = Y.Base.create("cartesianSeries", Y.Base, [Y.Renderer], {
groupMarkers: {
getter: function()
{
if(this._groupMarkers === undefined)
{
return this.get("graph").get("groupMarkers");
}
else
{
return this._groupMarkers;
var graph,
groupMarkers = this._groupMarkers;
if(!groupMarkers) {
graph = this.get("graph");
if(graph)
{
groupMarkers = graph.get("groupMarkers");
}
}
return groupMarkers;
},

setter: function(val)
Expand Down
3 changes: 1 addition & 2 deletions src/charts/js/ColumnSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ Y.ColumnSeries = Y.Base.create("columnSeries", Y.MarkerSeries, [Y.Histogram], {
ycoords = this.get("ycoords"),
marker = this._markers[i],
markers,
graph = this.get("graph"),
seriesStyles,
seriesCollection = graph.seriesTypes[this.get("type")],
seriesCollection = this.get("seriesTypeCollection"),
seriesLen = seriesCollection.length,
seriesSize = 0,
offset = 0,
Expand Down
8 changes: 3 additions & 5 deletions src/charts/js/Fills.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Fills.prototype = {
var path = this._path;
if(!path)
{
path = this.get("graph").get("graphic").addShape({type:"path"});
path = this.get("graphic").addShape({type:"path"});
this._path = path;
}
return path;
Expand Down Expand Up @@ -204,8 +204,7 @@ Fills.prototype = {
curvecoords,
order = this.get("order"),
type = this.get("type"),
graph = this.get("graph"),
seriesCollection = graph.seriesTypes[type],
seriesCollection = this.get("seriesTypeCollection"),
prevXCoords,
prevYCoords,
len,
Expand Down Expand Up @@ -388,9 +387,8 @@ Fills.prototype = {
{
var order = this.get("order"),
type = this.get("type"),
graph = this.get("graph"),
direction = this.get("direction"),
seriesCollection = graph.seriesTypes[type],
seriesCollection = this.get("seriesTypeCollection"),
firstValidIndex,
lastValidIndex,
xcoords = this.get("stackedXCoords"),
Expand Down
2 changes: 2 additions & 0 deletions src/charts/js/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Y.Graph = Y.Base.create("graph", Y.Widget, [Y.Renderer], {
series.set("graphOrder", graphSeriesLength);
series.set("order", typeSeriesCollection.length);
typeSeriesCollection.push(series);
series.set("seriesTypeCollection", typeSeriesCollection);
this.addDispatcher(series);
series.after("drawingComplete", Y.bind(this._drawingCompleteHandler, this));
this.fire("seriesAdded", series);
Expand Down Expand Up @@ -252,6 +253,7 @@ Y.Graph = Y.Base.create("graph", Y.Widget, [Y.Renderer], {
series.after("drawingComplete", Y.bind(this._drawingCompleteHandler, this));
typeSeriesCollection.push(series);
seriesCollection.push(series);
series.set("seriesTypeCollection", typeSeriesCollection);
if(this.get("rendered"))
{
series.render();
Expand Down
12 changes: 6 additions & 6 deletions src/charts/js/Histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Histogram.prototype = {
return;
}
var style = Y.clone(this.get("styles").marker),
graphic = this.get("graphic"),
setSize,
calculatedSize,
xcoords = this.get("xcoords"),
Expand All @@ -38,9 +39,8 @@ Histogram.prototype = {
len = xcoords.length,
top = ycoords[0],
type = this.get("type"),
graph = this.get("graph"),
seriesCollection = graph.seriesTypes[type],
seriesLen = seriesCollection.length,
seriesTypeCollection = this.get("seriesTypeCollection"),
seriesLen = seriesTypeCollection.length || 0,
seriesSize = 0,
totalSize = 0,
offset = 0,
Expand Down Expand Up @@ -91,18 +91,18 @@ Histogram.prototype = {
this._createMarkerCache();
for(; i < seriesLen; ++i)
{
renderer = seriesCollection[i];
renderer = seriesTypeCollection[i];
seriesSize += renderer.get("styles").marker[setSizeKey];
if(order > i)
{
offset = seriesSize;
}
}
totalSize = len * seriesSize;
this._maxSize = graph.get(setSizeKey);
this._maxSize = graphic.get(setSizeKey);
if(totalSize > this._maxSize)
{
ratio = graph.get(setSizeKey)/totalSize;
ratio = graphic.get(setSizeKey)/totalSize;
seriesSize *= ratio;
offset *= ratio;
setSize *= ratio;
Expand Down
38 changes: 30 additions & 8 deletions src/charts/js/PieSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ Y.PieSeries = Y.Base.create("pieSeries", Y.MarkerSeries, [], {
_setMap: function()
{
var id = "pieHotSpotMapi_" + Math.round(100000 * Math.random()),
cb = this.get("graph").get("contentBox"),
graph = this.get("graph"),
graphic,
cb,
areaNode;
if(graph)
{
cb = graph.get("contentBox");
}
else
{
graphic = this.get("graphic");
cb = graphic.get("node");
}
if(this._image)
{
cb.removeChild(this._image);
Expand Down Expand Up @@ -193,6 +204,18 @@ Y.PieSeries = Y.Base.create("pieSeries", Y.MarkerSeries, [], {
}
},

/**
* Returns the sum of all values for the series.
*
* @method getTotalValues
* @return Number
*/
getTotalValues: function()
{
var total = this.get("valueAxis").getTotalByKey(this.get("valueKey"));
return total;
},

/**
* Draws the series. Overrides the base implementation.
*
Expand All @@ -201,9 +224,9 @@ Y.PieSeries = Y.Base.create("pieSeries", Y.MarkerSeries, [], {
*/
draw: function()
{
var graph = this.get("graph"),
w = graph.get("width"),
h = graph.get("height");
var graphic = this.get("graphic"),
w = graphic.get("width"),
h = graphic.get("height");
if(isFinite(w) && isFinite(h) && w > 0 && h > 0)
{
this._rendered = true;
Expand Down Expand Up @@ -251,8 +274,8 @@ Y.PieSeries = Y.Base.create("pieSeries", Y.MarkerSeries, [], {
tfc,
tfa,
padding = styles.padding,
graph = this.get("graph"),
minDimension = Math.min(graph.get("width"), graph.get("height")),
graphic = this.get("graphic"),
minDimension = Math.min(graphic.get("width"), graphic.get("height")),
w = minDimension - (padding.left + padding.right),
h = minDimension - (padding.top + padding.bottom),
startAngle = -90,
Expand All @@ -267,7 +290,7 @@ Y.PieSeries = Y.Base.create("pieSeries", Y.MarkerSeries, [], {
lw,
wedgeStyle,
marker,
graphOrder = this.get("graphOrder"),
graphOrder = this.get("graphOrder") || 0,
isCanvas = Y.Graphic.NAME == "canvasGraphic";
for(; i < itemCount; ++i)
{
Expand Down Expand Up @@ -449,7 +472,6 @@ Y.PieSeries = Y.Base.create("pieSeries", Y.MarkerSeries, [], {
var graphic = this.get("graphic"),
marker,
cfg = Y.clone(styles);
graphic.set("autoDraw", false);
marker = graphic.addShape(cfg);
marker.addClass(SERIES_MARKER);
return marker;
Expand Down
5 changes: 2 additions & 3 deletions src/charts/js/Plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Plots.prototype = {
{
var marker,
border = styles.border;
styles.id = this.get("chart").get("id") + "_" + order + "_" + index;
styles.id = this._getChart().get("id") + "_" + order + "_" + index;
//fix name differences between graphic layer
border.opacity = border.alpha;
styles.stroke = border;
Expand Down Expand Up @@ -262,7 +262,6 @@ Plots.prototype = {
var graphic = this.get("graphic"),
marker,
cfg = Y.clone(styles);
graphic.set("autoDraw", false);
cfg.type = cfg.shape;
marker = graphic.addShape(cfg);
marker.addClass(SERIES_MARKER);
Expand Down Expand Up @@ -320,7 +319,7 @@ Plots.prototype = {
//fix name differences between graphic layer
border.opacity = border.alpha;
cfg = {
id: this.get("chart").get("id") + "_" + styles.graphOrder,
id: this._getChart().get("id") + "_" + styles.graphOrder,
stroke: border,
fill: styles.fill,
dimensions: styles.dimensions,
Expand Down
3 changes: 1 addition & 2 deletions src/charts/js/StackedBarSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ Y.StackedBarSeries = Y.Base.create("stackedBarSeries", Y.BarSeries, [Y.StackingU
len = xcoords.length,
top = ycoords[0],
type = this.get("type"),
graph = this.get("graph"),
seriesCollection = graph.seriesTypes[type],
seriesCollection = this.get("seriesTypeCollection"),
ratio,
order = this.get("order"),
graphOrder = this.get("graphOrder"),
Expand Down
3 changes: 1 addition & 2 deletions src/charts/js/StackedColumnSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Y.StackedColumnSeries = Y.Base.create("stackedColumnSeries", Y.ColumnSeries, [Y.
len = xcoords.length,
top = ycoords[0],
type = this.get("type"),
graph = this.get("graph"),
seriesCollection = graph.seriesTypes[type],
seriesCollection = this.get("seriesTypeCollection"),
ratio,
order = this.get("order"),
graphOrder = this.get("graphOrder"),
Expand Down
9 changes: 4 additions & 5 deletions src/charts/js/StackingUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ StackingUtil.prototype = {
{
var order = this.get("order"),
type = this.get("type"),
graph = this.get("graph"),
seriesCollection = graph.seriesTypes[type],
seriesCollection = this.get("seriesTypeCollection"),
i = 0,
xcoords = this.get("xcoords"),
ycoords = this.get("ycoords"),
Expand Down Expand Up @@ -135,9 +134,9 @@ StackingUtil.prototype = {
{
var order = this.get("order"),
type = this.get("type"),
graph = this.get("graph"),
h = graph.get("height"),
seriesCollection = graph.seriesTypes[type],
graphic = this.get("graphic"),
h = graphic.get("height"),
seriesCollection = this.get("seriesTypeCollection"),
i = 0,
xcoords = this.get("xcoords"),
ycoords = this.get("ycoords"),
Expand Down
2 changes: 1 addition & 1 deletion src/charts/meta/series-areaspline.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"series-areaspline": {
"requires":[
"series-fill-util",
"series-area",
"series-curve-util"
]
}
Expand Down
5 changes: 2 additions & 3 deletions src/charts/meta/series-combospline.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"series-combospline": {
"requires":[
"series-curve-util",
"series-plot-util",
"series-fill-util"
"series-combo",
"series-curve-util"
]
}
}
1 change: 1 addition & 0 deletions src/charts/meta/series-spline.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"series-spline": {
"requires":[
"series-line",
"series-curve-util"
]
}
Expand Down

0 comments on commit 90db190

Please sign in to comment.