|
1 | | -import { Config, Layout, Transform } from "plotly.js"; |
2 | | -import * as deepMerge from "deepmerge"; |
3 | | -import { Data } from "./namespaces"; |
| 1 | +import { Config, Layout } from "plotly.js"; |
4 | 2 |
|
5 | 3 | export const configs: SharedConfigs = { |
6 | 4 | layout: { |
@@ -29,100 +27,7 @@ export const configs: SharedConfigs = { |
29 | 27 | configuration: { displayModeBar: false, doubleClick: false } |
30 | 28 | }; |
31 | 29 |
|
32 | | -export const fetchThemeConfigs = (type: ChartType): Promise<ChartConfigs> => |
33 | | - new Promise<ChartConfigs>((resolve, reject) => { |
34 | | - try { |
35 | | - const cacheBurst = window.dojoConfig.cacheBust; |
36 | | - window |
37 | | - .fetch(`${window.mx.remoteUrl}com.mendix.charts.json?${cacheBurst}`) |
38 | | - .then(response => { |
39 | | - if (response.ok) { |
40 | | - return response.json(); |
41 | | - } |
42 | | - |
43 | | - return { layout: {}, configuration: {} }; |
44 | | - }) |
45 | | - .then(themeConfigs => { |
46 | | - resolve(processChartConfigs(type, themeConfigs)); |
47 | | - }) |
48 | | - .catch(error => { |
49 | | - console.log("An error occurred while fetching theme configs", error); // tslint:disable-line |
50 | | - reject(error); |
51 | | - }); |
52 | | - } catch (e) { |
53 | | - console.log("An error occurred while fetching theme configs", e); // tslint:disable-line |
54 | | - reject(e); |
55 | | - } |
56 | | - }); |
57 | | - |
58 | | -export const processChartConfigs = (type: ChartType, themeConfigs: ThemeConfigs): ChartConfigs => { |
59 | | - const sharedLayout = themeConfigs.layout || {}; |
60 | | - const sharedConfiguration = themeConfigs.configuration || {}; |
61 | | - const { charts } = themeConfigs; |
62 | | - if (charts) { |
63 | | - const chartConfigs = (charts as any)[type]; |
64 | | - |
65 | | - return { |
66 | | - layout: deepMerge.all([sharedLayout, (chartConfigs && chartConfigs.layout) || {}]), |
67 | | - configuration: deepMerge.all([sharedConfiguration, (chartConfigs && chartConfigs.configuration) || {}]), |
68 | | - data: (chartConfigs && chartConfigs.data) || {} |
69 | | - }; |
70 | | - } |
71 | | - |
72 | | - return { layout: sharedLayout, configuration: sharedConfiguration, data: {} }; |
73 | | -}; |
74 | | - |
75 | | -export const arrayOverwrite = (_destinationArray: any[], sourceArray: any[]) => sourceArray; |
76 | | - |
77 | | -export type ChartType = |
78 | | - | "LineChart" |
79 | | - | "BubbleChart" |
80 | | - | "PieChart" |
81 | | - | "HeatMap" |
82 | | - | "AnyChart" |
83 | | - | "PolarChart" |
84 | | - | "BarChart" |
85 | | - | "AreaChart" |
86 | | - | "TimeSeries" |
87 | | - | "ColumnChart"; |
88 | | - |
89 | 30 | interface SharedConfigs { |
90 | 31 | layout: Partial<Layout>; |
91 | 32 | configuration: Partial<Config>; |
92 | 33 | } |
93 | | - |
94 | | -export type ChartConfigs = SharedConfigs & { data: Partial<{}> }; |
95 | | -export interface ThemeConfigs extends SharedConfigs { |
96 | | - charts?: { |
97 | | - LineChart?: ChartConfigs; |
98 | | - BarChart?: ChartConfigs; |
99 | | - ColumnChart?: ChartConfigs; |
100 | | - TimeSeries?: ChartConfigs; |
101 | | - AreaChart?: ChartConfigs; |
102 | | - PieChart?: ChartConfigs; |
103 | | - PolarChart?: ChartConfigs; |
104 | | - HeatMap?: ChartConfigs; |
105 | | - BubbleChart?: ChartConfigs; |
106 | | - }; |
107 | | -} |
108 | | - |
109 | | -export const getTransforms = (series: Data.SeriesProps, traces: Data.ScatterTrace): Transform[] | undefined => { |
110 | | - const { aggregationType } = series; |
111 | | - if (aggregationType !== "none" && traces) { |
112 | | - return [ |
113 | | - { |
114 | | - type: "aggregate", |
115 | | - groups: traces.x, |
116 | | - aggregations: [ |
117 | | - { |
118 | | - target: "y", |
119 | | - func: aggregationType, |
120 | | - enabled: true |
121 | | - } |
122 | | - ] |
123 | | - } as Transform |
124 | | - ]; |
125 | | - } |
126 | | - |
127 | | - return undefined; |
128 | | -}; |
0 commit comments