Skip to content

Commit 6e1b3bd

Browse files
authored
Merge pull request #3512 from VisActor/fix/data-zoom-filter
Fix/data zoom filter
2 parents 2fa2ea3 + 4896e66 commit 6e1b3bd

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "fix: fix filter of lock domain when field is array, related #3469\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vchart"
7+
}
8+
],
9+
"packageName": "@visactor/vchart",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "fix: fix size of datazoom when update, fix #3521\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vchart"
7+
}
8+
],
9+
"packageName": "@visactor/vchart",
10+
"email": "[email protected]"
11+
}

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,33 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
148148
defaultSize + this._startHandlerSize / 2
149149
];
150150

151+
const compWidth = this._computeWidth();
152+
const compHeight = this._computeHeight();
153+
151154
if (this._isHorizontal) {
152155
stateScaleRange = this._visible
153-
? [this._startHandlerSize / 2, this._computeWidth() - handlerSize + this._startHandlerSize / 2]
156+
? [this._startHandlerSize / 2, compWidth - handlerSize + this._startHandlerSize / 2]
154157
: defaultRange;
155158
this._stateScale.range(stateScaleRange);
156-
this._valueScale.range([this._computeHeight() - this._middleHandlerSize, 0]);
157-
} else if (this.layoutOrient === 'left') {
158-
stateScaleRange = this._visible
159-
? [this._startHandlerSize / 2, this._computeHeight() - handlerSize + this._startHandlerSize / 2]
160-
: defaultRange;
161-
this._stateScale.range(stateScaleRange);
162-
this._valueScale.range([this._computeWidth() - this._middleHandlerSize, 0]);
159+
this._valueScale.range([compHeight - this._middleHandlerSize, 0]);
163160
} else {
164161
stateScaleRange = this._visible
165-
? [this._startHandlerSize / 2, this._computeHeight() - handlerSize + this._startHandlerSize / 2]
162+
? [this._startHandlerSize / 2, compHeight - handlerSize + this._startHandlerSize / 2]
166163
: defaultRange;
164+
167165
this._stateScale.range(stateScaleRange);
168-
this._valueScale.range([0, this._computeWidth() - this._middleHandlerSize]);
166+
167+
if (this.layoutOrient === 'left') {
168+
this._valueScale.range([compWidth - this._middleHandlerSize, 0]);
169+
} else {
170+
this._valueScale.range([0, compWidth - this._middleHandlerSize]);
171+
}
169172
}
170173
if (this._component && this._cacheVisibility !== false) {
171174
this._component.setAttributes({
172175
size: {
173-
width: this._computeWidth(),
174-
height: this._computeHeight()
176+
width: compWidth,
177+
height: compHeight
175178
},
176179
position: {
177180
x: this.getLayoutStartPoint().x,
@@ -226,7 +229,7 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
226229
if (this._isHorizontal) {
227230
return this._backgroundSize + this._middleHandlerSize;
228231
}
229-
return this.getLayoutRect().height - (this._startHandlerSize + this._endHandlerSize) / 2;
232+
return this.getLayoutRect().height;
230233
}
231234

232235
protected _isScaleValid(scale: IBaseScale | ILinearScale) {
@@ -287,8 +290,8 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
287290
},
288291
orient: this._orient,
289292
size: {
290-
width: this.getLayoutRect().width,
291-
height: this.getLayoutRect().height
293+
width: this._computeWidth(),
294+
height: this._computeHeight()
292295
},
293296
showDetail: spec.showDetail,
294297
brushSelect: spec.brushSelect ?? false,
@@ -313,6 +316,7 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
313316
const isNeedPreview =
314317
this._isScaleValid(xScale) && this._isScaleValid(yScale) && this._spec.showBackgroundChart !== false;
315318
const attrs = this._getAttrs(isNeedPreview);
319+
316320
if (this._component) {
317321
this._component.setAttributes(attrs);
318322
} else {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { last } from '@visactor/vutils';
1+
import { isArray, last } from '@visactor/vutils';
22
import { array, isNil } from '../../util';
33
import type { DataView } from '@visactor/vdataset';
44

@@ -22,15 +22,16 @@ export const lockStatisticsFilter = (
2222
return statisticsData;
2323
}
2424
const fields = originalFields();
25+
const realField = isArray(datumField) ? datumField[0] : datumField;
2526

2627
if (
27-
statisticsData[datumField] &&
28+
statisticsData[realField] &&
2829
fields &&
29-
fields[datumField] &&
30-
fields[datumField].lockStatisticsByDomain &&
30+
fields[realField] &&
31+
fields[realField].lockStatisticsByDomain &&
3132
!isContinuous()
3233
) {
33-
statisticsData[datumField].values = newDomain;
34+
statisticsData[realField].values = newDomain;
3435
}
3536

3637
return statisticsData;

0 commit comments

Comments
 (0)