@orbcharts/core 3.0.0-alpha.68 → 3.0.0-beta.10
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/dist/orbcharts-core.es.js +3239 -2854
- package/dist/orbcharts-core.umd.js +4 -4
- package/dist/src/defaults.d.ts +24 -23
- package/dist/src/utils/d3Scale.d.ts +28 -0
- package/dist/src/utils/gridObservables.d.ts +29 -19
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/multiGridObservables.d.ts +2 -2
- package/dist/src/utils/multiValueObservables.d.ts +73 -0
- package/dist/src/utils/orbchartsUtils.d.ts +24 -10
- package/dist/src/utils/relationshipObservables.d.ts +13 -0
- package/dist/src/utils/seriesObservables.d.ts +4 -4
- package/dist/src/utils/treeObservables.d.ts +2 -5
- package/package.json +2 -2
- package/src/GridChart.ts +2 -2
- package/src/MultiGridChart.ts +2 -2
- package/src/MultiValueChart.ts +2 -2
- package/src/RelationshipChart.ts +2 -2
- package/src/SeriesChart.ts +2 -2
- package/src/TreeChart.ts +2 -2
- package/src/base/createBaseChart.ts +13 -13
- package/src/base/validators/chartParamsValidator.ts +6 -6
- package/src/defaults.ts +63 -47
- package/src/grid/computedDataFn.ts +4 -4
- package/src/grid/contextObserverCallback.ts +58 -37
- package/src/grid/dataFormatterValidator.ts +14 -14
- package/src/multiGrid/computedDataFn.ts +2 -2
- package/src/multiValue/computedDataFn.ts +81 -147
- package/src/multiValue/contextObserverCallback.ts +150 -2
- package/src/relationship/computedDataFn.ts +94 -60
- package/src/relationship/contextObserverCallback.ts +68 -0
- package/src/tree/computedDataFn.ts +9 -10
- package/src/tree/contextObserverCallback.ts +6 -9
- package/src/utils/d3Scale.ts +198 -0
- package/src/utils/gridObservables.ts +320 -248
- package/src/utils/index.ts +1 -1
- package/src/utils/multiGridObservables.ts +75 -49
- package/src/utils/multiValueObservables.ts +662 -0
- package/src/utils/observables.ts +30 -12
- package/src/utils/orbchartsUtils.ts +90 -65
- package/src/utils/relationshipObservables.ts +85 -0
- package/src/utils/seriesObservables.ts +7 -7
- package/src/utils/treeObservables.ts +44 -33
- package/src/utils/validator.ts +5 -4
- package/dist/src/utils/d3Utils.d.ts +0 -19
- package/src/utils/d3Utils.ts +0 -108
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { DataMultiValueDatum, ComputedDataFn, ComputedDatumMultiValue } from '../../lib/core-types'
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import { getMinAndMaxValue } from '../utils/orbchartsUtils'
|
2
|
+
import { createDefaultCategoryLabel, createDefaultDatumId, seriesColorPredicate } from '../utils/orbchartsUtils'
|
3
|
+
import { isPlainObject } from '../utils'
|
5
4
|
|
6
5
|
export const computedDataFn: ComputedDataFn<'multiValue'> = (context) => {
|
7
6
|
const { data, dataFormatter, chartParams } = context
|
@@ -9,163 +8,98 @@ export const computedDataFn: ComputedDataFn<'multiValue'> = (context) => {
|
|
9
8
|
return []
|
10
9
|
}
|
11
10
|
|
12
|
-
|
13
|
-
const layout = {
|
14
|
-
width: 1000,
|
15
|
-
height: 1000
|
16
|
-
}
|
11
|
+
const defaultCategoryLabel = createDefaultCategoryLabel()
|
17
12
|
|
18
13
|
let computedDataMultiValue: ComputedDatumMultiValue[][] = []
|
19
14
|
|
20
15
|
try {
|
21
|
-
const dataMultiValue: DataMultiValueDatum[]
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
value: _d
|
32
|
-
}
|
33
|
-
: {
|
34
|
-
id: _d.id ?? '',
|
35
|
-
label: _d.label ?? '',
|
36
|
-
description: _d.description ?? '',
|
37
|
-
// tooltipContent: _d.tooltipContent ?? '',
|
38
|
-
data: _d.data ?? {},
|
39
|
-
categoryLabel: _d.categoryLabel ??'',
|
40
|
-
value: _d.value
|
41
|
-
}
|
42
|
-
|
43
|
-
return datum
|
44
|
-
})
|
45
|
-
})
|
46
|
-
|
47
|
-
// x軸資料最小及最大值(第二維陣列中的第1筆為x軸資料)
|
48
|
-
const [xMinValue, xMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[0]))
|
49
|
-
// y軸資料最小及最大值(第二維陣列中的第2筆為y軸資料)
|
50
|
-
const [yMinValue, yMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[1]))
|
51
|
-
|
52
|
-
// const axisWidth = layout.width - dataFormatter.padding.left - dataFormatter.padding.right
|
53
|
-
// const axisHeight = layout.height - dataFormatter.padding.top - dataFormatter.padding.bottom
|
54
|
-
// const axisWidth = layout.width
|
55
|
-
// const axisHeight = layout.height
|
56
|
-
const xAxisWidth = (dataFormatter.xAxis.position === 'top' || dataFormatter.xAxis.position === 'bottom')
|
57
|
-
? layout.width
|
58
|
-
: layout.height
|
59
|
-
const yAxisWidth = (dataFormatter.yAxis.position === 'left' || dataFormatter.yAxis.position === 'right')
|
60
|
-
? layout.height
|
61
|
-
: layout.width
|
62
|
-
|
63
|
-
const xScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
64
|
-
maxValue: xMaxValue,
|
65
|
-
minValue: xMinValue,
|
66
|
-
axisWidth: xAxisWidth,
|
67
|
-
// scaleDomain: dataFormatter.xAxis.scaleDomain,
|
68
|
-
// scaleRange: dataFormatter.xAxis.scaleRange
|
69
|
-
scaleDomain: [xMinValue, xMaxValue],
|
70
|
-
scaleRange: [0, 1]
|
71
|
-
})
|
72
|
-
const yScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
73
|
-
maxValue: yMaxValue,
|
74
|
-
minValue: yMinValue,
|
75
|
-
axisWidth: yAxisWidth,
|
76
|
-
// scaleDomain: dataFormatter.yAxis.scaleDomain,
|
77
|
-
// scaleRange: dataFormatter.yAxis.scaleRange
|
78
|
-
scaleDomain: [yMinValue, yMaxValue],
|
79
|
-
scaleRange: [0, 1]
|
80
|
-
})
|
81
|
-
|
82
|
-
const _xScaleDoamin: [number, number] = [
|
83
|
-
// dataFormatter.xAxis.scaleDomain[0] === 'auto' ? xMinValue : dataFormatter.xAxis.scaleDomain[0],
|
84
|
-
(() => {
|
85
|
-
if (dataFormatter.xAxis.scaleDomain[0] === 'auto') {
|
86
|
-
return xMinValue < 0 ? xMinValue : 0
|
87
|
-
} else if (dataFormatter.xAxis.scaleDomain[0] === 'min') {
|
88
|
-
return xMinValue
|
89
|
-
} else {
|
90
|
-
return dataFormatter.xAxis.scaleDomain[0]
|
16
|
+
const dataMultiValue: DataMultiValueDatum[] = data.map((d, i) => {
|
17
|
+
if (Array.isArray(d)) {
|
18
|
+
return {
|
19
|
+
id: '',
|
20
|
+
label: '',
|
21
|
+
description: '',
|
22
|
+
// tooltipContent: '',
|
23
|
+
data: {},
|
24
|
+
categoryLabel: defaultCategoryLabel,
|
25
|
+
value: d
|
91
26
|
}
|
92
|
-
}
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
27
|
+
} else if (isPlainObject(d)) {
|
28
|
+
return {
|
29
|
+
id: d.id ?? '',
|
30
|
+
label: d.label ?? '',
|
31
|
+
description: d.description ?? '',
|
32
|
+
// tooltipContent: _d.tooltipContent ?? '',
|
33
|
+
data: d.data ?? {},
|
34
|
+
categoryLabel: d.categoryLabel ?? defaultCategoryLabel,
|
35
|
+
value: d.value
|
101
36
|
}
|
102
|
-
}
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
} else {
|
112
|
-
return dataFormatter.yAxis.scaleDomain[0]
|
37
|
+
} else {
|
38
|
+
return {
|
39
|
+
id: '',
|
40
|
+
label: '',
|
41
|
+
description: '',
|
42
|
+
// tooltipContent: '',
|
43
|
+
data: {},
|
44
|
+
categoryLabel: defaultCategoryLabel,
|
45
|
+
value: []
|
113
46
|
}
|
114
|
-
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
}
|
125
|
-
|
47
|
+
}
|
48
|
+
})
|
49
|
+
|
50
|
+
const categoryLabels = (() => {
|
51
|
+
// 先使用 dataFormatter.categoryLabels
|
52
|
+
const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
|
53
|
+
// 再加入 datum 中的 categoryLabel
|
54
|
+
for (let datum of dataMultiValue) {
|
55
|
+
const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
|
56
|
+
CategoryLabelsSet.add(categoryLabel) // 不重覆
|
57
|
+
}
|
58
|
+
return Array.from(CategoryLabelsSet)
|
59
|
+
})()
|
126
60
|
|
127
|
-
//
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
// }
|
133
|
-
// if (columnIndex === 1 && datum.value != null && (datum.value < _yScaleDoamin[0] || datum.value > _yScaleDoamin[1])) {
|
134
|
-
// return false
|
135
|
-
// }
|
136
|
-
|
137
|
-
// return dataFormatter.visibleFilter(datum, rowIndex, columnIndex, context)
|
138
|
-
// }
|
61
|
+
// <categoryLabel, categoryIndex>
|
62
|
+
const CategoryIndexMap = new Map<string, number>(
|
63
|
+
categoryLabels.map((label, index) => [label, index])
|
64
|
+
)
|
65
|
+
|
139
66
|
|
140
67
|
let index = 0
|
141
68
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
69
|
+
dataMultiValue.forEach((d, i) => {
|
70
|
+
const currentIndex = index
|
71
|
+
index++
|
72
|
+
|
73
|
+
const defaultId = createDefaultDatumId(dataFormatter.type, i)
|
74
|
+
|
75
|
+
const categoryIndex = CategoryIndexMap.get(d.categoryLabel) ?? 0
|
76
|
+
|
77
|
+
const color = seriesColorPredicate(categoryIndex, chartParams)
|
78
|
+
|
79
|
+
const computedDatum: ComputedDatumMultiValue = {
|
80
|
+
id: d.id ? d.id : defaultId,
|
81
|
+
index: currentIndex,
|
82
|
+
label: d.label ? d.label : defaultId,
|
83
|
+
description: d.description ?? '',
|
84
|
+
// tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
|
85
|
+
data: d.data,
|
86
|
+
datumIndex: i,
|
87
|
+
value: d.value,
|
88
|
+
categoryIndex,
|
89
|
+
categoryLabel: d.categoryLabel,
|
90
|
+
// valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
|
91
|
+
// axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
|
92
|
+
visible: true, // 先給預設值
|
93
|
+
color
|
94
|
+
}
|
164
95
|
|
165
|
-
|
96
|
+
computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
|
166
97
|
|
167
|
-
|
168
|
-
|
98
|
+
// 依 categoryIndex 分組
|
99
|
+
if (!computedDataMultiValue[categoryIndex]) {
|
100
|
+
computedDataMultiValue[categoryIndex] = []
|
101
|
+
}
|
102
|
+
computedDataMultiValue[categoryIndex].push(computedDatum)
|
169
103
|
})
|
170
104
|
} catch (e) {
|
171
105
|
// console.error(e)
|
@@ -1,12 +1,160 @@
|
|
1
|
-
import
|
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'
|
2
21
|
|
3
22
|
export const contextObserverCallback: ContextObserverCallback<'multiValue'> = ({ subject, observer }) => {
|
4
23
|
|
5
|
-
|
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>>{
|
6
138
|
fullParams$: observer.fullParams$,
|
7
139
|
fullChartParams$: observer.fullChartParams$,
|
8
140
|
fullDataFormatter$: observer.fullDataFormatter$,
|
9
141
|
computedData$: observer.computedData$,
|
10
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$,
|
11
159
|
}
|
12
160
|
}
|
@@ -8,10 +8,13 @@ import type {
|
|
8
8
|
ComputedNode,
|
9
9
|
ComputedEdge
|
10
10
|
} from '../../lib/core-types'
|
11
|
+
import { createDefaultCategoryLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
|
11
12
|
|
12
13
|
export const computedDataFn: ComputedDataFn<'relationship'> = (context) => {
|
13
14
|
const { data, dataFormatter, chartParams } = context
|
14
15
|
|
16
|
+
const defaultCategoryLabel = createDefaultCategoryLabel()
|
17
|
+
|
15
18
|
let computedNodes: ComputedNode[] = []
|
16
19
|
let computedEdges: ComputedEdge[] = []
|
17
20
|
|
@@ -33,86 +36,117 @@ export const computedDataFn: ComputedDataFn<'relationship'> = (context) => {
|
|
33
36
|
} as ComputedDataRelationship
|
34
37
|
}
|
35
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
|
+
|
36
59
|
// -- nodes --
|
37
60
|
computedNodes = nodes.map((node, i) => {
|
61
|
+
const categoryLabel = node.categoryLabel ?? defaultCategoryLabel
|
62
|
+
const categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
|
63
|
+
|
38
64
|
const computedNode: ComputedNode = {
|
39
65
|
id: node.id,
|
40
66
|
index: i,
|
41
67
|
label: node.label ?? '',
|
42
68
|
description: node.description ?? '',
|
43
|
-
// tooltipContent: node.tooltipContent ? node.tooltipContent : dataFormatter.tooltipContentFormat(node, 0, i, context), // 0代表node
|
44
69
|
data: node.data ?? {},
|
45
70
|
value: node.value ?? 0,
|
46
|
-
categoryIndex
|
47
|
-
categoryLabel
|
48
|
-
color:
|
49
|
-
startNodes: [], // 後面再取得資料
|
50
|
-
startNodeIds: [], // 後面再取得資料
|
51
|
-
endNodes: [], // 後面再取得資料
|
52
|
-
endNodeIds: [], // 後面再取得資料
|
53
|
-
visible: true //
|
71
|
+
categoryIndex,
|
72
|
+
categoryLabel,
|
73
|
+
color: seriesColorPredicate(categoryIndex, chartParams),
|
74
|
+
// startNodes: [], // 後面再取得資料
|
75
|
+
// startNodeIds: [], // 後面再取得資料
|
76
|
+
// endNodes: [], // 後面再取得資料
|
77
|
+
// endNodeIds: [], // 後面再取得資料
|
78
|
+
visible: true // 先給預設值
|
54
79
|
}
|
80
|
+
|
81
|
+
computedNode.visible = dataFormatter.visibleFilter(computedNode, context)
|
82
|
+
|
55
83
|
return computedNode
|
56
84
|
})
|
57
85
|
|
58
86
|
const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
|
59
87
|
|
60
|
-
//
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
})
|
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
|
+
// })()
|
79
107
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
const
|
84
|
-
|
85
|
-
|
108
|
+
// -- edges --
|
109
|
+
computedEdges = edges
|
110
|
+
.map((edge, i) => {
|
111
|
+
const startNode = NodesMap.get(edge.start)
|
112
|
+
const endNode = NodesMap.get(edge.end)
|
113
|
+
return {
|
114
|
+
edge,
|
115
|
+
startNode,
|
116
|
+
endNode
|
117
|
+
}
|
86
118
|
})
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
const _EndNodesMap = new Map()
|
92
|
-
computedEdges.forEach(edge => {
|
93
|
-
const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
|
94
|
-
endNodes.push(edge.endNode)
|
95
|
-
_EndNodesMap.set(edge.startNodeId, endNodes)
|
119
|
+
.filter(({ edge }) => {
|
120
|
+
const startNode = NodesMap.get(edge.start)
|
121
|
+
const endNode = NodesMap.get(edge.end)
|
122
|
+
return startNode != null && endNode != null
|
96
123
|
})
|
97
|
-
|
98
|
-
|
124
|
+
.map(({ edge, startNode, endNode }, i) => {
|
125
|
+
const categoryLabel = edge.categoryLabel ?? defaultCategoryLabel
|
126
|
+
// const startNode = NodesMap.get(edge.start)
|
127
|
+
// const endNode = NodesMap.get(edge.end)
|
99
128
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
129
|
+
const computedEdge: ComputedEdge = {
|
130
|
+
id: edge.id,
|
131
|
+
index: i,
|
132
|
+
label: edge.label ?? '',
|
133
|
+
description: edge.description ?? '',
|
134
|
+
data: edge.data ?? {},
|
135
|
+
value: edge.value ?? 0,
|
136
|
+
categoryIndex: CategoryIndexMap.get(categoryLabel),
|
137
|
+
categoryLabel,
|
138
|
+
color: seriesColorPredicate(i, chartParams),
|
139
|
+
startNode,
|
140
|
+
// startNodeId: edge.start,
|
141
|
+
endNode,
|
142
|
+
// endNodeId: edge.end,
|
143
|
+
visible: startNode.visible && endNode.visible
|
144
|
+
}
|
108
145
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
: false
|
114
|
-
return edge
|
115
|
-
})
|
146
|
+
return computedEdge
|
147
|
+
})
|
148
|
+
|
149
|
+
|
116
150
|
} catch (e) {
|
117
151
|
// console.error(e)
|
118
152
|
throw Error(e)
|