@datarailsshared/dr_renderer 1.3.18 → 1.3.19

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.3.18",
3
+ "version": "1.3.19",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -338,8 +338,9 @@ function DrGaugeChart(pivotData, opts) {
338
338
  };
339
339
 
340
340
  this.setTicksStyles = function (chart, options) {
341
- Object.keys(chart.yAxis[0].ticks).forEach((i) => {
342
- const tick = chart.yAxis[0].ticks[i];
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: true,
549
+ allowOverlap: false,
515
550
  align: "left",
516
551
  style: {
517
552
  whiteSpace: "nowrap",
@@ -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
- 0: {
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[0].mark.attr).toHaveBeenCalledWith({
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(true),
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",