@orbcharts/core 3.0.0-alpha.32 → 3.0.0-alpha.34

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.
@@ -6,13 +6,14 @@ 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 { SeriesType, DataFormatterGrid } from '../types/DataFormatterGrid'
9
+ import type { SeriesDirection, DataFormatterGrid, DataFormatterGridContainer } from '../types/DataFormatterGrid'
10
10
  import type { ComputedDatumSeriesValue } from '../types/ComputedData'
11
11
  import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
12
12
  import type { ComputedDatumGrid, ComputedDataGrid } from '../types/ComputedDataGrid'
13
13
  import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
14
+ import type { Layout } from '../types/Layout'
14
15
  // import type { ComputedDatumMultiGrid } from '../types/ComputedDataMultiGrid'
15
- import { isObject } from './commonUtils'
16
+ import { isPlainObject } from './commonUtils'
16
17
 
17
18
  export function formatValueToLabel (value: any, valueFormatter: string | ((text: d3.NumberValue) => string)) {
18
19
  if (valueFormatter! instanceof Function == true) {
@@ -43,9 +44,9 @@ export function createGridSeriesLabels ({ transposedDataGrid, dataFormatter, cha
43
44
  chartType?: ChartType
44
45
  gridIndex?: number
45
46
  }) {
46
- const labels = dataFormatter.grid.seriesType === 'row'
47
- ? dataFormatter.grid.rowLabels
48
- : dataFormatter.grid.columnLabels
47
+ const labels = dataFormatter.grid.gridData.seriesDirection === 'row'
48
+ ? dataFormatter.grid.gridData.rowLabels
49
+ : dataFormatter.grid.gridData.columnLabels
49
50
  return transposedDataGrid.map((_, rowIndex) => {
50
51
  return labels[rowIndex] != null
51
52
  ? labels[rowIndex]
@@ -62,9 +63,9 @@ export function createGridGroupLabels ({ transposedDataGrid, dataFormatter, char
62
63
  if (transposedDataGrid[0] == null) {
63
64
  return []
64
65
  }
65
- const labels = dataFormatter.grid.seriesType === 'row'
66
- ? dataFormatter.grid.columnLabels
67
- : dataFormatter.grid.rowLabels
66
+ const labels = dataFormatter.grid.gridData.seriesDirection === 'row'
67
+ ? dataFormatter.grid.gridData.columnLabels
68
+ : dataFormatter.grid.gridData.rowLabels
68
69
  return transposedDataGrid[0].map((_, columnLabels) => {
69
70
  return labels[columnLabels] != null
70
71
  ? labels[columnLabels]
@@ -102,7 +103,7 @@ export function getMinAndMaxSeries (data: DataSeries): [number, number] {
102
103
  ? data.flat()
103
104
  : data as (DataSeriesValue | DataSeriesDatum)[]
104
105
  const arr = flatData
105
- .filter(d => (d == null || (isObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
106
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
106
107
  .map(d => typeof d === 'number' ? d : d.value )
107
108
  return getMinAndMax(arr)
108
109
  }
@@ -111,7 +112,7 @@ export function getMinAndMaxSeries (data: DataSeries): [number, number] {
111
112
  export function getMinAndMaxGrid (data: DataGrid): [number, number] {
112
113
  const flatData: (DataGridValue | DataGridDatum)[] = data.flat()
113
114
  const arr = flatData
114
- .filter(d => (d == null || (isObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
115
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
115
116
  .map(d => typeof d === 'number' ? d : d.value )
116
117
  return getMinAndMax(arr)
117
118
  }
@@ -120,7 +121,7 @@ export function getMinAndMaxGrid (data: DataGrid): [number, number] {
120
121
  export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
121
122
  const flatData: (DataGridValue | DataGridDatum)[] = data.flat().flat()
122
123
  const arr = flatData
123
- .filter(d => (d == null || (isObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
124
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
124
125
  .map(d => typeof d === 'number' ? d : d.value )
125
126
  return getMinAndMax(arr)
126
127
  }
@@ -129,7 +130,7 @@ export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
129
130
  export function getMinAndMaxMultiValue (data: DataMultiValue, valueIndex: number = 2): [number, number] {
130
131
  const flatData: (DataMultiValueDatum | DataMultiValueValue)[] = data.flat().filter((d, i) => i == valueIndex)
131
132
  const arr = flatData
132
- .filter(d => (d == null || (isObject(d) && (d as DataMultiValueDatum).value == null)) === false) // 過濾掉null
133
+ .filter(d => (d == null || (isPlainObject(d) && (d as DataMultiValueDatum).value == null)) === false) // 過濾掉null
133
134
  .map(d => typeof d === 'number' ? d : d.value )
134
135
  return getMinAndMax(arr)
135
136
  }
@@ -146,9 +147,9 @@ export function getMinAndMaxMultiValue (data: DataMultiValue, valueIndex: number
146
147
 
147
148
  // }
148
149
 
149
- // 轉置成seriesType為main的陣列格式
150
- export function transposeData<T> (seriesType: SeriesType, data: T[][]): T[][] {
151
- if (seriesType === 'row') {
150
+ // 轉置成seriesDirection為main的陣列格式
151
+ export function transposeData<T> (seriesDirection: SeriesDirection, data: T[][]): T[][] {
152
+ if (seriesDirection === 'row') {
152
153
  return Object.assign([], data)
153
154
  }
154
155
  // 取得原始陣列的維度
@@ -179,6 +180,21 @@ export function seriesColorPredicate (seriesIndex: number, chartParams: ChartPar
179
180
  ]
180
181
  }
181
182
 
183
+ export function calcGridContainerPosition (layout: Layout, container: DataFormatterGridContainer, rowIndex: number, columnIndex: number) {
184
+ const { gap, rowAmount, columnAmount } = container
185
+ const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
186
+ const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
187
+ const x = columnIndex * width + (columnIndex * gap)
188
+ const y = rowIndex * height + (rowIndex * gap)
189
+ const translate: [number, number] = [x, y]
190
+ const scale: [number, number] = [width / layout.width, height / layout.height]
191
+
192
+ return {
193
+ translate,
194
+ scale
195
+ }
196
+ }
197
+
182
198
  // // multiGrid datum color
183
199
  // export function multiGridColorPredicate ({ seriesIndex, groupIndex, data, chartParams }: {
184
200
  // seriesIndex: number