Skip to content

Commit

Permalink
Add Jasmine specs for stackMixin charts with elasticX enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sebgrohn authored and gordonwoodhull committed Jul 28, 2016
1 parent 66cb716 commit aa67976
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
33 changes: 29 additions & 4 deletions spec/bar-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,11 @@ describe('dc.barChart', function () {
});
});

describe('with negative data', function () {
describe('with mixed data', function () {
beforeEach(function () {
var negativeGroup = dimension.group().reduceSum(function (d) { return d.nvalue; });
var mixedGroup = dimension.group().reduceSum(function (d) { return d.nvalue; });

chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup);
chart.group(mixedGroup).stack(mixedGroup).stack(mixedGroup);
chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]));

chart.margins({top: 30, right: 50, bottom: 30, left: 30})
Expand Down Expand Up @@ -552,13 +552,38 @@ describe('dc.barChart', function () {
});

it('should generate y axis domain dynamically', function () {
var nthText = function (n) { return d3.select(chart.selectAll('g.y text')[0][n]); };
var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); };

expect(nthText(0).text()).toBe('-20');
expect(nthText(1).text()).toBe('0');
expect(nthText(2).text()).toBe('20');
});
});

describe('with negative data', function () {
beforeEach(function () {
var negativeGroup = dimension.group().reduceSum(function (d) { return -Math.abs(d.nvalue); });

chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup);
chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]));

chart.margins({top: 30, right: 50, bottom: 30, left: 30})
.elasticY(true)
.xUnits(d3.time.days.utc)
.yAxis().ticks(3);

chart.render();
});

it('should generate y axis domain dynamically', function () {
var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); };

expect(nthText(0).text()).toBe('-30');
expect(nthText(1).text()).toBe('-20');
expect(nthText(2).text()).toBe('-10');
expect(nthText(3).text()).toBe('0');
});
});
});

it('should not be focused by default', function () {
Expand Down
33 changes: 29 additions & 4 deletions spec/line-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,11 @@ describe('dc.lineChart', function () {
});
});

describe('with negative data', function () {
describe('with mixed data', function () {
beforeEach(function () {
var negativeGroup = dimension.group().reduceSum(function (d) { return d.nvalue; });
var mixedGroup = dimension.group().reduceSum(function (d) { return d.nvalue; });

chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup);
chart.group(mixedGroup).stack(mixedGroup).stack(mixedGroup);
chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]));

chart.margins({top: 30, right: 50, bottom: 30, left: 30})
Expand Down Expand Up @@ -531,7 +531,7 @@ describe('dc.lineChart', function () {
});

it('should generate y axis domain dynamically', function () {
var nthText = function (n) { return d3.select(chart.selectAll('g.y text')[0][n]); };
var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); };

expect(nthText(0).text()).toBe('-20');
expect(nthText(1).text()).toBe('0');
Expand All @@ -548,6 +548,31 @@ describe('dc.lineChart', function () {
it('should generate labels with positions corresponding to their data', lineLabelPositions);
});
});

describe('with negative data', function () {
beforeEach(function () {
var negativeGroup = dimension.group().reduceSum(function (d) { return -Math.abs(d.nvalue); });

chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup);
chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]));

chart.margins({top: 30, right: 50, bottom: 30, left: 30})
.elasticY(true)
.xUnits(d3.time.days.utc)
.yAxis().ticks(3);

chart.render();
});

it('should generate y axis domain dynamically', function () {
var nthText = function (n) { return d3.select(chart.selectAll('g.axis.y .tick text')[0][n]); };

expect(nthText(0).text()).toBe('-30');
expect(nthText(1).text()).toBe('-20');
expect(nthText(2).text()).toBe('-10');
expect(nthText(3).text()).toBe('0');
});
});
});

describe('legend hovering', function () {
Expand Down

0 comments on commit aa67976

Please sign in to comment.