@datarailsshared/dr_renderer 1.3.18 → 1.3.20
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
@@ -145,7 +145,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
145
145
|
return `<span style="display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: ${
|
146
146
|
options.label.font_size
|
147
147
|
}px;">
|
148
|
-
<span style="font-weight: 600; font-size: 1.
|
148
|
+
<span style="font-weight: 600; font-size: 1.3em; line-height: 1; color: ${options.label.font_color}">
|
149
149
|
${this.formatValue(value)}
|
150
150
|
${
|
151
151
|
options.label.show_percentage_in_value
|
@@ -338,8 +338,9 @@ function DrGaugeChart(pivotData, opts) {
|
|
338
338
|
};
|
339
339
|
|
340
340
|
this.setTicksStyles = function (chart, options) {
|
341
|
-
|
342
|
-
|
341
|
+
const ticks = chart.yAxis[0].ticks;
|
342
|
+
Object.keys(ticks).forEach((i) => {
|
343
|
+
const tick = ticks[i];
|
343
344
|
const isLeftQuarter = this.isLeftQuarter(tick.pos);
|
344
345
|
|
345
346
|
if (tick.pos === options.goal.value) {
|
@@ -357,8 +358,42 @@ function DrGaugeChart(pivotData, opts) {
|
|
357
358
|
transform: `translate(${isLeftQuarter ? "-100%" : 0}, 0)`,
|
358
359
|
});
|
359
360
|
});
|
361
|
+
|
362
|
+
// If goal is hidden, we need to always show goal and hide the closest visible label before it
|
363
|
+
this.updateLabelsWhenGoalIsHidden(ticks, options);
|
364
|
+
|
360
365
|
};
|
361
366
|
|
367
|
+
this.updateLabelsWhenGoalIsHidden = function (ticks, options) {
|
368
|
+
if (ticks[options.goal.value].label.opacity === 0) {
|
369
|
+
|
370
|
+
const ticksArray = Object.entries(ticks);
|
371
|
+
|
372
|
+
const goalTick = ticks[options.goal.value];
|
373
|
+
|
374
|
+
let firstVisibleLabelBeforeGoal = options.goal.value;
|
375
|
+
for (let i = ticksArray.findIndex(([key, _]) => Number(key) === options.goal.value) - 1; i >= 0; i--) {
|
376
|
+
const [key, tick] = ticksArray[i];
|
377
|
+
|
378
|
+
if (tick.label.opacity === 1) {
|
379
|
+
firstVisibleLabelBeforeGoal = Number(key);
|
380
|
+
break;
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
ticks[firstVisibleLabelBeforeGoal].label.css({
|
385
|
+
opacity: 0,
|
386
|
+
visibility: "hidden",
|
387
|
+
});
|
388
|
+
|
389
|
+
goalTick.label.css({
|
390
|
+
opacity: 1,
|
391
|
+
visibility: "visible",
|
392
|
+
});
|
393
|
+
|
394
|
+
}
|
395
|
+
}
|
396
|
+
|
362
397
|
this.addTooltips = function (chart, options) {
|
363
398
|
if (!options.tooltips.show) {
|
364
399
|
return false;
|
@@ -511,7 +546,7 @@ function DrGaugeChart(pivotData, opts) {
|
|
511
546
|
enabled: !!this.options.label.show,
|
512
547
|
distance: 0,
|
513
548
|
verticalAlign: "middle",
|
514
|
-
allowOverlap:
|
549
|
+
allowOverlap: false,
|
515
550
|
align: "left",
|
516
551
|
style: {
|
517
552
|
whiteSpace: "nowrap",
|
@@ -461,7 +461,7 @@ describe("DrGaugeChart", () => {
|
|
461
461
|
expect(simplifyString(label)).toBe(
|
462
462
|
simplifyString(
|
463
463
|
`<span style="display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 16px;">
|
464
|
-
<span style="font-weight: 600; font-size: 1.
|
464
|
+
<span style="font-weight: 600; font-size: 1.3em; line-height: 1; color: #000">
|
465
465
|
${mockFormattedValue}
|
466
466
|
</span>
|
467
467
|
<span style="font-weight: 500; font-size: 0.875em; line-height: 1; color: #808080;">Current status</span>
|
@@ -486,7 +486,7 @@ describe("DrGaugeChart", () => {
|
|
486
486
|
expect(simplifyString(label)).toBe(
|
487
487
|
simplifyString(
|
488
488
|
`<span style="display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 24px;">
|
489
|
-
<span style="font-weight: 600; font-size: 1.
|
489
|
+
<span style="font-weight: 600; font-size: 1.3em; line-height: 1; color: #000">
|
490
490
|
${mockFormattedValue}
|
491
491
|
<span style="font-size: 0.5833em; font-weight: 600; color: #929292;">(56%)</span>
|
492
492
|
</span>
|
@@ -1204,6 +1204,15 @@ describe("DrGaugeChart", () => {
|
|
1204
1204
|
css: jest.fn(),
|
1205
1205
|
},
|
1206
1206
|
},
|
1207
|
+
180: {
|
1208
|
+
pos: 180,
|
1209
|
+
label: {
|
1210
|
+
css: jest.fn(),
|
1211
|
+
},
|
1212
|
+
mark: {
|
1213
|
+
attr: jest.fn(),
|
1214
|
+
},
|
1215
|
+
},
|
1207
1216
|
},
|
1208
1217
|
},
|
1209
1218
|
],
|
@@ -1234,11 +1243,14 @@ describe("DrGaugeChart", () => {
|
|
1234
1243
|
yAxis: [
|
1235
1244
|
{
|
1236
1245
|
ticks: {
|
1237
|
-
|
1246
|
+
180: {
|
1238
1247
|
pos: 180,
|
1239
1248
|
mark: {
|
1240
1249
|
attr: jest.fn(),
|
1241
1250
|
},
|
1251
|
+
label: {
|
1252
|
+
css: jest.fn(),
|
1253
|
+
},
|
1242
1254
|
},
|
1243
1255
|
},
|
1244
1256
|
},
|
@@ -1256,7 +1268,7 @@ describe("DrGaugeChart", () => {
|
|
1256
1268
|
},
|
1257
1269
|
});
|
1258
1270
|
// add a goal tick styles
|
1259
|
-
expect(mockChart.yAxis[0].ticks[
|
1271
|
+
expect(mockChart.yAxis[0].ticks[180].mark.attr).toHaveBeenCalledWith({
|
1260
1272
|
"pointer-events": "none",
|
1261
1273
|
stroke: "blue",
|
1262
1274
|
"stroke-dasharray": 2,
|
@@ -1889,7 +1901,7 @@ describe("DrGaugeChart", () => {
|
|
1889
1901
|
expect(config.yAxis.labels.enabled).toBe(mockOptions.label.show);
|
1890
1902
|
expect(config.yAxis.labels.distance).toBe(0),
|
1891
1903
|
expect(config.yAxis.labels.verticalAlign).toBe("middle"),
|
1892
|
-
expect(config.yAxis.labels.allowOverlap).toBe(
|
1904
|
+
expect(config.yAxis.labels.allowOverlap).toBe(false),
|
1893
1905
|
expect(config.yAxis.labels.align).toBe("left");
|
1894
1906
|
expect(config.yAxis.labels.style).toEqual({
|
1895
1907
|
whiteSpace: "nowrap",
|