@orbcharts/core 3.0.0-alpha.33 → 3.0.0-alpha.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,14 @@ 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
9
  import type { SeriesDirection, DataFormatterGrid, DataFormatterGridContainer } from '../types/DataFormatterGrid'
10
+ import type { DataFormatterMultiGrid } from '../types/DataFormatterMultiGrid'
10
11
  import type { ComputedDatumSeriesValue } from '../types/ComputedData'
11
12
  import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
12
13
  import type { ComputedDatumGrid, ComputedDataGrid } from '../types/ComputedDataGrid'
13
14
  import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
14
15
  import type { Layout } from '../types/Layout'
15
16
  // import type { ComputedDatumMultiGrid } from '../types/ComputedDataMultiGrid'
16
- import { isObject } from './commonUtils'
17
+ import { isPlainObject } from './commonUtils'
17
18
 
18
19
  export function formatValueToLabel (value: any, valueFormatter: string | ((text: d3.NumberValue) => string)) {
19
20
  if (valueFormatter! instanceof Function == true) {
@@ -38,7 +39,22 @@ export function createDefaultGroupLabel (chartTypeOrPrefix: string, groupIndex:
38
39
  return `${chartTypeOrPrefix}_group${groupIndex}`
39
40
  }
40
41
 
41
- export function createGridSeriesLabels ({ transposedDataGrid, dataFormatter, chartType = 'grid', gridIndex = 0 }: {
42
+ export function createGridSeriesLabels ({ transposedDataGrid, dataFormatter, chartType = 'grid' }: {
43
+ transposedDataGrid: DataGridDatum[][],
44
+ dataFormatter: DataFormatterGrid
45
+ chartType?: ChartType
46
+ }) {
47
+ const labels = dataFormatter.grid.gridData.seriesDirection === 'row'
48
+ ? dataFormatter.grid.gridData.rowLabels
49
+ : dataFormatter.grid.gridData.columnLabels
50
+ return transposedDataGrid.map((_, rowIndex) => {
51
+ return labels[rowIndex] != null
52
+ ? labels[rowIndex]
53
+ : createDefaultSeriesLabel(chartType, rowIndex)
54
+ })
55
+ }
56
+
57
+ export function createMultiGridSeriesLabels ({ transposedDataGrid, dataFormatter, chartType = 'multiGrid', gridIndex = 0 }: {
42
58
  transposedDataGrid: DataGridDatum[][],
43
59
  dataFormatter: DataFormatterGrid
44
60
  chartType?: ChartType
@@ -54,7 +70,25 @@ export function createGridSeriesLabels ({ transposedDataGrid, dataFormatter, cha
54
70
  })
55
71
  }
56
72
 
57
- export function createGridGroupLabels ({ transposedDataGrid, dataFormatter, chartType = 'grid', gridIndex = 0 }: {
73
+ export function createGridGroupLabels ({ transposedDataGrid, dataFormatter, chartType = 'grid' }: {
74
+ transposedDataGrid: DataGridDatum[][],
75
+ dataFormatter: DataFormatterGrid
76
+ chartType?: ChartType
77
+ }) {
78
+ if (transposedDataGrid[0] == null) {
79
+ return []
80
+ }
81
+ const labels = dataFormatter.grid.gridData.seriesDirection === 'row'
82
+ ? dataFormatter.grid.gridData.columnLabels
83
+ : dataFormatter.grid.gridData.rowLabels
84
+ return transposedDataGrid[0].map((_, columnLabels) => {
85
+ return labels[columnLabels] != null
86
+ ? labels[columnLabels]
87
+ : createDefaultGroupLabel(chartType, columnLabels)
88
+ })
89
+ }
90
+
91
+ export function createMultiGridGroupLabels ({ transposedDataGrid, dataFormatter, chartType = 'multiGrid', gridIndex = 0 }: {
58
92
  transposedDataGrid: DataGridDatum[][],
59
93
  dataFormatter: DataFormatterGrid
60
94
  chartType?: ChartType
@@ -103,7 +137,7 @@ export function getMinAndMaxSeries (data: DataSeries): [number, number] {
103
137
  ? data.flat()
104
138
  : data as (DataSeriesValue | DataSeriesDatum)[]
105
139
  const arr = flatData
106
- .filter(d => (d == null || (isObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
140
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
107
141
  .map(d => typeof d === 'number' ? d : d.value )
108
142
  return getMinAndMax(arr)
109
143
  }
@@ -112,7 +146,7 @@ export function getMinAndMaxSeries (data: DataSeries): [number, number] {
112
146
  export function getMinAndMaxGrid (data: DataGrid): [number, number] {
113
147
  const flatData: (DataGridValue | DataGridDatum)[] = data.flat()
114
148
  const arr = flatData
115
- .filter(d => (d == null || (isObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
149
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
116
150
  .map(d => typeof d === 'number' ? d : d.value )
117
151
  return getMinAndMax(arr)
118
152
  }
@@ -121,7 +155,7 @@ export function getMinAndMaxGrid (data: DataGrid): [number, number] {
121
155
  export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
122
156
  const flatData: (DataGridValue | DataGridDatum)[] = data.flat().flat()
123
157
  const arr = flatData
124
- .filter(d => (d == null || (isObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
158
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
125
159
  .map(d => typeof d === 'number' ? d : d.value )
126
160
  return getMinAndMax(arr)
127
161
  }
@@ -130,7 +164,7 @@ export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
130
164
  export function getMinAndMaxMultiValue (data: DataMultiValue, valueIndex: number = 2): [number, number] {
131
165
  const flatData: (DataMultiValueDatum | DataMultiValueValue)[] = data.flat().filter((d, i) => i == valueIndex)
132
166
  const arr = flatData
133
- .filter(d => (d == null || (isObject(d) && (d as DataMultiValueDatum).value == null)) === false) // 過濾掉null
167
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataMultiValueDatum).value == null)) === false) // 過濾掉null
134
168
  .map(d => typeof d === 'number' ? d : d.value )
135
169
  return getMinAndMax(arr)
136
170
  }