@datarailsshared/dr_renderer 1.2.413 → 1.2.414

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
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.413",
3
+ "version": "1.2.414",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -2126,290 +2126,198 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2126
2126
  return {aggfunc: aggfunc, base: base};
2127
2127
  }
2128
2128
 
2129
- highchartsRenderer.ptRenderSolidGauge = function (pivotData, opts) {
2130
- var chartOptions = {};
2129
+ highchartsRenderer.ptRenderSolidGauge = (pivotData, opts) => {
2130
+ return highchartsRenderer.ptRenderGauge(pivotData, opts, true);
2131
+ };
2131
2132
 
2132
- var gaugeopts = opts.chartOptions ? opts.chartOptions : highchartsRenderer.getDefaultValueForChart('gauge-solid-chart');
2133
- chartOptions.chart = {
2134
- type: 'solidgauge'
2135
- };
2136
- if (disableAnimation) {
2137
- chartOptions.chart.animation = false;
2138
- }
2139
- highchartsRenderer.setTitleAndSubTitle(chartOptions, opts, gaugeopts);
2133
+ highchartsRenderer.ptRenderGauge = (pivotData, opts, isSolidGauge = false) => {
2134
+ const gaugeopts = opts.chartOptions
2135
+ || highchartsRenderer.getDefaultValueForChart(isSolidGauge ? 'gauge-solid-chart' : 'gauge-chart');
2140
2136
 
2141
- chartOptions.plotOptions = {
2142
- solidgauge: {
2143
- allowPointSelect: true,
2144
- cursor: 'pointer',
2145
- dataLabels: {
2146
- //formatter: function() {
2147
- // return '<b>' + this.point.name + ':</b> ' + Highcharts.numberFormat(this.point.percentage, 2) + '%';
2148
- //}
2149
- allowOverlap: gaugeopts && gaugeopts.label ? gaugeopts.label.overlap : false,
2150
- y: 5,
2151
- borderWidth: 0,
2152
- useHTML: true,
2153
- style: highchartsRenderer.getDataLabelsStyle(gaugeopts)
2154
- }
2137
+ const chartOptions = {
2138
+ chart: {
2139
+ type: isSolidGauge ? 'solidgauge' : 'gauge',
2140
+ animation: disableAnimation ? false : true,
2155
2141
  },
2156
- series: {
2157
- animation: !disableAnimation
2158
- }
2142
+ plotOptions: {
2143
+ solidgauge: {
2144
+ allowPointSelect: true,
2145
+ cursor: 'pointer',
2146
+ dataLabels: {
2147
+ allowOverlap: gaugeopts && gaugeopts.label
2148
+ ? gaugeopts.label.overlap
2149
+ : false,
2150
+ y: 5,
2151
+ borderWidth: 0,
2152
+ useHTML: true,
2153
+ style: highchartsRenderer.getDataLabelsStyle(gaugeopts),
2154
+ },
2155
+ },
2156
+ series: {
2157
+ animation: !disableAnimation,
2158
+ },
2159
+ },
2160
+ credits: {
2161
+ enabled: false,
2162
+ },
2163
+ xAxis: {
2164
+ categories: highchartsRenderer.getFormattedColKeys(pivotData, null),
2165
+ },
2166
+ yAxis: isSolidGauge
2167
+ ? {
2168
+ min: 0,
2169
+ max: gaugeopts.range.max,
2170
+ stops: [
2171
+ [gaugeopts.range.low / 100, '#55BF3B'], // green
2172
+ [gaugeopts.range.medium / 100, '#DDDF0D'], // yellow
2173
+ [gaugeopts.range.high / 100, '#DF5353'], // red
2174
+ ],
2175
+ lineWidth: 0,
2176
+ minorTickInterval: null,
2177
+ tickPixelInterval: 400,
2178
+ tickWidth: 0,
2179
+ labels: {
2180
+ y: 16,
2181
+ },
2182
+ }
2183
+ : {
2184
+ min: 0,
2185
+ max: gaugeopts.range.max,
2186
+ minorTickInterval: 'auto',
2187
+ minorTickWidth: 1,
2188
+ minorTickLength: 10,
2189
+ minorTickPosition: 'inside',
2190
+ minorTickColor: CHART_COLORS.TICK_COLOR,
2191
+ tickPixelInterval: 30,
2192
+ tickWidth: 2,
2193
+ tickPosition: 'inside',
2194
+ tickLength: 10,
2195
+ tickColor: CHART_COLORS.TICK_COLOR,
2196
+ labels: {
2197
+ step: 2,
2198
+ rotation: 'auto',
2199
+ },
2200
+ title: {
2201
+ text: '', //'km/h'
2202
+ },
2203
+ plotBands: [
2204
+ {
2205
+ from: 0,
2206
+ to: (gaugeopts.range.max * gaugeopts.range.low) / 100,
2207
+ color: '#55BF3B', // green
2208
+ },
2209
+ {
2210
+ from: (gaugeopts.range.max * gaugeopts.range.low) / 100,
2211
+ to: (gaugeopts.range.max * gaugeopts.range.medium) / 100,
2212
+ color: '#DDDF0D', // yellow
2213
+ },
2214
+ {
2215
+ from: (gaugeopts.range.max * gaugeopts.range.medium) / 100,
2216
+ to: gaugeopts.range.max,
2217
+ color: '#DF5353', // red
2218
+ },
2219
+ ],
2220
+ },
2221
+ pane: isSolidGauge
2222
+ ? {
2223
+ center: ['50%', '85%'],
2224
+ size: '140%',
2225
+ startAngle: -90,
2226
+ endAngle: 90,
2227
+ background: {
2228
+ backgroundColor: (highchartsRenderer.highcharts_theme && highchartsRenderer.highcharts_theme .background2) || '#EEE',
2229
+ innerRadius: '60%',
2230
+ outerRadius: '100%',
2231
+ shape: 'arc',
2232
+ },
2233
+ }
2234
+ : {
2235
+ startAngle: -150,
2236
+ endAngle: 150,
2237
+ background: [
2238
+ {
2239
+ backgroundColor: {
2240
+ linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
2241
+ stops: [
2242
+ [0, CHART_COLORS.BACKGROUND],
2243
+ [1, '#333'],
2244
+ ],
2245
+ },
2246
+ borderWidth: 0,
2247
+ outerRadius: '109%',
2248
+ },
2249
+ {
2250
+ backgroundColor: {
2251
+ linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
2252
+ stops: [
2253
+ [0, '#333'],
2254
+ [1, CHART_COLORS.BACKGROUND],
2255
+ ],
2256
+ },
2257
+ borderWidth: 1,
2258
+ outerRadius: '107%',
2259
+ },
2260
+ {
2261
+ // default background
2262
+ },
2263
+ {
2264
+ backgroundColor: '#DDD',
2265
+ borderWidth: 0,
2266
+ outerRadius: '105%',
2267
+ innerRadius: '103%',
2268
+ },
2269
+ ],
2270
+ },
2159
2271
  };
2272
+
2273
+ chartOptions.series = highchartsRenderer.ptCreateGaugeSeries(pivotData, opts, chartOptions, gaugeopts, isSolidGauge);
2160
2274
 
2275
+ highchartsRenderer.setTitleAndSubTitle(chartOptions, opts, gaugeopts);
2161
2276
  chartOptions.plotOptions.solidgauge = highchartsRenderer.getDataLabelsOptions(gaugeopts, chartOptions.plotOptions.solidgauge);
2162
- //chartOptions.tooltip = { pointFormat: '{series.name}: <b>{point.y}</b>', valueDecimals: 0 };
2163
-
2164
- chartOptions.credits = {
2165
- enabled: false
2166
- };
2167
-
2168
- chartOptions.pane = {
2169
- center: ['50%', '85%'],
2170
- size: "140%",
2171
- startAngle: -90,
2172
- endAngle: 90,
2173
- background: {
2174
- backgroundColor: (highchartsRenderer.highcharts_theme && highchartsRenderer.highcharts_theme.background2) || '#EEE',
2175
- innerRadius: '60%',
2176
- outerRadius: '100%',
2177
- shape: 'arc'
2178
- }
2179
- };
2180
-
2181
- chartOptions.xAxis = {
2182
- categories: highchartsRenderer.getFormattedColKeys(pivotData, null),
2183
- };
2184
- chartOptions.series = highchartsRenderer.ptCreateBasicLineSeries(pivotData, null, true, null, null, opts, chartOptions);
2185
-
2186
- var total = [];
2187
- lodash.forEach(chartOptions.series, function (obj) {
2188
- lodash.forEach(obj.data, function (arr2) {
2189
- total = total.concat(arr2)
2190
- })
2191
- })
2192
- total = lodash.filter(total, function (value) {
2193
- return !isNaN(value);
2194
- })
2195
- var aggfunc = (a, b) => a + b;
2196
-
2197
- var value = 0
2198
- var base = 0;
2199
- var __ret = highchartsRenderer.getSingleValueAgg(gaugeopts, aggfunc, base);
2200
- aggfunc = __ret.aggfunc;
2201
- base = __ret.base;
2202
- var aggregator = pivotData.getAggregator([], []);
2203
- if (total.length > 0) {
2204
- value = total.reduce(aggfunc, base);
2205
- } else {
2206
- value = aggregator.value();
2207
- }
2208
- var gauge_series = [value]
2209
- var valuef = lodash.isNumber(value) ? aggregator.format(value, true) : value;
2210
-
2211
- chartOptions.yAxis = {
2212
- min: 0,
2213
- max: gaugeopts.range.max,
2214
- //title: {
2215
- // text: '' //title
2216
- //},
2217
- stops: [
2218
- [gaugeopts.range.low / 100, '#55BF3B'], // green
2219
- [gaugeopts.range.medium / 100, '#DDDF0D'], // yellow
2220
- [gaugeopts.range.high / 100, '#DF5353'] // red
2221
- ],
2222
- lineWidth: 0,
2223
- minorTickInterval: null,
2224
- tickPixelInterval: 400,
2225
- tickWidth: 0,
2226
- labels: {
2227
- y: 16
2228
- }
2229
- },
2230
-
2231
-
2232
- chartOptions.series = [{
2233
- name: "", //tooltip title
2234
- colorByPoint: true,
2235
- data: gauge_series,
2236
- dataLabels: {
2237
- allowOverlap: gaugeopts && gaugeopts.label ? gaugeopts.label.overlap : false,
2238
- format: '<div style="text-align:center"><span style="font-size:25px;color:black">' + valuef + '</span><br/>' +
2239
- '<span style="font-size:12px;color:silver">' + '</span></div>',
2240
- style: highchartsRenderer.getDataLabelsStyle(gaugeopts)
2241
- }
2242
- //
2243
- //,tooltip: {
2244
- // valueSuffix: ''// km/h
2245
- //}
2246
- }];
2247
-
2248
- chartOptions.series[0] = highchartsRenderer.getDataLabelsOptions(gaugeopts, chartOptions.series[0]);
2249
-
2277
+
2250
2278
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2251
2279
  };
2252
-
2253
- highchartsRenderer.ptRenderGauge = function (pivotData, opts) {
2254
- var chartOptions = {};
2255
-
2256
- var gaugeopts = opts.chartOptions ? opts.chartOptions : highchartsRenderer.getDefaultValueForChart('gauge-chart');
2257
-
2258
- chartOptions.chart = {
2259
- type: 'gauge'
2260
- };
2261
- if (disableAnimation) {
2262
- chartOptions.chart.animation = false;
2263
- }
2264
- highchartsRenderer.setTitleAndSubTitle(chartOptions, opts, gaugeopts);
2265
- chartOptions.plotOptions = {
2266
- solidgauge: {
2267
- allowPointSelect: true,
2268
- cursor: 'pointer',
2269
- dataLabels: {
2270
- //formatter: function() {
2271
- // return '<b>' + this.point.name + ':</b> ' + Highcharts.numberFormat(this.point.percentage, 2) + '%';
2272
- //}
2273
- allowOverlap: gaugeopts && gaugeopts.label ? gaugeopts.label.overlap : false,
2274
- y: 5,
2275
- borderWidth: 0,
2276
- useHTML: true,
2277
- style: highchartsRenderer.getDataLabelsStyle(gaugeopts)
2278
- }
2279
- },
2280
- series: {
2281
- animation: !disableAnimation
2282
- }
2283
- };
2284
-
2285
- chartOptions.plotOptions.solidgauge = highchartsRenderer.getDataLabelsOptions(gaugeopts, chartOptions.plotOptions.solidgauge);
2286
-
2287
- chartOptions.credits = {
2288
- enabled: false
2289
- },
2290
-
2291
- chartOptions.pane = {
2292
- startAngle: -150,
2293
- endAngle: 150,
2294
- background: [{
2295
- backgroundColor: {
2296
- linearGradient: {x1: 0, y1: 0, x2: 0, y2: 1},
2297
- stops: [
2298
- [0, CHART_COLORS.BACKGROUND],
2299
- [1, '#333']
2300
- ]
2301
- },
2302
- borderWidth: 0,
2303
- outerRadius: '109%'
2304
- }, {
2305
- backgroundColor: {
2306
- linearGradient: {x1: 0, y1: 0, x2: 0, y2: 1},
2307
- stops: [
2308
- [0, '#333'],
2309
- [1, CHART_COLORS.BACKGROUND]
2310
- ]
2311
- },
2312
- borderWidth: 1,
2313
- outerRadius: '107%'
2314
- }, {
2315
- // default background
2316
- }, {
2317
- backgroundColor: '#DDD',
2318
- borderWidth: 0,
2319
- outerRadius: '105%',
2320
- innerRadius: '103%'
2321
- }]
2322
- };
2323
-
2324
-
2325
- chartOptions.xAxis = {
2326
- categories: highchartsRenderer.getFormattedColKeys(pivotData, null),
2327
- };
2328
- chartOptions.series = highchartsRenderer.ptCreateBasicLineSeries(pivotData, null, true, null, null, opts, chartOptions);
2329
-
2330
- var total = [];
2331
- lodash.forEach(chartOptions.series, function (obj) {
2332
- lodash.forEach(obj.data, function (arr2) {
2333
- total = total.concat(arr2)
2334
- })
2335
- })
2336
- total = lodash.filter(total, function (value) {
2337
- return !isNaN(value);
2338
- })
2339
- var aggfunc = (a, b) => a + b;
2340
- var value = 0
2341
- var base = 0;
2342
- var __ret = highchartsRenderer.getSingleValueAgg(gaugeopts, aggfunc, base);
2280
+
2281
+ highchartsRenderer.ptCreateGaugeSeries = (pivotData, opts, chartOptions, gaugeopts, isSolidGauge) => {
2282
+ const lineSeries = highchartsRenderer.ptCreateBasicLineSeries(pivotData, null, true, null, null, opts, chartOptions);
2283
+
2284
+ let total = [];
2285
+ lodash.forEach(lineSeries, (obj) => {
2286
+ lodash.forEach(obj.data, (arr2) => {
2287
+ total = total.concat(arr2);
2288
+ });
2289
+ });
2290
+ total = lodash.filter(total, value => !isNaN(value));
2291
+
2292
+ let aggfunc = (a, b) => a + b;
2293
+ let base = 0;
2294
+ let __ret = highchartsRenderer.getSingleValueAgg(gaugeopts, aggfunc, base);
2295
+
2343
2296
  aggfunc = __ret.aggfunc;
2344
2297
  base = __ret.base;
2298
+
2299
+ const aggregator = pivotData.getAggregator([], []);
2300
+ const value = total.length > 0 ? total.reduce(aggfunc, base) : aggregator.value();
2301
+ const valueFormatted = lodash.isNumber(value) ? aggregator.format(value, true) : value;
2345
2302
 
2346
- var aggregator = pivotData.getAggregator([], []);
2347
- if (total.length > 0) {
2348
- value = total.reduce(aggfunc, base);
2349
- } else {
2350
- value = aggregator.value();
2351
- }
2352
- var gauge_series = [value]
2353
-
2354
- var valuef = lodash.isNumber(value) ? aggregator.format(value, true) : value;
2355
-
2356
- chartOptions.yAxis = {
2357
- min: 0,
2358
- max: gaugeopts.range.max,
2359
- minorTickInterval: 'auto',
2360
- minorTickWidth: 1,
2361
- minorTickLength: 10,
2362
- minorTickPosition: 'inside',
2363
- minorTickColor: CHART_COLORS.TICK_COLOR,
2364
- tickPixelInterval: 30,
2365
- tickWidth: 2,
2366
- tickPosition: 'inside',
2367
- tickLength: 10,
2368
- tickColor: CHART_COLORS.TICK_COLOR,
2369
- labels: {
2370
- step: 2,
2371
- rotation: 'auto'
2372
- },
2373
- title: {
2374
- text: '' //'km/h'
2375
- },
2376
- plotBands: [{
2377
- from: 0,
2378
- to: gaugeopts.range.max * gaugeopts.range.low / 100,
2379
- color: '#55BF3B' // green
2380
- }, {
2381
- from: gaugeopts.range.max * gaugeopts.range.low / 100,
2382
- to: gaugeopts.range.max * gaugeopts.range.medium / 100,
2383
- color: '#DDDF0D' // yellow
2384
- }, {
2385
- from: gaugeopts.range.max * gaugeopts.range.medium / 100,
2386
- to: gaugeopts.range.max,
2387
- color: '#DF5353' // red
2388
- }]
2389
- },
2390
-
2391
-
2392
- chartOptions.series = [{
2393
- name: "", //tooltip title
2303
+ let gaugeSeries = [
2304
+ {
2305
+ name: '',
2394
2306
  colorByPoint: true,
2395
- data: gauge_series,
2307
+ data: [value],
2396
2308
  dataLabels: {
2309
+ format: `<div style="text-align:center"><span style="font-size:${ isSolidGauge ? 25 : 15 }px;color:black">`
2310
+ + valueFormatted + '</span><br/><span style="font-size:12px;color:silver"></span></div>',
2311
+ enabled: gaugeopts && gaugeopts.label && !isSolidGauge ? gaugeopts.label.show : true,
2397
2312
  allowOverlap: gaugeopts && gaugeopts.label ? gaugeopts.label.overlap : false,
2398
- enabled: gaugeopts && gaugeopts.label ? gaugeopts.label.show : true,
2399
- format: '<div style="text-align:center"><span style="font-size:15px;color:black">' + valuef + '</span><br/>' +
2400
- '<span style="font-size:12px;color:silver">' + '</span></div>',
2401
- style: highchartsRenderer.getDataLabelsStyle(gaugeopts)
2402
- }
2403
- //
2404
- //,tooltip: {
2405
- // valueSuffix: ''// km/h
2406
- //}
2407
- }];
2408
-
2409
- chartOptions.series[0] = highchartsRenderer.getDataLabelsOptions(gaugeopts, chartOptions.series[0]);
2410
-
2411
- return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2412
- };
2313
+ style: highchartsRenderer.getDataLabelsStyle(gaugeopts),
2314
+ },
2315
+ },
2316
+ ];
2317
+ gaugeSeries[0] = highchartsRenderer.getDataLabelsOptions(gaugeopts, gaugeSeries[0]);
2318
+
2319
+ return gaugeSeries;
2320
+ };
2413
2321
 
2414
2322
  highchartsRenderer.ptRenderKpi = function (pivotData, opts) {
2415
2323
  var chartOptions = {};
@@ -7964,24 +7872,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7964
7872
  type: 'gauge',
7965
7873
  name: 'Gauge',
7966
7874
  class: 'google-visualization-charteditor-mini-gauge',
7967
- subtypes: [{
7968
- type: 'gauge-solid-chart',
7969
- name: highchartsRenderer.chartsTypesInfo['gauge-solid-chart'].name,
7970
- class: 'google-visualization-charteditor-thumbs-gauge-solid',
7971
- render: highchartsRenderer.ptRenderSolidGauge,
7972
- suboptions: [
7973
- highchartsRenderer.suboptions["value"],
7974
- highchartsRenderer.suboptions["range"],
7975
- highchartsRenderer.suboptions["tooltips"],
7976
- highchartsRenderer.suboptions["subtitle"],
7977
- highchartsRenderer.suboptions["widget_library"],
7978
- highchartsRenderer.suboptions["table_options_transpose"],
7979
- highchartsRenderer.suboptions["table_design_options"],
7980
- highchartsRenderer.suboptions["chart_grid"],
7981
- highchartsRenderer.suboptions["negative_number_format"],
7982
- highchartsRenderer.suboptions["legends"],
7983
- ]
7984
- },
7875
+ subtypes: [
7876
+ {
7877
+ type: 'gauge-solid-chart',
7878
+ name: highchartsRenderer.chartsTypesInfo['gauge-solid-chart'].name,
7879
+ class: 'google-visualization-charteditor-thumbs-gauge-solid',
7880
+ render: highchartsRenderer.ptRenderSolidGauge,
7881
+ suboptions: [
7882
+ highchartsRenderer.suboptions["value"],
7883
+ highchartsRenderer.suboptions["range"],
7884
+ highchartsRenderer.suboptions["tooltips"],
7885
+ highchartsRenderer.suboptions["subtitle"],
7886
+ highchartsRenderer.suboptions["widget_library"],
7887
+ highchartsRenderer.suboptions["table_options_transpose"],
7888
+ highchartsRenderer.suboptions["table_design_options"],
7889
+ highchartsRenderer.suboptions["chart_grid"],
7890
+ highchartsRenderer.suboptions["negative_number_format"],
7891
+ highchartsRenderer.suboptions["legends"],
7892
+ ]
7893
+ },
7985
7894
  {
7986
7895
  type: 'gauge-chart',
7987
7896
  name: highchartsRenderer.chartsTypesInfo['gauge-chart'].name,
@@ -19,7 +19,6 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
19
19
  }
20
20
 
21
21
  publishedItemsRenderer.resizeTable = function (options, iframeWindow) {
22
- options.alreadySetTimeout = null;
23
22
  const publish_item_image = iframeWindow.document.getElementById('publish_item_image');
24
23
  const table = iframeWindow.document.getElementsByTagName("table")[0];
25
24
  const body = iframeWindow.document.getElementsByTagName("body")[0];
@@ -32,37 +31,13 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
32
31
  }
33
32
 
34
33
  publishedItemsRenderer.zoomTable = function(iframeWindow, table, body) {
35
- let body_zoom = body.style.zoom;
36
- body_zoom = parseFloat(body_zoom) || 1;
37
-
38
- let zoom = table.style.zoom;
39
- zoom = parseFloat(zoom) || 1;
40
-
41
- const positionInfo = table.getBoundingClientRect();
42
- let width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
34
+ const bodyZoom = parseFloat(body.style.zoom) || 1;
43
35
 
44
- if (width < iframeWindow.innerWidth) {
45
- zoom += 0.05;
46
-
47
- width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
48
- if (width < iframeWindow.innerWidth) {
49
- table.style.zoom = zoom;
50
- setTimeout(function () {
51
- publishedItemsRenderer.zoomTable(iframeWindow, table, body);
52
- }, 10);
53
- }
54
- } else if (width >= iframeWindow.innerWidth) {
55
- zoom -= 0.05;
56
-
57
- width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
58
- table.style.zoom = zoom;
59
- if (width >= iframeWindow.innerWidth) {
60
- setTimeout(function () {
61
- publishedItemsRenderer.zoomTable(iframeWindow, table, body);
62
- }, 10);
63
- }
64
- }
65
- }
36
+ const tableWidth = (table.getBoundingClientRect().width + (iframeWindow.innerWidth - body.offsetWidth)) * bodyZoom;
37
+ const requiredZoom = iframeWindow.innerWidth / tableWidth;
38
+
39
+ table.style.zoom = requiredZoom;
40
+ };
66
41
 
67
42
  publishedItemsRenderer.resizePublishedImage = function(publish_item_image, iframeWindow, body) {
68
43
  if (!publish_item_image) return;
@@ -107,11 +82,7 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
107
82
  if (!options.responsive) {
108
83
  publishedItemsRenderer.resetTableZoom(document);
109
84
  } else {
110
- if (!options.alreadySetTimeout) {
111
- options.alreadySetTimeout = setTimeout(function () {
112
- publishedItemsRenderer.resizeTable(options, iframeWindow);
113
- }, 100);
114
- }
85
+ publishedItemsRenderer.resizeTable(options, iframeWindow);
115
86
  }
116
87
  }
117
88
 
@@ -323,20 +294,19 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
323
294
  }
324
295
 
325
296
  publishedItemsRenderer.addEventListeners = function (document, iframeWindow, scope, options) {
326
- document.addEventListener("DOMContentLoaded", function () {
327
- if (!options.alreadySetTimeout) {
328
- options.alreadySetTimeout = setTimeout(function () {
329
- publishedItemsRenderer.resizeTable(options, iframeWindow);
330
- }, 50);
331
- }
332
- });
333
- iframeWindow.addEventListener("resize", function () {
334
- if (!options.alreadySetTimeout) {
335
- options.alreadySetTimeout = setTimeout(function () {
336
- publishedItemsRenderer.resizeTable(iframeWindow.__options__, iframeWindow);
337
- }, 100);
297
+ let resizeTimeout;
298
+ const handleDimensionChange = () => {
299
+ if (resizeTimeout) {
300
+ cancelAnimationFrame(resizeTimeout);
338
301
  }
339
- });
302
+
303
+ resizeTimeout = requestAnimationFrame(() => {
304
+ publishedItemsRenderer.resizeTable(iframeWindow.__options__, iframeWindow);
305
+ });
306
+ }
307
+
308
+ document.addEventListener("DOMContentLoaded", handleDimensionChange);
309
+ iframeWindow.addEventListener("resize", handleDimensionChange);
340
310
 
341
311
  // Add click event to cell with formula
342
312
  let all_a_hrefs = document.querySelectorAll('td a[location_id]');
@@ -7997,4 +7997,399 @@ describe('highcharts_renderer', () => {
7997
7997
  ]);
7998
7998
  });
7999
7999
  });
8000
+
8001
+ describe('Function ptCreateGaugeSeries', () => {
8002
+
8003
+ const pivotDataMock = {
8004
+ getAggregator: () => ({
8005
+ value: () => 1000,
8006
+ format: (val) => `formatted(${ val })`,
8007
+ })
8008
+ }
8009
+
8010
+ beforeEach(() => {
8011
+ spyOn(highchartsRenderer, 'getSingleValueAgg').and.callFake(
8012
+ (_gaugeOpts, aggfunc, base) => ({ aggfunc, base })
8013
+ );
8014
+ spyOn(highchartsRenderer, 'getDataLabelsStyle').and.returnValue('test_style');
8015
+ spyOn(highchartsRenderer, 'getDataLabelsOptions').and.callFake(
8016
+ (_gaugeOpts, seriesElement) => ({...seriesElement, additionalOptions: 'test_additional_opts'})
8017
+ );
8018
+ });
8019
+
8020
+ describe('with two calc values', () => {
8021
+
8022
+ const mockGaugeOpts = {
8023
+ label: {
8024
+ overlap: true,
8025
+ show: false,
8026
+ }
8027
+ };
8028
+
8029
+ beforeEach(() => {
8030
+ spyOn(highchartsRenderer, 'ptCreateBasicLineSeries').and.returnValue([
8031
+ {
8032
+ data: [39],
8033
+ initialName: "Test Calc",
8034
+ name: "Test Calc"
8035
+ },
8036
+ {
8037
+ data: [21],
8038
+ initialName: "Test Calc 2",
8039
+ name: "Test Calc 2"
8040
+ }
8041
+ ]);
8042
+ });
8043
+
8044
+ it('should create gauge series, two calc values, isSolidGauge = false, labels disabled', () => {
8045
+ expect(highchartsRenderer.ptCreateGaugeSeries(pivotDataMock, {}, {}, mockGaugeOpts, false)).toEqual([
8046
+ {
8047
+ additionalOptions: 'test_additional_opts',
8048
+ colorByPoint: true,
8049
+ data: [60],
8050
+ dataLabels: {
8051
+ allowOverlap: true,
8052
+ enabled: false,
8053
+ format: '<div style="text-align:center"><span style="font-size:15px;color:black">formatted(60)</span><br/><span style="font-size:12px;color:silver"></span></div>',
8054
+ style: 'test_style',
8055
+ },
8056
+ name: '',
8057
+ },
8058
+ ]);
8059
+ });
8060
+
8061
+ it('should create gauge series, two calc values, isSolidGauge = false, labels enabled', () => {
8062
+ const gaugeOpts = lodash.cloneDeep(mockGaugeOpts);
8063
+ gaugeOpts.label.show = true;
8064
+ expect(highchartsRenderer.ptCreateGaugeSeries(pivotDataMock, {}, {}, gaugeOpts, false)).toEqual([
8065
+ {
8066
+ additionalOptions: 'test_additional_opts',
8067
+ colorByPoint: true,
8068
+ data: [60],
8069
+ dataLabels: {
8070
+ allowOverlap: true,
8071
+ enabled: true,
8072
+ format: '<div style="text-align:center"><span style="font-size:15px;color:black">formatted(60)</span><br/><span style="font-size:12px;color:silver"></span></div>',
8073
+ style: 'test_style',
8074
+ },
8075
+ name: '',
8076
+ },
8077
+ ]);
8078
+ });
8079
+
8080
+ it('should create gauge series, two calc values, isSolidGauge = true', () => {
8081
+ expect(highchartsRenderer.ptCreateGaugeSeries(pivotDataMock, {}, {}, mockGaugeOpts, true)).toEqual([
8082
+ {
8083
+ additionalOptions: 'test_additional_opts',
8084
+ colorByPoint: true,
8085
+ data: [60],
8086
+ dataLabels: {
8087
+ allowOverlap: true,
8088
+ enabled: true,
8089
+ format: '<div style="text-align:center"><span style="font-size:25px;color:black">formatted(60)</span><br/><span style="font-size:12px;color:silver"></span></div>',
8090
+ style: 'test_style',
8091
+ },
8092
+ name: '',
8093
+ },
8094
+ ]);
8095
+ });
8096
+ });
8097
+
8098
+ it('should create gauge series, one calc value', () => {
8099
+ const mockGaugeOpts = {
8100
+ label: {
8101
+ overlap: true,
8102
+ show: false,
8103
+ }
8104
+ };
8105
+
8106
+ spyOn(highchartsRenderer, 'ptCreateBasicLineSeries').and.returnValue([
8107
+ {
8108
+ data: [39],
8109
+ initialName: "Test Calc",
8110
+ name: "Test Calc"
8111
+ },
8112
+ ]);
8113
+
8114
+ expect(highchartsRenderer.ptCreateGaugeSeries(pivotDataMock, {}, {}, mockGaugeOpts, false)).toEqual([
8115
+ {
8116
+ additionalOptions: 'test_additional_opts',
8117
+ colorByPoint: true,
8118
+ data: [39],
8119
+ dataLabels: {
8120
+ allowOverlap: true,
8121
+ enabled: false,
8122
+ format: '<div style="text-align:center"><span style="font-size:15px;color:black">formatted(39)</span><br/><span style="font-size:12px;color:silver"></span></div>',
8123
+ style: 'test_style',
8124
+ },
8125
+ name: '',
8126
+ },
8127
+ ]);
8128
+ });
8129
+
8130
+ it('should create gauge series, no calculated, one value field', () => {
8131
+ const mockGaugeOpts = {
8132
+ label: {
8133
+ overlap: true,
8134
+ show: false,
8135
+ }
8136
+ };
8137
+
8138
+ spyOn(highchartsRenderer, 'ptCreateBasicLineSeries').and.returnValue([
8139
+ {
8140
+ data: [32605]
8141
+ },
8142
+ ]);
8143
+
8144
+ expect(highchartsRenderer.ptCreateGaugeSeries(pivotDataMock, {}, {}, mockGaugeOpts, false)).toEqual([
8145
+ {
8146
+ additionalOptions: 'test_additional_opts',
8147
+ colorByPoint: true,
8148
+ data: [32605],
8149
+ dataLabels: {
8150
+ allowOverlap: true,
8151
+ enabled: false,
8152
+ format: '<div style="text-align:center"><span style="font-size:15px;color:black">formatted(32605)</span><br/><span style="font-size:12px;color:silver"></span></div>',
8153
+ style: 'test_style',
8154
+ },
8155
+ name: '',
8156
+ },
8157
+ ]);
8158
+ });
8159
+ });
8160
+
8161
+ describe('Function ptRenderGauge', () => {
8162
+
8163
+ const pivotDataMock = {
8164
+ getColKeys: () => [[1], [2], [3]],
8165
+ };
8166
+
8167
+ const commonExpectedOptions = {
8168
+ chart: { animation: true, type: 'gauge' },
8169
+ credits: { enabled: false },
8170
+ pane: {
8171
+ background: [
8172
+ {
8173
+ backgroundColor: {
8174
+ linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
8175
+ stops: [
8176
+ [0, '#fff'],
8177
+ [1, '#333'],
8178
+ ],
8179
+ },
8180
+ borderWidth: 0,
8181
+ outerRadius: '109%',
8182
+ },
8183
+ {
8184
+ backgroundColor: {
8185
+ linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
8186
+ stops: [
8187
+ [0, '#333'],
8188
+ [1, '#fff'],
8189
+ ],
8190
+ },
8191
+ borderWidth: 1,
8192
+ outerRadius: '107%',
8193
+ },
8194
+ {},
8195
+ { backgroundColor: '#DDD', borderWidth: 0, innerRadius: '103%', outerRadius: '105%' },
8196
+ ],
8197
+ endAngle: 150,
8198
+ startAngle: -150,
8199
+ },
8200
+ plotOptions: {
8201
+ series: { animation: true },
8202
+ solidgauge: {
8203
+ additionalOptions: 'test_additional_opts',
8204
+ allowPointSelect: true,
8205
+ cursor: 'pointer',
8206
+ dataLabels: { allowOverlap: true, borderWidth: 0, style: 'test_style', useHTML: true, y: 5 },
8207
+ },
8208
+ },
8209
+ series: 'test_gauge_series',
8210
+ subtitle: 'test_subtitle',
8211
+ title: 'test_title',
8212
+ xAxis: { categories: ['formatted(1)', 'formatted(2)', 'formatted(3)'] },
8213
+ };
8214
+
8215
+ const gaugeDefaultChartOptions = {
8216
+ label: {
8217
+ overlap: true,
8218
+ show: false,
8219
+ },
8220
+ range: {
8221
+ min: 0,
8222
+ max: 12345,
8223
+ low: 100,
8224
+ medium: 200,
8225
+ high: 300,
8226
+ },
8227
+ };
8228
+
8229
+ const chartOptionsInOpts = {
8230
+ label: {
8231
+ overlap: false,
8232
+ show: true,
8233
+ },
8234
+ range: {
8235
+ min: 1,
8236
+ max: 234567,
8237
+ low: 500,
8238
+ medium: 800,
8239
+ high: 1000,
8240
+ },
8241
+ };
8242
+
8243
+ beforeEach(() => {
8244
+ spyOn(highchartsRenderer, 'getDefaultValueForChart').and.returnValue(gaugeDefaultChartOptions);
8245
+ spyOn(highchartsRenderer, 'getDataLabelsStyle').and.returnValue('test_style');
8246
+ spyOn(highchartsRenderer, 'getDataLabelsOptions').and.callFake(
8247
+ (_gaugeOpts, seriesElement) => ({...seriesElement, additionalOptions: 'test_additional_opts'})
8248
+ );
8249
+ spyOn(highchartsRenderer, 'getFormattedColKeys').and.callFake(
8250
+ (pivotData, _keys) => pivotData.getColKeys().map(key => `formatted(${ key })`)
8251
+ );
8252
+ spyOn(highchartsRenderer, 'ptCreateGaugeSeries').and.returnValue('test_gauge_series');
8253
+ spyOn(highchartsRenderer, 'setTitleAndSubTitle').and.callFake((chartOptions, _opts, _gaugeopts) => {
8254
+ chartOptions.title = 'test_title';
8255
+ chartOptions.subtitle = 'test_subtitle';
8256
+ });
8257
+ spyOn(highchartsRenderer, 'ptCreateElementAndDraw').and.returnValue();
8258
+ });
8259
+
8260
+ it('should call ptCreateElementAndDraw with proper options: no chartOptions passed in opts', () => {
8261
+ const optsMock = {
8262
+ testOptsField: 'test_opts_field_value',
8263
+ };
8264
+
8265
+ highchartsRenderer.ptRenderGauge(pivotDataMock, lodash.cloneDeep(optsMock));
8266
+
8267
+ const expectedChartOptions = {
8268
+ ...commonExpectedOptions,
8269
+ yAxis: {
8270
+ labels: { rotation: 'auto', step: 2 },
8271
+ max: 12345,
8272
+ min: 0,
8273
+ minorTickColor: '#666',
8274
+ minorTickInterval: 'auto',
8275
+ minorTickLength: 10,
8276
+ minorTickPosition: 'inside',
8277
+ minorTickWidth: 1,
8278
+ plotBands: [
8279
+ { color: '#55BF3B', from: 0, to: 12345 },
8280
+ { color: '#DDDF0D', from: 12345, to: 24690 },
8281
+ { color: '#DF5353', from: 24690, to: 12345 },
8282
+ ],
8283
+ tickColor: '#666',
8284
+ tickLength: 10,
8285
+ tickPixelInterval: 30,
8286
+ tickPosition: 'inside',
8287
+ tickWidth: 2,
8288
+ title: { text: '' },
8289
+ },
8290
+ };
8291
+
8292
+ expect(highchartsRenderer.ptCreateGaugeSeries)
8293
+ .toHaveBeenCalledWith(pivotDataMock, optsMock, expectedChartOptions, gaugeDefaultChartOptions, false);
8294
+ expect(highchartsRenderer.ptCreateElementAndDraw).toHaveBeenCalledWith(expectedChartOptions, optsMock);
8295
+ });
8296
+
8297
+ it('should call ptCreateElementAndDraw with proper options: chartOptions passed in opts', () => {
8298
+ const optsMock = {
8299
+ testOptsField: 'test_opts_field_value',
8300
+ chartOptions: chartOptionsInOpts,
8301
+ };
8302
+
8303
+ highchartsRenderer.ptRenderGauge(pivotDataMock, lodash.cloneDeep(optsMock));
8304
+
8305
+ const expectedChartOptions = {
8306
+ ...commonExpectedOptions,
8307
+ yAxis: {
8308
+ labels: { rotation: 'auto', step: 2 },
8309
+ max: 234567,
8310
+ min: 0,
8311
+ minorTickColor: '#666',
8312
+ minorTickInterval: 'auto',
8313
+ minorTickLength: 10,
8314
+ minorTickPosition: 'inside',
8315
+ minorTickWidth: 1,
8316
+ plotBands: [
8317
+ { color: '#55BF3B', from: 0, to: 1172835 },
8318
+ { color: '#DDDF0D', from: 1172835, to: 1876536 },
8319
+ { color: '#DF5353', from: 1876536, to: 234567 },
8320
+ ],
8321
+ tickColor: '#666',
8322
+ tickLength: 10,
8323
+ tickPixelInterval: 30,
8324
+ tickPosition: 'inside',
8325
+ tickWidth: 2,
8326
+ title: { text: '' },
8327
+ },
8328
+ };
8329
+ lodash.set(expectedChartOptions, 'plotOptions.solidgauge.dataLabels.allowOverlap', false);
8330
+
8331
+ expect(highchartsRenderer.ptCreateGaugeSeries)
8332
+ .toHaveBeenCalledWith(pivotDataMock, optsMock, expectedChartOptions, optsMock.chartOptions, false);
8333
+ expect(highchartsRenderer.ptCreateElementAndDraw).toHaveBeenCalledWith(expectedChartOptions, optsMock);
8334
+ });
8335
+
8336
+ it('should call ptCreateElementAndDraw with proper options: for solid gauge', () => {
8337
+ const optsMock = {
8338
+ testOptsField: 'test_opts_field_value',
8339
+ chartOptions: chartOptionsInOpts,
8340
+ };
8341
+
8342
+ highchartsRenderer.ptRenderGauge(pivotDataMock, lodash.cloneDeep(optsMock), true);
8343
+
8344
+ const expectedChartOptions = {
8345
+ chart: { animation: true, type: 'solidgauge' },
8346
+ credits: { enabled: false },
8347
+ pane: {
8348
+ background: { backgroundColor: '#fff', innerRadius: '60%', outerRadius: '100%', shape: 'arc' },
8349
+ center: ['50%', '85%'],
8350
+ endAngle: 90,
8351
+ size: '140%',
8352
+ startAngle: -90,
8353
+ },
8354
+ plotOptions: {
8355
+ series: { animation: true },
8356
+ solidgauge: {
8357
+ additionalOptions: 'test_additional_opts',
8358
+ allowPointSelect: true,
8359
+ cursor: 'pointer',
8360
+ dataLabels: { allowOverlap: false, borderWidth: 0, style: 'test_style', useHTML: true, y: 5 },
8361
+ },
8362
+ },
8363
+ series: 'test_gauge_series',
8364
+ subtitle: 'test_subtitle',
8365
+ title: 'test_title',
8366
+ xAxis: { categories: ['formatted(1)', 'formatted(2)', 'formatted(3)'] },
8367
+ yAxis: {
8368
+ labels: { y: 16 },
8369
+ lineWidth: 0,
8370
+ max: 234567,
8371
+ min: 0,
8372
+ minorTickInterval: null,
8373
+ stops: [
8374
+ [5, '#55BF3B'],
8375
+ [8, '#DDDF0D'],
8376
+ [10, '#DF5353'],
8377
+ ],
8378
+ tickPixelInterval: 400,
8379
+ tickWidth: 0,
8380
+ },
8381
+ };
8382
+ lodash.set(expectedChartOptions, 'plotOptions.solidgauge.dataLabels.allowOverlap', false);
8383
+
8384
+ expect(highchartsRenderer.ptCreateGaugeSeries)
8385
+ .toHaveBeenCalledWith(pivotDataMock, optsMock, expectedChartOptions, optsMock.chartOptions, true);
8386
+ expect(highchartsRenderer.ptCreateElementAndDraw).toHaveBeenCalledWith(expectedChartOptions, optsMock);
8387
+ });
8388
+ });
8389
+
8390
+ it('ptRenderSolidGauge should call ptRenderGauge with isSolidGauge = true', () => {
8391
+ spyOn(highchartsRenderer, 'ptRenderGauge').and.returnValue();
8392
+ highchartsRenderer.ptRenderSolidGauge('mock_pivot_data', 'mock_opts');
8393
+ expect(highchartsRenderer.ptRenderGauge).toHaveBeenCalledWith('mock_pivot_data', 'mock_opts', true);
8394
+ });
8000
8395
  });