Skip to content

Commit 48736c1

Browse files
authored
Merge pull request #1980 from VisActor/fix/fix-issue-of-datazoom
Fix/fix issue of datazoom
2 parents 6564180 + 5562c28 commit 48736c1

File tree

3 files changed

+162
-116
lines changed

3 files changed

+162
-116
lines changed

packages/vrender-components/src/data-zoom/data-zoom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ export class DataZoom extends AbstractComponent<Required<DataZoomAttributes>> {
177177

178178
setAttributes(params: Partial<Required<DataZoomAttributes>>, forceUpdateTag?: boolean): void {
179179
const { start, end } = this.attribute as DataZoomAttributes;
180-
start && (this._state.start = start);
181-
end && (this._state.end = end);
180+
start && (this._state.start = params.start ?? start);
181+
end && (this._state.end = params.end ?? end);
182182

183183
this._renderer.setAttributes(this._getRendererAttrs());
184184
this._interaction.setAttributes(this._getInteractionAttrs());

packages/vrender-components/src/data-zoom/renderer.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class DataZoomRenderer {
230230
height,
231231
cursor: brushSelect ? 'crosshair' : 'auto',
232232
...backgroundStyle,
233-
pickable: zoomLock ? false : (backgroundStyle.pickable ?? true)
233+
pickable: zoomLock ? false : backgroundStyle.pickable ?? true
234234
},
235235
'rect'
236236
) as IRect;
@@ -264,7 +264,7 @@ export class DataZoomRenderer {
264264
width: (end - start) * width,
265265
height: middleHandlerBackgroundSize,
266266
...middleHandlerStyle.background?.style,
267-
pickable: zoomLock ? false : (middleHandlerStyle.background?.style?.pickable ?? true)
267+
pickable: zoomLock ? false : middleHandlerStyle.background?.style?.pickable ?? true
268268
},
269269
'rect'
270270
) as IRect;
@@ -277,7 +277,7 @@ export class DataZoomRenderer {
277277
angle: 0,
278278
symbolType: middleHandlerStyle.icon?.symbolType ?? 'square',
279279
...middleHandlerStyle.icon,
280-
pickable: zoomLock ? false : (middleHandlerStyle.icon.pickable ?? true)
280+
pickable: zoomLock ? false : middleHandlerStyle.icon.pickable ?? true
281281
},
282282
'symbol'
283283
) as ISymbol;
@@ -291,7 +291,7 @@ export class DataZoomRenderer {
291291
symbolType: startHandlerStyle.symbolType ?? 'square',
292292
...(DEFAULT_HANDLER_ATTR_MAP.horizontal as any),
293293
...startHandlerStyle,
294-
pickable: zoomLock ? false : (startHandlerStyle.pickable ?? true)
294+
pickable: zoomLock ? false : startHandlerStyle.pickable ?? true
295295
},
296296
'symbol'
297297
) as ISymbol;
@@ -304,7 +304,7 @@ export class DataZoomRenderer {
304304
symbolType: endHandlerStyle.symbolType ?? 'square',
305305
...(DEFAULT_HANDLER_ATTR_MAP.horizontal as any),
306306
...endHandlerStyle,
307-
pickable: zoomLock ? false : (endHandlerStyle.pickable ?? true)
307+
pickable: zoomLock ? false : endHandlerStyle.pickable ?? true
308308
},
309309
'symbol'
310310
) as ISymbol;
@@ -357,7 +357,7 @@ export class DataZoomRenderer {
357357
width: middleHandlerBackgroundSize,
358358
height: (end - start) * height,
359359
...middleHandlerStyle.background?.style,
360-
pickable: zoomLock ? false : (middleHandlerStyle.background?.style?.pickable ?? true)
360+
pickable: zoomLock ? false : middleHandlerStyle.background?.style?.pickable ?? true
361361
},
362362
'rect'
363363
) as IRect;
@@ -374,7 +374,7 @@ export class DataZoomRenderer {
374374
symbolType: middleHandlerStyle.icon?.symbolType ?? 'square',
375375
strokeBoundsBuffer: 0,
376376
...middleHandlerStyle.icon,
377-
pickable: zoomLock ? false : (middleHandlerStyle.icon?.pickable ?? true)
377+
pickable: zoomLock ? false : middleHandlerStyle.icon?.pickable ?? true
378378
},
379379
'symbol'
380380
) as ISymbol;
@@ -388,7 +388,7 @@ export class DataZoomRenderer {
388388
symbolType: startHandlerStyle.symbolType ?? 'square',
389389
...(DEFAULT_HANDLER_ATTR_MAP.vertical as any),
390390
...startHandlerStyle,
391-
pickable: zoomLock ? false : (startHandlerStyle.pickable ?? true)
391+
pickable: zoomLock ? false : startHandlerStyle.pickable ?? true
392392
},
393393
'symbol'
394394
) as ISymbol;
@@ -402,7 +402,7 @@ export class DataZoomRenderer {
402402
symbolType: endHandlerStyle.symbolType ?? 'square',
403403
...(DEFAULT_HANDLER_ATTR_MAP.vertical as any),
404404
...endHandlerStyle,
405-
pickable: zoomLock ? false : (endHandlerStyle.pickable ?? true)
405+
pickable: zoomLock ? false : endHandlerStyle.pickable ?? true
406406
},
407407
'symbol'
408408
) as ISymbol;
@@ -472,7 +472,7 @@ export class DataZoomRenderer {
472472
height: height,
473473
cursor: brushSelect ? 'crosshair' : 'move',
474474
...selectedBackgroundStyle,
475-
pickable: zoomLock ? false : ((selectedBackgroundChartStyle as any).pickable ?? true)
475+
pickable: zoomLock ? false : (selectedBackgroundChartStyle as any).pickable ?? true
476476
},
477477
'rect'
478478
) as IRect;
@@ -487,7 +487,7 @@ export class DataZoomRenderer {
487487
height: (end - start) * height,
488488
cursor: brushSelect ? 'crosshair' : 'move',
489489
...selectedBackgroundStyle,
490-
pickable: zoomLock ? false : (selectedBackgroundStyle.pickable ?? true)
490+
pickable: zoomLock ? false : selectedBackgroundStyle.pickable ?? true
491491
},
492492
'rect'
493493
) as IRect;
@@ -592,8 +592,13 @@ export class DataZoomRenderer {
592592
});
593593
}
594594

