@datarailsshared/dr_renderer 1.1.41 → 1.2.2

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.
@@ -0,0 +1,147 @@
1
+ /**
2
+ * @typedef {Object} HighChartsRenderer
3
+ * @property {(rows: Rows, options: GTROptions | null, isTable: boolean, widget: any, pivotModel?: PivotModel) => string} rhPivotViewV2
4
+ */
5
+
6
+ /**
7
+ * @typedef {Object} PivotUtilities
8
+ * @property {(rows: Rows, options: GTROptions) => PivotModel} getPivotDataModel
9
+ */
10
+
11
+ /**
12
+ * @typedef {Object} JQuery
13
+ * @property {PivotUtilities} pivotUtilities
14
+ */
15
+
16
+ /**
17
+ * @typedef {Object} PivotModel
18
+ */
19
+
20
+ /**
21
+ * @typedef {Object} RendererOptions
22
+ * @property {any} hcInstance
23
+ */
24
+
25
+ /**
26
+ * @typedef {Object} GTROptions
27
+ * @property {RendererOptions} rendererOptions
28
+ */
29
+
30
+ /**
31
+ * @typedef {Record<string, Record<string, number | string> | number | string>[]} Rows - BE data response
32
+ */
33
+
34
+ export class GraphTableRenderer {
35
+ /**
36
+ * @type {PivotModel | undefined}
37
+ */
38
+ #pivotModel;
39
+
40
+ /**
41
+ * @type {GTROptions | null}
42
+ */
43
+ #options = null;
44
+
45
+ /**
46
+ * @type {Record<string, Record<string, number | string> | number | string>[]}
47
+ *
48
+ */
49
+ #rows = [];
50
+
51
+ /**
52
+ * Utility properties
53
+ */
54
+ /**
55
+ * @type {HighChartsRenderer}
56
+ */
57
+ #hcr;
58
+ /**
59
+ * @type {JQuery}
60
+ */
61
+ #$;
62
+ /**
63
+ * @type {PivotUtilities}
64
+ */
65
+ #pivotUtilities;
66
+
67
+ /**
68
+ * @type {any | null}
69
+ */
70
+ #hcInstance = null;
71
+
72
+ /**
73
+ *
74
+ * @param {HighChartsRenderer} hcr
75
+ * @param {JQuery} $
76
+ */
77
+ constructor(hcr, $) {
78
+ this.#hcr = hcr;
79
+ this.#$ = $;
80
+ this.#pivotUtilities = this.#$.pivotUtilities;
81
+ }
82
+
83
+ /**
84
+ * Creates Pivot Data Model that works we BE data response to aggregate data to render with Chart and Table
85
+ * @param {Rows} rows BE data response
86
+ * @param {GTROptions} options
87
+ * @returns {this}
88
+ */
89
+ createPivotModel(rows, options) {
90
+ this.#options = options;
91
+ this.#rows = rows;
92
+ this.#pivotModel = this.#pivotUtilities.getPivotDataModel(rows, options);
93
+ return this;
94
+ }
95
+
96
+ /**
97
+ * @returns {void}
98
+ */
99
+ disposePivotModel() {
100
+ this.#pivotModel = undefined;
101
+ }
102
+
103
+ /**
104
+ * @see createPivotModel
105
+ * @returns {PivotModel | undefined}
106
+ */
107
+ getPivotModel() {
108
+ return this.#pivotModel;
109
+ }
110
+
111
+ /**
112
+ * @description returns Chart instance of HighCharts library
113
+ * @returns {any | null}
114
+ */
115
+ hcInstance() {
116
+ return this.#hcInstance;
117
+ }
118
+
119
+ #setHcInstance() {
120
+ if (!this.#options) {
121
+ return;
122
+ }
123
+ this.#hcInstance = this.#options.rendererOptions.hcInstance;
124
+ if (!this.#hcInstance) {
125
+ console.warn('[dr_renderer] HighCharts instance not found in options after the chart is rendered.');
126
+ }
127
+ /**
128
+ * hcInstance object is not needed in options after the chart is rendered - it's an internal object of HighCharts library
129
+ * Deleting to not supply it to widget object, so it cannot be used anywhere else
130
+ */
131
+ delete this.#options.rendererOptions.hcInstance;
132
+ }
133
+
134
+ renderTable(widget = null) {
135
+ return this.#hcr.rhPivotViewV2(this.#rows, this.#options, true, widget, this.#pivotModel);
136
+ }
137
+
138
+ renderChart(widget = null) {
139
+ const chart = this.#hcr.rhPivotViewV2(this.#rows, this.#options, false, widget, this.#pivotModel);
140
+ setTimeout(() => {
141
+ this.#setHcInstance();
142
+ });
143
+ return chart;
144
+ }
145
+ }
146
+
147
+ export default GraphTableRenderer;