Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/data zoom filter #3512

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix filter of lock domain when field is array, related #3469\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix size of datazoom when update, fix #3521\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "[email protected]"
}
34 changes: 19 additions & 15 deletions packages/vchart/src/component/data-zoom/data-zoom/data-zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,33 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
defaultSize + this._startHandlerSize / 2
];

const compWidth = this._computeWidth();
const compHeight = this._computeHeight();

if (this._isHorizontal) {
stateScaleRange = this._visible
? [this._startHandlerSize / 2, this._computeWidth() - handlerSize + this._startHandlerSize / 2]
? [this._startHandlerSize / 2, compWidth - handlerSize + this._startHandlerSize / 2]
: defaultRange;
this._stateScale.range(stateScaleRange);
this._valueScale.range([this._computeHeight() - this._middleHandlerSize, 0]);
} else if (this.layoutOrient === 'left') {
stateScaleRange = this._visible
? [this._startHandlerSize / 2, this._computeHeight() - handlerSize + this._startHandlerSize / 2]
: defaultRange;
this._stateScale.range(stateScaleRange);
this._valueScale.range([this._computeWidth() - this._middleHandlerSize, 0]);
this._valueScale.range([compHeight - this._middleHandlerSize, 0]);
} else {
stateScaleRange = this._visible
? [this._startHandlerSize / 2, this._computeHeight() - handlerSize + this._startHandlerSize / 2]
? [this._startHandlerSize / 2, compHeight - handlerSize + this._startHandlerSize / 2]
: defaultRange;

this._stateScale.range(stateScaleRange);
this._valueScale.range([0, this._computeWidth() - this._middleHandlerSize]);

if (this.layoutOrient === 'left') {
this._valueScale.range([compWidth - this._middleHandlerSize, 0]);
} else {
this._valueScale.range([0, compWidth - this._middleHandlerSize]);
}
}
if (this._component && this._cacheVisibility !== false) {
this._component.setAttributes({
size: {
width: this._computeWidth(),
height: this._computeHeight()
width: compWidth,
height: compHeight
},
position: {
x: this.getLayoutStartPoint().x,
Expand Down Expand Up @@ -226,7 +229,7 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
if (this._isHorizontal) {
return this._backgroundSize + this._middleHandlerSize;
}
return this.getLayoutRect().height - (this._startHandlerSize + this._endHandlerSize) / 2;
return this.getLayoutRect().height;
}

protected _isScaleValid(scale: IBaseScale | ILinearScale) {
Expand Down Expand Up @@ -287,8 +290,8 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
},
orient: this._orient,
size: {
width: this.getLayoutRect().width,
height: this.getLayoutRect().height
width: this._computeWidth(),
height: this._computeHeight()
},
showDetail: spec.showDetail,
brushSelect: spec.brushSelect ?? false,
Expand All @@ -313,6 +316,7 @@ export class DataZoom<T extends IDataZoomSpec = IDataZoomSpec> extends DataFilte
const isNeedPreview =
this._isScaleValid(xScale) && this._isScaleValid(yScale) && this._spec.showBackgroundChart !== false;
const attrs = this._getAttrs(isNeedPreview);

if (this._component) {
this._component.setAttributes(attrs);
} else {
Expand Down
11 changes: 6 additions & 5 deletions packages/vchart/src/component/data-zoom/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { last } from '@visactor/vutils';
import { isArray, last } from '@visactor/vutils';
import { array, isNil } from '../../util';
import type { DataView } from '@visactor/vdataset';

Expand All @@ -22,15 +22,16 @@ export const lockStatisticsFilter = (
return statisticsData;
}
const fields = originalFields();
const realField = isArray(datumField) ? datumField[0] : datumField;

if (
statisticsData[datumField] &&
statisticsData[realField] &&
fields &&
fields[datumField] &&
fields[datumField].lockStatisticsByDomain &&
fields[realField] &&
fields[realField].lockStatisticsByDomain &&
!isContinuous()
) {
statisticsData[datumField].values = newDomain;
statisticsData[realField].values = newDomain;
}

return statisticsData;
Expand Down
Loading