@orbcharts/core 3.0.0-alpha.51 → 3.0.0-alpha.53
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +200 -200
- package/dist/orbcharts-core.es.js +547 -544
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/types/ContextObserverMultiGrid.d.ts +2 -1
- package/dist/vite.config.d.ts +1 -1
- package/package.json +41 -41
- package/src/AbstractChart.ts +48 -48
- package/src/GridChart.ts +20 -20
- package/src/MultiGridChart.ts +20 -20
- package/src/MultiValueChart.ts +20 -20
- package/src/RelationshipChart.ts +20 -20
- package/src/SeriesChart.ts +20 -20
- package/src/TreeChart.ts +20 -20
- package/src/base/createBaseChart.ts +369 -369
- package/src/base/createBasePlugin.ts +95 -95
- package/src/defaults.ts +226 -226
- package/src/defineGridPlugin.ts +3 -3
- package/src/defineMultiGridPlugin.ts +3 -3
- package/src/defineMultiValuePlugin.ts +3 -3
- package/src/defineNoneDataPlugin.ts +4 -4
- package/src/defineRelationshipPlugin.ts +3 -3
- package/src/defineSeriesPlugin.ts +3 -3
- package/src/defineTreePlugin.ts +3 -3
- package/src/grid/computeGridData.ts +134 -134
- package/src/grid/createGridContextObserver.ts +155 -155
- package/src/grid/gridObservables.ts +607 -604
- package/src/index.ts +21 -21
- package/src/multiGrid/computeMultiGridData.ts +130 -130
- package/src/multiGrid/createMultiGridContextObserver.ts +41 -40
- package/src/multiGrid/multiGridObservables.ts +365 -364
- package/src/multiValue/computeMultiValueData.ts +143 -143
- package/src/multiValue/createMultiValueContextObserver.ts +12 -12
- package/src/relationship/computeRelationshipData.ts +118 -118
- package/src/relationship/createRelationshipContextObserver.ts +12 -12
- package/src/series/computeSeriesData.ts +90 -90
- package/src/series/createSeriesContextObserver.ts +93 -93
- package/src/series/seriesObservables.ts +175 -175
- package/src/tree/computeTreeData.ts +132 -132
- package/src/tree/createTreeContextObserver.ts +61 -61
- package/src/tree/treeObservables.ts +94 -94
- package/src/types/Chart.ts +50 -50
- package/src/types/ChartParams.ts +51 -51
- package/src/types/ComputedData.ts +83 -83
- package/src/types/ComputedDataGrid.ts +13 -13
- package/src/types/ComputedDataMultiGrid.ts +2 -2
- package/src/types/ComputedDataMultiValue.ts +9 -9
- package/src/types/ComputedDataRelationship.ts +19 -19
- package/src/types/ComputedDataSeries.ts +7 -7
- package/src/types/ComputedDataTree.ts +19 -19
- package/src/types/ContextObserver.ts +38 -38
- package/src/types/ContextObserverGrid.ts +42 -42
- package/src/types/ContextObserverMultiGrid.ts +16 -15
- package/src/types/ContextObserverMultiValue.ts +4 -4
- package/src/types/ContextObserverRelationship.ts +4 -4
- package/src/types/ContextObserverSeries.ts +29 -29
- package/src/types/ContextObserverTree.ts +11 -11
- package/src/types/ContextSubject.ts +18 -18
- package/src/types/Data.ts +45 -45
- package/src/types/DataFormatter.ts +74 -74
- package/src/types/DataFormatterGrid.ts +67 -67
- package/src/types/DataFormatterMultiGrid.ts +44 -44
- package/src/types/DataFormatterMultiValue.ts +23 -23
- package/src/types/DataFormatterRelationship.ts +25 -25
- package/src/types/DataFormatterSeries.ts +20 -20
- package/src/types/DataFormatterTree.ts +12 -12
- package/src/types/DataGrid.ts +11 -11
- package/src/types/DataMultiGrid.ts +6 -6
- package/src/types/DataMultiValue.ts +12 -12
- package/src/types/DataRelationship.ts +27 -27
- package/src/types/DataSeries.ts +11 -11
- package/src/types/DataTree.ts +20 -20
- package/src/types/Event.ts +153 -153
- package/src/types/Layout.ts +11 -11
- package/src/types/Padding.ts +5 -5
- package/src/types/Plugin.ts +60 -60
- package/src/types/TransformData.ts +7 -7
- package/src/types/index.ts +37 -37
- package/src/utils/commonUtils.ts +50 -50
- package/src/utils/d3Utils.ts +89 -89
- package/src/utils/index.ts +4 -4
- package/src/utils/observables.ts +201 -201
- package/src/utils/orbchartsUtils.ts +349 -349
- package/tsconfig.json +13 -13
- package/vite.config.js +22 -44
@@ -1,90 +1,90 @@
|
|
1
|
-
import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
|
2
|
-
import type { ComputedDataFn } from '../types/ComputedData'
|
3
|
-
import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
|
4
|
-
import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
|
5
|
-
|
6
|
-
export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
|
7
|
-
const { data = [], dataFormatter, chartParams } = context
|
8
|
-
if (!data.length) {
|
9
|
-
return []
|
10
|
-
}
|
11
|
-
|
12
|
-
let computedDataSeries: ComputedDatumSeries[][] = []
|
13
|
-
|
14
|
-
try {
|
15
|
-
|
16
|
-
const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
|
17
|
-
const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
|
18
|
-
const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
|
19
|
-
const color = seriesColorPredicate(seriesIndex, chartParams)
|
20
|
-
if (typeof seriesData === 'number') {
|
21
|
-
return {
|
22
|
-
id: defaultId,
|
23
|
-
index: currentIndex,
|
24
|
-
seq: 0, // 先給預設值
|
25
|
-
label: defaultId,
|
26
|
-
description: '',
|
27
|
-
data: {},
|
28
|
-
value: seriesData,
|
29
|
-
seriesIndex: seriesIndex,
|
30
|
-
seriesLabel,
|
31
|
-
color,
|
32
|
-
visible: true // 先給預設值
|
33
|
-
}
|
34
|
-
} else {
|
35
|
-
return {
|
36
|
-
id: seriesData.id ? seriesData.id : defaultId,
|
37
|
-
index: currentIndex,
|
38
|
-
seq: 0, // 先給預設值
|
39
|
-
label: seriesData.label ? seriesData.label : defaultId,
|
40
|
-
description: seriesData.description,
|
41
|
-
data: seriesData.data ?? {},
|
42
|
-
value: seriesData.value,
|
43
|
-
seriesIndex: seriesIndex,
|
44
|
-
seriesLabel,
|
45
|
-
color,
|
46
|
-
visible: true // 先給預設值
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
computedDataSeries = data
|
52
|
-
.map((seriesData, seriesIndex) => {
|
53
|
-
if (Array.isArray(seriesData)) {
|
54
|
-
return seriesData.map((item, itemIndex) =>
|
55
|
-
createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
|
56
|
-
)
|
57
|
-
} else {
|
58
|
-
return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
|
59
|
-
}
|
60
|
-
})
|
61
|
-
// 攤為一維陣列
|
62
|
-
.flat()
|
63
|
-
// 排序後給 seq
|
64
|
-
.sort(dataFormatter.sort ?? undefined)
|
65
|
-
.map((datum, index) => {
|
66
|
-
datum.seq = index
|
67
|
-
return datum
|
68
|
-
})
|
69
|
-
.map(datum => {
|
70
|
-
datum.visible = dataFormatter.visibleFilter(datum, context)
|
71
|
-
return datum
|
72
|
-
})
|
73
|
-
// 恢復原排序
|
74
|
-
.sort((a, b) => a.index - b.index)
|
75
|
-
// 依seriesIndex分組(二維陣列)
|
76
|
-
.reduce((acc, datum) => {
|
77
|
-
if (!acc[datum.seriesIndex]) {
|
78
|
-
acc[datum.seriesIndex] = []
|
79
|
-
}
|
80
|
-
acc[datum.seriesIndex].push(datum)
|
81
|
-
return acc
|
82
|
-
}, [])
|
83
|
-
|
84
|
-
} catch (e) {
|
85
|
-
// console.error(e)
|
86
|
-
throw Error(e)
|
87
|
-
}
|
88
|
-
|
89
|
-
return computedDataSeries
|
90
|
-
}
|
1
|
+
import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
|
2
|
+
import type { ComputedDataFn } from '../types/ComputedData'
|
3
|
+
import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
|
4
|
+
import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
|
5
|
+
|
6
|
+
export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
|
7
|
+
const { data = [], dataFormatter, chartParams } = context
|
8
|
+
if (!data.length) {
|
9
|
+
return []
|
10
|
+
}
|
11
|
+
|
12
|
+
let computedDataSeries: ComputedDatumSeries[][] = []
|
13
|
+
|
14
|
+
try {
|
15
|
+
|
16
|
+
const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
|
17
|
+
const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
|
18
|
+
const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
|
19
|
+
const color = seriesColorPredicate(seriesIndex, chartParams)
|
20
|
+
if (typeof seriesData === 'number') {
|
21
|
+
return {
|
22
|
+
id: defaultId,
|
23
|
+
index: currentIndex,
|
24
|
+
seq: 0, // 先給預設值
|
25
|
+
label: defaultId,
|
26
|
+
description: '',
|
27
|
+
data: {},
|
28
|
+
value: seriesData,
|
29
|
+
seriesIndex: seriesIndex,
|
30
|
+
seriesLabel,
|
31
|
+
color,
|
32
|
+
visible: true // 先給預設值
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
return {
|
36
|
+
id: seriesData.id ? seriesData.id : defaultId,
|
37
|
+
index: currentIndex,
|
38
|
+
seq: 0, // 先給預設值
|
39
|
+
label: seriesData.label ? seriesData.label : defaultId,
|
40
|
+
description: seriesData.description,
|
41
|
+
data: seriesData.data ?? {},
|
42
|
+
value: seriesData.value,
|
43
|
+
seriesIndex: seriesIndex,
|
44
|
+
seriesLabel,
|
45
|
+
color,
|
46
|
+
visible: true // 先給預設值
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
computedDataSeries = data
|
52
|
+
.map((seriesData, seriesIndex) => {
|
53
|
+
if (Array.isArray(seriesData)) {
|
54
|
+
return seriesData.map((item, itemIndex) =>
|
55
|
+
createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
|
56
|
+
)
|
57
|
+
} else {
|
58
|
+
return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
|
59
|
+
}
|
60
|
+
})
|
61
|
+
// 攤為一維陣列
|
62
|
+
.flat()
|
63
|
+
// 排序後給 seq
|
64
|
+
.sort(dataFormatter.sort ?? undefined)
|
65
|
+
.map((datum, index) => {
|
66
|
+
datum.seq = index
|
67
|
+
return datum
|
68
|
+
})
|
69
|
+
.map(datum => {
|
70
|
+
datum.visible = dataFormatter.visibleFilter(datum, context)
|
71
|
+
return datum
|
72
|
+
})
|
73
|
+
// 恢復原排序
|
74
|
+
.sort((a, b) => a.index - b.index)
|
75
|
+
// 依seriesIndex分組(二維陣列)
|
76
|
+
.reduce((acc, datum) => {
|
77
|
+
if (!acc[datum.seriesIndex]) {
|
78
|
+
acc[datum.seriesIndex] = []
|
79
|
+
}
|
80
|
+
acc[datum.seriesIndex].push(datum)
|
81
|
+
return acc
|
82
|
+
}, [])
|
83
|
+
|
84
|
+
} catch (e) {
|
85
|
+
// console.error(e)
|
86
|
+
throw Error(e)
|
87
|
+
}
|
88
|
+
|
89
|
+
return computedDataSeries
|
90
|
+
}
|
@@ -1,93 +1,93 @@
|
|
1
|
-
import { map, shareReplay } from 'rxjs'
|
2
|
-
import type { ContextObserverFn } from '../types'
|
3
|
-
import {
|
4
|
-
seriesDataMapObservable,
|
5
|
-
groupDataMapObservable } from '../utils/observables'
|
6
|
-
import { highlightObservable, textSizePxObservable } from '../utils/observables'
|
7
|
-
|
8
|
-
import { separateSeriesObservable, visibleComputedDataObservable, computedLayoutDataObservable, seriesLabelsObservable, seriesContainerPositionObservable, seriesContainerPositionMapObservable } from './seriesObservables'
|
9
|
-
|
10
|
-
export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
|
11
|
-
|
12
|
-
const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
|
13
|
-
shareReplay(1)
|
14
|
-
)
|
15
|
-
|
16
|
-
const separateSeries$ = separateSeriesObservable({
|
17
|
-
fullDataFormatter$: observer.fullDataFormatter$
|
18
|
-
})
|
19
|
-
|
20
|
-
const visibleComputedData$ = visibleComputedDataObservable({
|
21
|
-
computedData$: observer.computedData$,
|
22
|
-
})
|
23
|
-
|
24
|
-
const computedLayoutData$ = computedLayoutDataObservable({
|
25
|
-
computedData$: observer.computedData$,
|
26
|
-
fullDataFormatter$: observer.fullDataFormatter$
|
27
|
-
}).pipe(
|
28
|
-
shareReplay(1)
|
29
|
-
)
|
30
|
-
|
31
|
-
const visibleComputedLayoutData$ = visibleComputedDataObservable({
|
32
|
-
computedData$: computedLayoutData$,
|
33
|
-
})
|
34
|
-
|
35
|
-
const datumList$ = observer.computedData$.pipe(
|
36
|
-
map(d => d.flat())
|
37
|
-
).pipe(
|
38
|
-
shareReplay(1)
|
39
|
-
)
|
40
|
-
|
41
|
-
const seriesHighlight$ = highlightObservable({
|
42
|
-
datumList$,
|
43
|
-
fullChartParams$: observer.fullChartParams$,
|
44
|
-
event$: subject.event$
|
45
|
-
}).pipe(
|
46
|
-
shareReplay(1)
|
47
|
-
)
|
48
|
-
|
49
|
-
const seriesLabels$ = seriesLabelsObservable({
|
50
|
-
computedData$: observer.computedData$,
|
51
|
-
})
|
52
|
-
|
53
|
-
|
54
|
-
const SeriesDataMap$ = seriesDataMapObservable({
|
55
|
-
datumList$
|
56
|
-
}).pipe(
|
57
|
-
shareReplay(1)
|
58
|
-
)
|
59
|
-
|
60
|
-
const seriesContainerPosition$ = seriesContainerPositionObservable({
|
61
|
-
computedData$: observer.computedData$,
|
62
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
63
|
-
layout$: observer.layout$,
|
64
|
-
}).pipe(
|
65
|
-
shareReplay(1)
|
66
|
-
)
|
67
|
-
|
68
|
-
const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
|
69
|
-
seriesContainerPosition$: seriesContainerPosition$,
|
70
|
-
seriesLabels$: seriesLabels$,
|
71
|
-
separateSeries$: separateSeries$,
|
72
|
-
}).pipe(
|
73
|
-
shareReplay(1)
|
74
|
-
)
|
75
|
-
|
76
|
-
return {
|
77
|
-
fullParams$: observer.fullParams$,
|
78
|
-
fullChartParams$: observer.fullChartParams$,
|
79
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
80
|
-
computedData$: observer.computedData$,
|
81
|
-
layout$: observer.layout$,
|
82
|
-
textSizePx$,
|
83
|
-
visibleComputedData$,
|
84
|
-
visibleComputedLayoutData$,
|
85
|
-
separateSeries$,
|
86
|
-
computedLayoutData$,
|
87
|
-
seriesHighlight$,
|
88
|
-
seriesLabels$,
|
89
|
-
SeriesDataMap$,
|
90
|
-
seriesContainerPosition$,
|
91
|
-
SeriesContainerPositionMap$,
|
92
|
-
}
|
93
|
-
}
|
1
|
+
import { map, shareReplay } from 'rxjs'
|
2
|
+
import type { ContextObserverFn } from '../types'
|
3
|
+
import {
|
4
|
+
seriesDataMapObservable,
|
5
|
+
groupDataMapObservable } from '../utils/observables'
|
6
|
+
import { highlightObservable, textSizePxObservable } from '../utils/observables'
|
7
|
+
|
8
|
+
import { separateSeriesObservable, visibleComputedDataObservable, computedLayoutDataObservable, seriesLabelsObservable, seriesContainerPositionObservable, seriesContainerPositionMapObservable } from './seriesObservables'
|
9
|
+
|
10
|
+
export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
|
11
|
+
|
12
|
+
const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
|
13
|
+
shareReplay(1)
|
14
|
+
)
|
15
|
+
|
16
|
+
const separateSeries$ = separateSeriesObservable({
|
17
|
+
fullDataFormatter$: observer.fullDataFormatter$
|
18
|
+
})
|
19
|
+
|
20
|
+
const visibleComputedData$ = visibleComputedDataObservable({
|
21
|
+
computedData$: observer.computedData$,
|
22
|
+
})
|
23
|
+
|
24
|
+
const computedLayoutData$ = computedLayoutDataObservable({
|
25
|
+
computedData$: observer.computedData$,
|
26
|
+
fullDataFormatter$: observer.fullDataFormatter$
|
27
|
+
}).pipe(
|
28
|
+
shareReplay(1)
|
29
|
+
)
|
30
|
+
|
31
|
+
const visibleComputedLayoutData$ = visibleComputedDataObservable({
|
32
|
+
computedData$: computedLayoutData$,
|
33
|
+
})
|
34
|
+
|
35
|
+
const datumList$ = observer.computedData$.pipe(
|
36
|
+
map(d => d.flat())
|
37
|
+
).pipe(
|
38
|
+
shareReplay(1)
|
39
|
+
)
|
40
|
+
|
41
|
+
const seriesHighlight$ = highlightObservable({
|
42
|
+
datumList$,
|
43
|
+
fullChartParams$: observer.fullChartParams$,
|
44
|
+
event$: subject.event$
|
45
|
+
}).pipe(
|
46
|
+
shareReplay(1)
|
47
|
+
)
|
48
|
+
|
49
|
+
const seriesLabels$ = seriesLabelsObservable({
|
50
|
+
computedData$: observer.computedData$,
|
51
|
+
})
|
52
|
+
|
53
|
+
|
54
|
+
const SeriesDataMap$ = seriesDataMapObservable({
|
55
|
+
datumList$
|
56
|
+
}).pipe(
|
57
|
+
shareReplay(1)
|
58
|
+
)
|
59
|
+
|
60
|
+
const seriesContainerPosition$ = seriesContainerPositionObservable({
|
61
|
+
computedData$: observer.computedData$,
|
62
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
63
|
+
layout$: observer.layout$,
|
64
|
+
}).pipe(
|
65
|
+
shareReplay(1)
|
66
|
+
)
|
67
|
+
|
68
|
+
const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
|
69
|
+
seriesContainerPosition$: seriesContainerPosition$,
|
70
|
+
seriesLabels$: seriesLabels$,
|
71
|
+
separateSeries$: separateSeries$,
|
72
|
+
}).pipe(
|
73
|
+
shareReplay(1)
|
74
|
+
)
|
75
|
+
|
76
|
+
return {
|
77
|
+
fullParams$: observer.fullParams$,
|
78
|
+
fullChartParams$: observer.fullChartParams$,
|
79
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
80
|
+
computedData$: observer.computedData$,
|
81
|
+
layout$: observer.layout$,
|
82
|
+
textSizePx$,
|
83
|
+
visibleComputedData$,
|
84
|
+
visibleComputedLayoutData$,
|
85
|
+
separateSeries$,
|
86
|
+
computedLayoutData$,
|
87
|
+
seriesHighlight$,
|
88
|
+
seriesLabels$,
|
89
|
+
SeriesDataMap$,
|
90
|
+
seriesContainerPosition$,
|
91
|
+
SeriesContainerPositionMap$,
|
92
|
+
}
|
93
|
+
}
|