fix: fix bug of sortDataByAxis not work well in combination chart

This commit is contained in:
lixuefei.1313 2024-02-26 18:04:00 +08:00
parent 0a34288733
commit 33d37ecc90
8 changed files with 81 additions and 33 deletions

View File

@ -21,7 +21,7 @@ importers:
'@visactor/vmind': 1.2.4-alpha.5
'@visactor/vrender': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vutils': ~0.17.5
'@visactor/vutils': ~0.18.1
'@vitejs/plugin-react': 3.1.0
axios: ^1.4.0
canvas: 2.11.2
@ -50,7 +50,7 @@ importers:
'@visactor/vmind': 1.2.4-alpha.5
'@visactor/vrender': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vutils': 0.17.5
'@visactor/vutils': 0.18.1
axios: 1.6.7
highlight.js: 11.9.0
markdown-it: 13.0.2
@ -131,7 +131,7 @@ importers:
'@visactor/vgrammar-core': 0.11.12
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vutils': ~0.17.5
'@visactor/vutils': ~0.18.1
'@vitejs/plugin-react': 3.1.0
eslint: ~8.18.0
eslint-config-prettier: 8.5.0
@ -153,7 +153,7 @@ importers:
'@visactor/vgrammar-core': 0.11.12
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vutils': 0.17.5
'@visactor/vutils': 0.18.1
react-is: 18.2.0
devDependencies:
'@internal/bundler': link:../../tools/bundler
@ -284,7 +284,7 @@ importers:
'@types/jest': ^26.0.0
'@types/node': '*'
'@types/offscreencanvas': 2019.6.4
'@visactor/vdataset': ~0.17.5
'@visactor/vdataset': ~0.18.1
'@visactor/vgrammar-core': 0.11.12
'@visactor/vgrammar-hierarchy': 0.11.12
'@visactor/vgrammar-projection': 0.11.12
@ -295,8 +295,8 @@ importers:
'@visactor/vrender-components': 0.17.24
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vscale': ~0.17.5
'@visactor/vutils': ~0.17.5
'@visactor/vscale': ~0.18.1
'@visactor/vutils': ~0.18.1
'@visactor/vutils-extension': workspace:1.9.3
canvas: 2.11.2
d3-array: ^1.2.4
@ -329,7 +329,7 @@ importers:
typescript: 4.9.5
vite: 3.2.6
dependencies:
'@visactor/vdataset': 0.17.5
'@visactor/vdataset': 0.18.1
'@visactor/vgrammar-core': 0.11.12
'@visactor/vgrammar-hierarchy': 0.11.12
'@visactor/vgrammar-projection': 0.11.12
@ -340,8 +340,8 @@ importers:
'@visactor/vrender-components': 0.17.24
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vscale': 0.17.5
'@visactor/vutils': 0.17.5
'@visactor/vscale': 0.18.1
'@visactor/vutils': 0.18.1
'@visactor/vutils-extension': link:../vutils-extension
devDependencies:
'@esbuild-plugins/node-globals-polyfill': 0.1.1
@ -435,8 +435,8 @@ importers:
'@types/offscreencanvas': 2019.6.4
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vscale': ~0.17.5
'@visactor/vutils': ~0.17.5
'@visactor/vscale': ~0.18.1
'@visactor/vutils': ~0.18.1
eslint: ~8.18.0
husky: 7.0.4
jest: ^26.0.0
@ -455,8 +455,8 @@ importers:
dependencies:
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vscale': 0.17.5
'@visactor/vutils': 0.17.5
'@visactor/vscale': 0.18.1
'@visactor/vutils': 0.18.1
devDependencies:
'@internal/bundler': link:../../tools/bundler
'@internal/eslint-config': link:../../share/eslint-config
@ -702,7 +702,7 @@ importers:
'@visactor/vrender': 0.17.24
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vutils': ~0.17.5
'@visactor/vutils': ~0.18.1
cross-env: ^7.0.3
eslint: ~8.18.0
jest: ^26.0.0
@ -717,7 +717,7 @@ importers:
'@visactor/vrender': 0.17.24
'@visactor/vrender-core': 0.17.24
'@visactor/vrender-kits': 0.17.24
'@visactor/vutils': 0.17.5
'@visactor/vutils': 0.18.1
devDependencies:
'@internal/bundler': link:../bundler
'@internal/eslint-config': link:../../share/eslint-config
@ -4576,6 +4576,28 @@ packages:
topojson-client: 3.1.0
dev: false
/@visactor/vdataset/0.18.1:
resolution: {integrity: sha512-ByrBt2kgLvYRve+Q+9oo3Ibav5WVSyWPuxdDJHK7kDTJGtTuV8z4qKcqArB86PcAOJS1s5L0TtHlV4Femm2xoA==}
dependencies:
'@turf/flatten': 6.5.0
'@turf/helpers': 6.5.0
'@turf/rewind': 6.5.0
'@visactor/vutils': 0.18.1
d3-dsv: 2.0.0
d3-geo: 1.12.1
d3-hexbin: 0.2.2
d3-hierarchy: 3.1.2
eventemitter3: 4.0.7
geobuf: 3.0.2
geojson-dissolve: 3.1.0
path-browserify: 1.0.1
pbf: 3.2.1
point-at-length: 1.1.0
simple-statistics: 7.8.3
simplify-geojson: 1.0.5
topojson-client: 3.1.0
dev: false
/@visactor/vgrammar-coordinate/0.11.12:
resolution: {integrity: sha512-xF0+24RubiiXDcuFqsGE5KyW8IZaIHNCfjK5aiHXtuAY444M2z5vA2Xw3coQZdgfEAlYDDTWn7APsea/djF2tQ==}
dependencies:
@ -4714,6 +4736,12 @@ packages:
'@visactor/vutils': 0.17.5
dev: false
/@visactor/vscale/0.18.1:
resolution: {integrity: sha512-0wpd0avbFLvuDKNHt2PxdKdqLSU9+zUkM6GJYWbXsUUYOiKaFkt2xTkdwUHKq66v23C7Iy14Pm7VVr0wVgflbA==}
dependencies:
'@visactor/vutils': 0.18.1
dev: false
/@visactor/vutils/0.17.5:
resolution: {integrity: sha512-HFN6Pk1Wc1RK842g02MeKOlvdri5L7/nqxMVTqxIvi0XMhHXpmoqN4+/9H+h8LmJpVohyrI/MT85TRBV/rManw==}
dependencies:
@ -4722,6 +4750,14 @@ packages:
eventemitter3: 4.0.7
dev: false
/@visactor/vutils/0.18.1:
resolution: {integrity: sha512-XGq9a85HrVP3Rbby1qO2/JS9GewJtZv6y35Xujcb2ZGLEjnpCK61Y1OXwSC5SZOKmtsH4SjYMf5czlnNhQ3GeA==}
dependencies:
'@turf/helpers': 6.5.0
'@turf/invariant': 6.5.0
eventemitter3: 4.0.7
dev: false
/@vitejs/plugin-react/3.1.0_vite@3.2.6:
resolution: {integrity: sha512-AfgcRL8ZBhAlc3BFdigClmTUMISmmzHn7sB2h9U1odvc5U/MjWXsAaz18b/WoppUTDBzxOJwo2VdClfUcItu9g==}
engines: {node: ^14.18.0 || >=16.0.0}

