Skip to content

Commit 57b48be

Browse files
authored
Merge pull request #222 from VisActor/fix/phase2
Fix/phase2
2 parents 7117bff + 2a19e94 commit 57b48be

File tree

6 files changed

+68
-147
lines changed

6 files changed

+68
-147
lines changed

apps/website/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"rspress": "1.45.3",
1414
"@visactor/vseed": "workspace:*",
1515
"@visactor/vquery": "workspace:*",
16-
"@visactor/vchart": "2.0.9",
17-
"@visactor/vtable": "1.22.5-alpha.2",
16+
"@visactor/vchart": "2.0.10",
17+
"@visactor/vtable": "1.22.5",
1818
"zustand": "5.0.6"
1919
},
2020
"devDependencies": {

packages/vseed/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"@rstest/coverage-istanbul": "0.0.3",
4545
"@types/node": "22.16.5",
4646
"@typescript-eslint/eslint-plugin": "8.38.0",
47-
"@visactor/vchart": "2.0.9",
48-
"@visactor/vtable": "1.22.5-alpha.2",
47+
"@visactor/vchart": "2.0.10",
48+
"@visactor/vtable": "1.22.5",
4949
"@vitest/coverage-istanbul": "3.2.4",
5050
"@vitest/coverage-v8": "3.2.4",
5151
"eslint": "9.30.0",

packages/vseed/src/pipeline/spec/chart/pipes/pivotChart/dimensionLinkage.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
import type { ICartesianCrosshairSpec, ILineChartSpec } from '@visactor/vchart'
2-
import { isNullish } from 'remeda'
32
import type { DimensionLinkage, PivotChartSpecPipe } from 'src/types'
43

5-
const defaultScatterFormatter = (val: number | string) => {
6-
if (isNullish(val)) {
7-
return ''
8-
}
9-
if (typeof val === 'string') {
10-
return val
11-
}
12-
13-
if (val === 0) {
14-
return '0'
15-
}
16-
if (Math.abs(val) < 1) {
17-
return val.toFixed(2)
18-
}
19-
20-
return val === Math.floor(val) ? `${val}` : val.toFixed(1)
21-
}
22-
234
export const dimensionLinkage: PivotChartSpecPipe = (spec, context) => {
245
const { advancedVSeed, vseed } = context
256
const { chartType } = vseed
@@ -40,15 +21,15 @@ export const dimensionLinkage: PivotChartSpecPipe = (spec, context) => {
4021
visible: config.showLabel ?? crosshair.xField.label?.visible ?? true,
4122
background: crosshair.xField.label?.labelBackground,
4223
textStyle: crosshair.xField.label?.style,
43-
formatMethod: chartType === 'scatter' ? defaultScatterFormatter : undefined,
24+
formatMethod: crosshair.xField.label?.formatMethod || undefined,
4425
}
4526
}
4627
if (crosshair?.yField) {
4728
;(labelHoverOnAxis as any).left = {
4829
visible: config.showLabel ?? crosshair.yField.label?.visible ?? true,
4930
background: crosshair.yField.label?.labelBackground,
5031
textStyle: crosshair.yField.label?.style,
51-
formatMethod: chartType === 'scatter' ? defaultScatterFormatter : undefined,
32+
formatMethod: crosshair.yField.label?.formatMethod || undefined,
5233
}
5334
}
5435

packages/vseed/src/pipeline/spec/chart/pipes/regressionLine/kdeRegressionLine.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const kdeRegressionLine: VChartSpecPipe = (spec, context) => {
1212
const { chartType, encoding = {} as Encoding, dimensions, regressionLine } = advancedVSeed
1313
const { dataset } = vseed
1414
const lineTheme = advancedVSeed.config[chartType as 'histogram']?.regressionLine as RegressionLineConfig
15+
const binValueType = advancedVSeed.config[chartType as 'histogram']?.binValueType
1516

1617
if (!regressionLine || !regressionLine.kdeRegressionLine) {
1718
return result
@@ -74,8 +75,18 @@ export const kdeRegressionLine: VChartSpecPipe = (spec, context) => {
7475
} as KDEOptions)
7576
const N = Math.max(3, Math.floor(simpleData.length / 4))
7677
const lineData = res.evaluateGrid(N)
78+
79+
// 根据 binValueType 决定如何转换 KDE 密度值
80+
// - 频次模式 (count): 频次 = 密度 × 样本数 × 带宽
81+
// - 百分比模式 (percentage): 百分比 = 密度 × 带宽
7782
const scaleR = (k: number) => {
78-
return scaleY.scale(k * simpleData.length * res.bandwidth)
83+
if (binValueType === 'percentage') {
84+
// 百分比模式:y轴是0-1的百分比,KDE密度值乘以带宽即可
85+
return scaleY.scale(k * res.bandwidth)
86+
} else {
87+
// 频次模式:y轴是实际计数,需要乘以样本数量
88+
return scaleY.scale(k * simpleData.length * res.bandwidth)
89+
}
7990
}
8091

8192
const linePoints = lineData.map((ld: Datum) => {

packages/vseed/tests/pipeline/chartType/histogram/__snapshots__/pivotHistogram.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ exports[`pivotHistogram 2`] = `
11431143
},
11441144
"visible": true,
11451145
},
1146-
"formatMethod": undefined,
1146+
"formatMethod": [Function],
11471147
"textStyle": {
11481148
"fill": "#ffffff",
11491149
},

pnpm-lock.yaml

Lines changed: 49 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)