Skip to content

Refactor/datazoom enhance and bugfix #4065

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

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
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,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: bar always display when set bar minHeight. fix#3284",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: dot series display bug. fix #3282",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: brush range not correct. fix #3091",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: datazoom layout when set scale. fix #2574 & #2535",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: domain will follow axis. fix #2770",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: update perview when update data. fix #3331",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
8 changes: 7 additions & 1 deletion packages/vchart/src/component/axis/base-axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ export abstract class AxisComponent<T extends ICommonAxisSpec & Record<string, a
const viewData = s.getViewData();
if (rawData) {
field.forEach(f => {
data.push(s.getRawDataStatisticsByField(f, false) as { min: number; max: number; values: any[] });
data.push(
s.getRawDataStatisticsByField(f, !!isContinuous(this._scale.type)) as {
min: number;
max: number;
values: any[];
}
);
});
} else if (viewData && viewData.latestData && viewData.latestData.length) {
const seriesData = s.getViewDataStatistics?.();
Expand Down
8 changes: 8 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 @@ -74,6 +74,10 @@ export class BandAxisMixin {
}
}
protected _rawDomainIndex: { [key: string | number | symbol]: number }[] = [];
protected _rawDomain: StringOrNumber[][] = [];
getRawDomain() {
return this._rawDomain;
}

