@orbcharts/core 3.0.0-alpha.39 → 3.0.0-alpha.40
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 +6 -6
- package/dist/orbcharts-core.umd.js +1 -1
- package/dist/src/types/ContextObserverGrid.d.ts +1 -1
- package/dist/src/types/ContextObserverSeries.d.ts +1 -1
- package/dist/src/types/ContextObserverTree.d.ts +1 -1
- package/dist/src/utils/observables.d.ts +5 -5
- 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 +367 -367
- package/src/base/createBasePlugin.ts +89 -89
- package/src/defaults.ts +247 -247
- 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 +205 -205
- package/src/grid/createGridContextObserver.ts +124 -124
- package/src/grid/gridObservables.ts +486 -486
- package/src/index.ts +21 -21
- package/src/multiGrid/computeMultiGridData.ts +173 -173
- package/src/multiGrid/createMultiGridContextObserver.ts +34 -34
- package/src/multiGrid/multiGridObservables.ts +285 -285
- package/src/multiValue/computeMultiValueData.ts +136 -136
- package/src/multiValue/createMultiValueContextObserver.ts +12 -12
- package/src/relationship/computeRelationshipData.ts +106 -106
- package/src/relationship/createRelationshipContextObserver.ts +12 -12
- package/src/series/computeSeriesData.ts +153 -153
- package/src/series/createSeriesContextObserver.ts +33 -33
- package/src/series/seriesObservables.ts +23 -23
- package/src/tree/computeTreeData.ts +128 -128
- package/src/tree/createTreeContextObserver.ts +56 -56
- package/src/tree/treeObservables.ts +94 -94
- package/src/types/Chart.ts +48 -48
- package/src/types/ChartParams.ts +51 -51
- package/src/types/ComputedData.ts +82 -82
- 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 +33 -33
- package/src/types/ContextObserverMultiGrid.ts +27 -27
- package/src/types/ContextObserverMultiValue.ts +4 -4
- package/src/types/ContextObserverRelationship.ts +4 -4
- package/src/types/ContextObserverSeries.ts +7 -7
- package/src/types/ContextObserverTree.ts +10 -10
- package/src/types/ContextSubject.ts +18 -18
- package/src/types/Data.ts +45 -45
- package/src/types/DataFormatter.ts +95 -95
- package/src/types/DataFormatterGrid.ts +55 -55
- package/src/types/DataFormatterMultiGrid.ts +42 -42
- package/src/types/DataFormatterMultiValue.ts +20 -20
- package/src/types/DataFormatterRelationship.ts +22 -22
- package/src/types/DataFormatterSeries.ts +29 -29
- 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 +181 -183
- package/src/utils/orbchartsUtils.ts +253 -253
- package/tsconfig.json +13 -13
- package/vite.config.js +44 -44
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
import * as d3 from 'd3'
|
|
2
|
-
import type { ComputedDataFn } from '../types/ComputedData'
|
|
3
|
-
import type { DataGrid, DataGridDatum } from '../types/DataGrid'
|
|
4
|
-
import type { DataFormatterContext } from '../types/DataFormatter'
|
|
5
|
-
import type { DataFormatterGrid } from '../types/DataFormatterGrid'
|
|
6
|
-
import type { ComputedDataGrid, ComputedDatumGrid } from '../types/ComputedDataGrid'
|
|
7
|
-
import type { Layout } from '../types/Layout'
|
|
8
|
-
import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, createDefaultGroupLabel } from '../utils/orbchartsUtils'
|
|
9
|
-
import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
|
|
10
|
-
import { getMinAndMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels, seriesColorPredicate } from '../utils/orbchartsUtils'
|
|
11
|
-
|
|
12
|
-
export interface DataGridDatumTemp extends DataGridDatum {
|
|
13
|
-
// _color: string // 暫放的顏色資料
|
|
14
|
-
_visible: boolean // 暫放的visible
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function createTransposedDataGrid (context: DataFormatterContext<'grid'>): DataGridDatumTemp[][] {
|
|
18
|
-
const { data = [], dataFormatter, chartParams, layout } = context
|
|
19
|
-
if (!data.length) {
|
|
20
|
-
return []
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
// 最多的array length
|
|
24
|
-
const maxArrayLength = data.reduce((prev, current) => {
|
|
25
|
-
return current.length > prev ? current.length : prev
|
|
26
|
-
}, 0)
|
|
27
|
-
|
|
28
|
-
// 補齊短少資料
|
|
29
|
-
const fullData = data.map((d, i) => {
|
|
30
|
-
if (d.length === maxArrayLength) {
|
|
31
|
-
return d
|
|
32
|
-
}
|
|
33
|
-
const newD = Object.assign([], d)
|
|
34
|
-
for (let _i = newD.length; _i < maxArrayLength; _i++) {
|
|
35
|
-
newD[_i] = null
|
|
36
|
-
}
|
|
37
|
-
return newD
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
// 完整的資料格式
|
|
41
|
-
const dataGrid: DataGridDatumTemp[][] = fullData.map((d, i) => {
|
|
42
|
-
return d.map((_d, _i) => {
|
|
43
|
-
|
|
44
|
-
// const _color = dataFormatter.colorsPredicate(_d, i, _i, context)
|
|
45
|
-
const _visible = dataFormatter.grid.visibleFilter(_d, i, _i, context)
|
|
46
|
-
|
|
47
|
-
const datum: DataGridDatumTemp = _d == null
|
|
48
|
-
? {
|
|
49
|
-
id: '',
|
|
50
|
-
label: '',
|
|
51
|
-
// tooltipContent: '',
|
|
52
|
-
data: {},
|
|
53
|
-
value: null,
|
|
54
|
-
// _color,
|
|
55
|
-
_visible
|
|
56
|
-
}
|
|
57
|
-
: typeof _d === 'number'
|
|
58
|
-
? {
|
|
59
|
-
id: '',
|
|
60
|
-
label: '',
|
|
61
|
-
// tooltipContent: '',
|
|
62
|
-
data: {},
|
|
63
|
-
value: _d,
|
|
64
|
-
// _color,
|
|
65
|
-
_visible
|
|
66
|
-
}
|
|
67
|
-
: {
|
|
68
|
-
id: _d.id ?? '',
|
|
69
|
-
label: _d.label ?? '',
|
|
70
|
-
// tooltipContent: _d.tooltipContent ?? '',
|
|
71
|
-
data: _d.data ?? {},
|
|
72
|
-
value: _d.value,
|
|
73
|
-
// _color,
|
|
74
|
-
_visible
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return datum
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
// 依seriesDirection轉置資料矩陣
|
|
82
|
-
const transposedDataGrid = transposeData(dataFormatter.grid.gridData.seriesDirection, dataGrid)
|
|
83
|
-
|
|
84
|
-
return transposedDataGrid
|
|
85
|
-
} catch (e) {
|
|
86
|
-
return []
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function createGroupScale (transposedDataGrid: DataGridDatumTemp[][], dataFormatter: DataFormatterGrid, layout: Layout) {
|
|
91
|
-
const groupAxisWidth = (dataFormatter.grid.groupAxis.position === 'top' || dataFormatter.grid.groupAxis.position === 'bottom')
|
|
92
|
-
? layout.width
|
|
93
|
-
: layout.height
|
|
94
|
-
const groupEndIndex = transposedDataGrid[0] ? transposedDataGrid[0].length - 1 : 0
|
|
95
|
-
const groupScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
96
|
-
maxValue: groupEndIndex,
|
|
97
|
-
minValue: 0,
|
|
98
|
-
axisWidth: groupAxisWidth,
|
|
99
|
-
scaleDomain: [0, groupEndIndex], // 不使用dataFormatter設定
|
|
100
|
-
scaleRange: [0, 1] // 不使用dataFormatter設定
|
|
101
|
-
})
|
|
102
|
-
return groupScale
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function createSeriesValueScaleArr (transposedDataGrid: DataGridDatumTemp[][], dataFormatter: DataFormatterGrid, layout: Layout) {
|
|
106
|
-
const valueAxisWidth = (dataFormatter.grid.valueAxis.position === 'left' || dataFormatter.grid.valueAxis.position === 'right')
|
|
107
|
-
? layout.height
|
|
108
|
-
: layout.width
|
|
109
|
-
|
|
110
|
-
const visibleData = transposedDataGrid.flat().filter(d => d._visible != false)
|
|
111
|
-
const [minValue, maxValue] = getMinAndMaxValue(visibleData)
|
|
112
|
-
|
|
113
|
-
return transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
114
|
-
const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
115
|
-
maxValue,
|
|
116
|
-
minValue,
|
|
117
|
-
axisWidth: valueAxisWidth,
|
|
118
|
-
scaleDomain: [minValue, maxValue], // 不使用dataFormatter設定
|
|
119
|
-
scaleRange: [0, 1] // 不使用dataFormatter設定
|
|
120
|
-
})
|
|
121
|
-
return valueScale
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
126
|
-
const { data = [], dataFormatter, chartParams, layout } = context
|
|
127
|
-
if (!data.length) {
|
|
128
|
-
return []
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let computedDataGrid: ComputedDatumGrid[][]
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
|
|
135
|
-
// 依seriesDirection轉置資料矩陣
|
|
136
|
-
const transposedDataGrid = createTransposedDataGrid(context)
|
|
137
|
-
|
|
138
|
-
const groupScale = createGroupScale(transposedDataGrid, dataFormatter, layout)
|
|
139
|
-
|
|
140
|
-
const seriesLabels = createGridSeriesLabels({
|
|
141
|
-
transposedDataGrid,
|
|
142
|
-
dataFormatter,
|
|
143
|
-
chartType: 'grid'
|
|
144
|
-
})
|
|
145
|
-
const groupLabels = createGridGroupLabels({
|
|
146
|
-
transposedDataGrid,
|
|
147
|
-
dataFormatter,
|
|
148
|
-
chartType: 'grid'
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
// 每一個series的valueScale
|
|
152
|
-
const seriesValueScaleArr = createSeriesValueScaleArr(transposedDataGrid, dataFormatter, layout)
|
|
153
|
-
|
|
154
|
-
const zeroYArr = transposedDataGrid.map((series, seriesIndex) => {
|
|
155
|
-
return seriesValueScaleArr[seriesIndex]!(0)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
let _index = 0
|
|
159
|
-
computedDataGrid = transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
160
|
-
return seriesData.map((groupDatum, groupIndex) => {
|
|
161
|
-
|
|
162
|
-
const defaultId = createDefaultDatumId('grid', 0, seriesIndex, groupIndex)
|
|
163
|
-
// const visible = visibleFilter(groupDatum, seriesIndex, groupIndex, context)
|
|
164
|
-
const groupLabel = groupLabels[groupIndex]
|
|
165
|
-
const valueScale = seriesValueScaleArr[seriesIndex]
|
|
166
|
-
const axisY = valueScale(groupDatum.value ?? 0)
|
|
167
|
-
const zeroY = zeroYArr[seriesIndex]
|
|
168
|
-
|
|
169
|
-
const computedDatum: ComputedDatumGrid = {
|
|
170
|
-
id: groupDatum.id ? groupDatum.id : defaultId,
|
|
171
|
-
index: _index,
|
|
172
|
-
label: groupDatum.label ? groupDatum.label : defaultId,
|
|
173
|
-
description: groupDatum.description ?? '',
|
|
174
|
-
// tooltipContent: groupDatum.tooltipContent ? groupDatum.tooltipContent : dataFormatter.tooltipContentFormat(groupDatum, seriesIndex, groupIndex, context),
|
|
175
|
-
data: groupDatum.data,
|
|
176
|
-
value: groupDatum.value,
|
|
177
|
-
// valueLabel: formatValueToLabel(groupDatum.value, dataFormatter.valueFormat),
|
|
178
|
-
gridIndex: 0,
|
|
179
|
-
// accSeriesIndex: seriesIndex, // 預設為seriesIndex
|
|
180
|
-
seriesIndex,
|
|
181
|
-
seriesLabel: seriesLabels[seriesIndex],
|
|
182
|
-
groupIndex,
|
|
183
|
-
groupLabel,
|
|
184
|
-
// color: groupDatum._color,
|
|
185
|
-
color: seriesColorPredicate(seriesIndex, chartParams),
|
|
186
|
-
axisX: groupScale(groupIndex),
|
|
187
|
-
axisY,
|
|
188
|
-
axisYFromZero: axisY - zeroY,
|
|
189
|
-
// visible: groupDatum._visible == true && scaleDomainFilter(groupIndex) == true ? true : false // 兩者有一個false即為false
|
|
190
|
-
visible: groupDatum._visible
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
_index ++
|
|
194
|
-
|
|
195
|
-
return computedDatum
|
|
196
|
-
})
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
} catch (e) {
|
|
200
|
-
// console.error(e)
|
|
201
|
-
throw Error(e)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return computedDataGrid
|
|
205
|
-
}
|
|
1
|
+
import * as d3 from 'd3'
|
|
2
|
+
import type { ComputedDataFn } from '../types/ComputedData'
|
|
3
|
+
import type { DataGrid, DataGridDatum } from '../types/DataGrid'
|
|
4
|
+
import type { DataFormatterContext } from '../types/DataFormatter'
|
|
5
|
+
import type { DataFormatterGrid } from '../types/DataFormatterGrid'
|
|
6
|
+
import type { ComputedDataGrid, ComputedDatumGrid } from '../types/ComputedDataGrid'
|
|
7
|
+
import type { Layout } from '../types/Layout'
|
|
8
|
+
import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, createDefaultGroupLabel } from '../utils/orbchartsUtils'
|
|
9
|
+
import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
|
|
10
|
+
import { getMinAndMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels, seriesColorPredicate } from '../utils/orbchartsUtils'
|
|
11
|
+
|
|
12
|
+
export interface DataGridDatumTemp extends DataGridDatum {
|
|
13
|
+
// _color: string // 暫放的顏色資料
|
|
14
|
+
_visible: boolean // 暫放的visible
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createTransposedDataGrid (context: DataFormatterContext<'grid'>): DataGridDatumTemp[][] {
|
|
18
|
+
const { data = [], dataFormatter, chartParams, layout } = context
|
|
19
|
+
if (!data.length) {
|
|
20
|
+
return []
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
// 最多的array length
|
|
24
|
+
const maxArrayLength = data.reduce((prev, current) => {
|
|
25
|
+
return current.length > prev ? current.length : prev
|
|
26
|
+
}, 0)
|
|
27
|
+
|
|
28
|
+
// 補齊短少資料
|
|
29
|
+
const fullData = data.map((d, i) => {
|
|
30
|
+
if (d.length === maxArrayLength) {
|
|
31
|
+
return d
|
|
32
|
+
}
|
|
33
|
+
const newD = Object.assign([], d)
|
|
34
|
+
for (let _i = newD.length; _i < maxArrayLength; _i++) {
|
|
35
|
+
newD[_i] = null
|
|
36
|
+
}
|
|
37
|
+
return newD
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// 完整的資料格式
|
|
41
|
+
const dataGrid: DataGridDatumTemp[][] = fullData.map((d, i) => {
|
|
42
|
+
return d.map((_d, _i) => {
|
|
43
|
+
|
|
44
|
+
// const _color = dataFormatter.colorsPredicate(_d, i, _i, context)
|
|
45
|
+
const _visible = dataFormatter.grid.visibleFilter(_d, i, _i, context)
|
|
46
|
+
|
|
47
|
+
const datum: DataGridDatumTemp = _d == null
|
|
48
|
+
? {
|
|
49
|
+
id: '',
|
|
50
|
+
label: '',
|
|
51
|
+
// tooltipContent: '',
|
|
52
|
+
data: {},
|
|
53
|
+
value: null,
|
|
54
|
+
// _color,
|
|
55
|
+
_visible
|
|
56
|
+
}
|
|
57
|
+
: typeof _d === 'number'
|
|
58
|
+
? {
|
|
59
|
+
id: '',
|
|
60
|
+
label: '',
|
|
61
|
+
// tooltipContent: '',
|
|
62
|
+
data: {},
|
|
63
|
+
value: _d,
|
|
64
|
+
// _color,
|
|
65
|
+
_visible
|
|
66
|
+
}
|
|
67
|
+
: {
|
|
68
|
+
id: _d.id ?? '',
|
|
69
|
+
label: _d.label ?? '',
|
|
70
|
+
// tooltipContent: _d.tooltipContent ?? '',
|
|
71
|
+
data: _d.data ?? {},
|
|
72
|
+
value: _d.value,
|
|
73
|
+
// _color,
|
|
74
|
+
_visible
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return datum
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
// 依seriesDirection轉置資料矩陣
|
|
82
|
+
const transposedDataGrid = transposeData(dataFormatter.grid.gridData.seriesDirection, dataGrid)
|
|
83
|
+
|
|
84
|
+
return transposedDataGrid
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return []
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function createGroupScale (transposedDataGrid: DataGridDatumTemp[][], dataFormatter: DataFormatterGrid, layout: Layout) {
|
|
91
|
+
const groupAxisWidth = (dataFormatter.grid.groupAxis.position === 'top' || dataFormatter.grid.groupAxis.position === 'bottom')
|
|
92
|
+
? layout.width
|
|
93
|
+
: layout.height
|
|
94
|
+
const groupEndIndex = transposedDataGrid[0] ? transposedDataGrid[0].length - 1 : 0
|
|
95
|
+
const groupScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
96
|
+
maxValue: groupEndIndex,
|
|
97
|
+
minValue: 0,
|
|
98
|
+
axisWidth: groupAxisWidth,
|
|
99
|
+
scaleDomain: [0, groupEndIndex], // 不使用dataFormatter設定
|
|
100
|
+
scaleRange: [0, 1] // 不使用dataFormatter設定
|
|
101
|
+
})
|
|
102
|
+
return groupScale
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function createSeriesValueScaleArr (transposedDataGrid: DataGridDatumTemp[][], dataFormatter: DataFormatterGrid, layout: Layout) {
|
|
106
|
+
const valueAxisWidth = (dataFormatter.grid.valueAxis.position === 'left' || dataFormatter.grid.valueAxis.position === 'right')
|
|
107
|
+
? layout.height
|
|
108
|
+
: layout.width
|
|
109
|
+
|
|
110
|
+
const visibleData = transposedDataGrid.flat().filter(d => d._visible != false)
|
|
111
|
+
const [minValue, maxValue] = getMinAndMaxValue(visibleData)
|
|
112
|
+
|
|
113
|
+
return transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
114
|
+
const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
115
|
+
maxValue,
|
|
116
|
+
minValue,
|
|
117
|
+
axisWidth: valueAxisWidth,
|
|
118
|
+
scaleDomain: [minValue, maxValue], // 不使用dataFormatter設定
|
|
119
|
+
scaleRange: [0, 1] // 不使用dataFormatter設定
|
|
120
|
+
})
|
|
121
|
+
return valueScale
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
126
|
+
const { data = [], dataFormatter, chartParams, layout } = context
|
|
127
|
+
if (!data.length) {
|
|
128
|
+
return []
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let computedDataGrid: ComputedDatumGrid[][]
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
|
|
135
|
+
// 依seriesDirection轉置資料矩陣
|
|
136
|
+
const transposedDataGrid = createTransposedDataGrid(context)
|
|
137
|
+
|
|
138
|
+
const groupScale = createGroupScale(transposedDataGrid, dataFormatter, layout)
|
|
139
|
+
|
|
140
|
+
const seriesLabels = createGridSeriesLabels({
|
|
141
|
+
transposedDataGrid,
|
|
142
|
+
dataFormatter,
|
|
143
|
+
chartType: 'grid'
|
|
144
|
+
})
|
|
145
|
+
const groupLabels = createGridGroupLabels({
|
|
146
|
+
transposedDataGrid,
|
|
147
|
+
dataFormatter,
|
|
148
|
+
chartType: 'grid'
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
// 每一個series的valueScale
|
|
152
|
+
const seriesValueScaleArr = createSeriesValueScaleArr(transposedDataGrid, dataFormatter, layout)
|
|
153
|
+
|
|
154
|
+
const zeroYArr = transposedDataGrid.map((series, seriesIndex) => {
|
|
155
|
+
return seriesValueScaleArr[seriesIndex]!(0)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
let _index = 0
|
|
159
|
+
computedDataGrid = transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
160
|
+
return seriesData.map((groupDatum, groupIndex) => {
|
|
161
|
+
|
|
162
|
+
const defaultId = createDefaultDatumId('grid', 0, seriesIndex, groupIndex)
|
|
163
|
+
// const visible = visibleFilter(groupDatum, seriesIndex, groupIndex, context)
|
|
164
|
+
const groupLabel = groupLabels[groupIndex]
|
|
165
|
+
const valueScale = seriesValueScaleArr[seriesIndex]
|
|
166
|
+
const axisY = valueScale(groupDatum.value ?? 0)
|
|
167
|
+
const zeroY = zeroYArr[seriesIndex]
|
|
168
|
+
|
|
169
|
+
const computedDatum: ComputedDatumGrid = {
|
|
170
|
+
id: groupDatum.id ? groupDatum.id : defaultId,
|
|
171
|
+
index: _index,
|
|
172
|
+
label: groupDatum.label ? groupDatum.label : defaultId,
|
|
173
|
+
description: groupDatum.description ?? '',
|
|
174
|
+
// tooltipContent: groupDatum.tooltipContent ? groupDatum.tooltipContent : dataFormatter.tooltipContentFormat(groupDatum, seriesIndex, groupIndex, context),
|
|
175
|
+
data: groupDatum.data,
|
|
176
|
+
value: groupDatum.value,
|
|
177
|
+
// valueLabel: formatValueToLabel(groupDatum.value, dataFormatter.valueFormat),
|
|
178
|
+
gridIndex: 0,
|
|
179
|
+
// accSeriesIndex: seriesIndex, // 預設為seriesIndex
|
|
180
|
+
seriesIndex,
|
|
181
|
+
seriesLabel: seriesLabels[seriesIndex],
|
|
182
|
+
groupIndex,
|
|
183
|
+
groupLabel,
|
|
184
|
+
// color: groupDatum._color,
|
|
185
|
+
color: seriesColorPredicate(seriesIndex, chartParams),
|
|
186
|
+
axisX: groupScale(groupIndex),
|
|
187
|
+
axisY,
|
|
188
|
+
axisYFromZero: axisY - zeroY,
|
|
189
|
+
// visible: groupDatum._visible == true && scaleDomainFilter(groupIndex) == true ? true : false // 兩者有一個false即為false
|
|
190
|
+
visible: groupDatum._visible
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
_index ++
|
|
194
|
+
|
|
195
|
+
return computedDatum
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
} catch (e) {
|
|
200
|
+
// console.error(e)
|
|
201
|
+
throw Error(e)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return computedDataGrid
|
|
205
|
+
}
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import { map, shareReplay } from 'rxjs'
|
|
2
|
-
import type { ContextObserverFn } from '../types'
|
|
3
|
-
import {
|
|
4
|
-
highlightObservable,
|
|
5
|
-
seriesDataMapObservable,
|
|
6
|
-
groupDataMapObservable } from '../utils/observables'
|
|
7
|
-
import {
|
|
8
|
-
gridAxesTransformObservable,
|
|
9
|
-
gridAxesReverseTransformObservable,
|
|
10
|
-
gridGraphicTransformObservable,
|
|
11
|
-
gridGraphicReverseScaleObservable,
|
|
12
|
-
gridAxesSizeObservable,
|
|
13
|
-
existSeriesLabelsObservable,
|
|
14
|
-
gridVisibleComputedDataObservable,
|
|
15
|
-
isSeriesPositionSeprateObservable,
|
|
16
|
-
gridContainerObservable } from './gridObservables'
|
|
17
|
-
|
|
18
|
-
export const createGridContextObserver: ContextObserverFn<'grid'> = ({ subject, observer }) => {
|
|
19
|
-
|
|
20
|
-
const isSeriesPositionSeprate$ = isSeriesPositionSeprateObservable({
|
|
21
|
-
computedData$: observer.computedData$,
|
|
22
|
-
fullDataFormatter$: observer.fullDataFormatter$
|
|
23
|
-
}).pipe(
|
|
24
|
-
shareReplay(1)
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
const gridContainer$ = gridContainerObservable({
|
|
28
|
-
computedData$: observer.computedData$,
|
|
29
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
30
|
-
fullChartParams$: observer.fullChartParams$,
|
|
31
|
-
layout$: observer.layout$,
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const gridAxesTransform$ = gridAxesTransformObservable({
|
|
35
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
36
|
-
layout$: observer.layout$
|
|
37
|
-
}).pipe(
|
|
38
|
-
shareReplay(1)
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
|
|
42
|
-
gridAxesTransform$
|
|
43
|
-
}).pipe(
|
|
44
|
-
shareReplay(1)
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
const gridGraphicTransform$ = gridGraphicTransformObservable({
|
|
48
|
-
computedData$: observer.computedData$,
|
|
49
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
50
|
-
layout$: observer.layout$
|
|
51
|
-
}).pipe(
|
|
52
|
-
shareReplay(1)
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
const gridGraphicReverseScale$ = gridGraphicReverseScaleObservable({
|
|
56
|
-
gridContainer$: gridContainer$,
|
|
57
|
-
gridAxesTransform$: gridAxesTransform$,
|
|
58
|
-
gridGraphicTransform$: gridGraphicTransform$,
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const gridAxesSize$ = gridAxesSizeObservable({
|
|
62
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
63
|
-
layout$: observer.layout$
|
|
64
|
-
}).pipe(
|
|
65
|
-
shareReplay(1)
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const datumList$ = observer.computedData$.pipe(
|
|
69
|
-
map(d => d.flat())
|
|
70
|
-
).pipe(
|
|
71
|
-
shareReplay(1)
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
const gridHighlight$ = highlightObservable({
|
|
75
|
-
datumList$,
|
|
76
|
-
fullChartParams$: observer.fullChartParams$,
|
|
77
|
-
event$: subject.event$
|
|
78
|
-
}).pipe(
|
|
79
|
-
shareReplay(1)
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
const existSeriesLabels$ = existSeriesLabelsObservable({
|
|
83
|
-
computedData$: observer.computedData$,
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
const SeriesDataMap$ = seriesDataMapObservable({
|
|
87
|
-
datumList$: datumList$
|
|
88
|
-
}).pipe(
|
|
89
|
-
shareReplay(1)
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
const GroupDataMap$ = groupDataMapObservable({
|
|
93
|
-
datumList$: datumList$
|
|
94
|
-
}).pipe(
|
|
95
|
-
shareReplay(1)
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
const visibleComputedData$ = gridVisibleComputedDataObservable({
|
|
99
|
-
computedData$: observer.computedData$,
|
|
100
|
-
}).pipe(
|
|
101
|
-
shareReplay(1)
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
fullParams$: observer.fullParams$,
|
|
107
|
-
fullChartParams$: observer.fullChartParams$,
|
|
108
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
109
|
-
computedData$: observer.computedData$,
|
|
110
|
-
layout$: observer.layout$,
|
|
111
|
-
isSeriesPositionSeprate$,
|
|
112
|
-
gridContainer$,
|
|
113
|
-
gridAxesTransform$,
|
|
114
|
-
gridAxesReverseTransform$,
|
|
115
|
-
gridGraphicTransform$,
|
|
116
|
-
gridGraphicReverseScale$,
|
|
117
|
-
gridAxesSize$,
|
|
118
|
-
gridHighlight$,
|
|
119
|
-
existSeriesLabels$,
|
|
120
|
-
SeriesDataMap$,
|
|
121
|
-
GroupDataMap$,
|
|
122
|
-
visibleComputedData$,
|
|
123
|
-
}
|
|
124
|
-
}
|
|
1
|
+
import { map, shareReplay } from 'rxjs'
|
|
2
|
+
import type { ContextObserverFn } from '../types'
|
|
3
|
+
import {
|
|
4
|
+
highlightObservable,
|
|
5
|
+
seriesDataMapObservable,
|
|
6
|
+
groupDataMapObservable } from '../utils/observables'
|
|
7
|
+
import {
|
|
8
|
+
gridAxesTransformObservable,
|
|
9
|
+
gridAxesReverseTransformObservable,
|
|
10
|
+
gridGraphicTransformObservable,
|
|
11
|
+
gridGraphicReverseScaleObservable,
|
|
12
|
+
gridAxesSizeObservable,
|
|
13
|
+
existSeriesLabelsObservable,
|
|
14
|
+
gridVisibleComputedDataObservable,
|
|
15
|
+
isSeriesPositionSeprateObservable,
|
|
16
|
+
gridContainerObservable } from './gridObservables'
|
|
17
|
+
|
|
18
|
+
export const createGridContextObserver: ContextObserverFn<'grid'> = ({ subject, observer }) => {
|
|
19
|
+
|
|
20
|
+
const isSeriesPositionSeprate$ = isSeriesPositionSeprateObservable({
|
|
21
|
+
computedData$: observer.computedData$,
|
|
22
|
+
fullDataFormatter$: observer.fullDataFormatter$
|
|
23
|
+
}).pipe(
|
|
24
|
+
shareReplay(1)
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const gridContainer$ = gridContainerObservable({
|
|
28
|
+
computedData$: observer.computedData$,
|
|
29
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
30
|
+
fullChartParams$: observer.fullChartParams$,
|
|
31
|
+
layout$: observer.layout$,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const gridAxesTransform$ = gridAxesTransformObservable({
|
|
35
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
36
|
+
layout$: observer.layout$
|
|
37
|
+
}).pipe(
|
|
38
|
+
shareReplay(1)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
|
|
42
|
+
gridAxesTransform$
|
|
43
|
+
}).pipe(
|
|
44
|
+
shareReplay(1)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const gridGraphicTransform$ = gridGraphicTransformObservable({
|
|
48
|
+
computedData$: observer.computedData$,
|
|
49
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
50
|
+
layout$: observer.layout$
|
|
51
|
+
}).pipe(
|
|
52
|
+
shareReplay(1)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
const gridGraphicReverseScale$ = gridGraphicReverseScaleObservable({
|
|
56
|
+
gridContainer$: gridContainer$,
|
|
57
|
+
gridAxesTransform$: gridAxesTransform$,
|
|
58
|
+
gridGraphicTransform$: gridGraphicTransform$,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const gridAxesSize$ = gridAxesSizeObservable({
|
|
62
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
63
|
+
layout$: observer.layout$
|
|
64
|
+
}).pipe(
|
|
65
|
+
shareReplay(1)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const datumList$ = observer.computedData$.pipe(
|
|
69
|
+
map(d => d.flat())
|
|
70
|
+
).pipe(
|
|
71
|
+
shareReplay(1)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
const gridHighlight$ = highlightObservable({
|
|
75
|
+
datumList$,
|
|
76
|
+
fullChartParams$: observer.fullChartParams$,
|
|
77
|
+
event$: subject.event$
|
|
78
|
+
}).pipe(
|
|
79
|
+
shareReplay(1)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
const existSeriesLabels$ = existSeriesLabelsObservable({
|
|
83
|
+
computedData$: observer.computedData$,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const SeriesDataMap$ = seriesDataMapObservable({
|
|
87
|
+
datumList$: datumList$
|
|
88
|
+
}).pipe(
|
|
89
|
+
shareReplay(1)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const GroupDataMap$ = groupDataMapObservable({
|
|
93
|
+
datumList$: datumList$
|
|
94
|
+
}).pipe(
|
|
95
|
+
shareReplay(1)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const visibleComputedData$ = gridVisibleComputedDataObservable({
|
|
99
|
+
computedData$: observer.computedData$,
|
|
100
|
+
}).pipe(
|
|
101
|
+
shareReplay(1)
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
fullParams$: observer.fullParams$,
|
|
107
|
+
fullChartParams$: observer.fullChartParams$,
|
|
108
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
109
|
+
computedData$: observer.computedData$,
|
|
110
|
+
layout$: observer.layout$,
|
|
111
|
+
isSeriesPositionSeprate$,
|
|
112
|
+
gridContainer$,
|
|
113
|
+
gridAxesTransform$,
|
|
114
|
+
gridAxesReverseTransform$,
|
|
115
|
+
gridGraphicTransform$,
|
|
116
|
+
gridGraphicReverseScale$,
|
|
117
|
+
gridAxesSize$,
|
|
118
|
+
gridHighlight$,
|
|
119
|
+
existSeriesLabels$,
|
|
120
|
+
SeriesDataMap$,
|
|
121
|
+
GroupDataMap$,
|
|
122
|
+
visibleComputedData$,
|
|
123
|
+
}
|
|
124
|
+
}
|