View File

@ -15,7 +15,7 @@
"@visactor/vchart": "workspace:1.9.3",
"@visactor/vchart-theme": "~1.6.6",
"@visactor/vmind": "1.2.4-alpha.5",
"@visactor/vutils": "~0.17.5",
"@visactor/vutils": "~0.18.1",
"@visactor/vrender": "0.17.24",
"@visactor/vrender-kits": "0.17.24",
"@visactor/vgrammar": "0.11.12",

View File

@ -30,7 +30,7 @@
},
"dependencies": {
"@visactor/vchart": "workspace:1.9.3",
"@visactor/vutils": "~0.17.5",
"@visactor/vutils": "~0.18.1",
"@visactor/vrender-core": "0.17.24",
"@visactor/vrender-kits": "0.17.24",
"@visactor/vgrammar-core": "0.11.12",

View File

@ -118,9 +118,9 @@
"@size-limit/file": "9.0.0"
},
"dependencies": {
"@visactor/vutils": "~0.17.5",
"@visactor/vdataset": "~0.17.5",
"@visactor/vscale": "~0.17.5",
"@visactor/vutils": "~0.18.1",
"@visactor/vdataset": "~0.18.1",
"@visactor/vscale": "~0.18.1",
"@visactor/vrender-core": "0.17.24",
"@visactor/vrender-kits": "0.17.24",
"@visactor/vrender-components": "0.17.24",

View File

@ -10,7 +10,8 @@ import {
STACK_FIELD_START,
STACK_FIELD_START_PERCENT,
STACK_FIELD_START_OffsetSilhouette,
PREFIX
PREFIX,
ChartEvent
} from '../../constant';
import type { IAxisHelper } from '../../component/axis/cartesian/interface';
import type { DirectionType } from '../../typings/space';
@ -498,10 +499,22 @@ export abstract class CartesianSeries<T extends ICartesianSeriesSpec = ICartesia
return this._specYField;
}
viewDataUpdate(d: DataView): void {
super.viewDataUpdate(d);
initEvent() {
super.initEvent();
// 通过轴事件来进行排序。轴的domain数据变化在系列的统计数据完成后
if (this.sortDataByAxis) {
this._sortDataInAxisDomain();
this.event.on(
ChartEvent.scaleDomainUpdate,
{
filter: param =>
param.model.id ===
(this._direction === Direction.horizontal ? this._yAxisHelper : this._xAxisHelper)?.getAxisId()
},
() => {
// 只能排序,不能修改数据,此时已经在数据流的统计流程之后
this._sortDataInAxisDomain();
}
);
}
}

View File

@ -1,7 +1,7 @@
import type { IAxisHelper as CartesianHelper } from '../../component/axis/cartesian/interface/common';
import { SeriesTypeEnum } from '../interface/type';
import type { Datum } from '../../typings';
import { isContinuous } from '@visactor/vscale';
import { IOrdinalScale, isContinuous } from '@visactor/vscale';
import type { IPolarAxisHelper } from '../../component/axis';
import type { ICartesianSeries, ISeries } from '..';
@ -18,8 +18,7 @@ export function sortDataInAxisHelper(axisHelper: CartesianHelper | IPolarAxisHel
});
} else {
dataList.sort((datumA: Datum, datumB: Datum) => {
// @ts-ignore TODO: vscale support api to get index
return (scale._index.get(datumA[field]) - scale._index.get(datumB[field])) * (isRevert ? -1 : 1);
return ((scale as IOrdinalScale).index(datumA[field]) - scale.index(datumB[field])) * (isRevert ? -1 : 1);
});
}
}

View File

@ -22,8 +22,8 @@
"test-watch": "DEBUG_MODE=1 jest --watch"
},
"dependencies": {
"@visactor/vutils": "~0.17.5",
"@visactor/vscale": "~0.17.5",
"@visactor/vutils": "~0.18.1",
"@visactor/vscale": "~0.18.1",
"@visactor/vrender-core": "0.17.24",
"@visactor/vrender-kits": "0.17.24"
},
@ -66,4 +66,4 @@
"url": "https://www.visactor.io/"
},
"license": "MIT"
}
}

View File

@ -60,6 +60,6 @@
"@visactor/vrender-kits": "0.17.24",
"@visactor/vchart": "workspace:1.9.3",
"@visactor/vrender": "0.17.24",
"@visactor/vutils": "~0.17.5"
"@visactor/vutils": "~0.18.1"
}
}
}