diff --git a/spec/bar-chart-spec.js b/spec/bar-chart-spec.js index 35c752bb2..d9778f322 100644 --- a/spec/bar-chart-spec.js +++ b/spec/bar-chart-spec.js @@ -4,7 +4,7 @@ describe('dc.barChart', function() { beforeEach(function () { data = crossfilter(loadDateFixture()); - dimension = data.dimension(function(d) { return d3.time.day(d.dd); }); + dimension = data.dimension(function(d) { return d3.time.day.utc(d.dd); }); group = dimension.group(); id = 'bar-chart'; @@ -13,7 +13,7 @@ describe('dc.barChart', function() { chart = dc.barChart('#' + id); chart.dimension(dimension).group(group) .width(1100).height(200) - .x(d3.time.scale().domain([new Date("2012/01/01"), new Date("2012/12/31")])) + .x(d3.time.scale.utc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) .transitionDuration(0); }); @@ -61,15 +61,15 @@ describe('dc.barChart', function() { beforeEach(function() { chart.rescale(); // BUG: barWidth cannot change after initial rendering - var domain = [new Date("5/20/2012"), new Date("8/15/2012")]; + var domain = [makeDate(2012, 4, 20), makeDate(2012, 7, 15)]; - chart.x(d3.time.scale().domain(domain)) + chart.x(d3.time.scale.utc().domain(domain)) .group(dimension.group().reduceSum(function(d) { return +d.nvalue; })) .elasticY(true) .centerBar(false) - .xUnits(d3.time.days) + .xUnits(d3.time.days.utc) .yAxis().ticks(5); chart.render(); @@ -252,7 +252,7 @@ describe('dc.barChart', function() { chart .brushOn(false) - .x(d3.time.scale().domain([new Date("2012/5/20"), new Date("2012/8/15")])) + .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .group(idGroup, "stack 0") .title("stack 0", function (d) { return "stack 0: " + d.value; }) .stack(sumGroup, "stack 1") @@ -377,12 +377,12 @@ describe('dc.barChart', function() { var negativeGroup = dimension.group().reduceSum(function(d){ return d.nvalue; }); chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup); - chart.x(d3.time.scale().domain([new Date("2012/5/20"), new Date("2012/8/15")])); + 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}) .yAxisPadding(5) .elasticY(true) - .xUnits(d3.time.days) + .xUnits(d3.time.days.utc) .yAxis().ticks(5); chart.rescale(); // BUG: barWidth cannot change after initial rendering @@ -444,8 +444,8 @@ describe('dc.barChart', function() { describe('when focused', function() { beforeEach(function() { - chart.elasticY(true).gap(1).xUnits(d3.time.days); - chart.focus([new Date("2012/6/11"), new Date("2012/7/9")]); + chart.elasticY(true).gap(1).xUnits(d3.time.days.utc); + chart.focus([makeDate(2012, 5, 11), makeDate(2012, 6, 9)]); }); it('should render the one (focused) bar', function() { @@ -461,15 +461,7 @@ describe('dc.barChart', function() { }); it('should redraw the x-axis scale and ticks', function() { - chart.focus(null); - expect(nthXAxisText(0).text()).toBe("2012"); - expect(nthXAxisText(1).text()).toBe("February"); - expect(nthXAxisText(2).text()).toBe("March"); - expect(nthXAxisText(3).text()).toBe("April"); - - function nthXAxisText(n) { - return d3.select(chart.selectAll("g.x text")[0][n]); - } + expect(xAxisText().slice(0,4)).toEqual(["Mon 11", "Wed 13", "Fri 15", "Jun 17"]); }); it('should set its focus flag', function() { @@ -488,7 +480,13 @@ describe('dc.barChart', function() { function itBehavesLikeItWasReset() { expect(chart.refocused()).toBeFalsy(); - expect(chart.x().domain()).toEqual([new Date("2012/1/1"), new Date("2012/12/31")]); + expect(chart.x().domain()).toEqual([makeDate(2012, 0, 1), makeDate(2012, 11, 31)]); + + expect(xAxisText().slice(0,4)).toEqual(["2012", "February", "March", "April"]); + } + + function xAxisText() { + return chart.selectAll("g.x text")[0].map(function(x) { return d3.select(x).text(); }); } }); @@ -539,12 +537,13 @@ describe('dc.barChart', function() { beforeEach(function () { d3.select("#" + id).append("span").attr("class", "filter").style("display", "none"); d3.select("#" + id).append("a").attr("class", "reset").style("display", "none"); - chart.filter([new Date("2012/6/1"), new Date("2012/6/30")]).redraw(); + chart.filter([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]).redraw(); + dc.dateFormat = d3.time.format.utc("%m/%d/%Y"); chart.redraw(); }); it('should set the chart filter', function () { - expect(chart.filter()).toEqual([new Date("2012/6/1"), new Date("2012/6/30")]); + expect(chart.filter()).toEqual([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]); }); it("should enable the reset link after rendering", function() { @@ -625,7 +624,7 @@ describe('dc.barChart', function() { describe("a chart with a large domain", function() { beforeEach(function() { - chart.x(d3.time.scale().domain([new Date("2000/01/01"), new Date("2012/12/31")])); + chart.x(d3.time.scale.utc().domain([makeDate(2000, 0, 1), makeDate(2012, 11, 31)])); }); describe("when filters are applied", function() { @@ -685,7 +684,7 @@ describe('dc.barChart', function() { beforeEach(function () { chart .brushOn(true) - .round(d3.time.month.round) + .round(d3.time.month.utc.round) .centerBar(true); }); @@ -696,7 +695,7 @@ describe('dc.barChart', function() { chart.alwaysUseRounding(false); consoleWarnSpy = spyOn(console, "warn"); chart.render(); - chart.brush().extent([new Date(2012, 6, 1), new Date(2012, 7, 15)]); + chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]); chart.brush().event(chart.root()); }); @@ -706,7 +705,7 @@ describe('dc.barChart', function() { it("should not round the brush", function () { jasmine.clock().tick(100); - expect(chart.filter()).toEqual([new Date(2012, 6, 1), new Date(2012, 7, 15)]); + expect(chart.filter()).toEqual([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]); }); }); @@ -714,12 +713,13 @@ describe('dc.barChart', function() { beforeEach(function() { chart.alwaysUseRounding(true); chart.render(); - chart.brush().extent([new Date(2012, 6, 1), new Date(2012, 7, 15)]); + chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]); chart.brush().event(chart.root()); }); it("should round the brush", function () { - expect(chart.brush().extent()).toEqual([new Date(2012, 6, 1), new Date(2012, 7, 1)]); + jasmine.clock().tick(100); + expect(chart.brush().extent()).toEqual([makeDate(2012, 6, 1), makeDate(2012, 7, 1)]); }); }); }); diff --git a/spec/base-mixin-spec.js b/spec/base-mixin-spec.js index 3907237ca..4e53b7d43 100644 --- a/spec/base-mixin-spec.js +++ b/spec/base-mixin-spec.js @@ -4,7 +4,7 @@ describe("dc.baseMixin", function () { beforeEach(function () { var data = crossfilter(loadDateFixture()); dimension = data.dimension(function (d) { - return d3.time.day(d.dd); + return d3.time.day.utc(d.dd); }); group = dimension.group().reduceSum(function (d) { return d.value; diff --git a/spec/composite-chart-spec.js b/spec/composite-chart-spec.js index 3b60fc82d..9d8a4ba4c 100644 --- a/spec/composite-chart-spec.js +++ b/spec/composite-chart-spec.js @@ -3,7 +3,7 @@ describe('dc.compositeChart', function() { beforeEach(function () { data = crossfilter(loadDateFixture()); - dateDimension = data.dimension(function(d) { return d3.time.day(d.dd); }); + dateDimension = data.dimension(function(d) { return d3.time.day.utc(d.dd); }); dateValueSumGroup = dateDimension.group().reduceSum(function(d) { return d.value; }); dateIdSumGroup = dateDimension.group().reduceSum(function(d) { return d.id; }); dateGroup = dateDimension.group(); @@ -17,9 +17,9 @@ describe('dc.compositeChart', function() { .group(dateIdSumGroup) .width(500) .height(150) - .x(d3.time.scale().domain([new Date(2012, 4, 20), new Date(2012, 7, 15)])) + .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .transitionDuration(0) - .xUnits(d3.time.days) + .xUnits(d3.time.days.utc) .shareColors(true) .compose([ dc.barChart(chart) @@ -69,12 +69,12 @@ describe('dc.compositeChart', function() { }); it('should set the x domain to endpoint dates', function () { - expect(chart.x().domain()[0].getTime()).toBe(new Date(2012, 4, 20).getTime()); - expect(chart.x().domain()[1].getTime()).toBe(new Date(2012, 7, 15).getTime()); + expect(chart.x().domain()[0].getTime()).toBe(makeDate(2012, 4, 20).getTime()); + expect(chart.x().domain()[1].getTime()).toBe(makeDate(2012, 7, 15).getTime()); }); it('should set the x units', function(){ - expect(chart.xUnits()).toBe(d3.time.days); + expect(chart.xUnits()).toBe(d3.time.days.utc); }); it('should create the x axis', function(){ @@ -94,7 +94,7 @@ describe('dc.compositeChart', function() { }); it('can change round', function () { - chart.round(d3.time.day.round); + chart.round(d3.time.day.utc.round); expect(chart.round()).not.toBeNull(); }); @@ -257,7 +257,7 @@ describe('dc.compositeChart', function() { describe('when filtering the chart', function () { beforeEach(function () { - chart.filter([new Date(2012, 5, 1), new Date(2012, 5, 30)]).redraw(); + chart.filter([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]).redraw(); }); it('should set extent width to chart width based on filter set', function () { diff --git a/spec/coordinate-grid-chart-spec.js b/spec/coordinate-grid-chart-spec.js index 16df72222..37f6b35b9 100644 --- a/spec/coordinate-grid-chart-spec.js +++ b/spec/coordinate-grid-chart-spec.js @@ -5,7 +5,7 @@ describe('dc.coordinateGridChart', function() { beforeEach(function () { data = crossfilter(loadDateFixture()); - dimension = data.dimension(function(d) { return d3.time.day(d.dd); }); + dimension = data.dimension(function(d) { return d3.time.day.utc(d.dd); }); group = dimension.group(); id = "coordinate-grid-chart"; @@ -19,7 +19,7 @@ describe('dc.coordinateGridChart', function() { .transitionDuration(0) .brushOn(false) .margins({ top: 20, bottom: 0, right: 10, left: 0 }) - .x(d3.time.scale().domain([new Date("2012/5/20"), new Date("2012/8/15")])); + .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])); }); describe("rendering", function() { @@ -76,7 +76,7 @@ describe('dc.coordinateGridChart', function() { }); it('should set the x domain to endpoint dates', function () { - expect(chart.x().domain()).toEqual([new Date("2012/5/20"), new Date("2012/8/15")]); + expect(chart.x().domain()).toEqual([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]); }); it('should create the brush', function () { @@ -103,7 +103,7 @@ describe('dc.coordinateGridChart', function() { }); it('should be able to change round', function () { - chart.round(d3.time.day.round); + chart.round(d3.time.day.utc.round); expect(chart.round()).not.toBeNull(); }); @@ -281,7 +281,7 @@ describe('dc.coordinateGridChart', function() { describe('with custom tick values', function () { beforeEach(function () { - chart.xAxis().tickValues([new Date("2012/05/21"), new Date("2012/06/20"), new Date("2012/07/01")]); + chart.xAxis().tickValues([makeDate(2012, 4, 21), makeDate(2012, 5, 20), makeDate(2012, 6, 1)]); chart.render(); }); @@ -409,7 +409,7 @@ describe('dc.coordinateGridChart', function() { }); it('should shrink the x domain', function () { - expect(chart.x().domain()).toEqual([new Date("2012/5/25"), new Date("2012/8/10")]); + expect(chart.x().domain()).toEqual([makeDate(2012, 4, 25), makeDate(2012, 7, 10)]); }); }); @@ -435,7 +435,7 @@ describe('dc.coordinateGridChart', function() { beforeEach(function () { chart.render(); originalUnitCount = chart.xUnitCount(); - chart.x().domain([new Date(2012, 4, 20), new Date(2012, 6, 15)]); + chart.x().domain([makeDate(2012, 4, 20), makeDate(2012, 6, 15)]); chart.rescale(); }); @@ -532,7 +532,7 @@ describe('dc.coordinateGridChart', function() { }); describe("applying a filter", function () { - var filter = [new Date(2012, 5, 20), new Date(2012, 6, 15)]; + var filter = [makeDate(2012, 5, 20), makeDate(2012, 6, 15)]; beforeEach(function () { chart.brushOn(true); chart.render(); @@ -548,7 +548,7 @@ describe('dc.coordinateGridChart', function() { beforeEach(function () { chart.brushOn(true); chart.render(); - chart.brush().extent([new Date(2012, 5, 20), new Date(2012, 6, 15)]); + chart.brush().extent([makeDate(2012, 5, 20), makeDate(2012, 6, 15)]); chart.filter(null); }); @@ -624,7 +624,7 @@ describe('dc.coordinateGridChart', function() { describe("when chart is zoomed programatically via focus method", function () { beforeEach(function () { - chart.focus([new Date("2012/6/1"), new Date("2012/6/15")]); + chart.focus([makeDate(2012, 5, 1), makeDate(2012, 5, 15)]); }); itActsLikeItZoomed(context); @@ -699,12 +699,12 @@ describe('dc.coordinateGridChart', function() { spyOn(chart, '_enableMouseZoom'); chart.mouseZoomable(true); chart.render(); - chart.brush().extent([new Date(2012, 6, 1), new Date(2012, 6, 15)]); + chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 6, 15)]); chart.brush().event(chart.root()); }); it("should disable mouse zooming on brush start, and re-enables it afterwards", function () { - chart.brush().extent([new Date("2012/7/1"), new Date("2012/7/15")]); + chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 6, 15)]); chart.brush().event(chart.root()); expect(chart._disableMouseZoom).toHaveBeenCalled(); expect(chart._enableMouseZoom).toHaveBeenCalled(); @@ -716,7 +716,7 @@ describe('dc.coordinateGridChart', function() { spyOn(chart, "_enableMouseZoom"); chart.mouseZoomable(false); chart.render(); - chart.brush().extent([new Date(2012, 6, 1), new Date(2012, 6, 15)]); + chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 6, 15)]); chart.brush().event(chart.root()); }); @@ -741,7 +741,7 @@ describe('dc.coordinateGridChart', function() { describe("with a range chart", function () { var rangeChart; - var selectedRange = [new Date(2012, 6, 1), new Date(2012, 6, 15)]; + var selectedRange = [makeDate(2012, 6, 1), makeDate(2012, 6, 15)]; beforeEach(function () { rangeChart = buildRangeChart(); @@ -780,11 +780,11 @@ describe('dc.coordinateGridChart', function() { beforeEach(function () { chart.zoomOutRestrict(true); chart.render(); - chart.focus([new Date(2012, 8, 20), new Date(2012, 8, 25)]); + chart.focus([makeDate(2012, 8, 20), makeDate(2012, 8, 25)]); }); it("should not be able to zoom out past its original x domain", function () { - chart.focus([new Date(2012, 2, 20), new Date(2012, 9, 15)]); + chart.focus([makeDate(2012, 2, 20), makeDate(2012, 9, 15)]); expect(chart.x().domain()).toEqual(chart.xOriginalDomain()); }); @@ -794,11 +794,11 @@ describe('dc.coordinateGridChart', function() { chart.rangeChart(rangeChart); chart.render(); rangeChart.render(); - chart.focus([new Date(2012, 8, 20), new Date(2012, 8, 25)]); + chart.focus([makeDate(2012, 8, 20), makeDate(2012, 8, 25)]); }); it("should not be able to zoom out past its range chart origin x domain", function () { - chart.focus([new Date(2012, 2, 20), new Date(2012, 9, 15)]); + chart.focus([makeDate(2012, 2, 20), makeDate(2012, 9, 15)]); expect(chart.x().domain()).toEqual(chart.rangeChart().xOriginalDomain()); }); }); @@ -808,13 +808,13 @@ describe('dc.coordinateGridChart', function() { beforeEach(function () { chart.zoomOutRestrict(false); chart.render(); - chart.focus([new Date(2012, 8, 20), new Date(2012, 8, 25)]); + chart.focus([makeDate(2012, 8, 20), makeDate(2012, 8, 25)]); }); it("should be able to zoom out past its original x domain", function () { - chart.focus([new Date(2012, 2, 20), new Date(2012, 9, 15)]); + chart.focus([makeDate(2012, 2, 20), makeDate(2012, 9, 15)]); chart.render(); - expect(chart.x().domain()).toEqual([new Date(2012, 2, 20), new Date(2012, 9, 15)]); + expect(chart.x().domain()).toEqual([makeDate(2012, 2, 20), makeDate(2012, 9, 15)]); }); }); @@ -824,7 +824,7 @@ describe('dc.coordinateGridChart', function() { }); describe("when called with a range argument", function () { - var focusDomain = [new Date(2012,5,20), new Date(2012,5,30)]; + var focusDomain = [makeDate(2012,5,20), makeDate(2012,5,30)]; beforeEach(function () { chart.focus(focusDomain); @@ -837,7 +837,7 @@ describe('dc.coordinateGridChart', function() { describe("when called with no arguments", function () { beforeEach(function () { - chart.focus([new Date(2012,5,1), new Date(2012,5,2)]); + chart.focus([makeDate(2012,5,1), makeDate(2012,5,2)]); chart.focus(); }); @@ -853,7 +853,7 @@ describe('dc.coordinateGridChart', function() { return dc.lineChart("#" + rangeId) .dimension(dimension) .group(dimension.group().reduceSum(function(d) { return d.id; })) - .x(d3.time.scale().domain([new Date("2012/6/20"), new Date("2012/7/15")])); + .x(d3.time.scale.utc().domain([makeDate(2012, 5, 20), makeDate(2012, 6, 15)])); } function doubleClick(chart) { diff --git a/spec/data-addition-spec.js b/spec/data-addition-spec.js index bef184021..48be0ca18 100644 --- a/spec/data-addition-spec.js +++ b/spec/data-addition-spec.js @@ -67,9 +67,9 @@ describe('Dynamic data addition in crossfilter', function() { var chart = dc.lineChart("#" + id); chart.dimension(timeDimension).group(timeGroup) .width(width).height(height) - .x(d3.time.scale().domain([new Date(2012, 4, 20), new Date(2012, 7, 15)])) + .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .transitionDuration(0) - .xUnits(d3.time.days) + .xUnits(d3.time.days.utc) .brushOn(false) .renderArea(true) .renderTitle(true); diff --git a/spec/data-grid-spec.js b/spec/data-grid-spec.js index 10df0dfae..96691adb7 100644 --- a/spec/data-grid-spec.js +++ b/spec/data-grid-spec.js @@ -8,7 +8,7 @@ describe('dc.dataGrid', function() { dateFixture = loadDateFixture(); data = crossfilter(dateFixture); dimension = data.dimension(function(d) { - return d3.time.day(d.dd); + return d3.time.day.utc(d.dd); }); countryDimension = data.dimension(function(d) { return d.countrycode; diff --git a/spec/data-table-spec.js b/spec/data-table-spec.js index 1cace19d3..b2792c03e 100644 --- a/spec/data-table-spec.js +++ b/spec/data-table-spec.js @@ -8,7 +8,7 @@ describe('dc.dataTable', function() { dateFixture = loadDateFixture(); data = crossfilter(dateFixture); dimension = data.dimension(function(d) { - return d3.time.day(d.dd); + return d3.time.day.utc(d.dd); }); countryDimension = data.dimension(function(d) { return d.countrycode; diff --git a/spec/filter-dates-spec.js b/spec/filter-dates-spec.js index 53a4c010d..fd15f3844 100644 --- a/spec/filter-dates-spec.js +++ b/spec/filter-dates-spec.js @@ -12,8 +12,8 @@ describe('dc.filter-dates', function() { var margins = {top: 15, right: 10, bottom: 20, left: 40}; beforeEach(function () { // Months are 0 indexed... - var start = new Date(2013, 10, 1); - var end = new Date(2013, 11, 1); + var start = makeDate(2013, 10, 1); + var end = makeDate(2013, 11, 1); var stringLength = 2; // Generate Random Data [Date, VowelString, Random Number, Random Measure] @@ -57,7 +57,7 @@ describe('dc.filter-dates', function() { }); it('filtering on 11/8 should keep only that row', function() { - row1.filter(new Date(2013, 10, 8)); + row1.filter(makeDate(2013, 10, 8)); expect(group1.all()[6].value).not.toEqual(0); expect(group2.all()[6].value).toEqual(0); expect(group2.all()[7]).toEqual(group1.all()[7]); @@ -65,7 +65,7 @@ describe('dc.filter-dates', function() { }); it('filtering on 11/17 should keep only that row', function() { - row1.filter(new Date(2013, 10, 17)); + row1.filter(makeDate(2013, 10, 17)); expect(group1.all()[15].value).not.toEqual(0); expect(group2.all()[15].value).toEqual(0); expect(group2.all()[16]).toEqual(group1.all()[16]); @@ -75,7 +75,7 @@ describe('dc.filter-dates', function() { // Create a Random Date function randomDate(start, end) { var d = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime())); - d.setHours(0,0,0,0); + d.setUTCHours(0,0,0,0); return d; } diff --git a/spec/helpers/spec-helper.js b/spec/helpers/spec-helper.js index 6982d1f70..2c103445a 100644 --- a/spec/helpers/spec-helper.js +++ b/spec/helpers/spec-helper.js @@ -19,3 +19,10 @@ function coordsFromTranslate(translationString) { expect(result).not.toBeNull(); return { x: +result[1], y: +result[2] }; } + +// use UTC dates because these tests will be run in many time zones +function makeDate(year, month, day) { + if(typeof year === 'string' || arguments.length !== 3) + throw new Error("makeDate takes year, month, day"); + return new Date(Date.UTC(year, month, day, 0, 0, 0, 0)); +} diff --git a/spec/legend-spec.js b/spec/legend-spec.js index 775e9f9eb..4815fe997 100644 --- a/spec/legend-spec.js +++ b/spec/legend-spec.js @@ -3,7 +3,7 @@ describe("dc.legend", function() { beforeEach(function () { var data = crossfilter(loadDateFixture()); - dateDimension = data.dimension(function(d) { return d3.time.day(d.dd); }); + dateDimension = data.dimension(function(d) { return d3.time.day.utc(d.dd); }); dateValueSumGroup = dateDimension.group().reduceSum(function(d) { return d.value; }); dateIdSumGroup = dateDimension.group().reduceSum(function(d) { return d.id; }); @@ -16,7 +16,7 @@ describe("dc.legend", function() { .group(dateIdSumGroup, "Id Sum") .stack(dateValueSumGroup, "Value Sum") .stack(dateValueSumGroup, "Fixed", function () {}) - .x(d3.time.scale().domain([new Date(2012, 4, 20), new Date(2012, 7, 15)])) + .x(d3.time.scale.utc().domain([new Date(2012, 4, 20), new Date(2012, 7, 15)])) .legend(dc.legend().x(400).y(10).itemHeight(13).gap(5)); }); diff --git a/spec/line-chart-spec.js b/spec/line-chart-spec.js index 851149b90..b60ba9b2b 100644 --- a/spec/line-chart-spec.js +++ b/spec/line-chart-spec.js @@ -4,7 +4,7 @@ describe('dc.lineChart', function() { beforeEach(function () { data = crossfilter(loadDateFixture()); - dimension = data.dimension(function(d) { return d3.time.day(d.dd); }); + dimension = data.dimension(function(d) { return d3.time.day.utc(d.dd); }); group = dimension.group(); id = 'line-chart'; @@ -13,7 +13,7 @@ describe('dc.lineChart', function() { chart = dc.lineChart('#' + id); chart.dimension(dimension).group(group) .width(1100).height(200) - .x(d3.time.scale().domain([new Date("2012/01/01"), new Date("2012/12/31")])) + .x(d3.time.scale.utc().domain([makeDate(2012, 1, 1), makeDate(2012, 11, 31)])) .transitionDuration(0); }); @@ -174,39 +174,48 @@ describe('dc.lineChart', function() { describe('when dot is hovered over', function () { describe('for vertical ref lines', function () { + var x; beforeEach(function () { var dot = chart.select('circle.dot'); dot.on("mousemove").call(dot[0][0]); + x = dot.attr('cx'); }); it('shows the ref line from the bottom of the graph', function () { - expect(chart.select('path.xRef').attr('d')).toMatchPath("M405 160 L 405 107"); + var path = "M" + x + " 160 L " + x + " 107"; + expect(chart.select('path.xRef').attr('d')).toMatchPath(path); expect(chart.select('path.xRef').attr("display")).not.toBe("none"); }); }); describe('for horizontal ref lines', function () { describe('for a left y-axis chart', function () { + var x; beforeEach(function () { var dot = chart.select('circle.dot'); dot.on("mousemove").call(dot[0][0]); + x = dot.attr('cx'); }); it('shows the ref line on the left', function () { - expect(chart.select('path.yRef').attr("d")).toMatchPath("M0 107L405 107"); + var path = "M0 107 L " + x + " 107"; + expect(chart.select('path.yRef').attr("d")).toMatchPath(path); expect(chart.select('path.yRef').attr("display")).not.toBe("none"); }); }); describe('for a right y-axis chart', function () { + var x; beforeEach(function () { chart.useRightYAxis(true).render(); var dot = chart.select('circle.dot'); dot.on("mousemove").call(dot[0][0]); + x = dot.attr('cx'); }); it('shows the ref line on the right', function () { - expect(chart.select('path.yRef').attr("d")).toMatchPath("M1020 107L405 107"); + var path = "M1020 107L" + x + " 107"; + expect(chart.select('path.yRef').attr("d")).toMatchPath(path); //"M1020 107L405 107"); expect(chart.select('path.yRef').attr("display")).not.toBe("none"); }); }); @@ -217,7 +226,7 @@ describe('dc.lineChart', function() { describe('undefined points', function () { beforeEach(function () { - chart.defined(function(d) { return d.x.valueOf() != new Date("2012/06/10").getTime(); }); + chart.defined(function(d) { return d.x.valueOf() != makeDate(2012, 5, 10).getTime(); }); chart.brushOn(false).render(); }); @@ -236,11 +245,11 @@ describe('dc.lineChart', function() { }); it('should draw the chart line', function () { - expect(chart.select("path.line").attr("d")).toMatchPath("M405 107 L444 107L449 0L508 107L533 53L620 53"); + expect(chart.select("path.line").attr("d")).toMatchPath("M348,107 L390,107 L397,0 L461,107 L488,53 L583,53"); }); it('should draw the chart area', function () { - expect(chart.select("path.area").attr("d")).toMatchPath("M405 107L444 107L449 0L508 107L533 53L620 53L620 160L533 160L508 160L449 160L444 160L405 160Z"); + expect(chart.select("path.area").attr("d")).toMatchPath("M348,107 L390,107 L397,0 L461,107 L488,53 L583,53 L583,160 L488,160 L461,160 L397,160 L390,160 L348,160Z"); }); }); @@ -273,7 +282,7 @@ describe('dc.lineChart', function() { chart.dimension(dimension) .brushOn(false) - .x(d3.time.scale().domain([new Date("2012/5/20"), new Date("2012/8/15")])) + .x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)])) .group(idGroup, "stack 0") .title("stack 0", function (d) { return "stack 0: " + d.value; }) .stack(valueGroup, "stack 1") @@ -431,7 +440,7 @@ describe('dc.lineChart', function() { var negativeGroup = dimension.group().reduceSum(function(d){ return d.nvalue; }); chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup); - chart.x(d3.time.scale().domain([new Date("2012/5/20"), new Date("2012/8/15")])); + 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}) .renderArea(true) @@ -517,11 +526,11 @@ describe('dc.lineChart', function() { describe('filtering', function () { beforeEach(function () { - chart.filter([new Date("2012/6/1"), new Date("2012/6/30")]).redraw(); + chart.filter([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]).redraw(); }); it('should set the chart filter', function () { - expect(chart.filter()).toEqual([new Date("2012/6/1"), new Date("2012/6/30")]); + expect(chart.filter()).toEqual([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]); }); it('should set the filter printer', function () { @@ -563,7 +572,7 @@ describe('dc.lineChart', function() { }); it('should set extent width based on filter set', function () { - expect(chart.select("g.brush rect.extent").attr("width")).toBeWithinDelta(81, 1); + expect(chart.select("g.brush rect.extent").attr("width")).toBeWithinDelta(88, 1); }); it('should not have an area path', function () { diff --git a/spec/pie-chart-spec.js b/spec/pie-chart-spec.js index d96173526..6685e028a 100644 --- a/spec/pie-chart-spec.js +++ b/spec/pie-chart-spec.js @@ -24,7 +24,7 @@ describe('dc.pieChart', function() { }); countryGroup = countryDimension.group(); dateDimension = data.dimension(function(d) { - return d3.time.day(d.dd); + return d3.time.day.utc(d.dd); }); statusGroup = statusDimension.group(); statusMultiGroup = statusGroup.reduce( @@ -301,9 +301,9 @@ describe('dc.pieChart', function() { var chart; beforeEach(function() { chart = buildChart("pie-chart2"); - dateDimension.filter([new Date(2010, 0, 1), new Date(2010, 0, 3)]); + dateDimension.filter([makeDate(2010, 0, 1), makeDate(2010, 0, 3)]); chart.redraw(); - dateDimension.filter([new Date(2012, 0, 1), new Date(2012, 11, 30)]); + dateDimension.filter([makeDate(2012, 0, 1), makeDate(2012, 11, 30)]); chart.redraw(); }); it('pie chart should be restored', function() { diff --git a/spec/row-chart-spec.js b/spec/row-chart-spec.js index 828bd8670..5faadffdf 100644 --- a/spec/row-chart-spec.js +++ b/spec/row-chart-spec.js @@ -244,9 +244,9 @@ describe('dc.rowChart', function() { describe('redrawing after an empty selection', function () { beforeEach(function () { chart.render(); - dimension.filter([new Date("2010/1/1"), new Date("2010/1/3")]); + dimension.filter([makeDate(2010, 0, 1), makeDate(2010, 0, 3)]); chart.redraw(); - dimension.filter([new Date("2012/1/1"), new Date("2012/12/30")]); + dimension.filter([makeDate(2012, 0, 1), makeDate(2012, 11, 30)]); chart.redraw(); }); diff --git a/spec/scatter-plot-spec.js b/spec/scatter-plot-spec.js index 389146b9e..077a8e796 100644 --- a/spec/scatter-plot-spec.js +++ b/spec/scatter-plot-spec.js @@ -184,7 +184,7 @@ describe('dc.scatterPlot', function() { compositeChart = dc.compositeChart("#" + id); compositeChart .dimension(dimension) - .x(d3.time.scale().domain([new Date(2012, 0, 1), new Date(2012, 11, 31)])) + .x(d3.time.scale.utc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)])) .transitionDuration(0) .legend(dc.legend()) .compose([ diff --git a/spec/utils-spec.js b/spec/utils-spec.js index 36e72ca56..452c823bc 100644 --- a/spec/utils-spec.js +++ b/spec/utils-spec.js @@ -19,12 +19,13 @@ describe('dc utils', function() { var printer; beforeEach(function() { printer = dc.printers.filter; + dc.dateFormat = d3.time.format.utc("%m/%d/%Y"); }); it('print simple string', function() { expect(printer("a")).toEqual("a"); }); it('print date string', function() { - expect(printer(new Date(2012, 1, 1))).toEqual("02/01/2012"); + expect(printer(makeDate(2012, 1, 1))).toEqual("02/01/2012"); }); it('print int range', function() { expect(printer([10, 30])).toEqual("[10 -> 30]"); @@ -33,10 +34,10 @@ describe('dc utils', function() { expect(printer([10.124244, 30.635623])).toEqual("[10.12 -> 30.64]"); }); it('print date range', function() { - expect(printer([new Date(2012, 1, 1), new Date(2012, 1, 15)])).toEqual("[02/01/2012 -> 02/15/2012]"); + expect(printer([makeDate(2012, 1, 1), makeDate(2012, 1, 15)])).toEqual("[02/01/2012 -> 02/15/2012]"); }); it('print single element array', function() { - expect(printer([new Date(2012, 1, 1)])).toEqual("02/01/2012"); + expect(printer([makeDate(2012, 1, 1)])).toEqual("02/01/2012"); }); it('print null', function() { expect(printer(null)).toEqual(""); @@ -55,8 +56,8 @@ describe('dc utils', function() { add = dc.utils.add; }); it('should be able to add days', function() { - var date = add(new Date(2012, 0, 1), 10); - expect(date.toString()).toEqual((new Date(2012, 0, 11)).toString()); + var date = add(makeDate(2012, 0, 1), 10); + expect(date.toString()).toEqual((makeDate(2012, 0, 11)).toString()); }); it('should be able to add numbers', function() { var num = add(10, 10); @@ -71,8 +72,8 @@ describe('dc utils', function() { expect(num).toEqual(-9); }); it('should ignore % when adding dates', function() { - var date = add(new Date(2012, 0, 1), "10%"); - expect(date.toString()).toEqual(new Date(2012, 0, 11).toString()); + var date = add(makeDate(2012, 0, 1), "10%"); + expect(date.toString()).toEqual(makeDate(2012, 0, 11).toString()); }); }); describe('dc.utils.subtract', function() { @@ -81,8 +82,8 @@ describe('dc utils', function() { subtract = dc.utils.subtract; }); it('should be able to subtract dates', function() { - var date = subtract(new Date(2012, 0, 11), 10); - expect(date.toString()).toEqual((new Date(2012, 0, 1)).toString()); + var date = subtract(makeDate(2012, 0, 11), 10); + expect(date.toString()).toEqual((makeDate(2012, 0, 1)).toString()); }); it('should be able to subtract numbers', function() { var num = subtract(10, 10); @@ -97,8 +98,8 @@ describe('dc utils', function() { expect(num).toEqual(-11); }); it('should ignore % when subtracting dates', function() { - var date = subtract(new Date(2012, 0, 11), "10%"); - expect(date.toString()).toEqual(new Date(2012, 0, 1).toString()); + var date = subtract(makeDate(2012, 0, 11), "10%"); + expect(date.toString()).toEqual(makeDate(2012, 0, 1).toString()); }); }); }); diff --git a/web/docs/stock.html b/web/docs/stock.html index 701f332d7..77415ca13 100644 --- a/web/docs/stock.html +++ b/web/docs/stock.html @@ -156,19 +156,19 @@
.turnOnControls()

Load your data

Data can be loaded through regular means with your favorite javascript library

-
d3.csv("data.csv", function(data) {...};
-d3.json("data.json", function(data) {...};
-jQuery.getJson("data.json", function(data){...});
+
d3.csv("data.csv", function(data) {...};
+d3.json("data.json", function(data) {...};
+jQuery.getJson("data.json", function(data){...});
 
-
d3.csv("ndx.csv", function (data) {
+            
d3.csv("ndx.csv", function (data) {
     /* since its a csv file we need to format the data a bit */
     var dateFormat = d3.time.format("%m/%d/%Y");
     var numberFormat = d3.format(".2f");
 
-    data.forEach(function (d) {
+    data.forEach(function (d) {
         d.dd = dateFormat.parse(d.date);
         d.month = d3.time.month(d.dd); // pre-calculate month for better performance
         d.close = +d.close; // coerce to number
@@ -205,7 +205,7 @@ 

Create Crossfilter Dimensions

-
    var yearlyDimension = ndx.dimension(function (d) {
+            
    var yearlyDimension = ndx.dimension(function (d) {
         return d3.time.year(d.dd).getFullYear();
     });
@@ -224,7 +224,7 @@

Create Crossfilter Dimensions
    var yearlyPerformanceGroup = yearlyDimension.group().reduce(
         /* callback for when data is added to the current filter results */
-        function (p, v) {
+        function (p, v) {
             ++p.count;
             p.absGain += v.close - v.open;
             p.fluctuation += Math.abs(v.close - v.open);
@@ -235,7 +235,7 @@ 

Create Crossfilter Dimensions return p; }, /* callback for when data is removed from the current filter results */ - function (p, v) { + function (p, v) { --p.count; p.absGain -= v.close - v.open; p.fluctuation -= Math.abs(v.close - v.open); @@ -246,7 +246,7 @@

Create Crossfilter Dimensions return p; }, /* initialize p */ - function () { + function () { return {count: 0, absGain: 0, fluctuation: 0, fluctuationPercentage: 0, sumIndex: 0, avgIndex: 0, percentageGain: 0}; } );

@@ -264,7 +264,7 @@

Create Crossfilter Dimensions

-
    var dateDimension = ndx.dimension(function (d) {
+            
    var dateDimension = ndx.dimension(function (d) {
         return d.dd;
     });
@@ -281,7 +281,7 @@

Create Crossfilter Dimensions

-
    var moveMonths = ndx.dimension(function (d) {
+            
    var moveMonths = ndx.dimension(function (d) {
         return d.month;
     });
@@ -298,7 +298,7 @@

Create Crossfilter Dimensions

-
    var monthlyMoveGroup = moveMonths.group().reduceSum(function (d) {
+            
    var monthlyMoveGroup = moveMonths.group().reduceSum(function (d) {
         return Math.abs(d.close - d.open);
     });
@@ -315,23 +315,23 @@

Create Crossfilter Dimensions

-
    var volumeByMonthGroup = moveMonths.group().reduceSum(function (d) {
+            
    var volumeByMonthGroup = moveMonths.group().reduceSum(function (d) {
         return d.volume / 500000;
     });
     var indexAvgByMonthGroup = moveMonths.group().reduce(
-        function (p, v) {
+        function (p, v) {
             ++p.days;
             p.total += (v.open + v.close) / 2;
             p.avg = Math.round(p.total / p.days);
             return p;
         },
-        function (p, v) {
+        function (p, v) {
             --p.days;
             p.total -= (v.open + v.close) / 2;
             p.avg = p.days ? Math.round(p.total / p.days) : 0;
             return p;
         },
-        function () {
+        function () {
             return {days: 0, total: 0, avg: 0};
         }
     );
@@ -349,7 +349,7 @@

Create Crossfilter Dimensions

-
    var gainOrLoss = ndx.dimension(function (d) {
+            
    var gainOrLoss = ndx.dimension(function (d) {
         return d.open > d.close ? "Loss" : "Gain";
     });
@@ -381,7 +381,7 @@

Create Crossfilter Dimensions

-
    var fluctuation = ndx.dimension(function (d) {
+            
    var fluctuation = ndx.dimension(function (d) {
         return Math.round((d.close - d.open) / d.open * 100);
     });
     var fluctuationGroup = fluctuation.group();
@@ -399,7 +399,7 @@

Create Crossfilter Dimensions

-
    var quarter = ndx.dimension(function (d) {
+            
    var quarter = ndx.dimension(function (d) {
         var month = d.dd.getMonth();
         if (month <= 2)
             return "Q1";
@@ -410,7 +410,7 @@ 

Create Crossfilter Dimensions else return "Q4"; }); - var quarterGroup = quarter.group().reduceSum(function (d) { + var quarterGroup = quarter.group().reduceSum(function (d) { return d.volume; });

@@ -427,7 +427,7 @@

Create Crossfilter Dimensions

-
    var dayOfWeek = ndx.dimension(function (d) {
+            
    var dayOfWeek = ndx.dimension(function (d) {
         var day = d.dd.getDay();
         var name=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
         return day+"."+name[day];
@@ -511,16 +511,16 @@ 
Accessors
-
        .colorAccessor(function (d) {
+            
        .colorAccessor(function (d) {
             return d.value.absGain;
         })
-        .keyAccessor(function (p) {
+        .keyAccessor(function (p) {
             return p.value.absGain;
         })
-        .valueAccessor(function (p) {
+        .valueAccessor(function (p) {
             return p.value.percentageGain;
         })
-        .radiusValueAccessor(function (p) {
+        .radiusValueAccessor(function (p) {
             return p.value.fluctuationPercentage;
         })
         .maxBubbleRelativeSize(0.3)
@@ -567,11 +567,11 @@ 

Labels and Titles

        .renderLabel(true) // (optional) whether chart should render labels, :default = true
-        .label(function (p) {
+        .label(function (p) {
             return p.key;
         })
         .renderTitle(true) // (optional) whether chart should render titles, :default = false
-        .title(function (p) {
+        .title(function (p) {
             return [p.key,
                    "Index Gain: " + numberFormat(p.value.absGain),
                    "Index Gain in Percentage: " + numberFormat(p.value.percentageGain) + "%",
@@ -593,7 +593,7 @@ 

Customize Axis

-
        .yAxis().tickFormat(function (v) {
+            
        .yAxis().tickFormat(function (v) {
             return v + "%";
         });
@@ -623,7 +623,7 @@

Pie/Donut Chart

.group(gainOrLossGroup) // set group /* (optional) by default pie chart will use group.key as its label * but you can overwrite it with a closure */ - .label(function (d) { + .label(function (d) { if (gainOrLossChart.hasFilter() && !gainOrLossChart.hasFilter(d.key)) return d.key + "(0%)"; var label = d.key; @@ -764,7 +764,7 @@

Row Chart

        .ordinalColors(['#3182bd', '#6baed6', '#9ecae1', '#c6dbef', '#dadaeb'])
-        .label(function (d) {
+        .label(function (d) {
             return d.key.split(".")[1];
         })
@@ -781,7 +781,7 @@

Row Chart

-
        .title(function (d) {
+            
        .title(function (d) {
             return d.value;
         })
         .elasticX(true)
@@ -873,7 +873,7 @@ 

Bar Chart

-
        .filterPrinter(function (filters) {
+            
        .filterPrinter(function (filters) {
             var filter = filters[0], s = "";
             s += numberFormat(filter[0]) + "% -> " + numberFormat(filter[1]) + "%";
             return s;
@@ -893,7 +893,7 @@ 

Bar Chart

    fluctuationChart.xAxis().tickFormat(
-        function (v) { return v + "%"; });
+        function (v) { return v + "%"; });
     fluctuationChart.yAxis().ticks(5);
@@ -956,7 +956,7 @@

Stacked Area Chart

        .group(indexAvgByMonthGroup, "Monthly Index Average")
-        .valueAccessor(function (d) {
+        .valueAccessor(function (d) {
             return d.value.avg;
         })
@@ -974,7 +974,7 @@

Stacked Area Chart

-
        .stack(monthlyMoveGroup, "Monthly Index Move", function (d) {
+            
        .stack(monthlyMoveGroup, "Monthly Index Move", function (d) {
             return d.value;
         })
@@ -991,7 +991,7 @@

Stacked Area Chart

-
        .title(function (d) {
+            
        .title(function (d) {
             var value = d.value.avg ? d.value.avg : d.value;
             if (isNaN(value)) value = 0;
             return dateFormat(d.key) + "\n" + numberFormat(value);
@@ -1109,7 +1109,7 @@ 

Data Table

-
        .group(function (d) {
+            
        .group(function (d) {
             var format = d3.format("02d");
             return d.dd.getFullYear() + "/" + format((d.dd.getMonth() + 1));
         })
@@ -1129,19 +1129,19 @@ 

Data Table

        .columns([
-            function (d) {
+            function (d) {
                 return d.date;
             },
-            function (d) {
+            function (d) {
                 return numberFormat(d.open);
             },
-            function (d) {
+            function (d) {
                 return numberFormat(d.close);
             },
-            function (d) {
+            function (d) {
                 return numberFormat(d.close - d.open);
             },
-            function (d) {
+            function (d) {
                 return d.volume;
             }
         ])
@@ -1159,7 +1159,7 @@

Data Table

-
        .sortBy(function (d) {
+            
        .sortBy(function (d) {
             return d.dd;
         })
@@ -1191,7 +1191,7 @@

Data Table

-
        .renderlet(function (table) {
+            
        .renderlet(function (table) {
             table.selectAll(".dc-table-group").classed("info", true);
         });
 
@@ -1265,7 +1265,7 @@ 

Geo Choropleth Chart

-
        .colorAccessor(function(d, i){return d.value;})
+
        .colorAccessor(function(d, i){return d.value;})
@@ -1287,7 +1287,7 @@

Geo Choropleth Chart

-
        .overlayGeoJson(statesJson.features, "state", function(d) {
+            
        .overlayGeoJson(statesJson.features, "state", function(d) {
             return d.properties.name;
         })
@@ -1304,7 +1304,7 @@

Geo Choropleth Chart

-
        .title(function(d) {
+            
        .title(function(d) {
             return "State: " + d.key + "\nTotal Amount Raised: " + numberFormat(d.value ? d.value : 0) + "M";
         });
@@ -1361,7 +1361,7 @@

Bubble Overlay Chart

-
            .keyAccessor(function(p) {return p.value.absGain;})
+
            .keyAccessor(function(p) {return p.value.absGain;})
@@ -1376,7 +1376,7 @@

Bubble Overlay Chart

-
            .valueAccessor(function(p) {return p.value.percentageGain;})
+
            .valueAccessor(function(p) {return p.value.percentageGain;})
@@ -1421,7 +1421,7 @@

Bubble Overlay Chart

-
            .colorAccessor(function(d, i){return d.value;})
+
            .colorAccessor(function(d, i){return d.value;})
@@ -1436,7 +1436,7 @@

Bubble Overlay Chart

-
            .radiusValueAccessor(function(p) {return p.value.fluctuationPercentage;})
+
            .radiusValueAccessor(function(p) {return p.value.fluctuationPercentage;})
@@ -1481,7 +1481,7 @@

Bubble Overlay Chart

-
            .label(function(p) {return p.key.getFullYear();})
+
            .label(function(p) {return p.key.getFullYear();})
@@ -1511,7 +1511,7 @@

Bubble Overlay Chart

-
            .title(function(d) {
+            
            .title(function(d) {
                 return "Title: " + d.key;
             })
diff --git a/web/js/d3.js b/web/js/d3.js index 95b9361e3..82287776f 100644 --- a/web/js/d3.js +++ b/web/js/d3.js @@ -1,6 +1,6 @@ !function() { var d3 = { - version: "3.4.9" + version: "3.4.11" }; if (!Date.now) Date.now = function() { return +new Date(); @@ -1227,9 +1227,9 @@ x: 0, y: 0, k: 1 - }, translate0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1; + }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1; function zoom(g) { - g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted); + g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted); } zoom.event = function(g) { g.each(function() { @@ -1371,7 +1371,7 @@ zoomed(dispatch); } function ended() { - subject.on(mousemove, d3_window === that ? mousewheelreset : null).on(mouseup, null); + subject.on(mousemove, null).on(mouseup, null); dragRestore(dragged && d3.event.target === target); zoomended(dispatch); } @@ -1449,22 +1449,17 @@ } function mousewheeled() { var dispatch = event.of(this, arguments); - if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this), - zoomstarted(dispatch); + if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)), + d3_selection_interrupt.call(this), zoomstarted(dispatch); mousewheelTimer = setTimeout(function() { mousewheelTimer = null; zoomended(dispatch); }, 50); d3_eventPreventDefault(); - var point = center || d3.mouse(this); - if (!translate0) translate0 = location(point); scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k); - translateTo(point, translate0); + translateTo(center0, translate0); zoomed(dispatch); } - function mousewheelreset() { - translate0 = null; - } function dblclicked() { var dispatch = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2; zoomstarted(dispatch); @@ -4685,13 +4680,13 @@ (d3.geo.transverseMercator = function() { var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate; projection.center = function(_) { - return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ -_[1], _[0] ]); + return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]); }; projection.rotate = function(_) { return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(), [ _[0], _[1], _[2] - 90 ]); }; - return projection.rotate([ 0, 0 ]); + return rotate([ 0, 0, 90 ]); }).raw = d3_geo_transverseMercator; d3.geom = {}; function d3_geom_pointX(d) { @@ -9233,11 +9228,6 @@ d3.xml = d3_xhrType(function(request) { return request.responseXML; }); - if (typeof define === "function" && define.amd) { - define(d3); - } else if (typeof module === "object" && module.exports) { - module.exports = d3; - } else { - this.d3 = d3; - } + if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; + this.d3 = d3; }(); \ No newline at end of file