@orbcharts/core 3.0.0-alpha.41 → 3.0.0-alpha.43
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 +1906 -1897
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/defaults.d.ts +4 -3
- package/dist/src/grid/computeGridData.d.ts +4 -11
- package/dist/src/grid/gridObservables.d.ts +15 -18
- package/dist/src/multiGrid/multiGridObservables.d.ts +4 -11
- package/dist/src/series/seriesObservables.d.ts +26 -1
- package/dist/src/types/ComputedData.d.ts +1 -0
- package/dist/src/types/ComputedDataGrid.d.ts +0 -3
- package/dist/src/types/ComputedDataSeries.d.ts +1 -2
- package/dist/src/types/ContextObserverGrid.d.ts +11 -4
- package/dist/src/types/ContextObserverMultiGrid.d.ts +8 -3
- package/dist/src/types/ContextObserverSeries.d.ts +18 -0
- package/dist/src/types/DataFormatter.d.ts +8 -5
- package/dist/src/types/DataFormatterGrid.d.ts +13 -16
- package/dist/src/types/DataFormatterMultiGrid.d.ts +6 -3
- package/dist/src/types/DataFormatterMultiValue.d.ts +3 -0
- package/dist/src/types/DataFormatterRelationship.d.ts +3 -0
- package/dist/src/types/DataFormatterSeries.d.ts +10 -3
- package/dist/src/utils/orbchartsUtils.d.ts +14 -13
- 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 +220 -248
- 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 -205
- package/src/grid/createGridContextObserver.ts +147 -130
- package/src/grid/gridObservables.ts +573 -486
- package/src/index.ts +21 -21
- package/src/multiGrid/computeMultiGridData.ts +130 -173
- package/src/multiGrid/createMultiGridContextObserver.ts +40 -40
- package/src/multiGrid/multiGridObservables.ts +350 -285
- package/src/multiValue/computeMultiValueData.ts +143 -136
- package/src/multiValue/createMultiValueContextObserver.ts +12 -12
- package/src/relationship/computeRelationshipData.ts +118 -106
- package/src/relationship/createRelationshipContextObserver.ts +12 -12
- package/src/series/computeSeriesData.ts +90 -153
- package/src/series/createSeriesContextObserver.ts +93 -38
- package/src/series/seriesObservables.ts +176 -24
- package/src/tree/computeTreeData.ts +131 -128
- package/src/tree/createTreeContextObserver.ts +61 -61
- 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 +83 -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 +8 -8
- package/src/types/ComputedDataTree.ts +19 -19
- package/src/types/ContextObserver.ts +38 -38
- package/src/types/ContextObserverGrid.ts +41 -33
- package/src/types/ContextObserverMultiGrid.ts +16 -28
- package/src/types/ContextObserverMultiValue.ts +4 -4
- package/src/types/ContextObserverRelationship.ts +4 -4
- package/src/types/ContextObserverSeries.ts +29 -9
- 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 -95
- package/src/types/DataFormatterGrid.ts +67 -55
- package/src/types/DataFormatterMultiGrid.ts +44 -42
- package/src/types/DataFormatterMultiValue.ts +23 -20
- package/src/types/DataFormatterRelationship.ts +25 -22
- package/src/types/DataFormatterSeries.ts +20 -30
- 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 -253
- package/tsconfig.json +13 -13
- package/vite.config.js +44 -44
package/src/defineGridPlugin.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
-
|
3
|
-
export const defineGridPlugin = createBasePlugin<'grid'>()
|
1
|
+
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
+
|
3
|
+
export const defineGridPlugin = createBasePlugin<'grid'>()
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
-
|
3
|
-
export const defineMultiGridPlugin = createBasePlugin<'multiGrid'>()
|
1
|
+
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
+
|
3
|
+
export const defineMultiGridPlugin = createBasePlugin<'multiGrid'>()
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
-
|
3
|
-
export const defineMultiValuePlugin = createBasePlugin<'multiValue'>()
|
1
|
+
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
+
|
3
|
+
export const defineMultiValuePlugin = createBasePlugin<'multiValue'>()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
-
import { ChartType } from './types/Chart'
|
3
|
-
|
4
|
-
export const defineNoneDataPlugin = createBasePlugin<any>() // noneDataPlugin 可以使用在任何的 chartType
|
1
|
+
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
+
import { ChartType } from './types/Chart'
|
3
|
+
|
4
|
+
export const defineNoneDataPlugin = createBasePlugin<any>() // noneDataPlugin 可以使用在任何的 chartType
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
-
|
3
|
-
export const defineRelationshipPlugin = createBasePlugin<'relationship'>()
|
1
|
+
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
+
|
3
|
+
export const defineRelationshipPlugin = createBasePlugin<'relationship'>()
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
-
|
3
|
-
export const defineSeriesPlugin = createBasePlugin<'series'>()
|
1
|
+
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
+
|
3
|
+
export const defineSeriesPlugin = createBasePlugin<'series'>()
|
package/src/defineTreePlugin.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
-
|
3
|
-
export const defineTreePlugin = createBasePlugin<'tree'>()
|
1
|
+
import { createBasePlugin } from './base/createBasePlugin'
|
2
|
+
|
3
|
+
export const defineTreePlugin = createBasePlugin<'tree'>()
|
@@ -1,205 +1,134 @@
|
|
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 {
|
10
|
-
|
11
|
-
|
12
|
-
export
|
13
|
-
//
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
//
|
24
|
-
const
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
return
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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, DataFormatterGridGrid } 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 { getMinAndMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels, seriesColorPredicate } from '../utils/orbchartsUtils'
|
10
|
+
|
11
|
+
// 統一 DataGrid 格式、並欄列資料轉置為一致方式
|
12
|
+
export function createTransposedDataGrid (data: DataGrid, dataFormatterGrid: DataFormatterGridGrid): DataGridDatum[][] {
|
13
|
+
// const { data = [], dataFormatter, chartParams } = context
|
14
|
+
if (!data.length) {
|
15
|
+
return []
|
16
|
+
}
|
17
|
+
try {
|
18
|
+
// 最多的array length
|
19
|
+
const maxArrayLength = data.reduce((prev, current) => {
|
20
|
+
return current.length > prev ? current.length : prev
|
21
|
+
}, 0)
|
22
|
+
|
23
|
+
// 補齊短少資料
|
24
|
+
const fullData = data.map((d, i) => {
|
25
|
+
if (d.length === maxArrayLength) {
|
26
|
+
return d
|
27
|
+
}
|
28
|
+
const newD = Object.assign([], d)
|
29
|
+
for (let _i = newD.length; _i < maxArrayLength; _i++) {
|
30
|
+
newD[_i] = null
|
31
|
+
}
|
32
|
+
return newD
|
33
|
+
})
|
34
|
+
|
35
|
+
// 完整的資料格式
|
36
|
+
const dataGrid: DataGridDatum[][] = fullData.map((d, i) => {
|
37
|
+
return d.map((_d, _i) => {
|
38
|
+
|
39
|
+
const datum: DataGridDatum = _d == null
|
40
|
+
? {
|
41
|
+
id: '',
|
42
|
+
label: '',
|
43
|
+
data: {},
|
44
|
+
value: null,
|
45
|
+
}
|
46
|
+
: typeof _d === 'number'
|
47
|
+
? {
|
48
|
+
id: '',
|
49
|
+
label: '',
|
50
|
+
data: {},
|
51
|
+
value: _d,
|
52
|
+
}
|
53
|
+
: {
|
54
|
+
id: _d.id ?? '',
|
55
|
+
label: _d.label ?? '',
|
56
|
+
data: _d.data ?? {},
|
57
|
+
value: _d.value,
|
58
|
+
}
|
59
|
+
|
60
|
+
return datum
|
61
|
+
})
|
62
|
+
})
|
63
|
+
|
64
|
+
// 依seriesDirection轉置資料矩陣
|
65
|
+
const transposedDataGrid = transposeData(dataFormatterGrid.seriesDirection, dataGrid)
|
66
|
+
|
67
|
+
return transposedDataGrid
|
68
|
+
} catch (e) {
|
69
|
+
return []
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
74
|
+
const { data = [], dataFormatter, chartParams } = context
|
75
|
+
if (!data.length) {
|
76
|
+
return []
|
77
|
+
}
|
78
|
+
|
79
|
+
let computedDataGrid: ComputedDatumGrid[][]
|
80
|
+
|
81
|
+
try {
|
82
|
+
|
83
|
+
// 依seriesDirection轉置資料矩陣
|
84
|
+
const transposedDataGrid = createTransposedDataGrid(data, dataFormatter.grid)
|
85
|
+
|
86
|
+
const seriesLabels = createGridSeriesLabels({
|
87
|
+
transposedDataGrid,
|
88
|
+
dataFormatterGrid: dataFormatter.grid,
|
89
|
+
chartType: 'grid'
|
90
|
+
})
|
91
|
+
const groupLabels = createGridGroupLabels({
|
92
|
+
transposedDataGrid,
|
93
|
+
dataFormatterGrid: dataFormatter.grid,
|
94
|
+
chartType: 'grid'
|
95
|
+
})
|
96
|
+
|
97
|
+
let _index = 0
|
98
|
+
computedDataGrid = transposedDataGrid.map((seriesData, seriesIndex) => {
|
99
|
+
return seriesData.map((groupDatum, groupIndex) => {
|
100
|
+
|
101
|
+
const defaultId = createDefaultDatumId('grid', 0, seriesIndex, groupIndex)
|
102
|
+
const groupLabel = groupLabels[groupIndex]
|
103
|
+
|
104
|
+
const computedDatum: ComputedDatumGrid = {
|
105
|
+
id: groupDatum.id ? groupDatum.id : defaultId,
|
106
|
+
index: _index,
|
107
|
+
label: groupDatum.label ? groupDatum.label : defaultId,
|
108
|
+
description: groupDatum.description ?? '',
|
109
|
+
data: groupDatum.data,
|
110
|
+
value: groupDatum.value,
|
111
|
+
gridIndex: 0,
|
112
|
+
seriesIndex,
|
113
|
+
seriesLabel: seriesLabels[seriesIndex],
|
114
|
+
groupIndex,
|
115
|
+
groupLabel,
|
116
|
+
color: seriesColorPredicate(seriesIndex, chartParams),
|
117
|
+
visible: true // 先給一個預設值
|
118
|
+
}
|
119
|
+
|
120
|
+
// 先建立物件再計算visible欄位
|
121
|
+
computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
|
122
|
+
|
123
|
+
_index ++
|
124
|
+
|
125
|
+
return computedDatum
|
126
|
+
})
|
127
|
+
})
|
128
|
+
|
129
|
+
} catch (e) {
|
130
|
+
throw Error(e)
|
131
|
+
}
|
132
|
+
|
133
|
+
return computedDataGrid
|
134
|
+
}
|