Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charts - Address issue in which _maxSize property was not updated for single series histogram. #1480

Merged
merged 2 commits into from
Dec 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/charts/js/Histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Histogram.prototype = {
setSize = style[setSizeKey];
calculatedSize = style[calculatedSizeKey];
this._createMarkerCache();
this._maxSize = graphic.get(setSizeKey);
if(seriesTypeCollection && seriesLen > 1)
{
for(; i < seriesLen; ++i)
Expand All @@ -100,7 +101,6 @@ Histogram.prototype = {
}
}
totalSize = len * seriesSize;
this._maxSize = graphic.get(setSizeKey);
if(totalSize > this._maxSize)
{
ratio = graphic.get(setSizeKey)/totalSize;
Expand All @@ -114,6 +114,12 @@ Histogram.prototype = {
else
{
seriesSize = style[setSizeKey];
totalSize = len * seriesSize;
if(totalSize > this._maxSize)
{
seriesSize = this._maxSize/len;
this._maxSize = seriesSize;
}
}
offset -= seriesSize/2;
for(i = 0; i < len; ++i)
Expand Down
207 changes: 173 additions & 34 deletions src/charts/tests/unit/assets/series-histogram-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ YUI.add('series-histogram-tests', function(Y) {
suite = new Y.Test.Suite("Charts: Histogram");
Y.extend(MockSeries, Y.Histogram, {
_getDefaultColor: function(order, type) {
if(type === "border") {
if(type === "border") {
return "#00f";
} else {
return "#f00";
Expand All @@ -28,7 +28,7 @@ YUI.add('series-histogram-tests', function(Y) {
this.series = null;
Y.Event.purgeElement(DOC, false);
},

getDrawSeriesData: function(
xcoords,
ycoords,
Expand All @@ -38,9 +38,12 @@ YUI.add('series-histogram-tests', function(Y) {
groupMarkers,
order,
graphOrder,
direction
direction,
width,
height
) {
var markers = [],
style,
setSize,
calculatedSize,
i = 0,
Expand Down Expand Up @@ -95,27 +98,42 @@ YUI.add('series-histogram-tests', function(Y) {
}
setSize = style[setSizeKey];
calculatedSize = style[calculatedSizeKey];
this._createMarkerCache();
for(; i < seriesLen; ++i)
markerCacheCreated = true;

maxSize = graphic.get(setSizeKey);
if(seriesTypeCollection && seriesLen > 1)
{
renderer = seriesTypeCollection[i];
seriesSize += renderer.get("styles").marker[setSizeKey];
if(order > i)
for(; i < seriesLen; ++i)
{
renderer = seriesTypeCollection[i];
seriesSize += renderer.get("styles").marker[setSizeKey];
if(order > i)
{
offset = seriesSize;
}
}
totalSize = len * seriesSize;
if(totalSize > maxSize)
{
offset = seriesSize;
ratio = graphic.get(setSizeKey)/totalSize;
seriesSize *= ratio;
offset *= ratio;
setSize *= ratio;
setSize = Math.max(setSize, 1);
maxSize = setSize;
}
}
totalSize = len * seriesSize;
maxSize = graphic.get(setSizeKey);
if(totalSize > maxSize)
else
{
ratio = graphic.get(setSizeKey)/totalSize;
seriesSize *= ratio;
offset *= ratio;
setSize *= ratio;
setSize = Math.max(setSize, 1);
maxSize = setSize;
seriesSize = style[setSizeKey];
totalSize = len * seriesSize;
if(totalSize > maxSize)
{
seriesSize = maxSize/len;
maxSize = seriesSize;
}
}

offset -= seriesSize/2;
for(i = 0; i < len; ++i)
{
Expand All @@ -134,6 +152,11 @@ YUI.add('series-histogram-tests', function(Y) {
left: xcoords[i],
top: ycoords[i]
};
if(direction === "vertical") {
config.calculatedSize = xcoords[i];
} else {
config.calculatedSize = height - ycoords[i];
}
if(!isNaN(config.calculatedSize) && config.calculatedSize > 0)
{
top = config.top;
Expand Down Expand Up @@ -161,10 +184,12 @@ YUI.add('series-histogram-tests', function(Y) {
style.border.color = borderColors[i % borderColors.length];
}
marker = {
style: style,
fillColor: style.fill.color,
borderColor: style.border.color,
graphOrder: graphOrder,
i: i
};
markers.push(marker);
}

}
Expand Down Expand Up @@ -192,8 +217,6 @@ YUI.add('series-histogram-tests', function(Y) {
return {
maxSize: maxSize,
markers: markers,
fillColors: fillColors,
borderColors: borderColors,
setSize: setSize,
calculatedSize: calculatedSize,
groupMarker: groupMarker,
Expand All @@ -204,17 +227,22 @@ YUI.add('series-histogram-tests', function(Y) {
};
},

"test: _drawSeries()" : function() {
"test: drawSeries()" : function() {
var width = 400,
height = 400,
HistogramMockGraphic = Y.Base.create("histogramMockGraphic", Y.Base, [], {}, {
test = this,
HistogramMockGraphic = Y.Base.create("histogramMockGraphic", Y.Base, [], {
}, {
ATTRS: {
width: {
value: 0
valueFn: function() {
return width;
}
},
height: {
value: 0
valueFn: function() {
return height;
}
}
}
}),
Expand All @@ -226,12 +254,28 @@ YUI.add('series-histogram-tests', function(Y) {
_getMarkerDimensions: function(x, y, size, offset) {
return {
top: y,
left: x
left: x,
width: size,
height: size,
offset: offset,
calculatedSize: size
};
},


getMarker: function(style, graphOrder, i) {
var marker = {
fillColor: style.fill.color,
borderColor: style.border.color,
graphOrder: graphOrder,
i: i
};
this._markers.push(marker);
return marker;
},

_createMarkerCache: function() {
this._markerCacheCreated = true;
this._markers = [];
},

_clearMarkerCache: function() {
Expand All @@ -258,6 +302,8 @@ YUI.add('series-histogram-tests', function(Y) {
valueFn: function() {
return [];
}
},
graphic: {
}
}
}),
Expand All @@ -271,25 +317,118 @@ YUI.add('series-histogram-tests', function(Y) {
width: width,
height: height,
graphic: graphic,
seriesTypeCollection: seriesTypeCollection
seriesTypeCollection: seriesTypeCollection,
order: 0,
styles: {
marker: {
border: {
color: "#f00"
},
fill: {
color: "#00f"
}
}
}
}),
series2 = new HistogramDrawSeriesMock({
width: width,
height: height,
graphic: graphic,
seriesTypeCollection: seriesTypeCollection
});
seriesTypeCollection: seriesTypeCollection,
order: 1,
styles: {
marker: {
border: {
color: ["#f00", "#00f"]
},
fill: {
color: ["#00f", "#f00"]
}
}
}
}),
testDrawSeries = function(series) {
var i,
len,
fillColor,
strokeColor,
testMarker,
marker,
testData = test.getDrawSeriesData(
series.get("xcoords"),
series.get("ycoords"),
series.get("styles").marker,
series.get("graphic"),
seriesTypeCollection,
series.get("groupMarkers"),
series.get("order"),
series.get("graphOrder"),
series.get("direction"),
width,
height
);
//test _maxSize
Y.Assert.areEqual(
testData.maxSize, series._maxSize,
"The _maxSize of the series should be " + testData.maxSize + "."
);
//test markers
len = testData.markers.length;
Y.Assert.areEqual(
len,
series._markers.length,
"There should be " + len + " markers."
);
for(i = 0; i < len; i = i + 1) {
testMarker = testData.markers[i];
marker = series._markers[i];
if(testMarker) {
Y.Assert.isNotNull(marker, "There should be a marker.");
fillColor = testMarker.fillColor;
strokeColor = testMarker.borderColor;
Y.Assert.areEqual(fillColor, marker.fillColor, "The marker's fill color should be " + fillColor + ".");
Y.Assert.areEqual(strokeColor, marker.borderColor, "The marker's border color should be " + strokeColor + ".");
}
}
};
seriesTypeCollection.push(series1);
seriesTypeCollection.push(series2);
series1._markers = [];
series2._markers = [];
series.drawSeries.apply(series1);
series1.set("xcoords", [20, 60, 100, 140, 180, 220, 260, 300, 340, 380]);
series1.set("ycoords", [280, 80, 310, 270, 300, 210, 240, 160, 220, 40]);
series1.set("ycoords", [280, 80, 310, 270, 300, 400, 240, 160, 220, 40]);
series.drawSeries.apply(series1);

testDrawSeries(series1);
series1.set("styles", {
marker: {
width: 50
}
});
series.drawSeries.apply(series1);
testDrawSeries(series1);
series1.set("styles", {
marker: {
width: 12
}
});
series1.set("direction", "vertical");
series.drawSeries.apply(series1);
testDrawSeries(series1);
seriesTypeCollection.push(series2);
series2._markers = [];
series1.set("direction", "horizontal");
series.drawSeries.apply(series1);
testDrawSeries(series1);
series2.set("xcoords", [20, 60, 100, 140, 180, 220, 260, 300, 340, 380]);
series2.set("ycoords", [280, 80, 310, 270, 300, 210, 240, 160, 220, 40]);
series.drawSeries.apply(series2);
testDrawSeries(series2);
series1.set("styles", {
marker: {
width: 30
}
});
series.drawSeries.apply(series1);
testDrawSeries(series1);
},

"test: _getPlotDefaults()" : function() {
Expand Down