@datarailsshared/dr_renderer 1.2.463 → 1.3.1-27.merge
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/.circleci/config.yml +13 -7
- package/.github/workflows/build-deploy.yml +29 -0
- package/CODEOWNERS +1 -0
- package/package.json +1 -1
- package/src/charts/dr_donut_chart.js +163 -0
- package/src/charts/dr_gauge_categories_summary_chart.js +323 -0
- package/src/charts/dr_gauge_chart.js +179 -130
- package/src/dr-renderer-helpers.js +20 -0
- package/src/dr_chart_tooltip.js +16 -9
- package/src/dr_pivottable.js +27 -3
- package/src/highcharts_renderer.js +348 -301
- package/src/pivot.css +32 -18
- package/src/published_items_renderer.js +6 -6
- package/src/smart_queries_helper.js +96 -0
- package/tests/dr-renderer-helpers.test.js +48 -0
- package/tests/dr_chart_tooltip.test.js +50 -0
- package/tests/dr_gauge_chart.test.js +64 -40
- package/tests/highcharts_renderer.test.js +8 -397
@@ -37,13 +37,13 @@ const GAUGE_OPTIONS_DEFAULT = {
|
|
37
37
|
color: "#BF1D30",
|
38
38
|
},
|
39
39
|
{
|
40
|
-
from:
|
40
|
+
from: 50,
|
41
41
|
to: 90,
|
42
42
|
title: "Medium",
|
43
43
|
color: "#FFA310",
|
44
44
|
},
|
45
45
|
{
|
46
|
-
from:
|
46
|
+
from: 90,
|
47
47
|
to: 100,
|
48
48
|
title: "High",
|
49
49
|
color: "#037C5A",
|
@@ -80,38 +80,11 @@ function DrGaugeChart(pivotData, opts) {
|
|
80
80
|
return DrGaugeChart.highchartsRenderer.getSingleValueAgg(opts, aggfunc, base);
|
81
81
|
};
|
82
82
|
|
83
|
-
this.isLeftQuarter = function (value, max = this.max) {
|
84
|
-
return value < max / 2;
|
83
|
+
this.isLeftQuarter = function (value, max = this.max, min = this.min) {
|
84
|
+
return (value - min) < (max - min) / 2;
|
85
85
|
};
|
86
86
|
|
87
|
-
this.
|
88
|
-
const {
|
89
|
-
segments,
|
90
|
-
isAbsoluteValue,
|
91
|
-
goal: { value: goalValue },
|
92
|
-
gauge: { thickness },
|
93
|
-
} = options;
|
94
|
-
|
95
|
-
const bands = segments.map((item, index) => {
|
96
|
-
const itemFrom = !!index ? item.from - 1 : item.from;
|
97
|
-
return {
|
98
|
-
from: isAbsoluteValue ? itemFrom : (itemFrom * goalValue) / 100,
|
99
|
-
to: isAbsoluteValue ? item.to : (item.to * goalValue) / 100,
|
100
|
-
color: item.color,
|
101
|
-
thickness: thickness,
|
102
|
-
title: item.title,
|
103
|
-
};
|
104
|
-
});
|
105
|
-
|
106
|
-
// clamp last segment
|
107
|
-
bands[bands.length - 1].to = Math.max(bands[bands.length - 1].to, goalValue);
|
108
|
-
|
109
|
-
return bands;
|
110
|
-
};
|
111
|
-
|
112
|
-
this.createTicks = function (plotBands, options) {
|
113
|
-
return _.uniq([plotBands[0].from || 0, ...plotBands.map((b) => b.to), options.goal.value]).sort((a, b) => a - b);
|
114
|
-
};
|
87
|
+
this.createTicks = DrGaugeChart.createTicks;
|
115
88
|
|
116
89
|
this.mergeOptions = function (options) {
|
117
90
|
return helpers.mergeDeep(
|
@@ -142,21 +115,17 @@ function DrGaugeChart(pivotData, opts) {
|
|
142
115
|
};
|
143
116
|
|
144
117
|
this.formatValueLabel = function (value, options) {
|
145
|
-
return `<span style="display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: ${
|
146
|
-
|
147
|
-
|
148
|
-
<span style="font-weight: 600; font-size: 1.5em; line-height: 1; color: ${options.label.font_color}">
|
118
|
+
return `<span style="display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: ${options.label.font_size
|
119
|
+
}px;">
|
120
|
+
<span style="font-weight: 600; font-size: 1.3em; line-height: 1; color: ${options.label.font_color}">
|
149
121
|
${this.formatValue(value)}
|
150
|
-
${
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
: ""
|
156
|
-
}
|
122
|
+
${options.label.show_percentage_in_value
|
123
|
+
? `<span style="font-size: 0.5833em; font-weight: 600; color: ${options.gauge.colors.meta
|
124
|
+
};">(${this.toPercent(value)})</span>`
|
125
|
+
: ""
|
126
|
+
}
|
157
127
|
</span>
|
158
|
-
<span style="font-weight: 500; font-size: 0.875em; line-height: 1; color: ${
|
159
|
-
options.gauge.colors.meta
|
128
|
+
<span style="font-weight: 500; font-size: 0.875em; line-height: 1; color: ${options.gauge.colors.meta
|
160
129
|
};">Current status</span>
|
161
130
|
</span>`;
|
162
131
|
};
|
@@ -176,8 +145,8 @@ function DrGaugeChart(pivotData, opts) {
|
|
176
145
|
: "";
|
177
146
|
const percentage = options.label.show_percentage_in_segments
|
178
147
|
? `<span style="font-size: 0.75em; color: ${options.gauge.colors.meta}; font-weight: 400;">(${this.toPercent(
|
179
|
-
|
180
|
-
|
148
|
+
value
|
149
|
+
)})</span>`
|
181
150
|
: "";
|
182
151
|
|
183
152
|
return `<span style="
|
@@ -194,67 +163,6 @@ function DrGaugeChart(pivotData, opts) {
|
|
194
163
|
</span>`;
|
195
164
|
};
|
196
165
|
|
197
|
-
this.getValue = function (pivotData, opts) {
|
198
|
-
const lineSeries = this.ptCreateBasicLineSeries(pivotData, null, true, null, null, opts, {});
|
199
|
-
|
200
|
-
let total = _.flatten(lineSeries
|
201
|
-
.map((s) => s.data.map((v) => v))
|
202
|
-
.filter((v) => !_.isNaN(v))
|
203
|
-
);
|
204
|
-
|
205
|
-
let aggfunc = (a, b) => a + b;
|
206
|
-
let base = 0;
|
207
|
-
let singleValueAgg = this.getSingleValueAgg(
|
208
|
-
{
|
209
|
-
value: {
|
210
|
-
value: "Sum",
|
211
|
-
},
|
212
|
-
},
|
213
|
-
aggfunc,
|
214
|
-
base
|
215
|
-
);
|
216
|
-
|
217
|
-
aggfunc = singleValueAgg.aggfunc;
|
218
|
-
base = singleValueAgg.base;
|
219
|
-
|
220
|
-
const aggregator = pivotData.getAggregator([], []);
|
221
|
-
const value = total.length > 0 ? total.reduce(aggfunc, base) : aggregator.value();
|
222
|
-
|
223
|
-
return value;
|
224
|
-
};
|
225
|
-
|
226
|
-
this.getBorderPosition = function (chart, options, position) {
|
227
|
-
const { center, size } = chart.pane[0].options;
|
228
|
-
const {
|
229
|
-
gauge: { tickLength, tickWidth },
|
230
|
-
} = options;
|
231
|
-
|
232
|
-
return {
|
233
|
-
x: position === "start" ? center[0] - size / 2 + tickLength / 2 : center[0] + size / 2 - tickLength / 2,
|
234
|
-
y: center[1] + tickWidth / 2,
|
235
|
-
};
|
236
|
-
};
|
237
|
-
|
238
|
-
this.createBorder = function (chart, options, position) {
|
239
|
-
return chart.renderer
|
240
|
-
.arc(
|
241
|
-
Object.assign(this.getBorderPosition(chart, options, position), {
|
242
|
-
r: options.gauge.thickness / 2,
|
243
|
-
innerR: 0,
|
244
|
-
start: 0,
|
245
|
-
end: Math.PI,
|
246
|
-
})
|
247
|
-
)
|
248
|
-
.attr({
|
249
|
-
fill:
|
250
|
-
position === "start"
|
251
|
-
? chart.yAxis[0].options.plotBands[0].color
|
252
|
-
: chart.yAxis[0].options.plotBands.slice(-1)[0].color,
|
253
|
-
})
|
254
|
-
.add()
|
255
|
-
.toFront();
|
256
|
-
};
|
257
|
-
|
258
166
|
this.getGoalIconPosition = function (chart, options) {
|
259
167
|
const { center, size } = chart.pane[0].options;
|
260
168
|
const radius = size / 2;
|
@@ -277,20 +185,12 @@ function DrGaugeChart(pivotData, opts) {
|
|
277
185
|
.toFront();
|
278
186
|
};
|
279
187
|
|
280
|
-
this.getValueLabelPosition = function (chart, options) {
|
281
|
-
const { center } = chart.pane[0].options;
|
282
|
-
return {
|
283
|
-
x: center[0],
|
284
|
-
y: center[1] + options.gauge.valueOffset[0],
|
285
|
-
};
|
286
|
-
};
|
287
|
-
|
288
188
|
this.createValueLabel = function (chart, options) {
|
289
189
|
const label = chart.renderer.text(this.formatValueLabel(this.value, options), 0, 0, true).add().toFront();
|
290
190
|
|
291
191
|
helpers.removeSVGTextCorrection(label, "yCorr");
|
292
192
|
|
293
|
-
label.attr(
|
193
|
+
label.attr(DrGaugeChart.getValueLabelPosition(chart, options)).css({
|
294
194
|
transform: "translateX(-50%)",
|
295
195
|
});
|
296
196
|
|
@@ -314,12 +214,12 @@ function DrGaugeChart(pivotData, opts) {
|
|
314
214
|
// depends on label width
|
315
215
|
radiuses.push(
|
316
216
|
(chart.chartWidth / 2 - label.bBox.width - Math.max(offset[1], offset[3])) /
|
317
|
-
|
217
|
+
Math.sin(Math.abs(Math.PI / 2 - angle))
|
318
218
|
);
|
319
219
|
// depends on label height
|
320
220
|
radiuses.push(
|
321
221
|
(chart.chartHeight - offsetBottom - label.bBox.height / 2 - offset[0]) /
|
322
|
-
|
222
|
+
Math.cos(Math.abs(Math.PI / 2 - angle))
|
323
223
|
);
|
324
224
|
label.destroy();
|
325
225
|
});
|
@@ -338,8 +238,9 @@ function DrGaugeChart(pivotData, opts) {
|
|
338
238
|
};
|
339
239
|
|
340
240
|
this.setTicksStyles = function (chart, options) {
|
341
|
-
|
342
|
-
|
241
|
+
const ticks = chart.yAxis[0].ticks;
|
242
|
+
Object.keys(ticks).forEach((i) => {
|
243
|
+
const tick = ticks[i];
|
343
244
|
const isLeftQuarter = this.isLeftQuarter(tick.pos);
|
344
245
|
|
345
246
|
if (tick.pos === options.goal.value) {
|
@@ -357,8 +258,42 @@ function DrGaugeChart(pivotData, opts) {
|
|
357
258
|
transform: `translate(${isLeftQuarter ? "-100%" : 0}, 0)`,
|
358
259
|
});
|
359
260
|
});
|
261
|
+
|
262
|
+
// If goal is hidden, we need to always show goal and hide the closest visible label before it
|
263
|
+
this.updateLabelsWhenGoalIsHidden(ticks, options);
|
264
|
+
|
360
265
|
};
|
361
266
|
|
267
|
+
this.updateLabelsWhenGoalIsHidden = function (ticks, options) {
|
268
|
+
if (ticks[options.goal.value].label.opacity === 0) {
|
269
|
+
|
270
|
+
const ticksArray = Object.entries(ticks);
|
271
|
+
|
272
|
+
const goalTick = ticks[options.goal.value];
|
273
|
+
|
274
|
+
let firstVisibleLabelBeforeGoal = options.goal.value;
|
275
|
+
for (let i = ticksArray.findIndex(([key, _]) => Number(key) === options.goal.value) - 1; i >= 0; i--) {
|
276
|
+
const [key, tick] = ticksArray[i];
|
277
|
+
|
278
|
+
if (tick.label.opacity === 1) {
|
279
|
+
firstVisibleLabelBeforeGoal = Number(key);
|
280
|
+
break;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
ticks[firstVisibleLabelBeforeGoal].label.css({
|
285
|
+
opacity: 0,
|
286
|
+
visibility: "hidden",
|
287
|
+
});
|
288
|
+
|
289
|
+
goalTick.label.css({
|
290
|
+
opacity: 1,
|
291
|
+
visibility: "visible",
|
292
|
+
});
|
293
|
+
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
362
297
|
this.addTooltips = function (chart, options) {
|
363
298
|
if (!options.tooltips.show) {
|
364
299
|
return false;
|
@@ -395,8 +330,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
395
330
|
// goal tooltip if lebels are hidden
|
396
331
|
if (tick.pos === options.goal.value && !options.label.show) {
|
397
332
|
drTooltip.add(
|
398
|
-
`${
|
399
|
-
options.label.show_goal_name ? options.goal.title || "" : ""
|
333
|
+
`${options.label.show_goal_name ? options.goal.title || "" : ""
|
400
334
|
}<span style="font-weight: 600">${this.formatValue(options.goal.value)}</span>`,
|
401
335
|
chart.goalIcon.element,
|
402
336
|
{
|
@@ -426,16 +360,40 @@ function DrGaugeChart(pivotData, opts) {
|
|
426
360
|
|
427
361
|
this.setCustomElements = function (chart, options) {
|
428
362
|
chart.label = this.createValueLabel(chart, options);
|
429
|
-
chart.startBorder =
|
430
|
-
chart.endBorder =
|
363
|
+
chart.startBorder = DrGaugeChart.createBorder(chart, options, "start");
|
364
|
+
chart.endBorder = DrGaugeChart.createBorder(chart, options, "end");
|
431
365
|
chart.goalIcon = this.createGoalIcon(chart, options);
|
432
366
|
};
|
433
367
|
|
434
368
|
this.updateCustomElements = function (chart, options) {
|
435
|
-
chart.startBorder.attr(
|
436
|
-
chart.endBorder.attr(
|
369
|
+
chart.startBorder.attr(DrGaugeChart.getBorderPosition(chart, options, "start"));
|
370
|
+
chart.endBorder.attr(DrGaugeChart.getBorderPosition(chart, options, "end"));
|
437
371
|
chart.goalIcon.attr(this.getGoalIconPosition(chart, options));
|
438
|
-
chart.label.attr(
|
372
|
+
chart.label.attr(DrGaugeChart.getValueLabelPosition(chart, options));
|
373
|
+
};
|
374
|
+
|
375
|
+
this.createPlotBands = function (options) {
|
376
|
+
const {
|
377
|
+
segments,
|
378
|
+
isAbsoluteValue,
|
379
|
+
goal: { value: goalValue },
|
380
|
+
gauge: { thickness },
|
381
|
+
} = options;
|
382
|
+
|
383
|
+
const bands = segments.map((item) => {
|
384
|
+
return {
|
385
|
+
from: isAbsoluteValue ? item.from : (item.from * goalValue) / 100,
|
386
|
+
to: isAbsoluteValue ? item.to : (item.to * goalValue) / 100,
|
387
|
+
color: item.color,
|
388
|
+
thickness: thickness,
|
389
|
+
title: item.title,
|
390
|
+
};
|
391
|
+
});
|
392
|
+
|
393
|
+
// clamp last segment
|
394
|
+
bands[bands.length - 1].to = Math.max(bands[bands.length - 1].to, goalValue);
|
395
|
+
|
396
|
+
return bands;
|
439
397
|
};
|
440
398
|
|
441
399
|
this.moveCustomElementsToFront = function (chart) {
|
@@ -487,6 +445,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
487
445
|
},
|
488
446
|
margin: [0, 0, 0, 0],
|
489
447
|
spacing: [0, 0, 0, 0],
|
448
|
+
animation: !DrGaugeChart.highchartsRenderer.chartAnimationsDisabled(),
|
490
449
|
},
|
491
450
|
|
492
451
|
pane: {
|
@@ -511,7 +470,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
511
470
|
enabled: !!this.options.label.show,
|
512
471
|
distance: 0,
|
513
472
|
verticalAlign: "middle",
|
514
|
-
allowOverlap:
|
473
|
+
allowOverlap: false,
|
515
474
|
align: "left",
|
516
475
|
style: {
|
517
476
|
whiteSpace: "nowrap",
|
@@ -546,6 +505,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
546
505
|
backgroundColor: this.options.gauge.pivot.color,
|
547
506
|
radius: this.options.gauge.pivot.radius,
|
548
507
|
},
|
508
|
+
animation: !DrGaugeChart.highchartsRenderer.chartAnimationsDisabled(),
|
549
509
|
},
|
550
510
|
],
|
551
511
|
};
|
@@ -558,9 +518,98 @@ function DrGaugeChart(pivotData, opts) {
|
|
558
518
|
this.goal = this.options.goal;
|
559
519
|
this.plotBands = this.createPlotBands(this.options);
|
560
520
|
this.ticks = this.createTicks(this.plotBands, this.options);
|
561
|
-
this.value =
|
521
|
+
this.value = DrGaugeChart.getValue(pivotData, opts);
|
562
522
|
this.max = this.ticks[this.ticks.length - 1];
|
563
523
|
this.min = this.ticks[0];
|
564
524
|
}
|
565
525
|
|
526
|
+
DrGaugeChart.createTicks = function (plotBands, options) {
|
527
|
+
return _.uniq([plotBands[0].from || 0, ...plotBands.map((b) => b.to), options.goal.value]).sort((a, b) => a - b);
|
528
|
+
};
|
529
|
+
|
530
|
+
DrGaugeChart.getBorderPosition = function (chart, options, position) {
|
531
|
+
const { center, size } = chart.pane[0].options;
|
532
|
+
const {
|
533
|
+
gauge: { tickLength, tickWidth },
|
534
|
+
} = options;
|
535
|
+
|
536
|
+
return {
|
537
|
+
x: position === "start" ? center[0] - size / 2 + tickLength / 2 : center[0] + size / 2 - tickLength / 2,
|
538
|
+
y: center[1] + tickWidth / 2,
|
539
|
+
};
|
540
|
+
};
|
541
|
+
|
542
|
+
DrGaugeChart.createBorder = function (chart, options, position) {
|
543
|
+
return chart.renderer
|
544
|
+
.arc(
|
545
|
+
Object.assign(DrGaugeChart.getBorderPosition(chart, options, position), {
|
546
|
+
r: options.gauge.thickness / 2,
|
547
|
+
innerR: 0,
|
548
|
+
start: 0,
|
549
|
+
end: Math.PI,
|
550
|
+
})
|
551
|
+
)
|
552
|
+
.attr({
|
553
|
+
fill:
|
554
|
+
position === "start"
|
555
|
+
? chart.yAxis[0].options.plotBands[0].color
|
556
|
+
: chart.yAxis[0].options.plotBands.slice(-1)[0].color,
|
557
|
+
})
|
558
|
+
.add()
|
559
|
+
.toFront();
|
560
|
+
};
|
561
|
+
|
562
|
+
DrGaugeChart.getValueLabelPosition = function (chart, options) {
|
563
|
+
const { center } = chart.pane[0].options;
|
564
|
+
return {
|
565
|
+
x: center[0],
|
566
|
+
y: center[1] + options.gauge.valueOffset[0],
|
567
|
+
};
|
568
|
+
};
|
569
|
+
|
570
|
+
DrGaugeChart.ptCreateBasicLineSeries = function (pivotData, colors, onlyNumbers, isUniqueVals, additionOptions, opts, chartOptions) {
|
571
|
+
return DrGaugeChart.highchartsRenderer.ptCreateBasicLineSeries(
|
572
|
+
pivotData,
|
573
|
+
colors,
|
574
|
+
onlyNumbers,
|
575
|
+
isUniqueVals,
|
576
|
+
additionOptions,
|
577
|
+
opts,
|
578
|
+
chartOptions
|
579
|
+
);
|
580
|
+
};
|
581
|
+
|
582
|
+
DrGaugeChart.getSingleValueAgg = function (opts, aggfunc, base) {
|
583
|
+
return DrGaugeChart.highchartsRenderer.getSingleValueAgg(opts, aggfunc, base);
|
584
|
+
};
|
585
|
+
|
586
|
+
DrGaugeChart.getValue = function (pivotData, opts) {
|
587
|
+
const lineSeries = DrGaugeChart.ptCreateBasicLineSeries(pivotData, null, true, null, null, opts, {});
|
588
|
+
|
589
|
+
let total = _.flatten(lineSeries
|
590
|
+
.map((s) => s.data.map((v) => v))
|
591
|
+
.filter((v) => !_.isNaN(v))
|
592
|
+
);
|
593
|
+
|
594
|
+
let aggfunc = (a, b) => a + b;
|
595
|
+
let base = 0;
|
596
|
+
let singleValueAgg = DrGaugeChart.getSingleValueAgg(
|
597
|
+
{
|
598
|
+
value: {
|
599
|
+
value: "Sum",
|
600
|
+
},
|
601
|
+
},
|
602
|
+
aggfunc,
|
603
|
+
base
|
604
|
+
);
|
605
|
+
|
606
|
+
aggfunc = singleValueAgg.aggfunc;
|
607
|
+
base = singleValueAgg.base;
|
608
|
+
|
609
|
+
const aggregator = pivotData.getAggregator([], []);
|
610
|
+
const value = total.length > 0 ? total.reduce(aggfunc, base) : aggregator.value();
|
611
|
+
|
612
|
+
return value;
|
613
|
+
};
|
614
|
+
|
566
615
|
module.exports = { DrGaugeChart, GAUGE_OPTIONS_DEFAULT };
|
@@ -1,3 +1,5 @@
|
|
1
|
+
const _ = require('lodash');
|
2
|
+
|
1
3
|
function backendSortingKeysAreNotEmpty(keys) {
|
2
4
|
return !!keys && (!!keys.row_keys && !!keys.row_keys.length || !!keys.col_keys && !!keys.col_keys.length);
|
3
5
|
}
|
@@ -48,6 +50,22 @@ function removeSVGTextCorrection(svgEl, corr = 'yCorr') {
|
|
48
50
|
return svgEl;
|
49
51
|
}
|
50
52
|
|
53
|
+
function disableLegendInteractionIfRequired(chartOptions, additionOptions) {
|
54
|
+
const type = _.get(chartOptions, 'chart.type');
|
55
|
+
if (!type || !_.get(additionOptions, 'disable_legend_interaction')) return;
|
56
|
+
|
57
|
+
const legendItemClickFnPath = type === 'pie'
|
58
|
+
? 'plotOptions.pie.point.events.legendItemClick'
|
59
|
+
: 'plotOptions.series.events.legendItemClick';
|
60
|
+
|
61
|
+
_.set(chartOptions, legendItemClickFnPath, () => false);
|
62
|
+
_.set(chartOptions, 'legend.itemStyle.cursor', 'default');
|
63
|
+
}
|
64
|
+
|
65
|
+
function isShowingEmptyValues(additionOptions) {
|
66
|
+
return !additionOptions || !additionOptions.chart || additionOptions.chart.dislay_empty_values !== false;
|
67
|
+
}
|
68
|
+
|
51
69
|
module.exports = {
|
52
70
|
backendSortingKeysAreNotEmpty,
|
53
71
|
capitalize,
|
@@ -55,4 +73,6 @@ module.exports = {
|
|
55
73
|
isNumber,
|
56
74
|
mergeDeep,
|
57
75
|
removeSVGTextCorrection,
|
76
|
+
disableLegendInteractionIfRequired,
|
77
|
+
isShowingEmptyValues,
|
58
78
|
}
|
package/src/dr_chart_tooltip.js
CHANGED
@@ -226,24 +226,31 @@ function DrChartTooltip(chart, options) {
|
|
226
226
|
}
|
227
227
|
|
228
228
|
this.getAnchorBox = function(el) {
|
229
|
+
const containerRect = this.chart.container.getBoundingClientRect();
|
230
|
+
const zoom = this.chart.container.clientWidth / containerRect.width;
|
231
|
+
|
229
232
|
if (el.getBBox) {
|
230
|
-
|
231
|
-
|
233
|
+
const bBox = el.getBBox();
|
234
|
+
bBox.x = bBox.x * zoom;
|
235
|
+
bBox.y = bBox.y * zoom;
|
236
|
+
bBox.width = bBox.width * zoom;
|
237
|
+
bBox.height = bBox.height * zoom;
|
232
238
|
|
233
|
-
|
239
|
+
return bBox;
|
240
|
+
}
|
234
241
|
|
235
242
|
if (el.getBoundingClientRect) {
|
236
243
|
const elRect = el.getBoundingClientRect();
|
237
244
|
return {
|
238
|
-
x: elRect.x - containerRect.x,
|
239
|
-
y: elRect.y - containerRect.y,
|
240
|
-
width: elRect.width,
|
241
|
-
height: elRect.height,
|
245
|
+
x: (elRect.x - containerRect.x) * zoom,
|
246
|
+
y: (elRect.y - containerRect.y) * zoom,
|
247
|
+
width: elRect.width * zoom,
|
248
|
+
height: elRect.height * zoom,
|
242
249
|
};
|
243
250
|
}
|
244
251
|
return {
|
245
|
-
x: el.x - containerRect.x,
|
246
|
-
y: el.y - containerRect.y,
|
252
|
+
x: (el.x - containerRect.x) * zoom,
|
253
|
+
y: (el.y - containerRect.y) * zoom,
|
247
254
|
width: 0,
|
248
255
|
height: 0,
|
249
256
|
};
|
package/src/dr_pivottable.js
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
const { DR_SCENARIO } = require('./smart_queries_helper');
|
2
|
+
|
3
|
+
|
1
4
|
let initDRPivotTable = function($, window, document) {
|
2
5
|
var hasProp = {}.hasOwnProperty;
|
3
6
|
var slice = [].slice;
|
@@ -514,8 +517,8 @@ let initDRPivotTable = function($, window, document) {
|
|
514
517
|
isColHideOnExpand = (ref5 = opts.colSubtotalDisplay) != null ? ref5.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_columns;
|
515
518
|
isColDisableExpandCollapse = (ref6 = opts.colSubtotalDisplay) != null ? ref6.disableExpandCollapse : void 0;
|
516
519
|
colDisableAfter = (ref7 = opts.colSubtotalDisplay) != null ? ref7.disableAfter != null ? ref7.disableAfter : ref7.disableAfter = 9999 : void 0;
|
517
|
-
arrowCollapsed = opts.arrowCollapsed != null ? opts.arrowCollapsed : opts.arrowCollapsed = '<i class="
|
518
|
-
arrowExpanded = opts.arrowExpanded != null ? opts.arrowExpanded : opts.arrowExpanded = '<i class="
|
520
|
+
arrowCollapsed = opts.arrowCollapsed != null ? opts.arrowCollapsed : opts.arrowCollapsed = '<i class="dr-icon-add"></i> ';
|
521
|
+
arrowExpanded = opts.arrowExpanded != null ? opts.arrowExpanded : opts.arrowExpanded = '<i class="dr-icon-minus"></i> ';
|
519
522
|
colAttrs = pivotData.colAttrs;
|
520
523
|
rowAttrs = pivotData.rowAttrs;
|
521
524
|
rowKeys = pivotData.getRowKeys();
|
@@ -1269,6 +1272,9 @@ let initDRPivotTable = function($, window, document) {
|
|
1269
1272
|
"rowspan": rowHeader.descendants + 1,
|
1270
1273
|
"colspan": colspan
|
1271
1274
|
});
|
1275
|
+
if (opts.chartOptions.isSmartQueriesEnabled) {
|
1276
|
+
th.textContent = th.textContent.replace(DR_SCENARIO.Forecast, 'Forecast Smart Query');
|
1277
|
+
}
|
1272
1278
|
if (opts.chartOptions.table_options.hide_nulls_in_headers) {
|
1273
1279
|
th.textContent = th.textContent.replace('[null]', '');
|
1274
1280
|
}
|
@@ -1516,6 +1522,13 @@ let initDRPivotTable = function($, window, document) {
|
|
1516
1522
|
}
|
1517
1523
|
};
|
1518
1524
|
val = aggregator.value();
|
1525
|
+
|
1526
|
+
if (opts.chartOptions.isSmartQueriesEnabled && flatRowKey.split(' , ').includes(DR_SCENARIO.Forecast)) {
|
1527
|
+
const actualsRow = tree[flatRowKey.replace(DR_SCENARIO.Forecast, DR_SCENARIO.SQ_Actuals)] || {};
|
1528
|
+
if (actualsRow && actualsRow[flatColKey]) {
|
1529
|
+
val += actualsRow[flatColKey]?.value() || 0;
|
1530
|
+
}
|
1531
|
+
}
|
1519
1532
|
isColSubtotal = colHeader.children.length !== 0;
|
1520
1533
|
style = "pvtVal";
|
1521
1534
|
if (isColSubtotal) {
|
@@ -1558,6 +1571,9 @@ let initDRPivotTable = function($, window, document) {
|
|
1558
1571
|
}
|
1559
1572
|
|
1560
1573
|
val = totalAggregator.value();
|
1574
|
+
if (opts.chartOptions.isSmartQueriesEnabled && flatRowKey.split(' , ').includes(DR_SCENARIO.Forecast)) {
|
1575
|
+
val += rowTotals[flatRowKey.replace(DR_SCENARIO.Forecast, DR_SCENARIO.SQ_Actuals)]?.value() || 0;
|
1576
|
+
}
|
1561
1577
|
style = "pvtTotal rowTotal";
|
1562
1578
|
if (isRowSubtotal) {
|
1563
1579
|
style += " pvtRowSubtotal";
|
@@ -2338,6 +2354,9 @@ let initDRPivotTable = function($, window, document) {
|
|
2338
2354
|
}
|
2339
2355
|
|
2340
2356
|
main = function(rowAttrs, rowKeys, colAttrs, colKeys, pivotData) {
|
2357
|
+
if (opts.chartOptions.isSmartQueriesEnabled) {
|
2358
|
+
rowKeys = rowKeys.filter(rowKey => !rowKey.includes(DR_SCENARIO.SQ_Actuals));
|
2359
|
+
}
|
2341
2360
|
var c,rowspan, colHeaderCols, colHeaderHeaders, colHeaders, h, k, l, len, len1, result, rowHeaderHeaders, rowHeaderRows, rowHeaders, tbody, thead, tr;
|
2342
2361
|
rowHeaders = [];
|
2343
2362
|
colHeaders = [];
|
@@ -2476,7 +2495,12 @@ let initDRPivotTable = function($, window, document) {
|
|
2476
2495
|
}
|
2477
2496
|
|
2478
2497
|
if (tooMuch) {
|
2479
|
-
const defaultPlaceholder = $(
|
2498
|
+
const defaultPlaceholder = $(`
|
2499
|
+
<div class="noData--table-many-rows">
|
2500
|
+
<span><i class="noData-icon dr-icon-info"></i> There are too many rows to display in the table.</span>
|
2501
|
+
<span>Please filter or change the table type in options.</span>
|
2502
|
+
</div>
|
2503
|
+
`);
|
2480
2504
|
|
2481
2505
|
resultsArr.push($.pivotUtilities.errorHandling.getErrorPlaceholder(error_params) || defaultPlaceholder);
|
2482
2506
|
} else {
|