595-
private _computeBasePoints() {
595+
private _computeBasePoints(points: IPointLike[]) {
596596
const { orient } = this.attribute as DataZoomAttributes;
597+
const key = orient === 'bottom' || orient === 'top' ? 'x' : 'y';
598+
let lastPointSide = Math.sign(points[points.length - 1][key] - points[0][key]);
599+
if (lastPointSide === 0) {
600+
lastPointSide = 1;
601+
}
597602
const { position, width, height } = this._getLayoutAttrFromConfig();
598603
let basePointStart: any;
599604
let basePointEnd: any;
@@ -637,6 +642,14 @@ export class DataZoomRenderer {
637642
}
638643
];
639644
}
645+
646+
if (Math.sign(basePointEnd[0][key] - basePointStart[0][key]) !== lastPointSide) {
647+
return {
648+
basePointStart: basePointEnd,
649+
basePointEnd: basePointStart
650+
};
651+
}
652+
640653
return {
641654
basePointStart,
642655
basePointEnd
@@ -668,7 +681,7 @@ export class DataZoomRenderer {
668681
// 采样
669682
previewPoints = this._simplifyPoints(previewPoints);
670683

671-
const { basePointStart, basePointEnd } = this._computeBasePoints();
684+
const { basePointStart, basePointEnd } = this._computeBasePoints(previewPoints);
672685
return basePointStart.concat(previewPoints).concat(basePointEnd);
673686
}
674687

@@ -689,7 +702,7 @@ export class DataZoomRenderer {
689702
// 采样
690703
previewPoints = this._simplifyPoints(previewPoints);
691704

692-
const { basePointStart, basePointEnd } = this._computeBasePoints();
705+
const { basePointStart, basePointEnd } = this._computeBasePoints(previewPoints);
693706
return basePointStart.concat(previewPoints).concat(basePointEnd);
694707
}
695708

0 commit comments

Comments
 (0)