@orbcharts/core 3.0.0-alpha.27 → 3.0.0-alpha.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/dist/orbcharts-core.es.js +1070 -1070
  2. package/dist/orbcharts-core.umd.js +2 -2
  3. package/dist/src/defaults.d.ts +2 -3
  4. package/dist/src/grid/computeGridData.d.ts +3 -0
  5. package/dist/src/types/ComputedData.d.ts +1 -1
  6. package/dist/src/types/ComputedDataGrid.d.ts +2 -0
  7. package/dist/src/types/Data.d.ts +1 -1
  8. package/dist/src/types/DataFormatter.d.ts +0 -2
  9. package/dist/src/types/DataFormatterGrid.d.ts +2 -4
  10. package/dist/src/types/DataFormatterMultiGrid.d.ts +2 -1
  11. package/dist/src/types/DataFormatterMultiValue.d.ts +2 -1
  12. package/dist/src/types/DataFormatterRelationship.d.ts +2 -1
  13. package/dist/src/types/DataFormatterSeries.d.ts +2 -3
  14. package/dist/src/types/DataFormatterTree.d.ts +2 -1
  15. package/dist/src/utils/orbchartsUtils.d.ts +18 -5
  16. package/package.json +1 -1
  17. package/src/defaults.ts +30 -48
  18. package/src/grid/computeGridData.ts +31 -23
  19. package/src/multiGrid/computeMultiGridData.ts +37 -27
  20. package/src/multiGrid/multiGridObservables.ts +6 -4
  21. package/src/multiValue/computeMultiValueData.ts +6 -3
  22. package/src/relationship/computeRelationshipData.ts +4 -2
  23. package/src/series/computeSeriesData.ts +7 -8
  24. package/src/tree/computeTreeData.ts +5 -3
  25. package/src/types/ComputedData.ts +1 -1
  26. package/src/types/ComputedDataGrid.ts +2 -0
  27. package/src/types/Data.ts +1 -1
  28. package/src/types/DataFormatter.ts +0 -4
  29. package/src/types/DataFormatterGrid.ts +4 -3
  30. package/src/types/DataFormatterMultiGrid.ts +6 -5
  31. package/src/types/DataFormatterMultiValue.ts +2 -1
  32. package/src/types/DataFormatterRelationship.ts +2 -1
  33. package/src/types/DataFormatterSeries.ts +4 -3
  34. package/src/types/DataFormatterTree.ts +2 -1
  35. package/src/utils/orbchartsUtils.ts +64 -11
@@ -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) => {
@@ -18,7 +18,7 @@ export interface ComputedDatumBase {
18
18
  label: string
19
19
  value: number | null
20
20
  visible: boolean
21
- tooltipContent: string
21
+ description: string
22
22
  data: any // 使用者注入的資料
23
23
  }
24
24
 
@@ -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
package/src/types/Data.ts CHANGED
@@ -10,7 +10,7 @@ import { DataRelationship, Node, Edge } from './DataRelationship'
10
10
  export interface DatumBase {
11
11
  id?: string
12
12
  label?: string
13
- tooltipContent?: string
13
+ description?: string
14
14
  data?: any // 使用者注入的資料
15
15
  }
16
16
 
@@ -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, DataFormatterContext } from './DataFormatter'
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 { DataGridDatum, DataGridValue } from './DataGrid'
2
- import { DataFormatterGrid, DataFormatterGridGrid } from './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
- // // multiGrid欄位
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, DataFormatterContext } from './DataFormatter'
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 (type: string, levelOneIndex: number, levelTwoIndex: number) {
18
- return `${type}_${levelOneIndex}_${levelTwoIndex}`
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 (type: string, seriesIndex: number) {
22
- return `${type}_series${seriesIndex}`
32
+ export function createDefaultSeriesLabel (chartTypeOrPrefix: string, seriesIndex: number) {
33
+ return `${chartTypeOrPrefix}_series${seriesIndex}`
23
34
  }
24
35
 
25
- export function createDefaultGroupLabel (type: string, groupIndex: number) {
26
- return `${type}_group${groupIndex}`
36
+ export function createDefaultGroupLabel (chartTypeOrPrefix: string, groupIndex: number) {
37
+ return `${chartTypeOrPrefix}_group${groupIndex}`
27
38
  }
28
39
 
29
- export function createGridSeriesLabels (transposedDataGrid: DataGridDatum[][], dataFormatter: DataFormatterGrid) {
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('grid', rowIndex)
52
+ : createDefaultSeriesLabel(`${chartType}_grid${gridIndex}`, rowIndex)
37
53
  })
38
54
  }
39
55
 
40
- export function createGridGroupLabels (transposedDataGrid: DataGridDatum[][], dataFormatter: DataFormatterGrid) {
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('grid', columnLabels)
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
+