Skip to content

Commit 61eeb94

Browse files
authored
Merge pull request #20082 from apache/feat-dataZoom-label-show
feat(dataZoom): new option handleLabelShow
2 parents b6905aa + c3ce6e0 commit 61eeb94

File tree

3 files changed

+258
-8
lines changed

3 files changed

+258
-8
lines changed

src/component/dataZoom/SliderZoomModel.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import {
2828
} from '../../util/types';
2929
import { inheritDefaultOption } from '../../util/component';
3030

31+
interface SliderHandleLabelOption {
32+
show?: boolean
33+
}
34+
3135
export interface SliderDataZoomOption extends DataZoomOption, BoxLayoutOptionMixin {
3236

3337
show?: boolean
@@ -79,6 +83,8 @@ export interface SliderDataZoomOption extends DataZoomOption, BoxLayoutOptionMix
7983

8084
handleIcon?: string
8185

86+
handleLabel?: SliderHandleLabelOption
87+
8288
/**
8389
* number: height of icon. width will be calculated according to the aspect of icon.
8490
* string: percent of the slider height. width will be calculated according to the aspect of icon.
@@ -117,6 +123,7 @@ export interface SliderDataZoomOption extends DataZoomOption, BoxLayoutOptionMix
117123
brushStyle?: ItemStyleOption
118124

119125
emphasis?: {
126+
handleLabel: SliderHandleLabelOption
120127
handleStyle?: ItemStyleOption
121128
moveHandleStyle?: ItemStyleOption
122129
}
@@ -201,6 +208,9 @@ class SliderZoomModel extends DataZoomModel<SliderDataZoomOption> {
201208
},
202209

203210
emphasis: {
211+
handleLabel: {
212+
show: true
213+
},
204214
handleStyle: {
205215
borderColor: '#8FB0F7'
206216
},

src/component/dataZoom/SliderZoomView.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,13 @@ class SliderZoomView extends DataZoomView {
619619
sliderGroup.add(handles[handleIndex] = path);
620620

621621
const textStyleModel = dataZoomModel.getModel('textStyle');
622+
const handleLabel = dataZoomModel.get('handleLabel') || {};
623+
const handleLabelShow = handleLabel.show || false;
622624

623625
thisGroup.add(
624626
handleLabels[handleIndex] = new graphic.Text({
625627
silent: true,
626-
invisible: true,
628+
invisible: !handleLabelShow,
627629
style: createTextStyle(textStyleModel, {
628630
x: 0, y: 0, text: '',
629631
verticalAlign: 'middle',
@@ -885,19 +887,25 @@ class SliderZoomView extends DataZoomView {
885887
}
886888

887889
/**
888-
* @param showOrHide true: show, false: hide
890+
* @param isEmphasis true: show, false: hide
889891
*/
890-
private _showDataInfo(showOrHide?: boolean) {
891-
// Always show when drgging.
892-
showOrHide = this._dragging || showOrHide;
892+
private _showDataInfo(isEmphasis?: boolean) {
893+
const handleLabel = this.dataZoomModel.get('handleLabel') || {};
894+
const normalShow = handleLabel.show || false;
895+
const emphasisHandleLabel = this.dataZoomModel.getModel(['emphasis', 'handleLabel']);
896+
const emphasisShow = emphasisHandleLabel.get('show') || false;
897+
// Dragging is considered as emphasis, unless emphasisShow is false
898+
const toShow = (isEmphasis || this._dragging)
899+
? emphasisShow
900+
: normalShow;
893901
const displayables = this._displayables;
894902
const handleLabels = displayables.handleLabels;
895-
handleLabels[0].attr('invisible', !showOrHide);
896-
handleLabels[1].attr('invisible', !showOrHide);
903+
handleLabels[0].attr('invisible', !toShow);
904+
handleLabels[1].attr('invisible', !toShow);
897905

898906
// Highlight move handle
899907
displayables.moveHandle
900-
&& this.api[showOrHide ? 'enterEmphasis' : 'leaveEmphasis'](displayables.moveHandle, 1);
908+
&& this.api[toShow ? 'enterEmphasis' : 'leaveEmphasis'](displayables.moveHandle, 1);
901909
}
902910

903911
private _onDragMove(handleIndex: 0 | 1 | 'all', dx: number, dy: number, event: ZRElementEvent) {

test/dataZoom-handleLabelShow.html

Lines changed: 232 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)