Skip to content

Commit

Permalink
fix(shape, api.zoom): fix zoom for barchart
Browse files Browse the repository at this point in the history
Fix not zooming on other than line type

Ref #16 
Close #32
  • Loading branch information
sculove authored and netil committed Jun 22, 2017
1 parent f09d2ed commit 917384f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
35 changes: 34 additions & 1 deletion spec/api.zoom-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion src/api/api.zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/internals/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 917384f

Please sign in to comment.