@orbcharts/core 3.0.0-alpha.30 → 3.0.0-alpha.31

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.
@@ -3,8 +3,17 @@ import { DataFormatterGrid } from './DataFormatterGrid';
3
3
 
4
4
  export interface DataFormatterMultiGrid extends DataFormatterBase<'multiGrid'> {
5
5
  visibleFilter: VisibleFilter<'multiGrid'>;
6
- multiGrid: Array<DataFormatterGrid>;
6
+ multiGrid: Array<DataFormatterMultiGridMultiGrid>;
7
+ container: DataFormatterMultiGridContainer;
7
8
  }
8
9
  export interface DataFormatterMultiGridPartial extends DataFormatterBasePartial<'multiGrid'> {
9
- multiGrid?: Array<Partial<DataFormatterGrid>>;
10
+ multiGrid?: Array<Partial<DataFormatterMultiGridMultiGrid>>;
11
+ }
12
+ export interface DataFormatterMultiGridMultiGrid extends DataFormatterGrid {
13
+ slotIndex: number;
14
+ }
15
+ export interface DataFormatterMultiGridContainer {
16
+ gap: number;
17
+ rowAmount: number;
18
+ columnAmount: number;
10
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbcharts/core",
3
- "version": "3.0.0-alpha.30",
3
+ "version": "3.0.0-alpha.31",
4
4
  "description": "OrbCharts is an open source chart library based on d3.js and rx.js",
5
5
  "author": "Blue Planet Inc.",
6
6
  "license": "Apache-2.0",
package/src/defaults.ts CHANGED
@@ -10,7 +10,7 @@ import type { DataRelationship } from './types/DataRelationship'
10
10
  import type { DataFormatterBase, DataFormatterValueAxis, DataFormatterGroupAxis } from './types/DataFormatter'
11
11
  import type { DataFormatterSeries } from './types/DataFormatterSeries'
12
12
  import type { DataFormatterGrid } from './types/DataFormatterGrid'
13
- import type { DataFormatterMultiGrid } from './types/DataFormatterMultiGrid'
13
+ import type { DataFormatterMultiGrid, DataFormatterMultiGridMultiGrid } from './types/DataFormatterMultiGrid'
14
14
  import type { DataFormatterMultiValue } from './types/DataFormatterMultiValue'
15
15
  import type { DataFormatterTree } from './types/DataFormatterTree'
16
16
  import type { DataFormatterRelationship } from './types/DataFormatterRelationship'
@@ -180,24 +180,25 @@ export const DATA_FORMATTER_GRID_DEFAULT: DataFormatterGrid = {
180
180
  // },
181
181
  }
182
182
 
183
+ export const DATA_FORMATTER_MULTI_GRID_MULTI_GRID_DEFAULT: DataFormatterMultiGridMultiGrid = {
184
+ ...DATA_FORMATTER_GRID_DEFAULT,
185
+ slotIndex: 0,
186
+ }
187
+
183
188
  export const DATA_FORMATTER_MULTI_GRID_DEFAULT: DataFormatterMultiGrid = {
184
189
  type: 'multiGrid',
185
190
  visibleFilter: (datum, rowIndex, columnIndex, context) => true,
186
191
  multiGrid: [
187
192
  {
188
- ...DATA_FORMATTER_GRID_DEFAULT
193
+ ...DATA_FORMATTER_MULTI_GRID_MULTI_GRID_DEFAULT
189
194
  },
190
- // // @Q@ 暫時性的邏輯,之後colorsPredicate移除掉後,這邊也要移除(但colors使用的seriesIndex要接續前一組grid)
191
- // {
192
- // ...DATA_FORMATTER_GRID_DEFAULT,
193
- // colorsPredicate: (datum, rowIndex, columnIndex, { data, chartParams, dataFormatter }) => {
194
- // const seriesIndex = dataFormatter.grid.seriesType === 'row' ? rowIndex : columnIndex
195
- // const reverseIndex = chartParams.colors[chartParams.colorScheme].series.length - 1 - seriesIndex
196
- // return chartParams.colors[chartParams.colorScheme].series[reverseIndex]
197
- // },
198
- // }
199
195
  ],
200
196
  // visibleGroupRange: null,
197
+ container: {
198
+ gap: 120,
199
+ rowAmount: 1,
200
+ columnAmount: 1
201
+ }
201
202
  }
202
203
 
203
204
  export const DATA_FORMATTER_MULTI_VALUE_DEFAULT: DataFormatterMultiValue = {
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  shareReplay } from 'rxjs'
3
3
  import type { ContextObserverFn } from '../types'
4
- import { multiGridObservable } from './multiGridObservables'
4
+ import { multiGridEachDetailObservable } from './multiGridObservables'
5
5
 
6
6
  export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
7
7
 
8
- const multiGrid$ = multiGridObservable({
8
+ const multiGridEachDetail$ = multiGridEachDetailObservable({
9
9
  fullDataFormatter$: observer.fullDataFormatter$,
10
10
  computedData$: observer.computedData$,
11
11
  layout$: observer.layout$,
@@ -21,6 +21,6 @@ export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({
21
21
  fullDataFormatter$: observer.fullDataFormatter$,
22
22
  computedData$: observer.computedData$,
23
23
  layout$: observer.layout$,
24
- multiGrid$
24
+ multiGridEachDetail$
25
25
  }
26
26
  }
@@ -24,6 +24,7 @@ import type {
24
24
  DataFormatterContext,
25
25
  DataFormatterValueAxis,
26
26
  DataFormatterGroupAxis,
27
+ DataFormatterMultiGridContainer,
27
28
  EventMultiGrid,
28
29
  HighlightTarget,
29
30
  Layout,
@@ -41,7 +42,7 @@ import {
41
42
  gridAxesSizeObservable,
42
43
  gridVisibleComputedDataObservable } from '../grid/gridObservables'
43
44
 
44
- export const multiGridObservable = ({ fullDataFormatter$, computedData$, layout$, fullChartParams$, event$ }: {
45
+ export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData$, layout$, fullChartParams$, event$ }: {
45
46
  fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
46
47
  computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
47
48
  layout$: Observable<Layout>
@@ -151,4 +152,61 @@ export const multiGridObservable = ({ fullDataFormatter$, computedData$, layout$
151
152
  })
152
153
  })
153
154
  )
155
+ }
156
+
157
+ interface GridContainerBox {
158
+ slotIndex: number
159
+ rowIndex: number
160
+ columnIndex: number
161
+ translate: [number, number]
162
+ scale: [number, number]
163
+ }
164
+
165
+ // 每一個grid的container位置
166
+ export const multiGridContainerObservable = ({ fullDataFormatter$, layout$, fullChartParams$ }: {
167
+ fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
168
+ layout$: Observable<Layout>
169
+ fullChartParams$: Observable<ChartParams>
170
+ }) => {
171
+ function calcBox (layout: Layout, container: DataFormatterMultiGridContainer, rowIndex: number, columnIndex: number) {
172
+ const { gap, rowAmount, columnAmount } = container
173
+ const width = (layout.width / columnAmount) - (gap / 2)
174
+ const height = (layout.height / rowAmount) - (gap / 2)
175
+ const x = columnIndex * width + (columnIndex * gap)
176
+ const y = rowIndex * height + (columnIndex * gap)
177
+ const translate: [number, number] = [x, y]
178
+ const scale: [number, number] = [width / layout.width, height / layout.height]
179
+
180
+ return {
181
+ translate,
182
+ scale
183
+ }
184
+ }
185
+
186
+ const multiGridContainer$ = combineLatest({
187
+ fullDataFormatter: fullDataFormatter$,
188
+ layout: layout$,
189
+ fullChartParams: fullChartParams$
190
+ }).pipe(
191
+ switchMap(async (d) => d),
192
+ map(data => {
193
+ data.fullDataFormatter.container.rowAmount
194
+ const boxArr: GridContainerBox[] = data.fullDataFormatter.multiGrid.map((grid, gridIndex) => {
195
+ const columnIndex = grid.slotIndex % data.fullDataFormatter.container.columnAmount
196
+ const rowIndex = Math.floor(grid.slotIndex / data.fullDataFormatter.container.columnAmount)
197
+ const { translate, scale } = calcBox(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
198
+
199
+ return {
200
+ slotIndex: grid.slotIndex,
201
+ rowIndex,
202
+ columnIndex,
203
+ translate,
204
+ scale,
205
+ }
206
+ })
207
+ return boxArr
208
+ }),
209
+ )
210
+
211
+ return multiGridContainer$
154
212
  }
@@ -4,7 +4,7 @@ import type { ComputedDataGrid, ComputedDatumGrid } from './ComputedDataGrid'
4
4
  import type { TransformData } from './TransformData'
5
5
 
6
6
  export interface ContextObserverMultiGrid<PluginParams> extends ContextObserverBase<'multiGrid', PluginParams> {
7
- multiGrid$: Observable<MultiGridObservableAll[]>
7
+ multiGridEachDetail$: Observable<MultiGridObservableAll[]>
8
8
  }
9
9
 
10
10
  export interface MultiGridObservableAll {
@@ -10,12 +10,25 @@ import type { AxisPosition } from './Axis'
10
10
 
11
11
  export interface DataFormatterMultiGrid extends DataFormatterBase<'multiGrid'> {
12
12
  visibleFilter: VisibleFilter<'multiGrid'>
13
- multiGrid: Array<DataFormatterGrid>
13
+ multiGrid: Array<DataFormatterMultiGridMultiGrid>
14
14
  // visibleGroupRange: [number, number] | null
15
+ container: DataFormatterMultiGridContainer
15
16
  }
16
17
 
17
18
  export interface DataFormatterMultiGridPartial extends DataFormatterBasePartial<'multiGrid'> {
18
- multiGrid?: Array<Partial<DataFormatterGrid>>
19
+ multiGrid?: Array<Partial<DataFormatterMultiGridMultiGrid>>
20
+ }
21
+
22
+ // 比grid還多出來的額外參數
23
+ export interface DataFormatterMultiGridMultiGrid extends DataFormatterGrid {
24
+ slotIndex: number
25
+ }
26
+
27
+ // container
28
+ export interface DataFormatterMultiGridContainer {
29
+ gap: number
30
+ rowAmount: number
31
+ columnAmount: number
19
32
  }
20
33
 
21
34
  // multiGrid欄位