@orbcharts/core 3.0.0-beta.6 → 3.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +200 -200
- package/dist/orbcharts-core.es.js +486 -483
- package/dist/orbcharts-core.umd.js +3 -3
- package/dist/src/defaults.d.ts +1 -1
- package/lib/core-types.ts +7 -7
- package/package.json +42 -42
- package/src/AbstractChart.ts +57 -57
- package/src/GridChart.ts +24 -24
- package/src/MultiGridChart.ts +24 -24
- package/src/MultiValueChart.ts +24 -24
- package/src/RelationshipChart.ts +24 -24
- package/src/SeriesChart.ts +24 -24
- package/src/TreeChart.ts +24 -24
- package/src/base/createBaseChart.ts +505 -505
- package/src/base/createBasePlugin.ts +153 -153
- package/src/base/validators/chartOptionsValidator.ts +23 -23
- package/src/base/validators/chartParamsValidator.ts +133 -133
- package/src/base/validators/elementValidator.ts +13 -13
- package/src/base/validators/pluginsValidator.ts +14 -14
- package/src/defaults.ts +238 -235
- 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/computedDataFn.ts +129 -129
- package/src/grid/contextObserverCallback.ts +176 -176
- package/src/grid/dataFormatterValidator.ts +101 -101
- package/src/grid/dataValidator.ts +12 -12
- package/src/index.ts +20 -20
- package/src/multiGrid/computedDataFn.ts +123 -123
- package/src/multiGrid/contextObserverCallback.ts +41 -41
- package/src/multiGrid/dataFormatterValidator.ts +115 -115
- package/src/multiGrid/dataValidator.ts +12 -12
- package/src/multiValue/computedDataFn.ts +110 -110
- package/src/multiValue/contextObserverCallback.ts +160 -160
- package/src/multiValue/dataFormatterValidator.ts +9 -9
- package/src/multiValue/dataValidator.ts +9 -9
- package/src/relationship/computedDataFn.ts +144 -144
- package/src/relationship/contextObserverCallback.ts +80 -80
- package/src/relationship/dataFormatterValidator.ts +9 -9
- package/src/relationship/dataValidator.ts +9 -9
- package/src/series/computedDataFn.ts +88 -88
- package/src/series/contextObserverCallback.ts +100 -100
- package/src/series/dataFormatterValidator.ts +41 -41
- package/src/series/dataValidator.ts +12 -12
- package/src/tree/computedDataFn.ts +129 -129
- package/src/tree/contextObserverCallback.ts +58 -58
- package/src/tree/dataFormatterValidator.ts +13 -13
- package/src/tree/dataValidator.ts +13 -13
- package/src/utils/commonUtils.ts +55 -55
- package/src/utils/d3Scale.ts +198 -198
- package/src/utils/errorMessage.ts +42 -42
- package/src/utils/gridObservables.ts +683 -683
- package/src/utils/index.ts +9 -9
- package/src/utils/multiGridObservables.ts +392 -392
- package/src/utils/multiValueObservables.ts +661 -661
- package/src/utils/observables.ts +219 -219
- package/src/utils/orbchartsUtils.ts +377 -377
- package/src/utils/relationshipObservables.ts +84 -84
- package/src/utils/seriesObservables.ts +175 -175
- package/src/utils/treeObservables.ts +105 -105
- package/src/utils/validator.ts +126 -126
- package/tsconfig.base.json +13 -13
- package/tsconfig.json +2 -2
- package/vite-env.d.ts +6 -6
- package/vite.config.js +22 -22
@@ -1,160 +1,160 @@
|
|
1
|
-
import { map, shareReplay, distinctUntilChanged } from 'rxjs'
|
2
|
-
import type { ContextObserverCallback, ContextObserverTypeMap } from '../../lib/core-types'
|
3
|
-
import {
|
4
|
-
highlightObservable,
|
5
|
-
categoryDataMapObservable,
|
6
|
-
textSizePxObservable
|
7
|
-
} from '../utils/observables'
|
8
|
-
import {
|
9
|
-
multiValueComputedLayoutDataObservable,
|
10
|
-
// multiValueAxesTransformObservable,
|
11
|
-
// multiValueAxesReverseTransformObservable,
|
12
|
-
multiValueGraphicTransformObservable,
|
13
|
-
multiValueGraphicReverseScaleObservable,
|
14
|
-
multiValueCategoryLabelsObservable,
|
15
|
-
multiValueVisibleComputedDataObservable,
|
16
|
-
multiValueVisibleComputedLayoutDataObservable,
|
17
|
-
multiValueContainerPositionObservable,
|
18
|
-
minMaxXYObservable,
|
19
|
-
filteredMinMaxXYDataObservable
|
20
|
-
} from '../utils/multiValueObservables'
|
21
|
-
|
22
|
-
export const contextObserverCallback: ContextObserverCallback<'multiValue'> = ({ subject, observer }) => {
|
23
|
-
|
24
|
-
const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
|
25
|
-
shareReplay(1)
|
26
|
-
)
|
27
|
-
|
28
|
-
const isCategorySeprate$ = observer.fullDataFormatter$.pipe(
|
29
|
-
map(d => d.separateCategory),
|
30
|
-
distinctUntilChanged(),
|
31
|
-
shareReplay(1)
|
32
|
-
)
|
33
|
-
|
34
|
-
const multiValueContainerPosition$ = multiValueContainerPositionObservable({
|
35
|
-
computedData$: observer.computedData$,
|
36
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
37
|
-
layout$: observer.layout$,
|
38
|
-
})
|
39
|
-
|
40
|
-
// const multiValueAxesSize$ = multiValueAxesSizeObservable({
|
41
|
-
// fullDataFormatter$: observer.fullDataFormatter$,
|
42
|
-
// layout$: observer.layout$
|
43
|
-
// }).pipe(
|
44
|
-
// shareReplay(1)
|
45
|
-
// )
|
46
|
-
|
47
|
-
const datumList$ = observer.computedData$.pipe(
|
48
|
-
map(d => d.flat().flat())
|
49
|
-
).pipe(
|
50
|
-
shareReplay(1)
|
51
|
-
)
|
52
|
-
|
53
|
-
const multiValueHighlight$ = highlightObservable({
|
54
|
-
datumList$,
|
55
|
-
fullChartParams$: observer.fullChartParams$,
|
56
|
-
event$: subject.event$
|
57
|
-
}).pipe(
|
58
|
-
shareReplay(1)
|
59
|
-
)
|
60
|
-
|
61
|
-
const categoryLabels$ = multiValueCategoryLabelsObservable({
|
62
|
-
computedData$: observer.computedData$,
|
63
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
64
|
-
})
|
65
|
-
|
66
|
-
const CategoryDataMap$ = categoryDataMapObservable({
|
67
|
-
datumList$: datumList$
|
68
|
-
}).pipe(
|
69
|
-
shareReplay(1)
|
70
|
-
)
|
71
|
-
|
72
|
-
const minMaxXY$ = minMaxXYObservable({
|
73
|
-
computedData$: observer.computedData$
|
74
|
-
}).pipe(
|
75
|
-
shareReplay(1)
|
76
|
-
)
|
77
|
-
|
78
|
-
|
79
|
-
const computedLayoutData$ = multiValueComputedLayoutDataObservable({
|
80
|
-
computedData$: observer.computedData$,
|
81
|
-
minMaxXY$,
|
82
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
83
|
-
layout$: observer.layout$,
|
84
|
-
}).pipe(
|
85
|
-
shareReplay(1)
|
86
|
-
)
|
87
|
-
|
88
|
-
const visibleComputedData$ = multiValueVisibleComputedDataObservable({
|
89
|
-
computedData$: observer.computedData$,
|
90
|
-
}).pipe(
|
91
|
-
shareReplay(1)
|
92
|
-
)
|
93
|
-
|
94
|
-
const visibleComputedLayoutData$ = multiValueVisibleComputedLayoutDataObservable({
|
95
|
-
computedLayoutData$: computedLayoutData$,
|
96
|
-
}).pipe(
|
97
|
-
shareReplay(1)
|
98
|
-
)
|
99
|
-
|
100
|
-
const filteredMinMaxXYData$ = filteredMinMaxXYDataObservable({
|
101
|
-
visibleComputedLayoutData$: visibleComputedLayoutData$,
|
102
|
-
minMaxXY$,
|
103
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
104
|
-
}).pipe(
|
105
|
-
shareReplay(1)
|
106
|
-
)
|
107
|
-
|
108
|
-
// const multiValueAxesTransform$ = multiValueAxesTransformObservable({
|
109
|
-
// fullDataFormatter$: observer.fullDataFormatter$,
|
110
|
-
// layout$: observer.layout$
|
111
|
-
// }).pipe(
|
112
|
-
// shareReplay(1)
|
113
|
-
// )
|
114
|
-
|
115
|
-
// const multiValueAxesReverseTransform$ = multiValueAxesReverseTransformObservable({
|
116
|
-
// multiValueAxesTransform$
|
117
|
-
// }).pipe(
|
118
|
-
// shareReplay(1)
|
119
|
-
// )
|
120
|
-
|
121
|
-
const multiValueGraphicTransform$ = multiValueGraphicTransformObservable({
|
122
|
-
minMaxXY$,
|
123
|
-
filteredMinMaxXYData$,
|
124
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
125
|
-
layout$: observer.layout$
|
126
|
-
}).pipe(
|
127
|
-
shareReplay(1)
|
128
|
-
)
|
129
|
-
|
130
|
-
const multiValueGraphicReverseScale$ = multiValueGraphicReverseScaleObservable({
|
131
|
-
multiValueContainerPosition$: multiValueContainerPosition$,
|
132
|
-
// multiValueAxesTransform$: multiValueAxesTransform$,
|
133
|
-
multiValueGraphicTransform$: multiValueGraphicTransform$,
|
134
|
-
})
|
135
|
-
|
136
|
-
|
137
|
-
return <ContextObserverTypeMap<'multiValue', any>>{
|
138
|
-
fullParams$: observer.fullParams$,
|
139
|
-
fullChartParams$: observer.fullChartParams$,
|
140
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
141
|
-
computedData$: observer.computedData$,
|
142
|
-
layout$: observer.layout$,
|
143
|
-
textSizePx$,
|
144
|
-
isCategorySeprate$,
|
145
|
-
multiValueContainerPosition$,
|
146
|
-
// multiValueAxesSize$,
|
147
|
-
multiValueHighlight$,
|
148
|
-
categoryLabels$,
|
149
|
-
CategoryDataMap$,
|
150
|
-
minMaxXY$,
|
151
|
-
computedLayoutData$,
|
152
|
-
visibleComputedData$,
|
153
|
-
visibleComputedLayoutData$,
|
154
|
-
filteredMinMaxXYData$,
|
155
|
-
// multiValueAxesTransform$,
|
156
|
-
// multiValueAxesReverseTransform$,
|
157
|
-
multiValueGraphicTransform$,
|
158
|
-
multiValueGraphicReverseScale$,
|
159
|
-
}
|
160
|
-
}
|
1
|
+
import { map, shareReplay, distinctUntilChanged } from 'rxjs'
|
2
|
+
import type { ContextObserverCallback, ContextObserverTypeMap } from '../../lib/core-types'
|
3
|
+
import {
|
4
|
+
highlightObservable,
|
5
|
+
categoryDataMapObservable,
|
6
|
+
textSizePxObservable
|
7
|
+
} from '../utils/observables'
|
8
|
+
import {
|
9
|
+
multiValueComputedLayoutDataObservable,
|
10
|
+
// multiValueAxesTransformObservable,
|
11
|
+
// multiValueAxesReverseTransformObservable,
|
12
|
+
multiValueGraphicTransformObservable,
|
13
|
+
multiValueGraphicReverseScaleObservable,
|
14
|
+
multiValueCategoryLabelsObservable,
|
15
|
+
multiValueVisibleComputedDataObservable,
|
16
|
+
multiValueVisibleComputedLayoutDataObservable,
|
17
|
+
multiValueContainerPositionObservable,
|
18
|
+
minMaxXYObservable,
|
19
|
+
filteredMinMaxXYDataObservable
|
20
|
+
} from '../utils/multiValueObservables'
|
21
|
+
|
22
|
+
export const contextObserverCallback: ContextObserverCallback<'multiValue'> = ({ subject, observer }) => {
|
23
|
+
|
24
|
+
const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
|
25
|
+
shareReplay(1)
|
26
|
+
)
|
27
|
+
|
28
|
+
const isCategorySeprate$ = observer.fullDataFormatter$.pipe(
|
29
|
+
map(d => d.separateCategory),
|
30
|
+
distinctUntilChanged(),
|
31
|
+
shareReplay(1)
|
32
|
+
)
|
33
|
+
|
34
|
+
const multiValueContainerPosition$ = multiValueContainerPositionObservable({
|
35
|
+
computedData$: observer.computedData$,
|
36
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
37
|
+
layout$: observer.layout$,
|
38
|
+
})
|
39
|
+
|
40
|
+
// const multiValueAxesSize$ = multiValueAxesSizeObservable({
|
41
|
+
// fullDataFormatter$: observer.fullDataFormatter$,
|
42
|
+
// layout$: observer.layout$
|
43
|
+
// }).pipe(
|
44
|
+
// shareReplay(1)
|
45
|
+
// )
|
46
|
+
|
47
|
+
const datumList$ = observer.computedData$.pipe(
|
48
|
+
map(d => d.flat().flat())
|
49
|
+
).pipe(
|
50
|
+
shareReplay(1)
|
51
|
+
)
|
52
|
+
|
53
|
+
const multiValueHighlight$ = highlightObservable({
|
54
|
+
datumList$,
|
55
|
+
fullChartParams$: observer.fullChartParams$,
|
56
|
+
event$: subject.event$
|
57
|
+
}).pipe(
|
58
|
+
shareReplay(1)
|
59
|
+
)
|
60
|
+
|
61
|
+
const categoryLabels$ = multiValueCategoryLabelsObservable({
|
62
|
+
computedData$: observer.computedData$,
|
63
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
64
|
+
})
|
65
|
+
|
66
|
+
const CategoryDataMap$ = categoryDataMapObservable({
|
67
|
+
datumList$: datumList$
|
68
|
+
}).pipe(
|
69
|
+
shareReplay(1)
|
70
|
+
)
|
71
|
+
|
72
|
+
const minMaxXY$ = minMaxXYObservable({
|
73
|
+
computedData$: observer.computedData$
|
74
|
+
}).pipe(
|
75
|
+
shareReplay(1)
|
76
|
+
)
|
77
|
+
|
78
|
+
|
79
|
+
const computedLayoutData$ = multiValueComputedLayoutDataObservable({
|
80
|
+
computedData$: observer.computedData$,
|
81
|
+
minMaxXY$,
|
82
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
83
|
+
layout$: observer.layout$,
|
84
|
+
}).pipe(
|
85
|
+
shareReplay(1)
|
86
|
+
)
|
87
|
+
|
88
|
+
const visibleComputedData$ = multiValueVisibleComputedDataObservable({
|
89
|
+
computedData$: observer.computedData$,
|
90
|
+
}).pipe(
|
91
|
+
shareReplay(1)
|
92
|
+
)
|
93
|
+
|
94
|
+
const visibleComputedLayoutData$ = multiValueVisibleComputedLayoutDataObservable({
|
95
|
+
computedLayoutData$: computedLayoutData$,
|
96
|
+
}).pipe(
|
97
|
+
shareReplay(1)
|
98
|
+
)
|
99
|
+
|
100
|
+
const filteredMinMaxXYData$ = filteredMinMaxXYDataObservable({
|
101
|
+
visibleComputedLayoutData$: visibleComputedLayoutData$,
|
102
|
+
minMaxXY$,
|
103
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
104
|
+
}).pipe(
|
105
|
+
shareReplay(1)
|
106
|
+
)
|
107
|
+
|
108
|
+
// const multiValueAxesTransform$ = multiValueAxesTransformObservable({
|
109
|
+
// fullDataFormatter$: observer.fullDataFormatter$,
|
110
|
+
// layout$: observer.layout$
|
111
|
+
// }).pipe(
|
112
|
+
// shareReplay(1)
|
113
|
+
// )
|
114
|
+
|
115
|
+
// const multiValueAxesReverseTransform$ = multiValueAxesReverseTransformObservable({
|
116
|
+
// multiValueAxesTransform$
|
117
|
+
// }).pipe(
|
118
|
+
// shareReplay(1)
|
119
|
+
// )
|
120
|
+
|
121
|
+
const multiValueGraphicTransform$ = multiValueGraphicTransformObservable({
|
122
|
+
minMaxXY$,
|
123
|
+
filteredMinMaxXYData$,
|
124
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
125
|
+
layout$: observer.layout$
|
126
|
+
}).pipe(
|
127
|
+
shareReplay(1)
|
128
|
+
)
|
129
|
+
|
130
|
+
const multiValueGraphicReverseScale$ = multiValueGraphicReverseScaleObservable({
|
131
|
+
multiValueContainerPosition$: multiValueContainerPosition$,
|
132
|
+
// multiValueAxesTransform$: multiValueAxesTransform$,
|
133
|
+
multiValueGraphicTransform$: multiValueGraphicTransform$,
|
134
|
+
})
|
135
|
+
|
136
|
+
|
137
|
+
return <ContextObserverTypeMap<'multiValue', any>>{
|
138
|
+
fullParams$: observer.fullParams$,
|
139
|
+
fullChartParams$: observer.fullChartParams$,
|
140
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
141
|
+
computedData$: observer.computedData$,
|
142
|
+
layout$: observer.layout$,
|
143
|
+
textSizePx$,
|
144
|
+
isCategorySeprate$,
|
145
|
+
multiValueContainerPosition$,
|
146
|
+
// multiValueAxesSize$,
|
147
|
+
multiValueHighlight$,
|
148
|
+
categoryLabels$,
|
149
|
+
CategoryDataMap$,
|
150
|
+
minMaxXY$,
|
151
|
+
computedLayoutData$,
|
152
|
+
visibleComputedData$,
|
153
|
+
visibleComputedLayoutData$,
|
154
|
+
filteredMinMaxXYData$,
|
155
|
+
// multiValueAxesTransform$,
|
156
|
+
// multiValueAxesReverseTransform$,
|
157
|
+
multiValueGraphicTransform$,
|
158
|
+
multiValueGraphicReverseScale$,
|
159
|
+
}
|
160
|
+
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
|
2
|
-
|
3
|
-
export const dataFormatterValidator: DataFormatterValidator<'multiValue'> = (dataFormatter: DataFormatterTypeMap<'multiValue'>) => {
|
4
|
-
|
5
|
-
return {
|
6
|
-
status: 'success',
|
7
|
-
columnName: '',
|
8
|
-
expectToBe: ''
|
9
|
-
}
|
1
|
+
import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
|
2
|
+
|
3
|
+
export const dataFormatterValidator: DataFormatterValidator<'multiValue'> = (dataFormatter: DataFormatterTypeMap<'multiValue'>) => {
|
4
|
+
|
5
|
+
return {
|
6
|
+
status: 'success',
|
7
|
+
columnName: '',
|
8
|
+
expectToBe: ''
|
9
|
+
}
|
10
10
|
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import type { DataValidator, DataTypeMap } from '../../lib/core-types'
|
2
|
-
|
3
|
-
export const dataValidator: DataValidator<'multiValue'> = (data: DataTypeMap<'multiValue'>) => {
|
4
|
-
|
5
|
-
return {
|
6
|
-
status: 'success',
|
7
|
-
columnName: '',
|
8
|
-
expectToBe: ''
|
9
|
-
}
|
1
|
+
import type { DataValidator, DataTypeMap } from '../../lib/core-types'
|
2
|
+
|
3
|
+
export const dataValidator: DataValidator<'multiValue'> = (data: DataTypeMap<'multiValue'>) => {
|
4
|
+
|
5
|
+
return {
|
6
|
+
status: 'success',
|
7
|
+
columnName: '',
|
8
|
+
expectToBe: ''
|
9
|
+
}
|
10
10
|
}
|
@@ -1,144 +1,144 @@
|
|
1
|
-
import type {
|
2
|
-
DataRelationshipObj,
|
3
|
-
DataRelationshipList,
|
4
|
-
Node,
|
5
|
-
Edge,
|
6
|
-
ComputedDataFn,
|
7
|
-
ComputedDataRelationship,
|
8
|
-
ComputedNode,
|
9
|
-
ComputedEdge
|
10
|
-
} from '../../lib/core-types'
|
11
|
-
import { createDefaultCategoryLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
|
12
|
-
|
13
|
-
export const computedDataFn: ComputedDataFn<'relationship'> = (context) => {
|
14
|
-
const { data, dataFormatter, chartParams } = context
|
15
|
-
|
16
|
-
const defaultCategoryLabel = createDefaultCategoryLabel()
|
17
|
-
|
18
|
-
let computedNodes: ComputedNode[] = []
|
19
|
-
let computedEdges: ComputedEdge[] = []
|
20
|
-
|
21
|
-
try {
|
22
|
-
// -- 取得nodes和edges資料 --
|
23
|
-
let nodes: Node[] = []
|
24
|
-
let edges: Edge[] = []
|
25
|
-
if ((data as DataRelationshipObj).nodes) {
|
26
|
-
nodes = (data as DataRelationshipObj).nodes
|
27
|
-
edges = (data as DataRelationshipObj).edges
|
28
|
-
} else if ((data as DataRelationshipList)[0]) {
|
29
|
-
nodes = (data as DataRelationshipList)[0]
|
30
|
-
edges = (data as DataRelationshipList)[1]
|
31
|
-
} else {
|
32
|
-
// 無值直接回傳
|
33
|
-
return {
|
34
|
-
nodes: [],
|
35
|
-
edges: []
|
36
|
-
} as ComputedDataRelationship
|
37
|
-
}
|
38
|
-
|
39
|
-
const categoryLabels = (() => {
|
40
|
-
// 先使用 dataFormatter.categoryLabels
|
41
|
-
const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
|
42
|
-
// 再加入 datum 中的 categoryLabel
|
43
|
-
for (let datum of nodes) {
|
44
|
-
const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
|
45
|
-
CategoryLabelsSet.add(categoryLabel) // 不重覆
|
46
|
-
}
|
47
|
-
for (let datum of edges) {
|
48
|
-
const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
|
49
|
-
CategoryLabelsSet.add(categoryLabel) // 不重覆
|
50
|
-
}
|
51
|
-
return Array.from(CategoryLabelsSet)
|
52
|
-
})()
|
53
|
-
|
54
|
-
// <categoryLabel, categoryIndex>
|
55
|
-
const CategoryIndexMap = new Map<string, number>(
|
56
|
-
categoryLabels.map((label, index) => [label, index])
|
57
|
-
)
|
58
|
-
|
59
|
-
// -- nodes --
|
60
|
-
computedNodes = nodes.map((node, i) => {
|
61
|
-
const categoryLabel = node.categoryLabel ?? defaultCategoryLabel
|
62
|
-
const categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
|
63
|
-
|
64
|
-
const computedNode: ComputedNode = {
|
65
|
-
id: node.id,
|
66
|
-
index: i,
|
67
|
-
label: node.label ?? '',
|
68
|
-
description: node.description ?? '',
|
69
|
-
data: node.data ?? {},
|
70
|
-
value: node.value ?? 0,
|
71
|
-
categoryIndex,
|
72
|
-
categoryLabel,
|
73
|
-
color: seriesColorPredicate(categoryIndex, chartParams),
|
74
|
-
// startNodes: [], // 後面再取得資料
|
75
|
-
// startNodeIds: [], // 後面再取得資料
|
76
|
-
// endNodes: [], // 後面再取得資料
|
77
|
-
// endNodeIds: [], // 後面再取得資料
|
78
|
-
visible: true // 先給預設值
|
79
|
-
}
|
80
|
-
|
81
|
-
computedNode.visible = dataFormatter.visibleFilter(computedNode, context)
|
82
|
-
|
83
|
-
return computedNode
|
84
|
-
})
|
85
|
-
|
86
|
-
const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
|
87
|
-
|
88
|
-
// const StartNodesMap: Map<string, ComputedNode[]> = (function () {
|
89
|
-
// const _StartNodesMap = new Map()
|
90
|
-
// computedEdges.forEach(edge => {
|
91
|
-
// const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
|
92
|
-
// startNodes.push(edge.startNode)
|
93
|
-
// _StartNodesMap.set(edge.endNodeId, startNodes)
|
94
|
-
// })
|
95
|
-
// return _StartNodesMap
|
96
|
-
// })()
|
97
|
-
|
98
|
-
// const EndNodesMap: Map<string, ComputedNode[]> = (function () {
|
99
|
-
// const _EndNodesMap = new Map()
|
100
|
-
// computedEdges.forEach(edge => {
|
101
|
-
// const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
|
102
|
-
// endNodes.push(edge.endNode)
|
103
|
-
// _EndNodesMap.set(edge.startNodeId, endNodes)
|
104
|
-
// })
|
105
|
-
// return _EndNodesMap
|
106
|
-
// })()
|
107
|
-
|
108
|
-
// -- edges --
|
109
|
-
computedEdges = edges.map((edge, i) => {
|
110
|
-
const categoryLabel = edge.categoryLabel ?? defaultCategoryLabel
|
111
|
-
const startNode = NodesMap.get(edge.start)
|
112
|
-
const endNode = NodesMap.get(edge.end)
|
113
|
-
|
114
|
-
const computedEdge: ComputedEdge = {
|
115
|
-
id: edge.id,
|
116
|
-
index: i,
|
117
|
-
label: edge.label ?? '',
|
118
|
-
description: edge.description ?? '',
|
119
|
-
data: edge.data ?? {},
|
120
|
-
value: edge.value ?? 0,
|
121
|
-
categoryIndex: CategoryIndexMap.get(categoryLabel),
|
122
|
-
categoryLabel,
|
123
|
-
color: seriesColorPredicate(i, chartParams),
|
124
|
-
startNode,
|
125
|
-
// startNodeId: edge.start,
|
126
|
-
endNode,
|
127
|
-
// endNodeId: edge.end,
|
128
|
-
visible: startNode.visible && endNode.visible
|
129
|
-
}
|
130
|
-
|
131
|
-
return computedEdge
|
132
|
-
})
|
133
|
-
|
134
|
-
|
135
|
-
} catch (e) {
|
136
|
-
// console.error(e)
|
137
|
-
throw Error(e)
|
138
|
-
}
|
139
|
-
|
140
|
-
return {
|
141
|
-
nodes: computedNodes,
|
142
|
-
edges: computedEdges
|
143
|
-
}
|
144
|
-
}
|
1
|
+
import type {
|
2
|
+
DataRelationshipObj,
|
3
|
+
DataRelationshipList,
|
4
|
+
Node,
|
5
|
+
Edge,
|
6
|
+
ComputedDataFn,
|
7
|
+
ComputedDataRelationship,
|
8
|
+
ComputedNode,
|
9
|
+
ComputedEdge
|
10
|
+
} from '../../lib/core-types'
|
11
|
+
import { createDefaultCategoryLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
|
12
|
+
|
13
|
+
export const computedDataFn: ComputedDataFn<'relationship'> = (context) => {
|
14
|
+
const { data, dataFormatter, chartParams } = context
|
15
|
+
|
16
|
+
const defaultCategoryLabel = createDefaultCategoryLabel()
|
17
|
+
|
18
|
+
let computedNodes: ComputedNode[] = []
|
19
|
+
let computedEdges: ComputedEdge[] = []
|
20
|
+
|
21
|
+
try {
|
22
|
+
// -- 取得nodes和edges資料 --
|
23
|
+
let nodes: Node[] = []
|
24
|
+
let edges: Edge[] = []
|
25
|
+
if ((data as DataRelationshipObj).nodes) {
|
26
|
+
nodes = (data as DataRelationshipObj).nodes
|
27
|
+
edges = (data as DataRelationshipObj).edges
|
28
|
+
} else if ((data as DataRelationshipList)[0]) {
|
29
|
+
nodes = (data as DataRelationshipList)[0]
|
30
|
+
edges = (data as DataRelationshipList)[1]
|
31
|
+
} else {
|
32
|
+
// 無值直接回傳
|
33
|
+
return {
|
34
|
+
nodes: [],
|
35
|
+
edges: []
|
36
|
+
} as ComputedDataRelationship
|
37
|
+
}
|
38
|
+
|
39
|
+
const categoryLabels = (() => {
|
40
|
+
// 先使用 dataFormatter.categoryLabels
|
41
|
+
const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
|
42
|
+
// 再加入 datum 中的 categoryLabel
|
43
|
+
for (let datum of nodes) {
|
44
|
+
const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
|
45
|
+
CategoryLabelsSet.add(categoryLabel) // 不重覆
|
46
|
+
}
|
47
|
+
for (let datum of edges) {
|
48
|
+
const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
|
49
|
+
CategoryLabelsSet.add(categoryLabel) // 不重覆
|
50
|
+
}
|
51
|
+
return Array.from(CategoryLabelsSet)
|
52
|
+
})()
|
53
|
+
|
54
|
+
// <categoryLabel, categoryIndex>
|
55
|
+
const CategoryIndexMap = new Map<string, number>(
|
56
|
+
categoryLabels.map((label, index) => [label, index])
|
57
|
+
)
|
58
|
+
|
59
|
+
// -- nodes --
|
60
|
+
computedNodes = nodes.map((node, i) => {
|
61
|
+
const categoryLabel = node.categoryLabel ?? defaultCategoryLabel
|
62
|
+
const categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
|
63
|
+
|
64
|
+
const computedNode: ComputedNode = {
|
65
|
+
id: node.id,
|
66
|
+
index: i,
|
67
|
+
label: node.label ?? '',
|
68
|
+
description: node.description ?? '',
|
69
|
+
data: node.data ?? {},
|
70
|
+
value: node.value ?? 0,
|
71
|
+
categoryIndex,
|
72
|
+
categoryLabel,
|
73
|
+
color: seriesColorPredicate(categoryIndex, chartParams),
|
74
|
+
// startNodes: [], // 後面再取得資料
|
75
|
+
// startNodeIds: [], // 後面再取得資料
|
76
|
+
// endNodes: [], // 後面再取得資料
|
77
|
+
// endNodeIds: [], // 後面再取得資料
|
78
|
+
visible: true // 先給預設值
|
79
|
+
}
|
80
|
+
|
81
|
+
computedNode.visible = dataFormatter.visibleFilter(computedNode, context)
|
82
|
+
|
83
|
+
return computedNode
|
84
|
+
})
|
85
|
+
|
86
|
+
const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
|
87
|
+
|
88
|
+
// const StartNodesMap: Map<string, ComputedNode[]> = (function () {
|
89
|
+
// const _StartNodesMap = new Map()
|
90
|
+
// computedEdges.forEach(edge => {
|
91
|
+
// const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
|
92
|
+
// startNodes.push(edge.startNode)
|
93
|
+
// _StartNodesMap.set(edge.endNodeId, startNodes)
|
94
|
+
// })
|
95
|
+
// return _StartNodesMap
|
96
|
+
// })()
|
97
|
+
|
98
|
+
// const EndNodesMap: Map<string, ComputedNode[]> = (function () {
|
99
|
+
// const _EndNodesMap = new Map()
|
100
|
+
// computedEdges.forEach(edge => {
|
101
|
+
// const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
|
102
|
+
// endNodes.push(edge.endNode)
|
103
|
+
// _EndNodesMap.set(edge.startNodeId, endNodes)
|
104
|
+
// })
|
105
|
+
// return _EndNodesMap
|
106
|
+
// })()
|
107
|
+
|
108
|
+
// -- edges --
|
109
|
+
computedEdges = edges.map((edge, i) => {
|
110
|
+
const categoryLabel = edge.categoryLabel ?? defaultCategoryLabel
|
111
|
+
const startNode = NodesMap.get(edge.start)
|
112
|
+
const endNode = NodesMap.get(edge.end)
|
113
|
+
|
114
|
+
const computedEdge: ComputedEdge = {
|
115
|
+
id: edge.id,
|
116
|
+
index: i,
|
117
|
+
label: edge.label ?? '',
|
118
|
+
description: edge.description ?? '',
|
119
|
+
data: edge.data ?? {},
|
120
|
+
value: edge.value ?? 0,
|
121
|
+
categoryIndex: CategoryIndexMap.get(categoryLabel),
|
122
|
+
categoryLabel,
|
123
|
+
color: seriesColorPredicate(i, chartParams),
|
124
|
+
startNode,
|
125
|
+
// startNodeId: edge.start,
|
126
|
+
endNode,
|
127
|
+
// endNodeId: edge.end,
|
128
|
+
visible: startNode.visible && endNode.visible
|
129
|
+
}
|
130
|
+
|
131
|
+
return computedEdge
|
132
|
+
})
|
133
|
+
|
134
|
+
|
135
|
+
} catch (e) {
|
136
|
+
// console.error(e)
|
137
|
+
throw Error(e)
|
138
|
+
}
|
139
|
+
|
140
|
+
return {
|
141
|
+
nodes: computedNodes,
|
142
|
+
edges: computedEdges
|
143
|
+
}
|
144
|
+
}
|