Skip to content

Commit ada9997

Browse files
committed
feat: add params of startvalue and endvalue in brushend event
1 parent 5b3ee7a commit ada9997

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

docs/assets/api/en/API/event.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,14 @@ The event parameters are as follows:
380380
/** In linked series: vgrammar elements outside the marquee */
381381
linkedOutOfBrushElementsMap: { [elementKey: string]: IElement };
382382
/** record of axis and datazoom change */
383-
zoomRecord: { operateComponent: AxisComponent | DataZoom; start: number; end: number }[];
383+
zoomRecord: {
384+
operateComponent: AxisComponent | DataZoom;
385+
start: number;
386+
end: number;
387+
/** since 1.13.5+ version */
388+
startValue: number | string;
389+
endValue: number | string;
390+
}[];
384391
}
385392
}
386393
```

docs/assets/api/zh/API/event.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,14 @@ Brush 清除选框事件。
380380
/** 被链接的系列中:在选框外的 vgrammar elements */
381381
linkedOutOfBrushElementsMap: { [elementKey: string]: IElement };
382382
/** 轴/dataZoom的缩放操作记录 */
383-
zoomRecord: { operateComponent: AxisComponent | DataZoom; start: number; end: number }[];
383+
zoomRecord: {
384+
operateComponent: AxisComponent | DataZoom;
385+
start: number;
386+
end: number;
387+
/** 1.13.5以上版本支持 */
388+
startValue: number | string;
389+
endValue: number | string;
390+
}[];
384391
}
385392
}
386393
```

packages/vchart/src/component/brush/brush.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ export class Brush<T extends IBrushSpec = IBrushSpec> extends BaseComponent<T> i
6565
// 根据axis找dataZoom
6666
private _axisDataZoomMap: { [axisId: string]: DataZoom } = {};
6767
// 记录当前操作的axis或dataZoom的状态
68-
private _zoomRecord: { operateComponent: AxisComponent | DataZoom; start: number; end: number }[] = [];
68+
private _zoomRecord: {
69+
operateComponent: AxisComponent | DataZoom;
70+
start: number;
71+
end: number;
72+
startValue: number | string;
73+
endValue: number | string;
74+
}[] = [];
6975

7076
init() {
7177
const inBrushMarkAttr = this._transformBrushedMarkAttr(this._spec.inBrush);
@@ -516,7 +522,9 @@ export class Brush<T extends IBrushSpec = IBrushSpec> extends BaseComponent<T> i
516522
this._zoomRecord.push({
517523
operateComponent: dataZoom,
518524
start: newStartPercent,
519-
end: newEndPercent
525+
end: newEndPercent,
526+
startValue: dataZoom.statePointToData(newStartPercent),
527+
endValue: dataZoom.statePointToData(newEndPercent)
520528
});
521529
} else {
522530
const range = axis.getScale().range();
@@ -542,7 +550,9 @@ export class Brush<T extends IBrushSpec = IBrushSpec> extends BaseComponent<T> i
542550
this._zoomRecord.push({
543551
operateComponent: axis,
544552
start: newStart,
545-
end: newEnd
553+
end: newEnd,
554+
startValue: axis.getScale().invert(startPos),
555+
endValue: axis.getScale().invert(endPos)
546556
});
547557
}
548558
});

packages/vchart/src/component/data-zoom/data-filter-base-component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
581581
this._visible = this._spec.visible ?? true;
582582
}
583583

584-
protected _statePointToData(state: number) {
584+
statePointToData(state: number) {
585585
const scale = this._stateScale;
586586
const domain = scale.domain();
587587

@@ -644,8 +644,8 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
644644
: 0;
645645
end = this._spec.end ? this._spec.end : this._spec.endValue ? this.dataToStatePoint(this._spec.endValue) : 1;
646646
}
647-
this._startValue = this._statePointToData(start);
648-
this._endValue = this._statePointToData(end);
647+
this._startValue = this.statePointToData(start);
648+
this._endValue = this.statePointToData(end);
649649
this._start = start;
650650
this._end = end;
651651
this._minSpan = this._spec.minSpan ?? 0;

packages/vchart/src/component/data-zoom/data-zoom/data-zoom.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
328328
} else {
329329
isNeedPreview && this._component.setPreviewPointsX1(this._dataToPositionX2);
330330
}
331-
this._component.setStatePointToData((state: number) => this._statePointToData(state));
331+
this._component.setStatePointToData((state: number) => this.statePointToData(state));
332332

333333
this._component.addEventListener('change', (e: any) => {
334334
const { start, end, tag } = e.detail;
@@ -351,8 +351,8 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
351351

352352
this._start = start;
353353
this._end = end;
354-
const startValue = this._statePointToData(start);
355-
const endValue = this._statePointToData(end);
354+
const startValue = this.statePointToData(start);
355+
const endValue = this.statePointToData(end);
356356
const hasChange = isFunction(this._spec.updateDataAfterChange)
357357
? this._spec.updateDataAfterChange(start, end, startValue, endValue)
358358
: this._handleStateChange(startValue, endValue, tag);

packages/vchart/src/component/data-zoom/scroll-bar/scroll-bar.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ export class ScrollBar<T extends IScrollBarSpec = IScrollBarSpec> extends DataFi
136136

137137
this._start = start;
138138
this._end = end;
139-
const startValue = this._statePointToData(start);
140-
const endValue = this._statePointToData(end);
139+
const startValue = this.statePointToData(start);
140+
const endValue = this.statePointToData(end);
141141
const hasChange = isFunction(this._spec.updateDataAfterChange)
142142
? this._spec.updateDataAfterChange(start, end, startValue, endValue)
143-
: this._handleStateChange(this._statePointToData(start), this._statePointToData(end));
143+
: this._handleStateChange(this.statePointToData(start), this.statePointToData(end));
144144
if (hasChange) {
145145
this.event.emit(ChartEvent.scrollBarChange, {
146146
model: this,

0 commit comments

Comments
 (0)