|
1 | 1 | /* global appendChartID, loadDateFixture, makeDate */
|
2 | 2 | describe('dc.compositeChart', function () {
|
3 |
| - var id, chart, data, dateDimension, dateValueSumGroup, dateIdSumGroup, dateGroup; |
| 3 | + var id, chart, data, dateDimension, dateValueSumGroup, dateValueNegativeSumGroup, |
| 4 | + dateIdSumGroup, dateGroup; |
4 | 5 |
|
5 | 6 | beforeEach(function () {
|
6 | 7 | data = crossfilter(loadDateFixture());
|
7 | 8 | dateDimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); });
|
8 | 9 | dateValueSumGroup = dateDimension.group().reduceSum(function (d) { return d.value; });
|
| 10 | + dateValueNegativeSumGroup = dateDimension.group().reduceSum(function (d) { return -d.value; }); |
9 | 11 | dateIdSumGroup = dateDimension.group().reduceSum(function (d) { return d.id; });
|
10 | 12 | dateGroup = dateDimension.group();
|
11 | 13 |
|
@@ -547,6 +549,64 @@ describe('dc.compositeChart', function () {
|
547 | 549 | expect(chart.selectAll('.grid-line.horizontal line').size()).toBe(7);
|
548 | 550 | });
|
549 | 551 | });
|
| 552 | + |
| 553 | + describe('when composing a left axis chart with negative values', function () { |
| 554 | + var leftChart, rightChart; |
| 555 | + beforeEach(function () { |
| 556 | + chart |
| 557 | + .compose([ |
| 558 | + leftChart = dc.barChart(chart) |
| 559 | + .group(dateValueNegativeSumGroup, 'Date Value Group'), |
| 560 | + rightChart = dc.lineChart(chart) |
| 561 | + .group(dateIdSumGroup, 'Date ID Group') |
| 562 | + .useRightYAxis(true) |
| 563 | + ]) |
| 564 | + .render(); |
| 565 | + }); |
| 566 | + |
| 567 | + it('the axis baselines shouldn\'t match', function () { |
| 568 | + expect(leftChart.y()(0)).not.toEqual(rightChart.y()(0)); |
| 569 | + }); |
| 570 | + |
| 571 | + describe('with alignYAxes', function () { |
| 572 | + beforeEach(function () { |
| 573 | + chart.alignYAxes(true) |
| 574 | + .render(); |
| 575 | + }); |
| 576 | + it('the axis baselines should match', function () { |
| 577 | + expect(leftChart.y()(0)).toEqual(rightChart.y()(0)); |
| 578 | + }); |
| 579 | + }); |
| 580 | + }); |
| 581 | + |
| 582 | + describe('when composing a right axis chart with negative values', function () { |
| 583 | + var leftChart, rightChart; |
| 584 | + beforeEach(function () { |
| 585 | + chart |
| 586 | + .compose([ |
| 587 | + leftChart = dc.barChart(chart) |
| 588 | + .group(dateIdSumGroup, 'Date Value Group'), |
| 589 | + rightChart = dc.lineChart(chart) |
| 590 | + .group(dateValueNegativeSumGroup, 'Date ID Group') |
| 591 | + .useRightYAxis(true) |
| 592 | + ]) |
| 593 | + .render(); |
| 594 | + }); |
| 595 | + |
| 596 | + it('the axis baselines shouldn\'t match', function () { |
| 597 | + expect(leftChart.y()(0)).not.toEqual(rightChart.y()(0)); |
| 598 | + }); |
| 599 | + |
| 600 | + describe('with alignYAxes', function () { |
| 601 | + beforeEach(function () { |
| 602 | + chart.alignYAxes(true) |
| 603 | + .render(); |
| 604 | + }); |
| 605 | + it('the axis baselines should match', function () { |
| 606 | + expect(leftChart.y()(0)).toEqual(rightChart.y()(0)); |
| 607 | + }); |
| 608 | + }); |
| 609 | + }); |
550 | 610 | });
|
551 | 611 |
|
552 | 612 | describe('sub-charts with different filter types', function () {
|
|
0 commit comments