@orbcharts/core 3.0.0-alpha.28 → 3.0.0-alpha.29
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 +1047 -1044
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/defaults.d.ts +2 -3
- package/dist/src/grid/computeGridData.d.ts +3 -0
- package/dist/src/types/ComputedData.d.ts +1 -1
- package/dist/src/types/ComputedDataGrid.d.ts +2 -0
- package/dist/src/types/Data.d.ts +1 -1
- package/dist/src/types/DataFormatter.d.ts +0 -2
- package/dist/src/types/DataFormatterGrid.d.ts +2 -4
- package/dist/src/types/DataFormatterMultiGrid.d.ts +2 -1
- package/dist/src/types/DataFormatterMultiValue.d.ts +2 -1
- package/dist/src/types/DataFormatterRelationship.d.ts +2 -1
- package/dist/src/types/DataFormatterSeries.d.ts +2 -3
- package/dist/src/types/DataFormatterTree.d.ts +2 -1
- package/dist/src/utils/orbchartsUtils.d.ts +18 -5
- package/package.json +1 -1
- package/src/defaults.ts +30 -44
- package/src/grid/computeGridData.ts +31 -23
- package/src/multiGrid/computeMultiGridData.ts +37 -27
- package/src/multiValue/computeMultiValueData.ts +6 -3
- package/src/relationship/computeRelationshipData.ts +4 -2
- package/src/series/computeSeriesData.ts +7 -8
- package/src/tree/computeTreeData.ts +5 -3
- package/src/types/ComputedData.ts +1 -1
- package/src/types/ComputedDataGrid.ts +2 -0
- package/src/types/Data.ts +1 -1
- package/src/types/DataFormatter.ts +0 -4
- package/src/types/DataFormatterGrid.ts +4 -3
- package/src/types/DataFormatterMultiGrid.ts +6 -5
- package/src/types/DataFormatterMultiValue.ts +2 -1
- package/src/types/DataFormatterRelationship.ts +2 -1
- package/src/types/DataFormatterSeries.ts +4 -3
- package/src/types/DataFormatterTree.ts +2 -1
- package/src/utils/orbchartsUtils.ts +64 -11
|
@@ -20,8 +20,6 @@ export type DataFormatterTypeMap<T extends ChartType> = T extends 'series' ? Dat
|
|
|
20
20
|
export type DataFormatterPartialTypeMap<T extends ChartType> = T extends 'series' ? DataFormatterSeriesPartial : T extends 'grid' ? DataFormatterGridPartial : T extends 'multiGrid' ? DataFormatterMultiGridPartial : T extends 'multiValue' ? DataFormatterMultiValuePartial : T extends 'relationship' ? DataFormatterRelationshipPartial : T extends 'tree' ? DataFormatterTreePartial : DataFormatterBasePartial<T>;
|
|
21
21
|
export interface DataFormatterBase<T extends ChartType> {
|
|
22
22
|
type: T;
|
|
23
|
-
visibleFilter: VisibleFilter<T>;
|
|
24
|
-
tooltipContentFormat: TooltipContentFormat<T>;
|
|
25
23
|
}
|
|
26
24
|
export type DataFormatterBasePartial<T extends ChartType> = Partial<DataFormatterBase<T>>;
|
|
27
25
|
export interface DataFormatterValueAxis {
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, DataFormatterGroupAxis, DataFormatterContext } from './DataFormatter';
|
|
1
|
+
import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, DataFormatterGroupAxis, VisibleFilter } from './DataFormatter';
|
|
3
2
|
|
|
4
3
|
export type SeriesType = 'row' | 'column';
|
|
5
4
|
export interface DataFormatterGrid extends DataFormatterBase<'grid'> {
|
|
5
|
+
visibleFilter: VisibleFilter<'grid'>;
|
|
6
6
|
grid: DataFormatterGridGrid;
|
|
7
7
|
valueAxis: DataFormatterValueAxis;
|
|
8
8
|
groupAxis: DataFormatterGroupAxis;
|
|
9
|
-
colorsPredicate: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string;
|
|
10
9
|
}
|
|
11
10
|
export interface DataFormatterGridPartial extends DataFormatterBasePartial<'grid'> {
|
|
12
11
|
grid?: Partial<DataFormatterGridGrid>;
|
|
13
12
|
valueAxis?: Partial<DataFormatterValueAxis>;
|
|
14
13
|
groupAxis?: Partial<DataFormatterGroupAxis>;
|
|
15
|
-
colorsPredicate?: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string;
|
|
16
14
|
}
|
|
17
15
|
export interface DataFormatterGridGrid {
|
|
18
16
|
rowLabels: string[];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { VisibleFilter, DataFormatterBase, DataFormatterBasePartial } from './DataFormatter';
|
|
1
2
|
import { DataFormatterGrid } from './DataFormatterGrid';
|
|
2
|
-
import { DataFormatterBase, DataFormatterBasePartial } from './DataFormatter';
|
|
3
3
|
|
|
4
4
|
export interface DataFormatterMultiGrid extends DataFormatterBase<'multiGrid'> {
|
|
5
|
+
visibleFilter: VisibleFilter<'multiGrid'>;
|
|
5
6
|
multiGrid: Array<DataFormatterGrid>;
|
|
6
7
|
}
|
|
7
8
|
export interface DataFormatterMultiGridPartial extends DataFormatterBasePartial<'multiGrid'> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis } from './DataFormatter';
|
|
1
|
+
import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, VisibleFilter } from './DataFormatter';
|
|
2
2
|
|
|
3
3
|
export interface DataFormatterMultiValue extends DataFormatterBase<'multiValue'> {
|
|
4
|
+
visibleFilter: VisibleFilter<'multiValue'>;
|
|
4
5
|
multiValue: Array<DataFormatterMultiValueMultiValue>;
|
|
5
6
|
xAxis: DataFormatterValueAxis;
|
|
6
7
|
yAxis: DataFormatterValueAxis;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DataFormatterBase, DataFormatterBasePartial } from './DataFormatter';
|
|
1
|
+
import { DataFormatterBase, DataFormatterBasePartial, VisibleFilter } from './DataFormatter';
|
|
2
2
|
|
|
3
3
|
export interface DataFormatterRelationship extends DataFormatterBase<'relationship'> {
|
|
4
|
+
visibleFilter: VisibleFilter<'relationship'>;
|
|
4
5
|
}
|
|
5
6
|
export interface DataFormatterRelationshipPartial extends DataFormatterBasePartial<'relationship'> {
|
|
6
7
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { DataSeriesDatum, DataSeriesValue } from './DataSeries';
|
|
2
|
-
import { DataFormatterBase, DataFormatterBasePartial,
|
|
2
|
+
import { DataFormatterBase, DataFormatterBasePartial, VisibleFilter } from './DataFormatter';
|
|
3
3
|
|
|
4
4
|
export interface DataFormatterSeries extends DataFormatterBase<'series'> {
|
|
5
|
+
visibleFilter: VisibleFilter<'series'>;
|
|
5
6
|
unitLabel: string;
|
|
6
7
|
seriesLabels: string[];
|
|
7
|
-
colorsPredicate: (datum: DataSeriesDatum | DataSeriesValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'series'>) => string;
|
|
8
8
|
sort: ((a: DataSeriesDatum | DataSeriesValue, b: DataSeriesDatum | number) => number) | null;
|
|
9
9
|
}
|
|
10
10
|
export interface DataFormatterSeriesPartial extends DataFormatterBasePartial<'series'> {
|
|
11
11
|
unitLabel?: string;
|
|
12
12
|
seriesLabels?: string[];
|
|
13
|
-
colorsPredicate?: (datum: DataSeriesDatum | DataSeriesValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'series'>) => string;
|
|
14
13
|
sort?: ((a: DataSeriesDatum | DataSeriesValue, b: DataSeriesDatum | number) => number) | null;
|
|
15
14
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DataFormatterBase } from './DataFormatter';
|
|
1
|
+
import { DataFormatterBase, VisibleFilter } from './DataFormatter';
|
|
2
2
|
|
|
3
3
|
export interface DataFormatterTree extends DataFormatterBase<'tree'> {
|
|
4
|
+
visibleFilter: VisibleFilter<'tree'>;
|
|
4
5
|
}
|
|
5
6
|
export type DataFormatterTreePartial = Partial<DataFormatterTree>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ChartType } from '../types/Chart';
|
|
2
|
+
import { ChartParams } from '../types/ChartParams';
|
|
1
3
|
import { DatumValue } from '../types/Data';
|
|
2
4
|
import { DataSeries } from '../types/DataSeries';
|
|
3
5
|
import { DataGrid, DataGridDatum } from '../types/DataGrid';
|
|
@@ -6,11 +8,21 @@ import { DataMultiValue } from '../types/DataMultiValue';
|
|
|
6
8
|
import { SeriesType, DataFormatterGrid } from '../types/DataFormatterGrid';
|
|
7
9
|
import * as d3 from 'd3';
|
|
8
10
|
export declare function formatValueToLabel(value: any, valueFormatter: string | ((text: d3.NumberValue) => string)): string;
|
|
9
|
-
export declare function createDefaultDatumId(
|
|
10
|
-
export declare function createDefaultSeriesLabel(
|
|
11
|
-
export declare function createDefaultGroupLabel(
|
|
12
|
-
export declare function createGridSeriesLabels(transposedDataGrid
|
|
13
|
-
|
|
11
|
+
export declare function createDefaultDatumId(chartTypeOrPrefix: string, levelOneIndex: number, levelTwoIndex: number, levelThreeIndex?: number): string;
|
|
12
|
+
export declare function createDefaultSeriesLabel(chartTypeOrPrefix: string, seriesIndex: number): string;
|
|
13
|
+
export declare function createDefaultGroupLabel(chartTypeOrPrefix: string, groupIndex: number): string;
|
|
14
|
+
export declare function createGridSeriesLabels({ transposedDataGrid, dataFormatter, chartType, gridIndex }: {
|
|
15
|
+
transposedDataGrid: DataGridDatum[][];
|
|
16
|
+
dataFormatter: DataFormatterGrid;
|
|
17
|
+
chartType?: ChartType;
|
|
18
|
+
gridIndex?: number;
|
|
19
|
+
}): string[];
|
|
20
|
+
export declare function createGridGroupLabels({ transposedDataGrid, dataFormatter, chartType, gridIndex }: {
|
|
21
|
+
transposedDataGrid: DataGridDatum[][];
|
|
22
|
+
dataFormatter: DataFormatterGrid;
|
|
23
|
+
chartType?: ChartType;
|
|
24
|
+
gridIndex?: number;
|
|
25
|
+
}): string[];
|
|
14
26
|
export declare function getMinAndMax(data: number[]): [number, number];
|
|
15
27
|
export declare function getMinAndMaxValue(data: DatumValue[]): [number, number];
|
|
16
28
|
export declare function getMinAndMaxSeries(data: DataSeries): [number, number];
|
|
@@ -18,3 +30,4 @@ export declare function getMinAndMaxGrid(data: DataGrid): [number, number];
|
|
|
18
30
|
export declare function getMinAndMaxMultiGrid(data: DataMultiGrid): [number, number];
|
|
19
31
|
export declare function getMinAndMaxMultiValue(data: DataMultiValue, valueIndex?: number): [number, number];
|
|
20
32
|
export declare function transposeData<T>(seriesType: SeriesType, data: T[][]): T[][];
|
|
33
|
+
export declare function seriesColorPredicate(seriesIndex: number, chartParams: ChartParams): string;
|
package/package.json
CHANGED
package/src/defaults.ts
CHANGED
|
@@ -104,24 +104,10 @@ export const DATA_RELATIONA_DEFAULTL: DataRelationship = {
|
|
|
104
104
|
// -- Data Formatter --
|
|
105
105
|
|
|
106
106
|
// 基本欄位
|
|
107
|
-
export const DATA_FORMATTER: DataFormatterBase<ChartType> = {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
tooltipContentFormat: (datum, rowIndex, columnIndex, context) => {
|
|
112
|
-
if (typeof datum === 'object') {
|
|
113
|
-
if (datum.tooltipContent) {
|
|
114
|
-
return datum.tooltipContent
|
|
115
|
-
} else if (datum.value) {
|
|
116
|
-
return String(datum.value)
|
|
117
|
-
}
|
|
118
|
-
} else if (typeof datum === 'number') {
|
|
119
|
-
return String(datum)
|
|
120
|
-
} else {
|
|
121
|
-
return ''
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
107
|
+
// export const DATA_FORMATTER: DataFormatterBase<ChartType> = {
|
|
108
|
+
// // ...GLOBAL_DEFAULT,
|
|
109
|
+
// type: ('' as any), // 後面需複蓋掉否則會有問題
|
|
110
|
+
// }
|
|
125
111
|
// 有value
|
|
126
112
|
// export const DATA_FORMATTER_WITH_VALUE: DataFormatterValue = {
|
|
127
113
|
// valueFormat: ',.0f'
|
|
@@ -151,9 +137,9 @@ export const DATA_FORMATTER_GROUP_AXIS: DataFormatterGroupAxis = {
|
|
|
151
137
|
}
|
|
152
138
|
|
|
153
139
|
export const DATA_FORMATTER_SERIES_DEFAULT: DataFormatterSeries = {
|
|
154
|
-
...DATA_FORMATTER,
|
|
155
140
|
// ...DATA_FORMATTER_WITH_VALUE,
|
|
156
141
|
type: 'series',
|
|
142
|
+
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
157
143
|
unitLabel: '',
|
|
158
144
|
seriesLabels: [],
|
|
159
145
|
// mapSeries: (datum, rowIndex, columnIndex, { data, dataFormatter }) => {
|
|
@@ -162,20 +148,20 @@ export const DATA_FORMATTER_SERIES_DEFAULT: DataFormatterSeries = {
|
|
|
162
148
|
// : rowIndex
|
|
163
149
|
// return dataFormatter.seriesLabels[seriesIndex]
|
|
164
150
|
// },
|
|
165
|
-
colorsPredicate: (datum, rowIndex, columnIndex, { chartParams }) => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
},
|
|
151
|
+
// colorsPredicate: (datum, rowIndex, columnIndex, { chartParams }) => {
|
|
152
|
+
// return rowIndex < chartParams.colors[chartParams.colorScheme].series.length
|
|
153
|
+
// ? chartParams.colors[chartParams.colorScheme].series[rowIndex]
|
|
154
|
+
// : chartParams.colors[chartParams.colorScheme].series[
|
|
155
|
+
// rowIndex % chartParams.colors[chartParams.colorScheme].series.length
|
|
156
|
+
// ]
|
|
157
|
+
// },
|
|
172
158
|
sort: null,
|
|
173
159
|
}
|
|
174
160
|
|
|
175
161
|
export const DATA_FORMATTER_GRID_DEFAULT: DataFormatterGrid = {
|
|
176
|
-
...DATA_FORMATTER,
|
|
177
162
|
// ...DATA_FORMATTER_WITH_VALUE,
|
|
178
163
|
type: 'grid',
|
|
164
|
+
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
179
165
|
grid: {
|
|
180
166
|
// rowUnitLabel: '',
|
|
181
167
|
rowLabels: [],
|
|
@@ -188,35 +174,35 @@ export const DATA_FORMATTER_GRID_DEFAULT: DataFormatterGrid = {
|
|
|
188
174
|
valueAxis: { ...DATA_FORMATTER_VALUE_AXIS },
|
|
189
175
|
groupAxis: { ...DATA_FORMATTER_GROUP_AXIS, },
|
|
190
176
|
// visibleGroupRange: null,
|
|
191
|
-
colorsPredicate: (datum, rowIndex, columnIndex, { chartParams, dataFormatter }) => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
},
|
|
177
|
+
// colorsPredicate: (datum, rowIndex, columnIndex, { chartParams, dataFormatter }) => {
|
|
178
|
+
// const seriesIndex = dataFormatter.grid.seriesType === 'row' ? rowIndex : columnIndex
|
|
179
|
+
// return chartParams.colors[chartParams.colorScheme].series[seriesIndex]
|
|
180
|
+
// },
|
|
195
181
|
}
|
|
196
182
|
|
|
197
183
|
export const DATA_FORMATTER_MULTI_GRID_DEFAULT: DataFormatterMultiGrid = {
|
|
198
|
-
...DATA_FORMATTER,
|
|
199
184
|
type: 'multiGrid',
|
|
185
|
+
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
200
186
|
multiGrid: [
|
|
201
187
|
{
|
|
202
188
|
...DATA_FORMATTER_GRID_DEFAULT
|
|
203
189
|
},
|
|
204
|
-
// @Q@ 暫時性的邏輯,之後colorsPredicate移除掉後,這邊也要移除(但colors使用的seriesIndex要接續前一組grid)
|
|
205
|
-
{
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
190
|
+
// // @Q@ 暫時性的邏輯,之後colorsPredicate移除掉後,這邊也要移除(但colors使用的seriesIndex要接續前一組grid)
|
|
191
|
+
// {
|
|
192
|
+
// ...DATA_FORMATTER_GRID_DEFAULT,
|
|
193
|
+
// colorsPredicate: (datum, rowIndex, columnIndex, { data, chartParams, dataFormatter }) => {
|
|
194
|
+
// const seriesIndex = dataFormatter.grid.seriesType === 'row' ? rowIndex : columnIndex
|
|
195
|
+
// const reverseIndex = chartParams.colors[chartParams.colorScheme].series.length - 1 - seriesIndex
|
|
196
|
+
// return chartParams.colors[chartParams.colorScheme].series[reverseIndex]
|
|
197
|
+
// },
|
|
198
|
+
// }
|
|
213
199
|
],
|
|
214
200
|
// visibleGroupRange: null,
|
|
215
201
|
}
|
|
216
202
|
|
|
217
203
|
export const DATA_FORMATTER_MULTI_VALUE_DEFAULT: DataFormatterMultiValue = {
|
|
218
|
-
...DATA_FORMATTER,
|
|
219
204
|
type: 'multiValue',
|
|
205
|
+
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
220
206
|
// labelFormat: (datum: any) => (datum && datum.label) ?? '',
|
|
221
207
|
multiValue: [],
|
|
222
208
|
xAxis: { ...DATA_FORMATTER_VALUE_AXIS },
|
|
@@ -224,14 +210,14 @@ export const DATA_FORMATTER_MULTI_VALUE_DEFAULT: DataFormatterMultiValue = {
|
|
|
224
210
|
}
|
|
225
211
|
|
|
226
212
|
export const DATA_FORMATTER_TREE_DEFAULT: DataFormatterTree = {
|
|
227
|
-
...DATA_FORMATTER,
|
|
228
213
|
type: 'tree',
|
|
214
|
+
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
229
215
|
// labelFormat: (datum: any) => (datum && datum.label) ?? '',
|
|
230
216
|
}
|
|
231
217
|
|
|
232
218
|
export const DATA_FORMATTER_RELATIONAL_DEFAULT: DataFormatterRelationship = {
|
|
233
|
-
...DATA_FORMATTER,
|
|
234
219
|
type: 'relationship',
|
|
220
|
+
visibleFilter: (datum, rowIndex, columnIndex, context) => true,
|
|
235
221
|
// node: {
|
|
236
222
|
// // labelFormat: (node: any) => (node && node.label) ?? '',
|
|
237
223
|
// descriptionFormat: (node: any) => (node && node.label) ?? ''
|
|
@@ -6,14 +6,19 @@ import type { DataFormatterGrid } from '../types/DataFormatterGrid'
|
|
|
6
6
|
import type { ComputedDataGrid, ComputedDatumGrid } from '../types/ComputedDataGrid'
|
|
7
7
|
import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, createDefaultGroupLabel } from '../utils/orbchartsUtils'
|
|
8
8
|
import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
|
|
9
|
-
import { getMinAndMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels } from '../utils/orbchartsUtils'
|
|
9
|
+
import { getMinAndMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels, seriesColorPredicate } from '../utils/orbchartsUtils'
|
|
10
10
|
|
|
11
11
|
interface DataGridDatumTemp extends DataGridDatum {
|
|
12
|
-
_color: string // 暫放的顏色資料
|
|
12
|
+
// _color: string // 暫放的顏色資料
|
|
13
13
|
_visible: boolean // 暫放的visible
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
17
|
+
return computeBaseGridData(context, 'grid', 0)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 共用的計算grid資料 - 只有multiGrid計算時才會有gridIndex參數
|
|
21
|
+
export const computeBaseGridData = (context: DataFormatterContext<'grid'>, chartType: 'grid' | 'multiGrid', gridIndex = 0) => {
|
|
17
22
|
const { data = [], dataFormatter, chartParams, layout } = context
|
|
18
23
|
if (!data.length) {
|
|
19
24
|
return []
|
|
@@ -43,36 +48,36 @@ export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
|
43
48
|
const dataGrid: DataGridDatumTemp[][] = fullData.map((d, i) => {
|
|
44
49
|
return d.map((_d, _i) => {
|
|
45
50
|
|
|
46
|
-
const _color = dataFormatter.colorsPredicate(_d, i, _i, context)
|
|
51
|
+
// const _color = dataFormatter.colorsPredicate(_d, i, _i, context)
|
|
47
52
|
const _visible = dataFormatter.visibleFilter(_d, i, _i, context)
|
|
48
53
|
|
|
49
54
|
const datum: DataGridDatumTemp = _d == null
|
|
50
55
|
? {
|
|
51
56
|
id: '',
|
|
52
57
|
label: '',
|
|
53
|
-
tooltipContent: '',
|
|
58
|
+
// tooltipContent: '',
|
|
54
59
|
data: {},
|
|
55
60
|
value: null,
|
|
56
|
-
_color,
|
|
61
|
+
// _color,
|
|
57
62
|
_visible
|
|
58
63
|
}
|
|
59
64
|
: typeof _d === 'number'
|
|
60
65
|
? {
|
|
61
66
|
id: '',
|
|
62
67
|
label: '',
|
|
63
|
-
tooltipContent: '',
|
|
68
|
+
// tooltipContent: '',
|
|
64
69
|
data: {},
|
|
65
70
|
value: _d,
|
|
66
|
-
_color,
|
|
71
|
+
// _color,
|
|
67
72
|
_visible
|
|
68
73
|
}
|
|
69
74
|
: {
|
|
70
75
|
id: _d.id ?? '',
|
|
71
76
|
label: _d.label ?? '',
|
|
72
|
-
tooltipContent: _d.tooltipContent ?? '',
|
|
77
|
+
// tooltipContent: _d.tooltipContent ?? '',
|
|
73
78
|
data: _d.data ?? {},
|
|
74
79
|
value: _d.value,
|
|
75
|
-
_color,
|
|
80
|
+
// _color,
|
|
76
81
|
_visible
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -98,14 +103,14 @@ export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
|
98
103
|
|
|
99
104
|
// const seriesColors = chartParams.colors[chartParams.colorScheme].series
|
|
100
105
|
|
|
101
|
-
const groupScaleDomain = [
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
]
|
|
106
|
+
// const groupScaleDomain = [
|
|
107
|
+
// dataFormatter.groupAxis.scaleDomain[0] === 'auto'
|
|
108
|
+
// ? 0
|
|
109
|
+
// : dataFormatter.groupAxis.scaleDomain[0],
|
|
110
|
+
// dataFormatter.groupAxis.scaleDomain[1] === 'auto'
|
|
111
|
+
// ? groupEndIndex
|
|
112
|
+
// : dataFormatter.groupAxis.scaleDomain[1]
|
|
113
|
+
// ]
|
|
109
114
|
|
|
110
115
|
|
|
111
116
|
// -- 依groupScale算visible --
|
|
@@ -134,8 +139,8 @@ export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
|
134
139
|
? layout.height
|
|
135
140
|
: layout.width
|
|
136
141
|
|
|
137
|
-
const seriesLabels = createGridSeriesLabels(transposedDataGrid, dataFormatter)
|
|
138
|
-
const groupLabels = createGridGroupLabels(transposedDataGrid, dataFormatter)
|
|
142
|
+
const seriesLabels = createGridSeriesLabels({ transposedDataGrid, dataFormatter, chartType, gridIndex })
|
|
143
|
+
const groupLabels = createGridGroupLabels({ transposedDataGrid, dataFormatter, chartType, gridIndex })
|
|
139
144
|
|
|
140
145
|
const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
|
141
146
|
maxValue,
|
|
@@ -151,7 +156,7 @@ export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
|
151
156
|
computedDataGrid = transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
152
157
|
return seriesData.map((groupDatum, groupIndex) => {
|
|
153
158
|
|
|
154
|
-
const defaultId = createDefaultDatumId(
|
|
159
|
+
const defaultId = createDefaultDatumId(chartType, gridIndex, seriesIndex, groupIndex)
|
|
155
160
|
// const visible = visibleFilter(groupDatum, seriesIndex, groupIndex, context)
|
|
156
161
|
const groupLabel = groupLabels[groupIndex]
|
|
157
162
|
const axisY = valueScale(groupDatum.value ?? 0)
|
|
@@ -160,16 +165,19 @@ export const computeGridData: ComputedDataFn<'grid'> = (context) => {
|
|
|
160
165
|
id: groupDatum.id ? groupDatum.id : defaultId,
|
|
161
166
|
index: _index,
|
|
162
167
|
label: groupDatum.label ? groupDatum.label : defaultId,
|
|
163
|
-
|
|
168
|
+
description: groupDatum.description ?? '',
|
|
169
|
+
// tooltipContent: groupDatum.tooltipContent ? groupDatum.tooltipContent : dataFormatter.tooltipContentFormat(groupDatum, seriesIndex, groupIndex, context),
|
|
164
170
|
data: groupDatum.data,
|
|
165
171
|
value: groupDatum.value,
|
|
166
172
|
// valueLabel: formatValueToLabel(groupDatum.value, dataFormatter.valueFormat),
|
|
173
|
+
gridIndex,
|
|
174
|
+
accSeriesIndex: seriesIndex, // 預設為seriesIndex
|
|
167
175
|
seriesIndex,
|
|
168
176
|
seriesLabel: seriesLabels[seriesIndex],
|
|
169
177
|
groupIndex,
|
|
170
178
|
groupLabel,
|
|
171
|
-
// color:
|
|
172
|
-
color:
|
|
179
|
+
// color: groupDatum._color,
|
|
180
|
+
color: seriesColorPredicate(seriesIndex, chartParams),
|
|
173
181
|
axisX: groupScale(groupIndex),
|
|
174
182
|
axisY,
|
|
175
183
|
axisYFromZero: axisY - zeroY,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { DataGrid } from '../types/DataGrid'
|
|
1
2
|
import type { ComputedDataFn } from '../types/ComputedData'
|
|
2
|
-
import type {
|
|
3
|
+
import type { DataFormatterMultiGrid } from '../types/DataFormatterMultiGrid'
|
|
3
4
|
import type { ComputedDataGrid } from '../types/ComputedDataGrid'
|
|
4
|
-
import {
|
|
5
|
+
import { computeBaseGridData } from '../grid/computeGridData'
|
|
6
|
+
import { DATA_FORMATTER_MULTI_GRID_DEFAULT } from '../defaults'
|
|
7
|
+
import { seriesColorPredicate } from '../utils/orbchartsUtils'
|
|
5
8
|
|
|
6
9
|
export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], dataFormatter, chartParams, layout }) => {
|
|
7
10
|
if (!data.length) {
|
|
@@ -11,34 +14,41 @@ export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], d
|
|
|
11
14
|
let multiGridData: ComputedDataGrid[] = []
|
|
12
15
|
|
|
13
16
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
// const layoutGrid: ComputedLayoutBase = {
|
|
25
|
-
// width: layout.width,
|
|
26
|
-
// height: layout.height,
|
|
27
|
-
// top: layout.top,
|
|
28
|
-
// right: layout.right,
|
|
29
|
-
// bottom: layout.bottom,
|
|
30
|
-
// left: layout.left,
|
|
31
|
-
// rootWidth: layout.rootWidth,
|
|
32
|
-
// rootHeight: layout.rootHeight,
|
|
33
|
-
// // content: layout.content[i]
|
|
17
|
+
const defaultDataFormatterGrid = Object.assign({}, DATA_FORMATTER_MULTI_GRID_DEFAULT.multiGrid[0])
|
|
18
|
+
|
|
19
|
+
// 計算每個grid的資料
|
|
20
|
+
multiGridData = data.map((gridData, gridIndex) => {
|
|
21
|
+
const currentDataFormatterGrid = dataFormatter.multiGrid[gridIndex] || defaultDataFormatterGrid
|
|
22
|
+
// const dataFormatterGrid: DataFormatterGrid = {
|
|
23
|
+
// ...currentDataFormatterGrid,
|
|
24
|
+
// type: `multiGrid` as any,
|
|
25
|
+
// visibleFilter: dataFormatter.visibleFilter as any,
|
|
34
26
|
// }
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
return computeBaseGridData(
|
|
28
|
+
{
|
|
29
|
+
data: gridData,
|
|
30
|
+
dataFormatter: currentDataFormatterGrid,
|
|
31
|
+
chartParams,
|
|
32
|
+
layout
|
|
33
|
+
},
|
|
34
|
+
'multiGrid',
|
|
35
|
+
gridIndex
|
|
36
|
+
)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// 修正多個grid的欄位資料
|
|
40
|
+
let accSeriesIndex = -1
|
|
41
|
+
multiGridData = multiGridData.map((gridData, i) => {
|
|
42
|
+
return gridData.map((series, j) => {
|
|
43
|
+
accSeriesIndex ++
|
|
44
|
+
return series.map(d => {
|
|
45
|
+
d.accSeriesIndex = accSeriesIndex
|
|
46
|
+
d.color = seriesColorPredicate(accSeriesIndex, chartParams)
|
|
47
|
+
return d
|
|
48
|
+
})
|
|
40
49
|
})
|
|
41
50
|
})
|
|
51
|
+
|
|
42
52
|
} catch (e) {
|
|
43
53
|
// console.error(e)
|
|
44
54
|
throw Error(e)
|
|
@@ -21,14 +21,16 @@ export const computeMultiValueData: ComputedDataFn<'multiValue'> = (context) =>
|
|
|
21
21
|
? {
|
|
22
22
|
id: '',
|
|
23
23
|
label: '',
|
|
24
|
-
|
|
24
|
+
description: '',
|
|
25
|
+
// tooltipContent: '',
|
|
25
26
|
data: {},
|
|
26
27
|
value: _d
|
|
27
28
|
}
|
|
28
29
|
: {
|
|
29
30
|
id: _d.id ?? '',
|
|
30
31
|
label: _d.label ?? '',
|
|
31
|
-
|
|
32
|
+
description: _d.description ?? '',
|
|
33
|
+
// tooltipContent: _d.tooltipContent ?? '',
|
|
32
34
|
data: _d.data ?? {},
|
|
33
35
|
value: _d.value
|
|
34
36
|
}
|
|
@@ -108,7 +110,8 @@ export const computeMultiValueData: ComputedDataFn<'multiValue'> = (context) =>
|
|
|
108
110
|
id: _d.id ? _d.id : defaultId,
|
|
109
111
|
index: currentIndex,
|
|
110
112
|
label: _d.label ? _d.label : defaultId,
|
|
111
|
-
|
|
113
|
+
description: _d.description ?? '',
|
|
114
|
+
// tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
|
|
112
115
|
data: _d.data,
|
|
113
116
|
value: _d.value,
|
|
114
117
|
// valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
|
|
@@ -32,7 +32,8 @@ export const computeRelationshipData: ComputedDataFn<'relationship'> = (context)
|
|
|
32
32
|
id: node.id,
|
|
33
33
|
index: i,
|
|
34
34
|
label: node.label ?? '',
|
|
35
|
-
|
|
35
|
+
description: node.description ?? '',
|
|
36
|
+
// tooltipContent: node.tooltipContent ? node.tooltipContent : dataFormatter.tooltipContentFormat(node, 0, i, context), // 0代表node
|
|
36
37
|
data: node.data ?? {},
|
|
37
38
|
value: node.value ?? 0,
|
|
38
39
|
startNodes: [], // 後面再取得資料
|
|
@@ -51,7 +52,8 @@ export const computeRelationshipData: ComputedDataFn<'relationship'> = (context)
|
|
|
51
52
|
id: edge.id,
|
|
52
53
|
index: i,
|
|
53
54
|
label: edge.label ?? '',
|
|
54
|
-
|
|
55
|
+
description: edge.description ?? '',
|
|
56
|
+
// tooltipContent: edge.tooltipContent ? edge.tooltipContent : dataFormatter.tooltipContentFormat(edge, 1, i, context), // 1代表edge
|
|
55
57
|
data: edge.data ?? {},
|
|
56
58
|
value: edge.value ?? 0,
|
|
57
59
|
startNode: NodesMap.get(edge.start),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
|
|
2
2
|
import type { ComputedDataFn } from '../types/ComputedData'
|
|
3
3
|
import type { ComputedDataSeries, ComputedDatumSeries } from '../types/ComputedDataSeries'
|
|
4
|
-
import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel } from '../utils/orbchartsUtils'
|
|
4
|
+
import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
|
|
5
5
|
|
|
6
6
|
interface SortValue {
|
|
7
7
|
rowIndex: number
|
|
@@ -84,15 +84,13 @@ export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
|
|
|
84
84
|
// if (dataFormatter.sort) {
|
|
85
85
|
// SortedIndexMap = createSortedIndexMap(data, dataFormatter.sort)
|
|
86
86
|
// }
|
|
87
|
-
|
|
88
|
-
// const seriesColors = chartParams.colors[chartParams.colorScheme].series
|
|
89
87
|
|
|
90
88
|
const createComputedDatumSeries = (detailData: number | DataSeriesDatum, rowIndex: number, columnIndex: number, currentIndex: number, sortedIndex: number): ComputedDatumSeries => {
|
|
91
89
|
const defaultId = createDefaultDatumId(dataFormatter.type, rowIndex, columnIndex)
|
|
92
90
|
// const seriesLabel = dataFormatter.mapSeries(detailData, rowIndex, columnIndex, context)
|
|
93
91
|
const seriesLabel = dataFormatter.seriesLabels[rowIndex] || createDefaultSeriesLabel('series', rowIndex)
|
|
94
|
-
// const color =
|
|
95
|
-
const color =
|
|
92
|
+
// const color = dataFormatter.colorsPredicate(detailData, rowIndex, columnIndex, context)
|
|
93
|
+
const color = seriesColorPredicate(rowIndex, chartParams)
|
|
96
94
|
const visible = dataFormatter.visibleFilter(detailData, rowIndex, columnIndex, context)
|
|
97
95
|
if (typeof detailData === 'number') {
|
|
98
96
|
return {
|
|
@@ -100,7 +98,8 @@ export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
|
|
|
100
98
|
index: currentIndex,
|
|
101
99
|
sortedIndex,
|
|
102
100
|
label: defaultId,
|
|
103
|
-
|
|
101
|
+
description: '',
|
|
102
|
+
// tooltipContent: dataFormatter.tooltipContentFormat(detailData, rowIndex, columnIndex, context),
|
|
104
103
|
data: {},
|
|
105
104
|
value: detailData,
|
|
106
105
|
// valueLabel: formatValueToLabel(detailData, dataFormatter.valueFormat),
|
|
@@ -115,7 +114,8 @@ export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
|
|
|
115
114
|
index: currentIndex,
|
|
116
115
|
sortedIndex,
|
|
117
116
|
label: detailData.label ? detailData.label : defaultId,
|
|
118
|
-
|
|
117
|
+
description: detailData.description,
|
|
118
|
+
// tooltipContent: detailData.tooltipContent ? detailData.tooltipContent : dataFormatter.tooltipContentFormat(detailData, rowIndex, columnIndex, context),
|
|
119
119
|
data: detailData.data ?? {},
|
|
120
120
|
value: detailData.value,
|
|
121
121
|
// valueLabel: formatValueToLabel(detailData.value, dataFormatter.valueFormat),
|
|
@@ -126,7 +126,6 @@ export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
|
|
130
129
|
|
|
131
130
|
data.forEach((mainData, rowIndex) => {
|
|
132
131
|
if (Array.isArray(mainData)) {
|
|
@@ -10,8 +10,9 @@ export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
|
|
|
10
10
|
id: '',
|
|
11
11
|
index: 0,
|
|
12
12
|
label: '',
|
|
13
|
+
description: '',
|
|
13
14
|
visible: true,
|
|
14
|
-
tooltipContent: '',
|
|
15
|
+
// tooltipContent: '',
|
|
15
16
|
data: {},
|
|
16
17
|
value: 0,
|
|
17
18
|
level: 0,
|
|
@@ -53,7 +54,7 @@ export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
|
|
|
53
54
|
id: root.id,
|
|
54
55
|
label: root.label,
|
|
55
56
|
data: root.data,
|
|
56
|
-
tooltipContent: root.tooltipContent,
|
|
57
|
+
// tooltipContent: root.tooltipContent,
|
|
57
58
|
value: root.value,
|
|
58
59
|
children: (ChildrenMap.get(root.id) ?? []).map(d => {
|
|
59
60
|
// 遞迴
|
|
@@ -83,8 +84,9 @@ export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
|
|
|
83
84
|
level,
|
|
84
85
|
seq,
|
|
85
86
|
label: branchRoot.label ?? '',
|
|
87
|
+
description: branchRoot.description ?? '',
|
|
86
88
|
data: branchRoot.data ?? {},
|
|
87
|
-
tooltipContent: branchRoot.tooltipContent ? branchRoot.tooltipContent : dataFormatter.tooltipContentFormat(branchRoot, level, seq, context),
|
|
89
|
+
// tooltipContent: branchRoot.tooltipContent ? branchRoot.tooltipContent : dataFormatter.tooltipContentFormat(branchRoot, level, seq, context),
|
|
88
90
|
value: branchRoot.value,
|
|
89
91
|
visible,
|
|
90
92
|
children: (branchRoot.children ?? []).map((d, i) => {
|
|
@@ -2,6 +2,8 @@ import { ComputedDatumBase, ComputedDatumSeriesValue } from './ComputedData'
|
|
|
2
2
|
|
|
3
3
|
export interface ComputedDatumGrid
|
|
4
4
|
extends ComputedDatumBase, ComputedDatumSeriesValue {
|
|
5
|
+
accSeriesIndex: number // 每一個grid累加的seriesIndex
|
|
6
|
+
gridIndex: number
|
|
5
7
|
groupIndex: number
|
|
6
8
|
groupLabel: string
|
|
7
9
|
axisX: number
|