@orbcharts/core 3.0.0-alpha.42 → 3.0.0-alpha.44
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-core.es.js +1905 -1896
- 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 +11 -4
- package/dist/src/utils/orbchartsUtils.d.ts +14 -13
- package/package.json +1 -1
- package/src/base/createBaseChart.ts +10 -10
- package/src/defaults.ts +36 -64
- package/src/grid/computeGridData.ts +15 -86
- package/src/grid/createGridContextObserver.ts +33 -16
- package/src/grid/gridObservables.ts +157 -70
- package/src/multiGrid/computeMultiGridData.ts +77 -120
- package/src/multiGrid/createMultiGridContextObserver.ts +8 -8
- package/src/multiGrid/multiGridObservables.ts +236 -171
- package/src/multiValue/computeMultiValueData.ts +22 -15
- package/src/relationship/computeRelationshipData.ts +16 -4
- package/src/series/computeSeriesData.ts +51 -114
- package/src/series/createSeriesContextObserver.ts +59 -4
- package/src/series/seriesObservables.ts +162 -10
- package/src/tree/computeTreeData.ts +6 -3
- package/src/types/ComputedData.ts +1 -0
- package/src/types/ComputedDataGrid.ts +3 -3
- package/src/types/ComputedDataSeries.ts +2 -2
- package/src/types/ContextObserverGrid.ts +18 -10
- package/src/types/ContextObserverMultiGrid.ts +6 -18
- package/src/types/ContextObserverSeries.ts +21 -1
- package/src/types/DataFormatter.ts +11 -32
- package/src/types/DataFormatterGrid.ts +32 -20
- package/src/types/DataFormatterMultiGrid.ts +6 -4
- package/src/types/DataFormatterMultiValue.ts +3 -0
- package/src/types/DataFormatterRelationship.ts +3 -0
- package/src/types/DataFormatterSeries.ts +11 -21
- package/src/utils/d3Utils.ts +7 -7
- package/src/utils/orbchartsUtils.ts +128 -32
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { ChartType } from './Chart'
|
2
2
|
import type { ChartParams } from './ChartParams'
|
3
3
|
import type { DataTypeMap, DatumTypeMap } from './Data'
|
4
|
+
import type { ComputedDataTypeMap, ComputedDatumTypeMap } from './ComputedData'
|
4
5
|
import type { DataFormatterSeries, DataFormatterSeriesPartial } from './DataFormatterSeries'
|
5
6
|
import type { DataFormatterGrid, DataFormatterGridPartial } from './DataFormatterGrid'
|
6
7
|
import type { DataFormatterMultiGrid, DataFormatterMultiGridPartial } from './DataFormatterMultiGrid'
|
@@ -8,28 +9,14 @@ import type { DataFormatterMultiValue, DataFormatterMultiValuePartial } from './
|
|
8
9
|
import type { DataFormatterTree, DataFormatterTreePartial } from './DataFormatterTree'
|
9
10
|
import type { DataFormatterRelationship, DataFormatterRelationshipPartial } from './DataFormatterRelationship'
|
10
11
|
import type { AxisPosition } from './Axis'
|
11
|
-
import type { Layout } from './Layout'
|
12
12
|
|
13
|
-
// export type DataFormatter = DataFormatterSeries
|
14
|
-
// | DataFormatterGrid
|
15
|
-
// | DataFormatterMultiGrid
|
16
|
-
// | DataFormatterMultiValue
|
17
|
-
// | DataFormatterTree
|
18
|
-
// | DataFormatterRelationship
|
19
|
-
|
20
|
-
// export type DataFormatterPartial = DataFormatterSeriesPartial
|
21
|
-
// | DataFormatterGridPartial
|
22
|
-
// | DataFormatterMultiGridPartial
|
23
|
-
// | DataFormatterMultiValuePartial
|
24
|
-
// | DataFormatterTreePartial
|
25
|
-
// | DataFormatterRelationshipPartial
|
26
13
|
|
27
14
|
// dataFormatter計算當中會使用的資料
|
28
15
|
export interface DataFormatterContext<T extends ChartType> {
|
29
16
|
data: DataTypeMap<T>
|
30
17
|
dataFormatter: DataFormatterTypeMap<T>
|
31
18
|
chartParams: ChartParams
|
32
|
-
layout: Layout
|
19
|
+
// layout: Layout
|
33
20
|
}
|
34
21
|
|
35
22
|
|
@@ -58,21 +45,6 @@ export interface DataFormatterBase<T extends ChartType> {
|
|
58
45
|
|
59
46
|
export type DataFormatterBasePartial<T extends ChartType> = Partial<DataFormatterBase<T>>
|
60
47
|
|
61
|
-
// 有value
|
62
|
-
// export interface DataFormatterValue {
|
63
|
-
// valueFormat: ValueFormat
|
64
|
-
// }
|
65
|
-
|
66
|
-
// 有axis
|
67
|
-
// export interface DataFormatterAxis {
|
68
|
-
// // domainMinValue?: number
|
69
|
-
// // domainMaxValue?: number
|
70
|
-
// // domainMinRange?: number
|
71
|
-
// // domainMaxRange?: number
|
72
|
-
// valueDomain: [number | 'auto', number | 'auto']
|
73
|
-
// valueRange: [number, number] // 0-1
|
74
|
-
// }
|
75
|
-
|
76
48
|
export interface DataFormatterValueAxis {
|
77
49
|
position: AxisPosition
|
78
50
|
scaleDomain: [number | 'auto', number | 'auto']
|
@@ -90,6 +62,13 @@ export interface DataFormatterGroupAxis {
|
|
90
62
|
|
91
63
|
// export type ValueFormat = string | ((text: d3.NumberValue) => string)
|
92
64
|
|
93
|
-
export type VisibleFilter<T extends ChartType> = (datum:
|
65
|
+
export type VisibleFilter<T extends ChartType> = (datum: ComputedDatumTypeMap<T>, context: DataFormatterContext<T>) => boolean | null
|
66
|
+
|
67
|
+
// export type TooltipContentFormat<T extends ChartType> = (datum: DatumTypeMap<T>, rowIndex: number, columnIndex: number, context: DataFormatterContext<T>) => string | null
|
68
|
+
|
69
|
+
export interface DataFormatterContainer {
|
70
|
+
gap: number
|
71
|
+
rowAmount: number
|
72
|
+
columnAmount: number
|
73
|
+
}
|
94
74
|
|
95
|
-
export type TooltipContentFormat<T extends ChartType> = (datum: DatumTypeMap<T>, rowIndex: number, columnIndex: number, context: DataFormatterContext<T>) => string | null
|
@@ -1,37 +1,49 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
1
|
+
import type {
|
2
|
+
DataFormatterBase,
|
3
|
+
DataFormatterBasePartial,
|
4
|
+
DataFormatterValueAxis,
|
5
|
+
DataFormatterGroupAxis,
|
6
|
+
VisibleFilter,
|
7
|
+
DataFormatterContainer
|
8
|
+
} from './DataFormatter'
|
9
|
+
|
4
10
|
|
5
11
|
export type SeriesDirection = 'row' | 'column' // default: 'row'
|
6
12
|
|
7
13
|
export interface DataFormatterGrid extends DataFormatterBase<'grid'> {
|
14
|
+
visibleFilter: VisibleFilter<'grid'>
|
8
15
|
grid: DataFormatterGridGrid
|
9
|
-
container:
|
10
|
-
// visibleGroupRange: [number, number] | null
|
11
|
-
// colorsPredicate: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string
|
16
|
+
container: DataFormatterContainer
|
12
17
|
}
|
13
18
|
|
14
19
|
export interface DataFormatterGridPartial extends DataFormatterBasePartial<'grid'> {
|
20
|
+
visibleFilter?: VisibleFilter<'grid'>
|
15
21
|
grid?: DataFormatterGridGridPartial
|
16
|
-
container?: Partial<
|
22
|
+
container?: Partial<DataFormatterContainer>
|
17
23
|
}
|
18
24
|
|
19
25
|
export interface DataFormatterGridGrid {
|
20
|
-
|
21
|
-
|
26
|
+
// gridData: DataFormatterGridGridData
|
27
|
+
// slotIndex: number | null
|
28
|
+
// seriesSlotIndexes: number[] | null
|
29
|
+
seriesDirection: SeriesDirection
|
30
|
+
rowLabels: string[]
|
31
|
+
columnLabels: string[]
|
22
32
|
valueAxis: DataFormatterValueAxis
|
23
33
|
groupAxis: DataFormatterGroupAxis
|
24
|
-
|
25
|
-
seriesSlotIndexes: number[] | null
|
34
|
+
separateSeries: boolean
|
26
35
|
}
|
27
36
|
|
28
37
|
export interface DataFormatterGridGridPartial {
|
29
|
-
|
30
|
-
|
38
|
+
// gridData?: Partial<DataFormatterGridGridData>
|
39
|
+
// slotIndex?: number | null
|
40
|
+
// seriesSlotIndexes?: number[] | null
|
41
|
+
seriesDirection?: SeriesDirection
|
42
|
+
rowLabels?: string[]
|
43
|
+
columnLabels?: string[]
|
31
44
|
valueAxis?: Partial<DataFormatterValueAxis>
|
32
45
|
groupAxis?: Partial<DataFormatterGroupAxis>
|
33
|
-
|
34
|
-
seriesSlotIndexes?: number[] | null
|
46
|
+
separateSeries?: boolean
|
35
47
|
}
|
36
48
|
|
37
49
|
export interface DataFormatterGridContainer {
|
@@ -41,11 +53,11 @@ export interface DataFormatterGridContainer {
|
|
41
53
|
}
|
42
54
|
|
43
55
|
// grid欄位
|
44
|
-
export interface DataFormatterGridGridData {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
}
|
56
|
+
// export interface DataFormatterGridGridData {
|
57
|
+
// seriesDirection: SeriesDirection
|
58
|
+
// rowLabels: string[]
|
59
|
+
// columnLabels: string[]
|
60
|
+
// }
|
49
61
|
|
50
62
|
// const test: DataFormatterGridPartial = {
|
51
63
|
// type: 'grid',
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { VisibleFilter } from './DataFormatter'
|
2
|
-
import type { DataFormatterGridGrid, DataFormatterGridGridPartial
|
1
|
+
import type { VisibleFilter, DataFormatterContainer } from './DataFormatter'
|
2
|
+
import type { DataFormatterGridGrid, DataFormatterGridGridPartial } from './DataFormatterGrid'
|
3
3
|
import type {
|
4
4
|
DataFormatterBase,
|
5
5
|
DataFormatterBasePartial,
|
@@ -9,15 +9,17 @@ import type {
|
|
9
9
|
import type { AxisPosition } from './Axis'
|
10
10
|
|
11
11
|
export interface DataFormatterMultiGrid extends DataFormatterBase<'multiGrid'> {
|
12
|
-
|
12
|
+
visibleFilter: VisibleFilter<'multiGrid'>
|
13
13
|
gridList: Array<DataFormatterGridGrid>
|
14
14
|
container: DataFormatterMultiGridContainer
|
15
|
+
separateGrid: boolean
|
15
16
|
}
|
16
17
|
|
17
18
|
export interface DataFormatterMultiGridPartial extends DataFormatterBasePartial<'multiGrid'> {
|
18
19
|
// visibleFilter?: VisibleFilter<'multiGrid'>
|
19
20
|
gridList?: Array<DataFormatterGridGridPartial>
|
20
21
|
container?: Partial<DataFormatterMultiGridContainer>
|
22
|
+
separateGrid?: boolean
|
21
23
|
}
|
22
24
|
|
23
25
|
export interface DataFormatterMultiGridGrid extends DataFormatterGridGrid {
|
@@ -29,7 +31,7 @@ export interface DataFormatterMultiGridGridPartial extends DataFormatterGridGrid
|
|
29
31
|
}
|
30
32
|
|
31
33
|
// container
|
32
|
-
export interface DataFormatterMultiGridContainer extends
|
34
|
+
export interface DataFormatterMultiGridContainer extends DataFormatterContainer {
|
33
35
|
|
34
36
|
}
|
35
37
|
|
@@ -4,12 +4,15 @@ import { DataFormatterBase, DataFormatterBasePartial, DataFormatterValueAxis, Vi
|
|
4
4
|
export interface DataFormatterMultiValue extends DataFormatterBase<'multiValue'> {
|
5
5
|
visibleFilter: VisibleFilter<'multiValue'>
|
6
6
|
// labelFormat: (datum: unknown) => string
|
7
|
+
categoryLabels: string[]
|
7
8
|
multiValue: Array<DataFormatterMultiValueMultiValue>
|
8
9
|
xAxis: DataFormatterValueAxis
|
9
10
|
yAxis: DataFormatterValueAxis
|
10
11
|
}
|
11
12
|
|
12
13
|
export interface DataFormatterMultiValuePartial extends DataFormatterBasePartial<'multiValue'> {
|
14
|
+
visibleFilter?: VisibleFilter<'multiValue'>
|
15
|
+
categoryLabels?: string[]
|
13
16
|
multiValue?: Array<Partial<DataFormatterMultiValueMultiValue>>
|
14
17
|
xAxis?: Partial<DataFormatterValueAxis>
|
15
18
|
yAxis?: Partial<DataFormatterValueAxis>
|
@@ -3,11 +3,14 @@ import { DataFormatterBase, DataFormatterBasePartial, VisibleFilter } from './Da
|
|
3
3
|
|
4
4
|
export interface DataFormatterRelationship extends DataFormatterBase<'relationship'> {
|
5
5
|
visibleFilter: VisibleFilter<'relationship'>
|
6
|
+
categoryLabels: string[]
|
6
7
|
// node: DataFormatterRelationshipNode
|
7
8
|
// edge: DataFormatterRelationshipEdge
|
8
9
|
}
|
9
10
|
|
10
11
|
export interface DataFormatterRelationshipPartial extends DataFormatterBasePartial<'relationship'> {
|
12
|
+
visibleFilter?: VisibleFilter<'relationship'>
|
13
|
+
categoryLabels?: string[]
|
11
14
|
// node: Partial<DataFormatterRelationshipNode>
|
12
15
|
// edge: Partial<DataFormatterRelationshipEdge>
|
13
16
|
}
|
@@ -1,30 +1,20 @@
|
|
1
|
-
import {
|
2
|
-
import { DataFormatterBase, DataFormatterBasePartial, VisibleFilter } from './DataFormatter'
|
3
|
-
// import { ComputedDatumSeries } from './ComputedDataSeries'
|
1
|
+
import type { ComputedDatumSeries } from './ComputedDataSeries'
|
2
|
+
import type { DataFormatterBase, DataFormatterBasePartial, VisibleFilter, DataFormatterContainer } from './DataFormatter'
|
4
3
|
|
5
4
|
export interface DataFormatterSeries extends DataFormatterBase<'series'> {
|
6
5
|
visibleFilter: VisibleFilter<'series'>
|
7
|
-
|
8
|
-
// unitLabel: string
|
6
|
+
sort: ((a: ComputedDatumSeries, b: ComputedDatumSeries) => number) | null
|
9
7
|
seriesLabels: string[]
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
sort: ((a: DataSeriesDatum | DataSeriesValue, b: DataSeriesDatum | number) => number) | null
|
14
|
-
// colors: Colors
|
8
|
+
container: DataFormatterContainer
|
9
|
+
separateSeries: boolean
|
10
|
+
sumSeries: boolean
|
15
11
|
}
|
16
12
|
|
17
13
|
export interface DataFormatterSeriesPartial extends DataFormatterBasePartial<'series'> {
|
18
|
-
|
19
|
-
|
14
|
+
visibleFilter?: VisibleFilter<'series'>
|
15
|
+
sort?: ((a: ComputedDatumSeries, b: ComputedDatumSeries) => number) | null
|
20
16
|
seriesLabels?: string[]
|
21
|
-
|
22
|
-
|
17
|
+
container?: Partial<DataFormatterContainer>
|
18
|
+
separateSeries?: boolean
|
19
|
+
sumSeries?: boolean
|
23
20
|
}
|
24
|
-
|
25
|
-
// export interface DataFormatterSeriesSeries {
|
26
|
-
// unitLabel: string
|
27
|
-
// seriesLabels: string[]
|
28
|
-
// // labelFormat: (datum: DataSeriesDatum) => string
|
29
|
-
// sort: ((computedDatum: ComputedDatumSeries) => number) | null
|
30
|
-
// }
|
package/src/utils/d3Utils.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import * as d3 from 'd3'
|
2
|
-
import {
|
2
|
+
import { DATA_FORMATTER_VALUE_AXIS_DEFAULT } from '../defaults'
|
3
3
|
|
4
4
|
// scaleLinear - 連續資料對應到比較尺座標上
|
5
5
|
export const createAxisLinearScale = ({
|
6
6
|
maxValue = 1,
|
7
7
|
minValue = 0,
|
8
8
|
axisWidth,
|
9
|
-
scaleDomain =
|
10
|
-
scaleRange =
|
9
|
+
scaleDomain = DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleDomain,
|
10
|
+
scaleRange = DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleRange,
|
11
11
|
}: {
|
12
12
|
maxValue: number
|
13
13
|
minValue: number
|
@@ -16,10 +16,10 @@ export const createAxisLinearScale = ({
|
|
16
16
|
scaleRange: [number, number] // 0-1
|
17
17
|
}) => {
|
18
18
|
// -- 無值補上預設值 --
|
19
|
-
const domainMin: number | 'auto' = scaleDomain[0] ??
|
20
|
-
const domainMax: number | 'auto' = scaleDomain[1] ??
|
21
|
-
const rangeMin: number = scaleRange[0] ??
|
22
|
-
const rangeMax: number = scaleRange[1] ??
|
19
|
+
const domainMin: number | 'auto' = scaleDomain[0] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleDomain[0]
|
20
|
+
const domainMax: number | 'auto' = scaleDomain[1] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleDomain[1]
|
21
|
+
const rangeMin: number = scaleRange[0] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleRange[0]
|
22
|
+
const rangeMax: number = scaleRange[1] ?? DATA_FORMATTER_VALUE_AXIS_DEFAULT.scaleRange[1]
|
23
23
|
|
24
24
|
// -- 'auto'提換成實際值 --
|
25
25
|
const domainMinValue = domainMin === 'auto' ? minValue : domainMin
|
@@ -6,12 +6,15 @@ import type { DataSeries, DataSeriesDatum, DataSeriesValue } from '../types/Data
|
|
6
6
|
import type { DataGrid, DataGridDatum, DataGridValue } from '../types/DataGrid'
|
7
7
|
import type { DataMultiGrid } from '../types/DataMultiGrid'
|
8
8
|
import type { DataMultiValue, DataMultiValueDatum, DataMultiValueValue } from '../types/DataMultiValue'
|
9
|
-
import type {
|
9
|
+
import type { DataFormatterContainer } from '../types/DataFormatter'
|
10
|
+
import type { SeriesDirection, DataFormatterGrid, DataFormatterGridGrid } from '../types/DataFormatterGrid'
|
10
11
|
import type { DataFormatterMultiGrid } from '../types/DataFormatterMultiGrid'
|
11
12
|
import type { ComputedDatumSeriesValue } from '../types/ComputedData'
|
12
13
|
import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
|
13
14
|
import type { ComputedDatumGrid, ComputedDataGrid } from '../types/ComputedDataGrid'
|
14
15
|
import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
|
16
|
+
import type { SeriesContainerPosition } from '../types/ContextObserverSeries'
|
17
|
+
import type { GridContainerPosition } from '../types/ContextObserverGrid'
|
15
18
|
import type { Layout } from '../types/Layout'
|
16
19
|
// import type { ComputedDatumMultiGrid } from '../types/ComputedDataMultiGrid'
|
17
20
|
import { isPlainObject } from './commonUtils'
|
@@ -39,14 +42,14 @@ export function createDefaultGroupLabel (chartTypeOrPrefix: string, groupIndex:
|
|
39
42
|
return `${chartTypeOrPrefix}_group${groupIndex}`
|
40
43
|
}
|
41
44
|
|
42
|
-
export function createGridSeriesLabels ({ transposedDataGrid,
|
45
|
+
export function createGridSeriesLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'grid' }: {
|
43
46
|
transposedDataGrid: DataGridDatum[][],
|
44
|
-
|
47
|
+
dataFormatterGrid: DataFormatterGridGrid
|
45
48
|
chartType?: ChartType
|
46
49
|
}) {
|
47
|
-
const labels =
|
48
|
-
?
|
49
|
-
:
|
50
|
+
const labels = dataFormatterGrid.seriesDirection === 'row'
|
51
|
+
? dataFormatterGrid.rowLabels
|
52
|
+
: dataFormatterGrid.columnLabels
|
50
53
|
return transposedDataGrid.map((_, rowIndex) => {
|
51
54
|
return labels[rowIndex] != null
|
52
55
|
? labels[rowIndex]
|
@@ -54,15 +57,15 @@ export function createGridSeriesLabels ({ transposedDataGrid, dataFormatter, cha
|
|
54
57
|
})
|
55
58
|
}
|
56
59
|
|
57
|
-
export function createMultiGridSeriesLabels ({ transposedDataGrid,
|
60
|
+
export function createMultiGridSeriesLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'multiGrid', gridIndex = 0 }: {
|
58
61
|
transposedDataGrid: DataGridDatum[][],
|
59
|
-
|
62
|
+
dataFormatterGrid: DataFormatterGridGrid
|
60
63
|
chartType?: ChartType
|
61
64
|
gridIndex?: number
|
62
65
|
}) {
|
63
|
-
const labels =
|
64
|
-
?
|
65
|
-
:
|
66
|
+
const labels = dataFormatterGrid.seriesDirection === 'row'
|
67
|
+
? dataFormatterGrid.rowLabels
|
68
|
+
: dataFormatterGrid.columnLabels
|
66
69
|
return transposedDataGrid.map((_, rowIndex) => {
|
67
70
|
return labels[rowIndex] != null
|
68
71
|
? labels[rowIndex]
|
@@ -70,17 +73,17 @@ export function createMultiGridSeriesLabels ({ transposedDataGrid, dataFormatter
|
|
70
73
|
})
|
71
74
|
}
|
72
75
|
|
73
|
-
export function createGridGroupLabels ({ transposedDataGrid,
|
76
|
+
export function createGridGroupLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'grid' }: {
|
74
77
|
transposedDataGrid: DataGridDatum[][],
|
75
|
-
|
78
|
+
dataFormatterGrid: DataFormatterGridGrid
|
76
79
|
chartType?: ChartType
|
77
80
|
}) {
|
78
81
|
if (transposedDataGrid[0] == null) {
|
79
82
|
return []
|
80
83
|
}
|
81
|
-
const labels =
|
82
|
-
?
|
83
|
-
:
|
84
|
+
const labels = dataFormatterGrid.seriesDirection === 'row'
|
85
|
+
? dataFormatterGrid.columnLabels
|
86
|
+
: dataFormatterGrid.rowLabels
|
84
87
|
return transposedDataGrid[0].map((_, columnLabels) => {
|
85
88
|
return labels[columnLabels] != null
|
86
89
|
? labels[columnLabels]
|
@@ -88,18 +91,18 @@ export function createGridGroupLabels ({ transposedDataGrid, dataFormatter, char
|
|
88
91
|
})
|
89
92
|
}
|
90
93
|
|
91
|
-
export function createMultiGridGroupLabels ({ transposedDataGrid,
|
94
|
+
export function createMultiGridGroupLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'multiGrid', gridIndex = 0 }: {
|
92
95
|
transposedDataGrid: DataGridDatum[][],
|
93
|
-
|
96
|
+
dataFormatterGrid: DataFormatterGridGrid
|
94
97
|
chartType?: ChartType
|
95
98
|
gridIndex?: number
|
96
99
|
}) {
|
97
100
|
if (transposedDataGrid[0] == null) {
|
98
101
|
return []
|
99
102
|
}
|
100
|
-
const labels =
|
101
|
-
?
|
102
|
-
:
|
103
|
+
const labels = dataFormatterGrid.seriesDirection === 'row'
|
104
|
+
? dataFormatterGrid.columnLabels
|
105
|
+
: dataFormatterGrid.rowLabels
|
103
106
|
return transposedDataGrid[0].map((_, columnLabels) => {
|
104
107
|
return labels[columnLabels] != null
|
105
108
|
? labels[columnLabels]
|
@@ -214,19 +217,112 @@ export function seriesColorPredicate (seriesIndex: number, chartParams: ChartPar
|
|
214
217
|
]
|
215
218
|
}
|
216
219
|
|
217
|
-
export function
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
220
|
+
// export function calcSeriesContainerPosition (layout: Layout, container: DataFormatterContainer, rowIndex: number, columnIndex: number) {
|
221
|
+
// const { gap, rowAmount, columnAmount } = container
|
222
|
+
// const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
223
|
+
// const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
224
|
+
// const x = columnIndex * width + (columnIndex * gap)
|
225
|
+
// const y = rowIndex * height + (rowIndex * gap)
|
226
|
+
// // const translate: [number, number] = [x, y]
|
227
|
+
|
228
|
+
// return {
|
229
|
+
// // translate,
|
230
|
+
// startX: x,
|
231
|
+
// startY: y,
|
232
|
+
// centerX: x + width / 2,
|
233
|
+
// centerY: y + height / 2,
|
234
|
+
// width,
|
235
|
+
// height
|
236
|
+
// }
|
237
|
+
// }
|
225
238
|
|
226
|
-
|
227
|
-
|
228
|
-
|
239
|
+
// 計算預設欄列數量
|
240
|
+
// 規則1.rowAmount*columnAmount要大於或等於amount,並且數字要盡可能小
|
241
|
+
// 規則2.columnAmount要大於或等於rowAmount,並且數字要盡可能小
|
242
|
+
function calcGridDimensions (amount: number): { rowAmount: number; columnAmount: number } {
|
243
|
+
let rowAmount = Math.floor(Math.sqrt(amount))
|
244
|
+
let columnAmount = Math.ceil(amount / rowAmount)
|
245
|
+
while (rowAmount * columnAmount < amount) {
|
246
|
+
columnAmount++
|
229
247
|
}
|
248
|
+
return { rowAmount, columnAmount }
|
249
|
+
}
|
250
|
+
|
251
|
+
export function calcSeriesContainerLayout (layout: Layout, container: DataFormatterContainer, amount: number): SeriesContainerPosition[] {
|
252
|
+
const { gap } = container
|
253
|
+
const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
|
254
|
+
// 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
|
255
|
+
? container
|
256
|
+
// 否則計算一個合適的預設值
|
257
|
+
: calcGridDimensions(amount)
|
258
|
+
|
259
|
+
return new Array(amount).fill(null).map((_, index) => {
|
260
|
+
const columnIndex = index % columnAmount
|
261
|
+
const rowIndex = Math.floor(index / columnAmount)
|
262
|
+
|
263
|
+
const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
264
|
+
const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
265
|
+
const x = columnIndex * width + (columnIndex * gap)
|
266
|
+
const y = rowIndex * height + (rowIndex * gap)
|
267
|
+
// const translate: [number, number] = [x, y]
|
268
|
+
|
269
|
+
return {
|
270
|
+
slotIndex: index,
|
271
|
+
rowIndex,
|
272
|
+
columnIndex,
|
273
|
+
// translate,
|
274
|
+
startX: x,
|
275
|
+
startY: y,
|
276
|
+
centerX: x + width / 2,
|
277
|
+
centerY: y + height / 2,
|
278
|
+
width,
|
279
|
+
height
|
280
|
+
}
|
281
|
+
})
|
282
|
+
}
|
283
|
+
|
284
|
+
// export function calcGridContainerPosition (layout: Layout, container: DataFormatterContainer, rowIndex: number, columnIndex: number) {
|
285
|
+
// const { gap, rowAmount, columnAmount } = container
|
286
|
+
// const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
287
|
+
// const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
288
|
+
// const x = columnIndex * width + (columnIndex * gap)
|
289
|
+
// const y = rowIndex * height + (rowIndex * gap)
|
290
|
+
// const translate: [number, number] = [x, y]
|
291
|
+
// const scale: [number, number] = [width / layout.width, height / layout.height]
|
292
|
+
|
293
|
+
// return {
|
294
|
+
// translate,
|
295
|
+
// scale
|
296
|
+
// }
|
297
|
+
// }
|
298
|
+
|
299
|
+
export function calcGridContainerLayout (layout: Layout, container: DataFormatterContainer, amount: number): GridContainerPosition[] {
|
300
|
+
const { gap } = container
|
301
|
+
const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
|
302
|
+
// 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
|
303
|
+
? container
|
304
|
+
// 否則計算一個合適的預設值
|
305
|
+
: calcGridDimensions(amount)
|
306
|
+
|
307
|
+
return new Array(amount).fill(null).map((_, index) => {
|
308
|
+
const columnIndex = index % columnAmount
|
309
|
+
const rowIndex = Math.floor(index / columnAmount)
|
310
|
+
|
311
|
+
const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
312
|
+
const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
313
|
+
const x = columnIndex * width + (columnIndex * gap)
|
314
|
+
const y = rowIndex * height + (rowIndex * gap)
|
315
|
+
const translate: [number, number] = [x, y]
|
316
|
+
const scale: [number, number] = [width / layout.width, height / layout.height]
|
317
|
+
|
318
|
+
return {
|
319
|
+
slotIndex: index,
|
320
|
+
rowIndex,
|
321
|
+
columnIndex,
|
322
|
+
translate,
|
323
|
+
scale
|
324
|
+
}
|
325
|
+
})
|
230
326
|
}
|
231
327
|
|
232
328
|
// // multiGrid datum color
|