Skip to content

Commit 8d93109

Browse files
authored
Merge pull request #3556 from VisActor/fix/waterfall-break
Fix/waterfall break
2 parents 648977d + 0801f60 commit 8d93109

File tree

7 files changed

+56
-7
lines changed

7 files changed

+56
-7
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 break of waterfall, fix #3544\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(vchart-extension): series-break should keep align width axis break, related to #3560\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vchart"
7+
}
8+
],
9+
"packageName": "@visactor/vchart",
10+
"email": "[email protected]"
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@visactor/vchart",
5+
"comment": "fix: breaks should consider the `min` and `max` of axis, related to #3560",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@visactor/vchart"
10+
}

packages/vchart-extension/src/components/series-break/util.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export function getSeriesBreakConfig(axesSpec: ILinearAxisSpec[], axesIndex?: nu
5353
const parsedAxisId = axisId ?? `${axisModel.type}-${axisModel.id}`;
5454

5555
const regionBounds = getAllRegionBounds(axisModel.getRegions());
56-
array(spec.breaks).forEach((breakConfig: ILinearAxisBreakSpec) => {
56+
57+
// todo 这里用到了内部变量,不太安全
58+
array(axisModel._break?.breaks).forEach((breakConfig: ILinearAxisBreakSpec) => {
5759
const { range, breakSymbol, gap = 5 } = breakConfig;
5860
const pos1 = axisModel.valueToPosition(range[0]);
5961
const pos2 = axisModel.valueToPosition(range[1]);
@@ -356,7 +358,7 @@ function isPointInPolygon(point: Point, polygon: Point[]) {
356358

357359
export const appendSeriesBreakConfig = (rawSpec: ISpec) => {
358360
if (rawSpec.axes?.length) {
359-
const breakedAxes = rawSpec.axes.filter((axis: any) => axis.breaks && axis.breaks.length);
361+
const breakedAxes = rawSpec.axes.filter((axis: any) => axis.breaks && axis.breaks.length && axis.visible !== false);
360362

361363
if (breakedAxes.length) {
362364
(rawSpec as any).customMark = array((rawSpec as any).customMark).filter(
@@ -366,7 +368,7 @@ export const appendSeriesBreakConfig = (rawSpec: ISpec) => {
366368
getSeriesBreakConfig(
367369
breakedAxes as ILinearAxisSpec[],
368370
breakedAxes.map(axisSpec => {
369-
return rawSpec.axes.indexOf(axisSpec);
371+
return rawSpec.axes.indexOf(axisSpec as any);
370372
})
371373
)
372374
);

packages/vchart/src/component/axis/cartesian/axis.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ICartesianHorizontal } from './interface/spec';
22
import { Bounds, last, type IBounds, type IBoundsLike, type Maybe } from '@visactor/vutils';
33
// eslint-disable-next-line no-duplicate-imports
44
import type { IEffect, IModelInitOption, IModelSpecInfo } from '../../../model/interface';
5-
import type { ICartesianSeries } from '../../../series/interface';
5+
import { SeriesTypeEnum, type ICartesianSeries } from '../../../series/interface';
66
import type { IRegion } from '../../../region/interface';
77
import type { ICartesianAxisCommonSpec, IAxisHelper, ICartesianVertical } from './interface';
88
import { mergeSpec } from '@visactor/vutils-extension';
@@ -50,6 +50,7 @@ import type { IGraphic, IText } from '@visactor/vrender-core';
5050
// eslint-disable-next-line no-duplicate-imports
5151
import { createText } from '@visactor/vrender-core';
5252
import type { ICartesianChartSpec } from '../../../chart/cartesian/interface';
53+
import { STACK_FIELD_END, STACK_FIELD_START } from '../../../constant/data';
5354

5455
const CartesianAxisPlugin = [AxisSyncPlugin];
5556

packages/vchart/src/component/axis/mixin/linear-axis-mixin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export interface LinearAxisMixin {
3838
isSeriesDataEnable: any;
3939
computeDomain: any;
4040
collectData: (depth?: number) => { min: number; max: number; values: any[] }[];
41+
/**
42+
* 这个变量在其他break相关组件和扩展中都有使用
43+
*/
4144
_break: {
4245
domain: [number, number][];
4346
scope: [number, number][];
@@ -163,9 +166,11 @@ export class LinearAxisMixin {
163166
if (userSetBreaks) {
164167
const breakRanges = [];
165168
const breaks = [];
169+
// 如果用户手动的手指了max,可以将break的最大值限制在用户设置的最大值范围内
170+
const breakMaxLimit = isNil(this._domain.max) ? maxDomain : this._domain.max;
166171
for (let index = 0; index < this._spec.breaks.length; index++) {
167172
const { range } = this._spec.breaks[index];
168-
if (range[0] <= range[1] && range[1] <= maxDomain) {
173+
if (range[0] <= range[1] && range[1] <= breakMaxLimit) {
169174
breakRanges.push(range);
170175
breaks.push(this._spec.breaks[index]);
171176
}

packages/vchart/src/component/axis/mixin/util/break-data.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isEqual } from '@visactor/vutils';
2+
13
const setDomain = (min: number, max: number, breaks: number[]): [number, number][] =>
24
breaks.reduce(
35
(r, b, i) => {
@@ -15,6 +17,7 @@ function breakDomain(data: number[], points: number[]): [number, number][] {
1517
if (breaks.length === 0) {
1618
return [[min, max]];
1719
}
20+
1821
return setDomain(min, max, breaks);
1922
}
2023

@@ -65,8 +68,14 @@ function breakScope(data: number[], points: number[], scopeType: 'count' | 'leng
6568
res.push([0, i / bins.length - 1]);
6669
} else {
6770
const length = scopeType === 'count' ? bin.count : bin.max - bin.min;
68-
res.push([res[i - 1] ? res[i - 1][1] : 0, i === bins.length - 1 ? 1 : Math.min((acc + length) / totalLength, 1)]);
69-
acc += length;
71+
const b0 = res[i - 1] ? res[i - 1][1] : 0;
72+
const b1 = i === bins.length - 1 ? 1 : Math.min((acc + length) / totalLength, 1);
73+
74+
if (b0 === b1 && (b0 === 0 || b0 === 1)) {
75+
} else {
76+
res.push([b0, b1]);
77+
acc += length;
78+
}
7079
}
7180
});
7281

0 commit comments

Comments
 (0)