From 8b1ad283aa8daf4f59e1eebd46d62479c6abd81d Mon Sep 17 00:00:00 2001 From: tripp Date: Tue, 10 Dec 2013 18:39:31 -0800 Subject: [PATCH 1/2] Address issue in which _maxSize property was not updated for single series histogram. Fix #1475 --- src/charts/js/Histogram.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/charts/js/Histogram.js b/src/charts/js/Histogram.js index 38eef25cfaa..7335a266790 100644 --- a/src/charts/js/Histogram.js +++ b/src/charts/js/Histogram.js @@ -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) @@ -100,7 +101,6 @@ Histogram.prototype = { } } totalSize = len * seriesSize; - this._maxSize = graphic.get(setSizeKey); if(totalSize > this._maxSize) { ratio = graphic.get(setSizeKey)/totalSize; @@ -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) From 78b465485cccdde084e3349d77e238d5f2df8b7e Mon Sep 17 00:00:00 2001 From: tripp Date: Tue, 10 Dec 2013 18:54:10 -0800 Subject: [PATCH 2/2] Update series-histogram unit tests. --- .../unit/assets/series-histogram-tests.js | 207 +++++++++++++++--- 1 file changed, 173 insertions(+), 34 deletions(-) diff --git a/src/charts/tests/unit/assets/series-histogram-tests.js b/src/charts/tests/unit/assets/series-histogram-tests.js index 791370bf34c..7567079c094 100644 --- a/src/charts/tests/unit/assets/series-histogram-tests.js +++ b/src/charts/tests/unit/assets/series-histogram-tests.js @@ -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"; @@ -28,7 +28,7 @@ YUI.add('series-histogram-tests', function(Y) { this.series = null; Y.Event.purgeElement(DOC, false); }, - + getDrawSeriesData: function( xcoords, ycoords, @@ -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, @@ -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) { @@ -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; @@ -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); } } @@ -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, @@ -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; + } } } }), @@ -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() { @@ -258,6 +302,8 @@ YUI.add('series-histogram-tests', function(Y) { valueFn: function() { return []; } + }, + graphic: { } } }), @@ -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() {