Skip to content
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: tickData of axis should update when `sampling` is changed, fix #4059\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "dingling112@gmail.com"
}
21 changes: 20 additions & 1 deletion packages/vchart/src/component/axis/cartesian/band-axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BandScale, scaleWholeRangeSize } from '@visactor/vscale';
import { CartesianAxis } from './axis';
import type { ICartesianBandAxisSpec } from './interface';
import { ComponentTypeEnum } from '../../interface';
import { isNil, isString, isValid, mixin } from '@visactor/vutils';
import { isEqual, isNil, isString, isValid, mixin } from '@visactor/vutils';
import { BandAxisMixin } from '../mixin/band-axis-mixin';
import type { StringOrNumber } from '../../../typings';
import { Factory } from '../../../core/factory';
Expand Down Expand Up @@ -155,6 +155,25 @@ export class CartesianBandAxis<T extends ICartesianBandAxisSpec = ICartesianBand
minBandSize
};
}

_compareSpec(spec: T, prevSpec: T) {
const result = super._compareSpec(spec, prevSpec);
if (result.reMake) {
return result;
}

if (prevSpec?.showAllGroupLayers !== spec?.showAllGroupLayers || !isEqual(prevSpec?.layers, spec?.layers)) {
result.reMake = true;
}

return result;
}

reInit(spec?: T): void {
super.reInit();

(this as any)?._updateData();
}
}

mixin(CartesianBandAxis, BandAxisMixin);
Expand Down
25 changes: 25 additions & 0 deletions packages/vchart/src/component/axis/mixin/band-axis-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface BandAxisMixin {
_forceLayout: () => void;
_getNormalizedValue: (values: any[], length: number) => number;
_onTickDataChange: (compilableData: CompilableData) => void;
registerTicksTransform: () => string;
}

export class BandAxisMixin {
Expand Down Expand Up @@ -73,6 +74,30 @@ export class BandAxisMixin {
};
}
}

protected _updateData() {
const tickTransformType = this.registerTicksTransform();

if (this._spec.showAllGroupLayers && this._scales.length > 1) {
const layers = this._spec.layers ?? [];
Object.keys(this._tickDataMap).forEach(layer => {
const layerConfig = layers[this._scales.length - 1 - +layer] || {};
const tickData = this._tickDataMap[layer];
const tickTransform = tickData?.getDataView().transformsArr.find((t: any) => t.type === tickTransformType);

tickTransform &&
(tickTransform.options = {
...this._tickTransformOption(),
...layerConfig
});
});
} else {
const tickTransform = this._tickData?.[0]?.getDataView().transformsArr.find(t => t.type === tickTransformType);

tickTransform && (tickTransform.options = this._tickTransformOption());
}
}

protected _rawDomainIndex: { [key: string | number | symbol]: number }[] = [];

dataToPosition(values: any[], cfg: IAxisLocationCfg = {}): number {
Expand Down
Loading