From a76000a5d31a8d03258a6ec09a50746eb3741ec4 Mon Sep 17 00:00:00 2001 From: Jae Sung Park Date: Fri, 11 Jan 2019 17:00:21 +0900 Subject: [PATCH] fix(line): Correct zoom with data.regions Correct the condition on getting x scale. It was set the condition in opposite way. Fix #728 Close #729 --- spec/interactions/zoom-spec.js | 18 +++++++++++++++--- src/shape/line.js | 9 ++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/spec/interactions/zoom-spec.js b/spec/interactions/zoom-spec.js index 4bc9236a0..52d5935c5 100644 --- a/spec/interactions/zoom-spec.js +++ b/spec/interactions/zoom-spec.js @@ -221,7 +221,6 @@ describe("ZOOM", function() { onclick: d => { clickedData = d; } - }, zoom: { enabled: { @@ -350,7 +349,16 @@ describe("ZOOM", function() { data: { columns: [ ["sample", 30, 200, 100, 400, 150, 250] - ] + ], + regions: { + sample: [{ + start: 1, + end: 2, + style: { + dasharray: "5 2" + } + }] + } }, regions: [ { @@ -362,7 +370,10 @@ describe("ZOOM", function() { }); it("region area should be resized on zoom", done => { - const regionRect = chart.$.main.select(`.${CLASS.region}-0 rect`); + const main = chart.$.main; + const regionRect = main.select(`.${CLASS.region}-0 rect`); + const lineWidth = chart.$.line.lines.node().getBBox().width; + const size = { width: +regionRect.attr("width"), x: +regionRect.attr("x") @@ -374,6 +385,7 @@ describe("ZOOM", function() { setTimeout(() => { expect(+regionRect.attr("width")).to.be.above(size.width); expect(+regionRect.attr("x")).to.be.below(size.x); + expect(+chart.$.line.lines.node().getBBox().width).to.be.above(lineWidth); done(); }, 500); diff --git a/src/shape/line.js b/src/shape/line.js index 1f0785a09..e3627c62d 100644 --- a/src/shape/line.js +++ b/src/shape/line.js @@ -167,8 +167,9 @@ extend(ChartInternal.prototype, { line = line.defined(d => $$.getBaseValue(d) !== null); } + const x = isSub ? $$.subX : $$.x; + return d => { - const x = isSub ? $$.x : $$.subX; const y = yScaleGetter.call($$, d.id); let values = lineConnectNull ? $$.filterRemoveNull(d.values) : d.values; let x0 = 0; @@ -176,8 +177,10 @@ extend(ChartInternal.prototype, { let path; if ($$.isLineType(d)) { - if (config.data_regions[d.id]) { - path = $$.lineWithRegions(values, x, y, config.data_regions[d.id]); + const regions = config.data_regions[d.id]; + + if (regions) { + path = $$.lineWithRegions(values, x, y, regions); } else { if ($$.isStepType(d)) { values = $$.convertValuesToStep(values);