dataToPosition(values: any[], cfg: IAxisLocationCfg = {}): number {
if (values.length === 0 || this._scales.length === 0) {
Expand Down Expand Up @@ -229,6 +233,7 @@ export class BandAxisMixin {
protected _updateRawDomain() {
// 默认值设置了无效?
this._rawDomainIndex = [];
this._rawDomain = [];

const userDomain = this._spec.domain;
for (let i = 0; i < this._scales.length; i++) {
Expand All @@ -239,12 +244,15 @@ export class BandAxisMixin {
const data = this.collectData(i, true);
const domain = this.computeBandDomain(data);
this._rawDomainIndex[i] = {};
this._rawDomain[i] = domain;
domain.forEach((d, _i) => (this._rawDomainIndex[i][d] = _i));
}
}
this.event.emit(ChartEvent.scaleRawDomainUpdate, { model: this as unknown as IModel });
}

protected _clearRawDomain() {
this._rawDomainIndex = [];
this._rawDomain = [];
}
}
21 changes: 20 additions & 1 deletion packages/vchart/src/component/axis/mixin/linear-axis-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { IOrientType } from '../../../typings/space';
import type { IComponentOption } from '../../interface/common';
import type { StringOrNumber } from '../../../typings';
import { breakData } from './util/break-data';
import type { IModel } from '../../../model/interface';

export const e10 = Math.sqrt(50);
export const e5 = Math.sqrt(10);
Expand Down Expand Up @@ -37,7 +38,7 @@ export interface LinearAxisMixin {
_tick: ITick | undefined;
isSeriesDataEnable: any;
computeDomain: any;
collectData: (depth?: number) => { min: number; max: number; values: any[] }[];
collectData: (depth?: number, rawData?: boolean) => { min: number; max: number; values: any[] }[];
/**
* 这个变量在其他break相关组件和扩展中都有使用
*/
Expand All @@ -55,6 +56,10 @@ export interface LinearAxisMixin {

export class LinearAxisMixin {
protected _extend: { [key: string]: number } = {};
protected _rawDomain: StringOrNumber[] = [];
getRawDomain() {
return this._rawDomain;
}

niceLabelFormatter: (value: StringOrNumber) => StringOrNumber = null;

Expand Down Expand Up @@ -367,6 +372,9 @@ export class LinearAxisMixin {
if (!this.isSeriesDataEnable()) {
return;
}
if (!this._rawDomain?.length && this._scale) {
this._updateRawDomain();
}
const data = this.collectData();
const domain: number[] = this.computeLinearDomain(data) as number[];
this.updateScaleDomainByModel(domain);
Expand Down Expand Up @@ -415,4 +423,15 @@ export class LinearAxisMixin {
return value;
};
}

protected _updateRawDomain() {
const data = this.collectData(0, true);
const domain: number[] = this.computeLinearDomain(data) as number[];
this._rawDomain = domain;
this.event.emit(ChartEvent.scaleRawDomainUpdate, { model: this as unknown as IModel });
}

protected _clearRawDomain() {
this._rawDomain = [];
}
}
28 changes: 18 additions & 10 deletions packages/vchart/src/component/brush/brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ComponentTypeEnum } from '../interface/type';
import { Brush as BrushComponent, IOperateType as BrushEvent } from '@visactor/vrender-components';
import type { IBounds, IPointLike, Maybe } from '@visactor/vutils';
// eslint-disable-next-line no-duplicate-imports
import { array, polygonIntersectPolygon, isValid, last, cloneDeep } from '@visactor/vutils';
import { array, polygonIntersectPolygon, isValid, last } from '@visactor/vutils';
import type { IModelRenderOption, IModelSpecInfo } from '../../model/interface';
import type { IRegion } from '../../region/interface';
import type { IGraphic, IGroup, INode, IPolygon } from '@visactor/vrender-core';
Expand All @@ -22,6 +22,8 @@ import type { DataZoom } from '../data-zoom';
import type { AxisComponent } from '../axis/base-axis';
import { getSpecInfo } from '../util';
import { brush } from '../../theme/builtin/common/component/brush';
import { isReverse, statePointToData } from '../data-zoom/util';
import type { CartesianAxis } from '../axis/cartesian';

const IN_BRUSH_STATE = 'inBrush';
const OUT_BRUSH_STATE = 'outOfBrush';
Expand Down Expand Up @@ -663,18 +665,16 @@ export class Brush<T extends IBrushSpec = IBrushSpec> extends BaseComponent<T> i
const axisRangeExpand = this._spec.axisRangeExpand ?? 0;
const { x1, x2, y1, y2 } = operateMaskBounds;
const regionStartAttr = isHorizontal ? 'x' : 'y';
const regionSizeAttr = isHorizontal ? 'width' : 'height';
const boundsStart = isHorizontal ? x1 : y1;
const boundsEnd = isHorizontal ? x2 : y2;

if (this._axisDataZoomMap[axis.id]) {
const dataZoom = this._axisDataZoomMap[axis.id];
const releatedAxis = dataZoom.relatedAxisComponent as AxisComponent;
const startValue = releatedAxis
.getScale()
.invert(boundsStart - region.getLayoutStartPoint()[regionStartAttr]);
const endValue = releatedAxis.getScale().invert(boundsEnd - region.getLayoutStartPoint()[regionStartAttr]);
const startPercent = dataZoom.dataToStatePoint(startValue);
const endPercent = dataZoom.dataToStatePoint(endValue);
const startPercent =
(boundsStart - region.getLayoutStartPoint()[regionStartAttr]) / region.getLayoutRect()[regionSizeAttr];
const endPercent =
(boundsEnd - region.getLayoutStartPoint()[regionStartAttr]) / region.getLayoutRect()[regionSizeAttr];
const newStartPercent = this._stateClamp(startPercent - axisRangeExpand);
const newEndPercent = this._stateClamp(endPercent + axisRangeExpand);
dataZoom.setStartAndEnd(Math.min(newStartPercent, newEndPercent), Math.max(newStartPercent, newEndPercent), [
Expand All @@ -686,8 +686,16 @@ export class Brush<T extends IBrushSpec = IBrushSpec> extends BaseComponent<T> i
operateComponent: dataZoom,
start: newStartPercent,
end: newEndPercent,
startValue: dataZoom.statePointToData(newStartPercent),
endValue: dataZoom.statePointToData(newEndPercent)
startValue: statePointToData(
newStartPercent,
dataZoom.stateScale,
isReverse(dataZoom.relatedAxisComponent as CartesianAxis<any>, dataZoom.isHorizontal)
),
endValue: statePointToData(
newEndPercent,
dataZoom.stateScale,
isReverse(dataZoom.relatedAxisComponent as CartesianAxis<any>, dataZoom.isHorizontal)
)
});
} else {
const range = axis.getScale().range();
Expand Down
Loading