From 917384f97115732bd2ce50d04a5f976730ab2ee4 Mon Sep 17 00:00:00 2001 From: Son Chan Uk Date: Thu, 22 Jun 2017 19:30:48 +0900 Subject: [PATCH] fix(shape, api.zoom): fix zoom for barchart Fix not zooming on other than line type Ref #16 Close #32 --- spec/api.zoom-spec.js | 35 ++++++++++++++++++++++++++++++++++- src/api/api.zoom.js | 3 ++- src/internals/shape.js | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/spec/api.zoom-spec.js b/spec/api.zoom-spec.js index ef202cd6b..070346bdd 100644 --- a/spec/api.zoom-spec.js +++ b/spec/api.zoom-spec.js @@ -13,7 +13,7 @@ describe("API zoom", function() { chart = util.initChart(chart, args, done); }); - describe("zoom", () => { + describe("zoom line chart", () => { it("should update args", () => { args = { @@ -108,6 +108,39 @@ describe("API zoom", function() { }); + describe("zoom bar chart", () => { + + it("should update args", () => { + args = { + data: { + columns: [ + ["data1", 30, 200, 100, 400, 150, 250], + ["data2", 50, 20, 10, 40, 15, 25], + ["data3", 150, 120, 110, 140, 115, 125] + ], + type: "bar" + }, + zoom: { + enabled: true + }, + }; + + expect(true).to.be.ok; + }); + + it("should be zoomed properly", (done) => { + const target = [3, 5]; + const bars = d3.select(".bb-chart-bars").node(); + const orgWidth = bars.getBoundingClientRect().width; + chart.zoom(target); + setTimeout(() => { + expect(bars.getBoundingClientRect().width/orgWidth).to.be.above(2.5); + done(); + }, 500) + }); + }); + + describe("unzoom", () => { it("should load indexed data", () => { args = { diff --git a/src/api/api.zoom.js b/src/api/api.zoom.js index 09d65d3bc..921c94c98 100644 --- a/src/api/api.zoom.js +++ b/src/api/api.zoom.js @@ -52,7 +52,8 @@ const zoom = function(domainValue) { $$.redraw({ withTransition: true, - withY: $$.config.zoom_rescale + withY: $$.config.zoom_rescale, + withDimension: false }); $$.config.zoom_onzoom.call(this, $$.x.orgDomain()); diff --git a/src/internals/shape.js b/src/internals/shape.js index 6686b9856..f45ecdf16 100644 --- a/src/internals/shape.js +++ b/src/internals/shape.js @@ -53,7 +53,7 @@ extend(ChartInternal.prototype, { getShapeX(offset, targetsNum, indices, isSub) { const $$ = this; - const scale = isSub ? $$.subX : $$.x; + const scale = isSub ? $$.subX : ($$.zoomScale ? $$.zoomScale : $$.x); return d => { const index = d.id in indices ? indices[d.id] : 0;