Skip to content

Commit

Permalink
fix(line): Correct zoom with data.regions
Browse files Browse the repository at this point in the history
Correct the condition on getting x scale.
It was set the condition in opposite way.

Fix #728
Close #729
  • Loading branch information
netil committed Jan 11, 2019
1 parent c3f5008 commit a76000a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
18 changes: 15 additions & 3 deletions spec/interactions/zoom-spec.js
Expand Up @@ -221,7 +221,6 @@ describe("ZOOM", function() {
onclick: d => {
clickedData = d;
}

},
zoom: {
enabled: {
Expand Down Expand Up @@ -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: [
{
Expand All @@ -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")
Expand All @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/shape/line.js
Expand Up @@ -167,17 +167,20 @@ 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;
let y0 = 0;
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);
Expand Down

0 comments on commit a76000a

Please sign in to comment.