Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare x axis - added warning #1414

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions spec/bar-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('dc.barChart', function () {
chart.dimension(stateDimension)
.group(stateGroup)
.xUnits(dc.units.ordinal)
.x(d3.scaleOrdinal().domain(ordinalDomainValues))
.x(d3.scaleBand().domain(ordinalDomainValues))
.barPadding(0)
.outerPadding(0.1)
.render();
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('dc.barChart', function () {

describe('with an unspecified domain', function () {
beforeEach(function () {
chart.x(d3.scaleOrdinal()).render();
chart.x(d3.scaleBand()).render();
});

it('should use alphabetical ordering', function () {
Expand Down Expand Up @@ -295,6 +295,37 @@ describe('dc.barChart', function () {
});
});

describe('d3.scaleOrdinal() deprecation for ordinal x domain', function () {
var stateDimension;

beforeEach(function () {
spyOn(dc.logger, 'warn');

stateDimension = data.dimension(function (d) { return d.state; });
var stateGroup = stateDimension.group();
var ordinalDomainValues = ['California', 'Colorado', 'Delaware', 'Ontario', 'Mississippi', 'Oklahoma'];

chart.rescale(); // BUG: barWidth cannot change after initial rendering

chart.dimension(stateDimension)
.group(stateGroup)
.xUnits(dc.units.ordinal)
.x(d3.scaleOrdinal().domain(ordinalDomainValues))
.barPadding(0)
.outerPadding(0.1)
.render();
});

it('should work with a warning', function () {
expect(dc.logger.warn).toHaveBeenCalled();

expect(typeof chart.x().bandwidth).toEqual('function');
expect(nthStack(0).nthBar(0).attr('x')).toBeWithinDelta(16, 1);
expect(nthStack(0).nthBar(3).attr('x')).toBeWithinDelta(674, 1);
expect(nthStack(0).nthBar(5).attr('x')).toBeWithinDelta(509, 1);
});
});

describe('with a linear x domain', function () {
beforeEach(function () {
var linearDimension = data.dimension(function (d) { return +d.value; });
Expand Down Expand Up @@ -849,7 +880,7 @@ describe('dc.barChart', function () {

chart = dc.barChart('#' + id);
chart.xUnits(dc.units.ordinal)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.transitionDuration(0)
.dimension(dimension)
.group(group, 'Population');
Expand Down Expand Up @@ -901,7 +932,7 @@ describe('dc.barChart', function () {
.outerPadding(0)
.dimension(dimension)
.group(group)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal);
chart.render();
});
Expand Down Expand Up @@ -1073,7 +1104,7 @@ describe('dc.barChart', function () {

chart = dc.barChart('#' + id);
chart.width(500).transitionDuration(0)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.elasticY(true).elasticX(true)
.dimension(dimension)
Expand Down Expand Up @@ -1170,7 +1201,7 @@ describe('dc.barChart', function () {

chart = dc.barChart('#' + id);
chart.width(500).transitionDuration(0)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.elasticY(true).elasticX(true)
.dimension(dimension)
Expand Down Expand Up @@ -1231,7 +1262,7 @@ describe('dc.barChart', function () {

chart = dc.barChart('#' + id);
chart.width(500).transitionDuration(0)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.elasticY(true).elasticX(true)
.dimension(dimension)
Expand Down
2 changes: 1 addition & 1 deletion spec/composite-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ describe('dc.compositeChart', function () {
.brushOn(false)
.dimension(dimension)
.shareTitle(false)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.compose([
dc.lineChart(chart)
Expand Down
2 changes: 1 addition & 1 deletion spec/coordinate-grid-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ describe('dc.coordinateGridChart', function () {

describe('with an ordinal x axis', function () {
beforeEach(function () {
chart.x(d3.scaleOrdinal())
chart.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.render();
});
Expand Down
2 changes: 1 addition & 1 deletion spec/line-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ describe('dc.lineChart', function () {
chart.dimension(stateDimension)
.group(stateGroup)
.xUnits(dc.units.ordinal)
.x(d3.scaleOrdinal().domain(['California', 'Colorado', 'Delaware', 'Mississippi', 'Oklahoma', 'Ontario']))
.x(d3.scaleBand().domain(['California', 'Colorado', 'Delaware', 'Mississippi', 'Oklahoma', 'Ontario']))
.render();
});

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 @@ -468,6 +468,10 @@ dc.coordinateGridMixin = function (_chart) {
if (!_x.bandwidth) {
// If _x is not a scaleBand create a new scale and
// copy the original domain to the new scale
dc.logger.warn('Since DCv3 Ordinal bar/line/bubble charts need d3.scaleBand() for x scale. ' +
'Please update your code to pass a d3.scaleBand. ' +
'Changing d3.scaleOrdinal() to d3.scaleBand() should work. ' +
'For now DC has created an equivalent d3.scaleBand.');
_x = d3.scaleBand().domain(_x.domain());
}

Expand Down
4 changes: 2 additions & 2 deletions web/ep/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
});

var ageGroup = age.group().reduceSum(function(d) { return 1; });
//.x(d3.scaleOrdinal())

chart_age
.width(444)
.height(200)
Expand Down Expand Up @@ -123,7 +123,7 @@
.outerPadding(0)
.gap(1)
.margins({top: 0, right: 0, bottom: 95, left: 30})
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(false)
.elasticY(true)
Expand Down
106 changes: 0 additions & 106 deletions web/ep/list.js

This file was deleted.

2 changes: 1 addition & 1 deletion web/examples/adjustable-threshold.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
.dimension(bookDimension)
.group(bookscoresGroup)
.elasticY(true)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.colors(["orange"])
.yAxis().ticks(5);
Expand Down
2 changes: 1 addition & 1 deletion web/examples/bar-single-select.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
chart
.width(768)
.height(480)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(true)
.yAxisLabel("This is the Y Axis!")
Expand Down
4 changes: 2 additions & 2 deletions web/examples/complex-reduce.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ <h4>Experiment</h4>
runChart
.width(400)
.height(300)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.valueAccessor(medianSpeed)
.elasticY(true)
Expand All @@ -149,7 +149,7 @@ <h4>Experiment</h4>
exptChart
.width(400)
.height(300)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.valueAccessor(medianSpeed)
.elasticY(true)
Expand Down
2 changes: 1 addition & 1 deletion web/examples/filtering-removing.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
.width(300).height(200)
.dimension(spendDim)
.group(nonEmptyHist)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.elasticX(true)
.elasticY(true);
Expand Down
2 changes: 1 addition & 1 deletion web/examples/ordinal-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
chart
.width(768)
.height(380)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(false)
.xAxisLabel('Fruit')
Expand Down
2 changes: 1 addition & 1 deletion web/examples/ordinal-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
chart
.width(768)
.height(380)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(false)
.xAxisLabel('Fruit')
Expand Down
6 changes: 3 additions & 3 deletions web/play-ground.html
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@
.radiusValueAccessor(function (p) {
return p.value.count;
})
.x(d3.scaleOrdinal().domain(["A", "T", "F", "Z"]))
.x(d3.scaleBand().domain(["A", "T", "F", "Z"]))
.xUnits(dc.units.ordinal)
.y(d3.scaleLinear().domain([0, 10]))
.r(d3.scaleLinear().domain([0, 30]))
Expand All @@ -822,7 +822,7 @@
.dimension(stateDimension)
.group(stateGroup)
.elasticY(true)
.x(d3.scaleOrdinal().domain(["California", "Colorado", "Delaware", "Mississippi", "Oklahoma", "Ontario"]))
.x(d3.scaleBand().domain(["California", "Colorado", "Delaware", "Mississippi", "Oklahoma", "Ontario"]))
.xUnits(dc.units.ordinal);

var ordinalLineChart = dc.lineChart("#ordinal-line-chart");
Expand All @@ -833,7 +833,7 @@
.y(d3.scaleLinear().domain([0, 3]))
.renderArea(true)
.renderTitle(true)
.x(d3.scaleOrdinal().domain(["California", "Colorado", "Delaware", "Mississippi", "Oklahoma", "Ontario"]))
.x(d3.scaleBand().domain(["California", "Colorado", "Delaware", "Mississippi", "Oklahoma", "Ontario"]))
.xUnits(dc.units.ordinal);

var linearBarChart = dc.barChart("#linear-bar-chart");
Expand Down
2 changes: 1 addition & 1 deletion web/transitions/ordinal-bar-transitions.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
return chart
.width(768)
.height(380)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.elasticX(true)
.elasticY(true)
Expand Down
2 changes: 1 addition & 1 deletion web/transitions/ordinal-line-transitions.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
return chart
.width(768)
.height(380)
.x(d3.scaleOrdinal())
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.elasticX(true)
.elasticY(true)
Expand Down