Skip to content

Commit

Permalink
cleanup of #985
Browse files Browse the repository at this point in the history
add tests
force resize when changing alignYAxes
rename calculateYAxisRanges
add author
  • Loading branch information
gordonwoodhull committed Oct 31, 2015
1 parent 606b218 commit 2dd561f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ Chris Alvino <alvino.chris@gmail.com>
Emiliano Guevara <emiliano@opoint.com>
Wang Xuan <wangxuan927@gmail.com>
Ethan Jewett <esjewett@gmail.com>
Mohamed Gazal <mohamed.gazal@gmail.com>
62 changes: 61 additions & 1 deletion spec/composite-chart-spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* global appendChartID, loadDateFixture, makeDate */
describe('dc.compositeChart', function () {
var id, chart, data, dateDimension, dateValueSumGroup, dateIdSumGroup, dateGroup;
var id, chart, data, dateDimension, dateValueSumGroup, dateValueNegativeSumGroup,
dateIdSumGroup, dateGroup;

beforeEach(function () {
data = crossfilter(loadDateFixture());
dateDimension = data.dimension(function (d) { return d3.time.day.utc(d.dd); });
dateValueSumGroup = dateDimension.group().reduceSum(function (d) { return d.value; });
dateValueNegativeSumGroup = dateDimension.group().reduceSum(function (d) { return -d.value; });
dateIdSumGroup = dateDimension.group().reduceSum(function (d) { return d.id; });
dateGroup = dateDimension.group();

Expand Down Expand Up @@ -547,6 +549,64 @@ describe('dc.compositeChart', function () {
expect(chart.selectAll('.grid-line.horizontal line').size()).toBe(7);
});
});

describe('when composing a left axis chart with negative values', function () {
var leftChart, rightChart;
beforeEach(function () {
chart
.compose([
leftChart = dc.barChart(chart)
.group(dateValueNegativeSumGroup, 'Date Value Group'),
rightChart = dc.lineChart(chart)
.group(dateIdSumGroup, 'Date ID Group')
.useRightYAxis(true)
])
.render();
});

it('the axis baselines shouldn\'t match', function () {
expect(leftChart.y()(0)).not.toEqual(rightChart.y()(0));
});

describe('with alignYAxes', function () {
beforeEach(function () {
chart.alignYAxes(true)
.render();
});
it('the axis baselines should match', function () {
expect(leftChart.y()(0)).toEqual(rightChart.y()(0));
});
});
});

describe('when composing a right axis chart with negative values', function () {
var leftChart, rightChart;
beforeEach(function () {
chart
.compose([
leftChart = dc.barChart(chart)
.group(dateIdSumGroup, 'Date Value Group'),
rightChart = dc.lineChart(chart)
.group(dateValueNegativeSumGroup, 'Date ID Group')
.useRightYAxis(true)
])
.render();
});

it('the axis baselines shouldn\'t match', function () {
expect(leftChart.y()(0)).not.toEqual(rightChart.y()(0));
});

describe('with alignYAxes', function () {
beforeEach(function () {
chart.alignYAxes(true)
.render();
});
it('the axis baselines should match', function () {
expect(leftChart.y()(0)).toEqual(rightChart.y()(0));
});
});
});
});

describe('sub-charts with different filter types', function () {
Expand Down
9 changes: 5 additions & 4 deletions src/composite-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dc.compositeChart = function (parent, chartGroup) {
_chart._prepareYAxis = function () {
var left = (leftYAxisChildren().length !== 0);
var right = (rightYAxisChildren().length !== 0);
var ranges = calculateYAxesRanges(left, right);
var ranges = calculateYAxisRanges(left, right);

if (left) { prepareLeftYAxis(ranges); }
if (right) { prepareRightYAxis(ranges); }
Expand All @@ -107,7 +107,7 @@ dc.compositeChart = function (parent, chartGroup) {
}
};

function calculateYAxesRanges (left, right) {
function calculateYAxisRanges (left, right) {
var lyAxisMin, lyAxisMax, ryAxisMin, ryAxisMax;

if (left) {
Expand Down Expand Up @@ -153,7 +153,7 @@ dc.compositeChart = function (parent, chartGroup) {
}

function prepareRightYAxis (ranges) {
if (_chart.rightY() === undefined || _chart.elasticY()) {
if (_chart.rightY() === undefined || _chart.elasticY() || _chart.resizing()) {
if (_chart.rightY() === undefined) {
_chart.rightY(d3.scale.linear());
}
Expand All @@ -167,7 +167,7 @@ dc.compositeChart = function (parent, chartGroup) {
}

function prepareLeftYAxis (ranges) {
if (_chart.y() === undefined || _chart.elasticY()) {
if (_chart.y() === undefined || _chart.elasticY() || _chart.resizing()) {
if (_chart.y() === undefined) {
_chart.y(d3.scale.linear());
}
Expand Down Expand Up @@ -403,6 +403,7 @@ dc.compositeChart = function (parent, chartGroup) {
return _alignYAxes;
}
_alignYAxes = alignYAxes;
_chart.rescale();
return _chart;
};

Expand Down
4 changes: 4 additions & 0 deletions src/coordinate-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ dc.coordinateGridMixin = function (_chart) {
return _chart;
};

_chart.resizing = function () {
return _resizing;
};

/**
* Get or set the range selection chart associated with this instance. Setting the range selection
* chart using this function will automatically update its selection brush when the current chart
Expand Down

0 comments on commit 2dd561f

Please sign in to comment.