@orbcharts/core 3.0.0-beta.4 → 3.0.0-beta.6

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.
@@ -123,60 +123,60 @@ export function createMultiGridGroupLabels ({ transposedDataGrid, dataFormatterG
123
123
  }
124
124
 
125
125
  // 取得最小及最大值 - 數字陣列
126
- export function getMinAndMax (data: number[]): [number, number] {
127
- const defaultMinAndMax: [number, number] = [0, 0] // default
126
+ export function getMinMax (data: number[]): [number, number] {
127
+ const defaultMinMax: [number, number] = [0, 0] // default
128
128
  if (!data.length) {
129
- return defaultMinAndMax
129
+ return defaultMinMax
130
130
  }
131
- const minAndMax: [number, number] = data.reduce((prev, current) => {
131
+ const minMax: [number, number] = data.reduce((prev, current) => {
132
132
  // [min, max]
133
133
  return [
134
134
  current < prev[0] ? current : prev[0],
135
135
  current > prev[1] ? current : prev[1]
136
136
  ]
137
137
  }, [data[0], data[0]])
138
- return minAndMax
138
+ return minMax
139
139
  }
140
140
 
141
141
  // 取得最小及最大值 - datum格式陣列資料
142
- export function getMinAndMaxValue (data: DatumValue[]): [number, number] {
142
+ export function getMinMaxValue (data: DatumValue[]): [number, number] {
143
143
  const arr = data
144
144
  .filter(d => d != null && d.value != null)
145
145
  .map(d => d.value )
146
- return getMinAndMax(arr)
146
+ return getMinMax(arr)
147
147
  }
148
148
 
149
149
  // 取得最小及最大值 - Series Data
150
- export function getMinAndMaxSeries (data: DataSeries): [number, number] {
150
+ export function getMinMaxSeries (data: DataSeries): [number, number] {
151
151
  const flatData: (DataSeriesValue | DataSeriesDatum)[] = data[0] && Array.isArray((data as (DataSeriesValue | DataSeriesDatum)[][])[0])
152
152
  ? data.flat()
153
153
  : data as (DataSeriesValue | DataSeriesDatum)[]
154
154
  const arr = flatData
155
155
  .filter(d => (d == null || (isPlainObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
156
156
  .map(d => typeof d === 'number' ? d : d.value )
157
- return getMinAndMax(arr)
157
+ return getMinMax(arr)
158
158
  }
159
159
 
160
160
  // 取得最小及最大值 - Grid Data
161
- export function getMinAndMaxGrid (data: DataGrid): [number, number] {
161
+ export function getMinMaxGrid (data: DataGrid): [number, number] {
162
162
  const flatData: (DataGridValue | DataGridDatum)[] = data.flat()
163
163
  const arr = flatData
164
164
  .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
165
165
  .map(d => typeof d === 'number' ? d : d.value )
166
- return getMinAndMax(arr)
166
+ return getMinMax(arr)
167
167
  }
168
168
 
169
169
  // 取得最小及最大值 - MultiGrid Data
170
- export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
170
+ export function getMinMaxMultiGrid (data: DataMultiGrid): [number, number] {
171
171
  const flatData: (DataGridValue | DataGridDatum)[] = data.flat().flat()
172
172
  const arr = flatData
173
173
  .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
174
174
  .map(d => typeof d === 'number' ? d : d.value )
175
- return getMinAndMax(arr)
175
+ return getMinMax(arr)
176
176
  }
177
177
 
178
178
  // 取得最小及最大值 - MultiValue Data
179
- export function getMinAndMaxMultiValue (data: DataMultiValue, valueIndex: number): [number, number] {
179
+ export function getMinMaxMultiValue (data: DataMultiValue, valueIndex: number): [number, number] {
180
180
  const arr: number[] = data
181
181
  .map(d => {
182
182
  if (Array.isArray(d)) {
@@ -188,10 +188,10 @@ export function getMinAndMaxMultiValue (data: DataMultiValue, valueIndex: number
188
188
  }
189
189
  })
190
190
  .filter(d => d != null)
191
- return getMinAndMax(arr)
191
+ return getMinMax(arr)
192
192
  }
193
193
 
194
- export function getMinAndMaxMultiValueXY ({ data, minX, maxX, minY, maxY }: {
194
+ export function getMinMaxMultiValueXY ({ data, minX, maxX, minY, maxY }: {
195
195
  data: ComputedLayoutDatumMultiValue[][]
196
196
  minX: number
197
197
  maxX: number
@@ -235,13 +235,13 @@ export function getMinAndMaxMultiValueXY ({ data, minX, maxX, minY, maxY }: {
235
235
 
236
236
  // @Q@ 待處理
237
237
  // // 取得最小及最大值 - Relationship Data
238
- // export function getMinAndMaxRelationship (data: DataRelationship, target: 'nodes' | 'edges' = 'nodes'): [number, number] {
238
+ // export function getMinMaxRelationship (data: DataRelationship, target: 'nodes' | 'edges' = 'nodes'): [number, number] {
239
239
 
240
240
  // }
241
241
 
242
242
  // @Q@ 待處理
243
243
  // // 取得最小及最大值 - Tree Data
244
- // export function getMinAndMaxTree (data: DataTree): [number, number] {
244
+ // export function getMinMaxTree (data: DataTree): [number, number] {
245
245
 
246
246
  // }
247
247
 
@@ -271,10 +271,10 @@ export function transposeData<T> (seriesDirection: SeriesDirection, data: T[][])
271
271
 
272
272
 
273
273
  export function seriesColorPredicate (seriesIndex: number, chartParams: ChartParams) {
274
- return seriesIndex < chartParams.colors[chartParams.colorScheme].series.length
275
- ? chartParams.colors[chartParams.colorScheme].series[seriesIndex]
276
- : chartParams.colors[chartParams.colorScheme].series[
277
- seriesIndex % chartParams.colors[chartParams.colorScheme].series.length
274
+ return seriesIndex < chartParams.colors[chartParams.colorScheme].label.length
275
+ ? chartParams.colors[chartParams.colorScheme].label[seriesIndex]
276
+ : chartParams.colors[chartParams.colorScheme].label[
277
+ seriesIndex % chartParams.colors[chartParams.colorScheme].label.length
278
278
  ]
279
279
  }
280
280
 
@@ -0,0 +1,85 @@
1
+ import {
2
+ combineLatest,
3
+ distinctUntilChanged,
4
+ filter,
5
+ map,
6
+ merge,
7
+ takeUntil,
8
+ shareReplay,
9
+ switchMap,
10
+ Subject,
11
+ Observable } from 'rxjs'
12
+ import type {
13
+ ChartParams,
14
+ ComputedDataRelationship,
15
+ ComputedDataTypeMap,
16
+ ComputedNode,
17
+ ComputedEdge,
18
+ DataFormatterTree } from '../../lib/core-types'
19
+
20
+
21
+ export const categoryLabelsObservable = (
22
+ CategoryNodeMap$: Observable<Map<string, ComputedNode[]>>,
23
+ CategoryEdgeMap$: Observable<Map<string, ComputedEdge[]>>
24
+ ): Observable<string[]> => {
25
+ return combineLatest({
26
+ CategoryNodeMap: CategoryNodeMap$,
27
+ CategoryEdgeMap: CategoryEdgeMap$
28
+ }).pipe(
29
+ switchMap(async d => d),
30
+ map(data => {
31
+ return [...Array.from(data.CategoryNodeMap.keys()), ...Array.from(data.CategoryEdgeMap.keys())]
32
+ }),
33
+ distinctUntilChanged((a, b) => {
34
+ return JSON.stringify(a).length === JSON.stringify(b).length
35
+ }),
36
+ )
37
+ }
38
+
39
+ export const NodeMapObservable = (computedData$: Observable<ComputedDataRelationship>) => {
40
+ return computedData$.pipe(
41
+ map(data => {
42
+ const nodeMap = new Map<string, ComputedNode>()
43
+ data.nodes.forEach(node => {
44
+ nodeMap.set(node.id, node)
45
+ })
46
+ return nodeMap
47
+ }),
48
+ )
49
+ }
50
+
51
+ export const EdgeMapObservable = (computedData$: Observable<ComputedDataRelationship>) => {
52
+ return computedData$.pipe(
53
+ map(data => {
54
+ const edgeMap = new Map<string, ComputedEdge>()
55
+ data.edges.forEach(edge => {
56
+ edgeMap.set(edge.id, edge)
57
+ })
58
+ return edgeMap
59
+ }),
60
+ )
61
+ }
62
+
63
+ // 所有可見的節點
64
+ export const relationshipVisibleComputedDataObservable = ({ computedData$, NodeMap$ }: {
65
+ computedData$: Observable<ComputedDataRelationship>
66
+ NodeMap$: Observable<Map<string, ComputedNode>>
67
+ }) => {
68
+ return combineLatest({
69
+ computedData: computedData$,
70
+ NodeMap: NodeMap$
71
+ }).pipe(
72
+ switchMap(async d => d),
73
+ map(data => {
74
+ return {
75
+ nodes: data.computedData.nodes.filter(node => node.visible),
76
+ edges: data.computedData.edges
77
+ .filter(edge => edge.visible)
78
+ // 依照節點是否存在篩選
79
+ .filter(edge => {
80
+ return data.NodeMap.has(edge.startNode.id) && data.NodeMap.has(edge.endNode.id)
81
+ })
82
+ }
83
+ })
84
+ )
85
+ }
@@ -43,7 +43,7 @@ function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
43
43
  const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
44
44
  ColorType: (value: ColorType) => {
45
45
  return value === 'none'
46
- || value === 'series'
46
+ || value === 'label'
47
47
  || value === 'primary'
48
48
  || value === 'secondary'
49
49
  || value === 'white'