@datarailsshared/dr_renderer 1.2.418 → 1.2.419
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.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* @typedef {Object} HighChartsRenderer
|
3
|
-
* @property {(rows: Rows, options: GTROptions, isTable: boolean, widget: any, pivotModel?: PivotModel) => string} rhPivotViewV2
|
3
|
+
* @property {(rows: Rows, options: GTROptions | null, isTable: boolean, widget: any, pivotModel?: PivotModel) => string} rhPivotViewV2
|
4
4
|
*/
|
5
5
|
|
6
6
|
/**
|
@@ -17,8 +17,14 @@
|
|
17
17
|
* @typedef {Object} PivotModel
|
18
18
|
*/
|
19
19
|
|
20
|
+
/**
|
21
|
+
* @typedef {Object} RendererOptions
|
22
|
+
* @property {any} hcInstance
|
23
|
+
*/
|
24
|
+
|
20
25
|
/**
|
21
26
|
* @typedef {Object} GTROptions
|
27
|
+
* @property {RendererOptions} rendererOptions
|
22
28
|
*/
|
23
29
|
|
24
30
|
/**
|
@@ -58,6 +64,11 @@ export class GraphTableRenderer {
|
|
58
64
|
*/
|
59
65
|
#pivotUtilities;
|
60
66
|
|
67
|
+
/**
|
68
|
+
* @type {any | null}
|
69
|
+
*/
|
70
|
+
#hcInstance = null;
|
71
|
+
|
61
72
|
/**
|
62
73
|
*
|
63
74
|
* @param {HighChartsRenderer} hcr
|
@@ -97,12 +108,39 @@ export class GraphTableRenderer {
|
|
97
108
|
return this.#pivotModel;
|
98
109
|
}
|
99
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
|
+
|
100
134
|
renderTable(widget = null) {
|
101
|
-
return this.#hcr.rhPivotViewV2(this.#rows, this.#options
|
135
|
+
return this.#hcr.rhPivotViewV2(this.#rows, this.#options, true, widget, this.#pivotModel);
|
102
136
|
}
|
103
137
|
|
104
138
|
renderChart(widget = null) {
|
105
|
-
|
139
|
+
const chart = this.#hcr.rhPivotViewV2(this.#rows, this.#options, false, widget, this.#pivotModel);
|
140
|
+
setTimeout(() => {
|
141
|
+
this.#setHcInstance();
|
142
|
+
});
|
143
|
+
return chart;
|
106
144
|
}
|
107
145
|
}
|
108
146
|
|
@@ -473,18 +473,16 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
473
473
|
return chart_option;
|
474
474
|
}
|
475
475
|
|
476
|
+
/**
|
477
|
+
* @deprecated For new angular just use hcInstance
|
478
|
+
*/
|
476
479
|
highchartsRenderer.downloadFile = function (title, graph_id, type) {
|
477
480
|
let chart = null;
|
478
481
|
|
479
482
|
const chartElement = $('#' + graph_id).find('div.chart');
|
480
483
|
if (chartElement.highcharts) {
|
484
|
+
// old angular
|
481
485
|
chart = chartElement.highcharts();
|
482
|
-
} else {
|
483
|
-
const graphIdString = graph_id.split('_')[1];
|
484
|
-
const graphId = Number(graphIdString) || graphIdString;
|
485
|
-
chart = lodash.findLast(Highcharts.charts, function(value) {
|
486
|
-
return value.options.widgetId === graphId;
|
487
|
-
});
|
488
486
|
}
|
489
487
|
|
490
488
|
if (!chart) return;
|
@@ -1090,19 +1088,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1090
1088
|
chartOptions = highchartsRenderer.updateChartOptions(chartOptions, opts);
|
1091
1089
|
chartOptions = highchartsRenderer.updateChartOptions(chartOptions, {credits: {enabled: false}});
|
1092
1090
|
result = $("<div>").addClass("chart");
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1091
|
+
|
1092
|
+
// old angular
|
1093
|
+
if (result.highcharts) {
|
1094
|
+
setTimeout(() => {
|
1096
1095
|
result.highcharts(chartOptions);
|
1097
|
-
chart = result.highcharts();
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1096
|
+
const chart = result.highcharts();
|
1097
|
+
if (opts && opts.testChart) {
|
1098
|
+
opts.testChart.chart = chart;
|
1099
|
+
}
|
1100
|
+
});
|
1101
|
+
} else {
|
1102
|
+
// new angular
|
1103
|
+
setTimeout(() => {
|
1104
|
+
const chart = Highcharts.chart(result[0], chartOptions);
|
1105
|
+
if (opts) {
|
1106
|
+
opts.hcInstance = chart;
|
1107
|
+
}
|
1108
|
+
});
|
1109
|
+
}
|
1106
1110
|
}
|
1107
1111
|
return result;
|
1108
1112
|
};
|
@@ -4612,26 +4616,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4612
4616
|
highchartsRenderer.sanitizeOptions(opts);
|
4613
4617
|
options.rendererOptions.labelsConvertFunction = highchartsRenderer.getFieldNameForTable(options);
|
4614
4618
|
opts.isTable = isTable;
|
4615
|
-
if (isTable == true && options.rendererOptions.chartOptions && options.rendererOptions.chartOptions.table_options && options.rendererOptions.chartOptions.table_options.transpose_table == true) {
|
4616
|
-
var temp_cols = opts.cols;
|
4617
|
-
opts.cols = opts.rows;
|
4618
|
-
opts.rows = temp_cols;
|
4619
|
-
|
4620
|
-
if (highchartsRenderer.sortHasBeenDoneOnBE(lodash.get(widget.pivot, 'keysObject'))) {
|
4621
|
-
opts.keysObject = lodash.cloneDeep(widget.pivot.keysObject);
|
4622
|
-
const tempColKeys = opts.keysObject.col_keys;
|
4623
|
-
opts.keysObject.col_keys = opts.keysObject.row_keys;
|
4624
|
-
opts.keysObject.row_keys = tempColKeys;
|
4625
|
-
}
|
4626
|
-
}
|
4627
4619
|
|
4628
4620
|
optsFiltered = $.extend(defaults, opts);
|
4629
4621
|
result = null;
|
4630
4622
|
try {
|
4631
|
-
const isTranspose = lodash.get(opts, 'rendererOptions.chartOptions.table_options.transpose_table', false);
|
4632
|
-
opts.getFormattedColKeys = isTranspose ? highchartsRenderer.getFormattedRowKeys : highchartsRenderer.getFormattedColKeys;
|
4633
|
-
opts.getFormattedRowKeys = isTranspose ? highchartsRenderer.getFormattedColKeys : highchartsRenderer.getFormattedRowKeys;
|
4634
|
-
|
4635
4623
|
pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
|
4636
4624
|
pivotData.sortByValueAttrs = [];
|
4637
4625
|
try {
|
@@ -4782,26 +4770,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4782
4770
|
highchartsRenderer.sanitizeOptions(opts);
|
4783
4771
|
options.rendererOptions.labelsConvertFunction = highchartsRenderer.getFieldNameForTable(options);
|
4784
4772
|
opts.isTable = isTable;
|
4785
|
-
if (isTable == true && options.rendererOptions.chartOptions && options.rendererOptions.chartOptions.table_options && options.rendererOptions.chartOptions.table_options.transpose_table == true) {
|
4786
|
-
var temp_cols = opts.cols;
|
4787
|
-
opts.cols = opts.rows;
|
4788
|
-
opts.rows = temp_cols;
|
4789
|
-
|
4790
|
-
if (highchartsRenderer.sortHasBeenDoneOnBE(lodash.get(widget.pivot, 'keysObject'))) {
|
4791
|
-
opts.keysObject = lodash.cloneDeep(widget.pivot.keysObject);
|
4792
|
-
const tempColKeys = opts.keysObject.col_keys;
|
4793
|
-
opts.keysObject.col_keys = opts.keysObject.row_keys;
|
4794
|
-
opts.keysObject.row_keys = tempColKeys;
|
4795
|
-
}
|
4796
|
-
}
|
4797
4773
|
|
4798
4774
|
optsFiltered = $.extend(defaults, opts);
|
4799
4775
|
result = null;
|
4800
4776
|
try {
|
4801
|
-
const isTranspose = lodash.get(opts, 'rendererOptions.chartOptions.table_options.transpose_table', false);
|
4802
|
-
opts.getFormattedColKeys = isTranspose ? highchartsRenderer.getFormattedRowKeys : highchartsRenderer.getFormattedColKeys;
|
4803
|
-
opts.getFormattedRowKeys = isTranspose ? highchartsRenderer.getFormattedColKeys : highchartsRenderer.getFormattedRowKeys;
|
4804
|
-
|
4805
4777
|
pivotData.sortByValueAttrs = [];
|
4806
4778
|
try {
|
4807
4779
|
if (options && options.onlyOptions) {
|
@@ -9185,9 +9157,28 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9185
9157
|
return {};
|
9186
9158
|
}
|
9187
9159
|
subopts.total_value_options = widget_obj.options.total_value_options;
|
9188
|
-
|
9189
|
-
|
9190
|
-
|
9160
|
+
subopts.getFormattedColKeys = highchartsRenderer.getFormattedColKeys;
|
9161
|
+
subopts.getFormattedRowKeys = highchartsRenderer.getFormattedRowKeys;
|
9162
|
+
|
9163
|
+
const is_transpose = lodash.get(widget_obj.options, 'chartOptions.table_options.transpose_table', false);
|
9164
|
+
|
9165
|
+
if (is_transpose) {
|
9166
|
+
subopts.getFormattedColKeys = highchartsRenderer.getFormattedRowKeys;
|
9167
|
+
subopts.getFormattedRowKeys = highchartsRenderer.getFormattedColKeys;
|
9168
|
+
|
9169
|
+
const tempCols = subopts.cols;
|
9170
|
+
subopts.cols = subopts.rows;
|
9171
|
+
subopts.rows = tempCols;
|
9172
|
+
|
9173
|
+
if (highchartsRenderer.sortHasBeenDoneOnBE(lodash.get(pivot, 'keysObject'))) {
|
9174
|
+
subopts.keysObject = lodash.cloneDeep(pivot.keysObject);
|
9175
|
+
const tempColKeys = subopts.keysObject.col_keys;
|
9176
|
+
subopts.keysObject.col_keys = subopts.keysObject.row_keys;
|
9177
|
+
subopts.keysObject.row_keys = tempColKeys;
|
9178
|
+
}
|
9179
|
+
}
|
9180
|
+
|
9181
|
+
if (isEditor == true) {
|
9191
9182
|
subopts.rendererOptions.totalFilterElements = {
|
9192
9183
|
col_total: $('<span>Grand Totals ' + highchartsRenderer.getIconsForTotalOptions(widget_obj.options, "col_total") + '</span>')[0],
|
9193
9184
|
row_total: $('<span>Grand Totals ' + highchartsRenderer.getIconsForTotalOptions(widget_obj.options, "row_total") + '</span>')[0]
|
@@ -9232,7 +9223,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9232
9223
|
}
|
9233
9224
|
} else {
|
9234
9225
|
if (widget_obj.options && widget_obj.options.total_value_options && widget_obj.options.total_value_options) {
|
9235
|
-
is_transpose = lodash.get(widget_obj.options, 'chartOptions.table_options.transpose_table', false);
|
9236
9226
|
subopts.rendererOptions.totalFilterElements = {
|
9237
9227
|
col_total: $('<span>Grand Totals ' + highchartsRenderer.getIconsForTotalOptions(widget_obj.options, "col_total") + '</span>')[0],
|
9238
9228
|
row_total: $('<span>Grand Totals ' + highchartsRenderer.getIconsForTotalOptions(widget_obj.options, "row_total") + '</span>')[0]
|
@@ -367,23 +367,9 @@ describe('highcharts_renderer', () => {
|
|
367
367
|
});
|
368
368
|
|
369
369
|
describe('function downloadFile', () => {
|
370
|
-
const graphId = '1_1';
|
371
|
-
|
372
370
|
it('Old angular. No chart', () => {
|
373
371
|
expect(highchartsRenderer.downloadFile('test', '2_2', 'png')).toEqual(undefined)
|
374
372
|
});
|
375
|
-
|
376
|
-
it('New angular. png', () => {
|
377
|
-
jest.spyOn(Highcharts.charts[0], 'exportChartLocal', null);
|
378
|
-
highchartsRenderer.downloadFile('test', graphId, 'png')
|
379
|
-
expect(Highcharts.charts[0].exportChartLocal).toHaveBeenCalled();
|
380
|
-
});
|
381
|
-
|
382
|
-
it('New angular. XLS', () => {
|
383
|
-
jest.spyOn(Highcharts.charts[0], 'downloadXLS', null);
|
384
|
-
highchartsRenderer.downloadFile('test', graphId, 'XLS')
|
385
|
-
expect(Highcharts.charts[0].downloadXLS).toHaveBeenCalled();
|
386
|
-
});
|
387
373
|
});
|
388
374
|
|
389
375
|
describe('function defaultValueLabelsFormatter', () => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* @typedef {Object} HighChartsRenderer
|
3
|
-
* @property {(rows: Rows, options: GTROptions, isTable: boolean, widget: any, pivotModel?: PivotModel) => string} rhPivotViewV2
|
3
|
+
* @property {(rows: Rows, options: GTROptions | null, isTable: boolean, widget: any, pivotModel?: PivotModel) => string} rhPivotViewV2
|
4
4
|
*/
|
5
5
|
/**
|
6
6
|
* @typedef {Object} PivotUtilities
|
@@ -13,8 +13,13 @@
|
|
13
13
|
/**
|
14
14
|
* @typedef {Object} PivotModel
|
15
15
|
*/
|
16
|
+
/**
|
17
|
+
* @typedef {Object} RendererOptions
|
18
|
+
* @property {any} hcInstance
|
19
|
+
*/
|
16
20
|
/**
|
17
21
|
* @typedef {Object} GTROptions
|
22
|
+
* @property {RendererOptions} rendererOptions
|
18
23
|
*/
|
19
24
|
/**
|
20
25
|
* @typedef {Record<string, Record<string, number | string> | number | string>[]} Rows - BE data response
|
@@ -42,13 +47,18 @@ export class GraphTableRenderer {
|
|
42
47
|
* @returns {PivotModel | undefined}
|
43
48
|
*/
|
44
49
|
getPivotModel(): PivotModel | undefined;
|
50
|
+
/**
|
51
|
+
* @description returns Chart instance of HighCharts library
|
52
|
+
* @returns {any | null}
|
53
|
+
*/
|
54
|
+
hcInstance(): any | null;
|
45
55
|
renderTable(widget?: null): string;
|
46
56
|
renderChart(widget?: null): string;
|
47
57
|
#private;
|
48
58
|
}
|
49
59
|
export default GraphTableRenderer;
|
50
60
|
export type HighChartsRenderer = {
|
51
|
-
rhPivotViewV2: (rows: Rows, options: GTROptions, isTable: boolean, widget: any, pivotModel?: PivotModel) => string;
|
61
|
+
rhPivotViewV2: (rows: Rows, options: GTROptions | null, isTable: boolean, widget: any, pivotModel?: PivotModel) => string;
|
52
62
|
};
|
53
63
|
export type PivotUtilities = {
|
54
64
|
getPivotDataModel: (rows: Rows, options: GTROptions) => PivotModel;
|
@@ -57,7 +67,12 @@ export type JQuery = {
|
|
57
67
|
pivotUtilities: PivotUtilities;
|
58
68
|
};
|
59
69
|
export type PivotModel = Object;
|
60
|
-
export type
|
70
|
+
export type RendererOptions = {
|
71
|
+
hcInstance: any;
|
72
|
+
};
|
73
|
+
export type GTROptions = {
|
74
|
+
rendererOptions: RendererOptions;
|
75
|
+
};
|
61
76
|
/**
|
62
77
|
* - BE data response
|
63
78
|
*/
|