Skip to content

Commit 159fcdd

Browse files
style compliance
1 parent ae486a9 commit 159fcdd

File tree

5 files changed

+60
-54
lines changed

5 files changed

+60
-54
lines changed

dc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3259,7 +3259,13 @@ dc.stackMixin = function (_chart) {
32593259
};
32603260

32613261
function flattenStack() {
3262-
return _chart.data().reduce(function (all, layer) {
3262+
var groups = _chart.data();
3263+
3264+
if (groups.length) {
3265+
groups[0].values = _chart._computeOrderedGroups(groups[0].values);
3266+
}
3267+
3268+
return groups.reduce(function (all, layer) {
32633269
return all.concat(layer.values);
32643270
}, []);
32653271
}

dc.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dc.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/bar-chart-spec.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -980,61 +980,61 @@ describe('dc.barChart', function() {
980980
});
981981

982982
describe('check ordering option of the x axis', function() {
983-
beforeEach(function() {
984-
var rows = [
985-
{x: 'a', y: 1},
986-
{x: 'b', y: 3},
987-
{x: 'd', y: 4},
988-
{x: 'c', y: 2}
989-
];
990-
991-
id = 'bar-chart';
992-
appendChartID(id);
993-
data = crossfilter(rows);
994-
dimension = data.dimension(function(d) {
995-
return d.x;
996-
});
997-
group = dimension.group().reduceSum(function(d) {
998-
return d.y;
999-
});
983+
beforeEach(function() {
984+
var rows = [
985+
{x: 'a', y: 1},
986+
{x: 'b', y: 3},
987+
{x: 'd', y: 4},
988+
{x: 'c', y: 2}
989+
];
1000990

1001-
chart = dc.barChart('#' + id);
1002-
chart.width(500).transitionDuration(0)
1003-
.x(d3.scale.ordinal())
1004-
.xUnits(dc.units.ordinal)
1005-
.elasticY(true).elasticX(true)
1006-
.dimension(dimension)
1007-
.group(group);
1008-
chart.render();
991+
id = 'bar-chart';
992+
appendChartID(id);
993+
data = crossfilter(rows);
994+
dimension = data.dimension(function(d) {
995+
return d.x;
1009996
});
1010-
1011-
it('should be ordered by default alphabetical order', function() {
1012-
var data = chart.data()["0"].values;
1013-
var expectedData = ["a", "b", "c", "d"];
1014-
expect(data.map(function(d) { return d.x; })).toEqual(expectedData);
997+
group = dimension.group().reduceSum(function(d) {
998+
return d.y;
1015999
});
10161000

1017-
it('should be ordered by value increasing', function() {
1018-
chart.ordering(function(d) { return d.data.value; });
1019-
chart.redraw();
1020-
expect(xAxisText()).toEqual(["a", "c", "b", "d"]);
1021-
});
1001+
chart = dc.barChart('#' + id);
1002+
chart.width(500).transitionDuration(0)
1003+
.x(d3.scale.ordinal())
1004+
.xUnits(dc.units.ordinal)
1005+
.elasticY(true).elasticX(true)
1006+
.dimension(dimension)
1007+
.group(group);
1008+
chart.render();
1009+
});
10221010

1023-
it('should be ordered by value decreasing', function() {
1024-
chart.ordering(function(d) { return -d.data.value; });
1025-
chart.redraw();
1026-
expect(xAxisText()).toEqual(["d", "b", "c", "a"]);
1027-
});
1011+
it('should be ordered by default alphabetical order', function() {
1012+
var data = chart.data()["0"].values;
1013+
var expectedData = ["a", "b", "c", "d"];
1014+
expect(data.map(function(d) { return d.x; })).toEqual(expectedData);
1015+
});
10281016

1029-
it('should be ordered by alphabetical order', function() {
1030-
chart.ordering(function(d) { return d.data.key; });
1031-
chart.redraw();
1032-
expect(xAxisText()).toEqual(["a", "b", "c", "d"]);
1033-
});
1017+
it('should be ordered by value increasing', function() {
1018+
chart.ordering(function(d) { return d.data.value; });
1019+
chart.redraw();
1020+
expect(xAxisText()).toEqual(["a", "c", "b", "d"]);
1021+
});
10341022

1035-
function xAxisText() {
1036-
return chart.selectAll("g.x text")[0].map(function(x) { return d3.select(x).text(); });
1037-
}
1023+
it('should be ordered by value decreasing', function() {
1024+
chart.ordering(function(d) { return -d.data.value; });
1025+
chart.redraw();
1026+
expect(xAxisText()).toEqual(["d", "b", "c", "a"]);
1027+
});
1028+
1029+
it('should be ordered by alphabetical order', function() {
1030+
chart.ordering(function(d) { return d.data.key; });
1031+
chart.redraw();
1032+
expect(xAxisText()).toEqual(["a", "b", "c", "d"]);
1033+
});
1034+
1035+
function xAxisText() {
1036+
return chart.selectAll("g.x text")[0].map(function(x) { return d3.select(x).text(); });
1037+
}
10381038
});
10391039

10401040
function nthStack(n) {

src/stack-mixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ dc.stackMixin = function (_chart) {
172172
function flattenStack() {
173173
var groups = _chart.data();
174174

175-
if(groups.length){
175+
if (groups.length) {
176176
groups[0].values = _chart._computeOrderedGroups(groups[0].values);
177177
}
178178

0 commit comments

Comments
 (0)