@orbcharts/core 3.0.0-alpha.28 → 3.0.0-alpha.29
Sign up to get free protection for your applications and to get access to all the features.
- 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
package/src/types/Data.ts
CHANGED
@@ -53,11 +53,7 @@ export type DataFormatterPartialTypeMap<T extends ChartType> = T extends 'series
|
|
53
53
|
|
54
54
|
// 基本介面
|
55
55
|
export interface DataFormatterBase<T extends ChartType> {
|
56
|
-
// colors: Colors
|
57
|
-
// padding: Padding
|
58
56
|
type: T
|
59
|
-
visibleFilter: VisibleFilter<T>
|
60
|
-
tooltipContentFormat: TooltipContentFormat<T>
|
61
57
|
}
|
62
58
|
|
63
59
|
export type DataFormatterBasePartial<T extends ChartType> = Partial<DataFormatterBase<T>>
|
@@ -1,22 +1,23 @@
|
|
1
1
|
import type { DataGridDatum, DataGridValue } from './DataGrid'
|
2
|
-
import type { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, DataFormatterGroupAxis,
|
2
|
+
import type { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, DataFormatterGroupAxis, VisibleFilter } from './DataFormatter'
|
3
3
|
// import type { AxisPosition } from './Axis'
|
4
4
|
|
5
5
|
export type SeriesType = 'row' | 'column' // default: 'row'
|
6
6
|
|
7
7
|
export interface DataFormatterGrid extends DataFormatterBase<'grid'> {
|
8
|
+
visibleFilter: VisibleFilter<'grid'>
|
8
9
|
grid: DataFormatterGridGrid
|
9
10
|
valueAxis: DataFormatterValueAxis
|
10
11
|
groupAxis: DataFormatterGroupAxis
|
11
12
|
// visibleGroupRange: [number, number] | null
|
12
|
-
colorsPredicate: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string
|
13
|
+
// colorsPredicate: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string
|
13
14
|
}
|
14
15
|
|
15
16
|
export interface DataFormatterGridPartial extends DataFormatterBasePartial<'grid'> {
|
16
17
|
grid?: Partial<DataFormatterGridGrid>
|
17
18
|
valueAxis?: Partial<DataFormatterValueAxis>
|
18
19
|
groupAxis?: Partial<DataFormatterGroupAxis>
|
19
|
-
colorsPredicate?: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string
|
20
|
+
// colorsPredicate?: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string
|
20
21
|
}
|
21
22
|
|
22
23
|
// grid欄位
|
@@ -1,14 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
import { DataFormatterGrid
|
3
|
-
import {
|
1
|
+
import type { VisibleFilter } from './DataFormatter'
|
2
|
+
import type { DataFormatterGrid } from './DataFormatterGrid'
|
3
|
+
import type {
|
4
4
|
DataFormatterBase,
|
5
5
|
DataFormatterBasePartial,
|
6
6
|
DataFormatterValueAxis,
|
7
7
|
DataFormatterGroupAxis,
|
8
8
|
DataFormatterContext } from './DataFormatter'
|
9
|
-
import { AxisPosition } from './Axis'
|
9
|
+
import type { AxisPosition } from './Axis'
|
10
10
|
|
11
11
|
export interface DataFormatterMultiGrid extends DataFormatterBase<'multiGrid'> {
|
12
|
+
visibleFilter: VisibleFilter<'multiGrid'>
|
12
13
|
multiGrid: Array<DataFormatterGrid>
|
13
14
|
// visibleGroupRange: [number, number] | null
|
14
15
|
}
|
@@ -17,7 +18,7 @@ export interface DataFormatterMultiGridPartial extends DataFormatterBasePartial<
|
|
17
18
|
multiGrid?: Array<Partial<DataFormatterGrid>>
|
18
19
|
}
|
19
20
|
|
20
|
-
//
|
21
|
+
// multiGrid欄位
|
21
22
|
// export interface DataFormatterMultiGridMultiGrid {
|
22
23
|
// grid: DataFormatterGridGrid
|
23
24
|
// valueAxis: DataFormatterValueAxis // default: 'left'
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { DataMultiValueDatum, DataMultiValue } from './DataMultiValue'
|
2
|
-
import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis } from './DataFormatter'
|
2
|
+
import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, VisibleFilter } from './DataFormatter'
|
3
3
|
|
4
4
|
export interface DataFormatterMultiValue extends DataFormatterBase<'multiValue'> {
|
5
|
+
visibleFilter: VisibleFilter<'multiValue'>
|
5
6
|
// labelFormat: (datum: unknown) => string
|
6
7
|
multiValue: Array<DataFormatterMultiValueMultiValue>
|
7
8
|
xAxis: DataFormatterValueAxis
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { Node, Edge, DataRelationship } from './DataRelationship'
|
2
|
-
import { DataFormatterBase, DataFormatterBasePartial } from './DataFormatter'
|
2
|
+
import { DataFormatterBase, DataFormatterBasePartial, VisibleFilter } from './DataFormatter'
|
3
3
|
|
4
4
|
export interface DataFormatterRelationship extends DataFormatterBase<'relationship'> {
|
5
|
+
visibleFilter: VisibleFilter<'relationship'>
|
5
6
|
// node: DataFormatterRelationshipNode
|
6
7
|
// edge: DataFormatterRelationshipEdge
|
7
8
|
}
|
@@ -1,14 +1,15 @@
|
|
1
1
|
import { DataSeriesDatum, DataSeriesValue, DataSeries } from './DataSeries'
|
2
|
-
import { DataFormatterBase, DataFormatterBasePartial,
|
2
|
+
import { DataFormatterBase, DataFormatterBasePartial, VisibleFilter } from './DataFormatter'
|
3
3
|
// import { ComputedDatumSeries } from './ComputedDataSeries'
|
4
4
|
|
5
5
|
export interface DataFormatterSeries extends DataFormatterBase<'series'> {
|
6
|
+
visibleFilter: VisibleFilter<'series'>
|
6
7
|
// series: DataFormatterSeriesSeries
|
7
8
|
unitLabel: string
|
8
9
|
seriesLabels: string[]
|
9
10
|
// labelFormat: (datum: DataSeriesDatum) => string
|
10
11
|
// mapSeries: (datum: DataSeriesDatum | DataSeriesValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'series'>) => string
|
11
|
-
colorsPredicate: (datum: DataSeriesDatum | DataSeriesValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'series'>) => string
|
12
|
+
// colorsPredicate: (datum: DataSeriesDatum | DataSeriesValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'series'>) => string
|
12
13
|
sort: ((a: DataSeriesDatum | DataSeriesValue, b: DataSeriesDatum | number) => number) | null
|
13
14
|
// colors: Colors
|
14
15
|
}
|
@@ -17,7 +18,7 @@ export interface DataFormatterSeriesPartial extends DataFormatterBasePartial<'se
|
|
17
18
|
// series: Partial<DataFormatterSeriesSeries>
|
18
19
|
unitLabel?: string
|
19
20
|
seriesLabels?: string[]
|
20
|
-
colorsPredicate?: (datum: DataSeriesDatum | DataSeriesValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'series'>) => string
|
21
|
+
// colorsPredicate?: (datum: DataSeriesDatum | DataSeriesValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'series'>) => string
|
21
22
|
sort?: ((a: DataSeriesDatum | DataSeriesValue, b: DataSeriesDatum | number) => number) | null
|
22
23
|
}
|
23
24
|
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { DataTreeDatum, DataTree } from './DataTree'
|
2
|
-
import { DataFormatterBase } from './DataFormatter'
|
2
|
+
import { DataFormatterBase, VisibleFilter } from './DataFormatter'
|
3
3
|
|
4
4
|
export interface DataFormatterTree
|
5
5
|
extends DataFormatterBase<'tree'> {
|
6
|
+
visibleFilter: VisibleFilter<'tree'>
|
6
7
|
// labelFormat: (datum: unknown) => string
|
7
8
|
// descriptionFormat: (datum: unknown) => string
|
8
9
|
}
|
@@ -1,10 +1,17 @@
|
|
1
1
|
import * as d3 from 'd3'
|
2
|
+
import type { ChartType } from '../types/Chart'
|
3
|
+
import type { ChartParams } from '../types/ChartParams'
|
2
4
|
import type { DatumBase, DatumValue } from '../types/Data'
|
3
5
|
import type { DataSeries, DataSeriesDatum, DataSeriesValue } from '../types/DataSeries'
|
4
6
|
import type { DataGrid, DataGridDatum, DataGridValue } from '../types/DataGrid'
|
5
7
|
import type { DataMultiGrid } from '../types/DataMultiGrid'
|
6
8
|
import type { DataMultiValue, DataMultiValueDatum, DataMultiValueValue } from '../types/DataMultiValue'
|
7
9
|
import type { SeriesType, DataFormatterGrid } from '../types/DataFormatterGrid'
|
10
|
+
import type { ComputedDatumSeriesValue } from '../types/ComputedData'
|
11
|
+
import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
|
12
|
+
import type { ComputedDatumGrid, ComputedDataGrid } from '../types/ComputedDataGrid'
|
13
|
+
import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
|
14
|
+
// import type { ComputedDatumMultiGrid } from '../types/ComputedDataMultiGrid'
|
8
15
|
import { isObject } from './commonUtils'
|
9
16
|
|
10
17
|
export function formatValueToLabel (value: any, valueFormatter: string | ((text: d3.NumberValue) => string)) {
|
@@ -14,30 +21,44 @@ export function formatValueToLabel (value: any, valueFormatter: string | ((text:
|
|
14
21
|
return d3.format(valueFormatter as string)!(value)
|
15
22
|
}
|
16
23
|
|
17
|
-
export function createDefaultDatumId (
|
18
|
-
|
24
|
+
export function createDefaultDatumId (chartTypeOrPrefix: string, levelOneIndex: number, levelTwoIndex: number, levelThreeIndex?: number) {
|
25
|
+
let text = `${chartTypeOrPrefix}_${levelOneIndex}_${levelTwoIndex}`
|
26
|
+
if (levelThreeIndex != null) {
|
27
|
+
text += `_${levelThreeIndex}`
|
28
|
+
}
|
29
|
+
return text
|
19
30
|
}
|
20
31
|
|
21
|
-
export function createDefaultSeriesLabel (
|
22
|
-
return `${
|
32
|
+
export function createDefaultSeriesLabel (chartTypeOrPrefix: string, seriesIndex: number) {
|
33
|
+
return `${chartTypeOrPrefix}_series${seriesIndex}`
|
23
34
|
}
|
24
35
|
|
25
|
-
export function createDefaultGroupLabel (
|
26
|
-
return `${
|
36
|
+
export function createDefaultGroupLabel (chartTypeOrPrefix: string, groupIndex: number) {
|
37
|
+
return `${chartTypeOrPrefix}_group${groupIndex}`
|
27
38
|
}
|
28
39
|
|
29
|
-
export function createGridSeriesLabels (transposedDataGrid
|
40
|
+
export function createGridSeriesLabels ({ transposedDataGrid, dataFormatter, chartType = 'grid', gridIndex = 0 }: {
|
41
|
+
transposedDataGrid: DataGridDatum[][],
|
42
|
+
dataFormatter: DataFormatterGrid
|
43
|
+
chartType?: ChartType
|
44
|
+
gridIndex?: number
|
45
|
+
}) {
|
30
46
|
const labels = dataFormatter.grid.seriesType === 'row'
|
31
47
|
? dataFormatter.grid.rowLabels
|
32
48
|
: dataFormatter.grid.columnLabels
|
33
49
|
return transposedDataGrid.map((_, rowIndex) => {
|
34
50
|
return labels[rowIndex] != null
|
35
51
|
? labels[rowIndex]
|
36
|
-
: createDefaultSeriesLabel(
|
52
|
+
: createDefaultSeriesLabel(`${chartType}_grid${gridIndex}`, rowIndex)
|
37
53
|
})
|
38
54
|
}
|
39
55
|
|
40
|
-
export function createGridGroupLabels (transposedDataGrid
|
56
|
+
export function createGridGroupLabels ({ transposedDataGrid, dataFormatter, chartType = 'grid', gridIndex = 0 }: {
|
57
|
+
transposedDataGrid: DataGridDatum[][],
|
58
|
+
dataFormatter: DataFormatterGrid
|
59
|
+
chartType?: ChartType
|
60
|
+
gridIndex?: number
|
61
|
+
}) {
|
41
62
|
if (transposedDataGrid[0] == null) {
|
42
63
|
return []
|
43
64
|
}
|
@@ -47,7 +68,7 @@ export function createGridGroupLabels (transposedDataGrid: DataGridDatum[][], da
|
|
47
68
|
return transposedDataGrid[0].map((_, columnLabels) => {
|
48
69
|
return labels[columnLabels] != null
|
49
70
|
? labels[columnLabels]
|
50
|
-
: createDefaultGroupLabel(
|
71
|
+
: createDefaultGroupLabel(`${chartType}_grid${gridIndex}`, columnLabels)
|
51
72
|
})
|
52
73
|
}
|
53
74
|
|
@@ -147,4 +168,36 @@ export function transposeData<T> (seriesType: SeriesType, data: T[][]): T[][] {
|
|
147
168
|
}
|
148
169
|
|
149
170
|
return transposedArray
|
150
|
-
}
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
export function seriesColorPredicate (seriesIndex: number, chartParams: ChartParams) {
|
175
|
+
return seriesIndex < chartParams.colors[chartParams.colorScheme].series.length
|
176
|
+
? chartParams.colors[chartParams.colorScheme].series[seriesIndex]
|
177
|
+
: chartParams.colors[chartParams.colorScheme].series[
|
178
|
+
seriesIndex % chartParams.colors[chartParams.colorScheme].series.length
|
179
|
+
]
|
180
|
+
}
|
181
|
+
|
182
|
+
// // multiGrid datum color
|
183
|
+
// export function multiGridColorPredicate ({ seriesIndex, groupIndex, data, chartParams }: {
|
184
|
+
// seriesIndex: number
|
185
|
+
// groupIndex: number
|
186
|
+
// data: ComputedDataMultiGrid
|
187
|
+
// chartParams: ChartParams
|
188
|
+
// }) {
|
189
|
+
// // 累加前面的grid的seriesIndex
|
190
|
+
// const accSeriesIndex = data.reduce((prev, current) => {
|
191
|
+
// if (current[0] && current[0][0] && groupIndex > current[0][0].gridIndex) {
|
192
|
+
// return prev + current[0].length
|
193
|
+
// } else if (current[0] && current[0][0] && groupIndex == current[0][0].gridIndex) {
|
194
|
+
// return prev + seriesIndex
|
195
|
+
// } else {
|
196
|
+
// return prev
|
197
|
+
// }
|
198
|
+
// }, 0)
|
199
|
+
|
200
|
+
// return seriesColorPredicate(accSeriesIndex, chartParams)
|
201
|
+
// }
|
202
|
+
|
203
|
+
|