evui 3.1.39 → 3.1.43

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.
@@ -5,6 +5,7 @@ import {
5
5
  AXIS_UNITS,
6
6
  PLOT_LINE_OPTION,
7
7
  PLOT_LINE_LABEL_OPTION,
8
+ PLOT_BAND_OPTION,
8
9
  } from '../helpers/helpers.constant';
9
10
  import Util from '../helpers/helpers.util';
10
11
 
@@ -219,82 +220,115 @@ class Scale {
219
220
  return;
220
221
  }
221
222
 
222
- const labelGap = (endPoint - startPoint) / steps;
223
- const ticks = [];
224
- let labelCenter = null;
225
- let linePosition = null;
223
+ if (this.labelStyle?.show) {
224
+ const labelGap = (endPoint - startPoint) / steps;
225
+ const ticks = [];
226
+ let labelCenter = null;
227
+ let linePosition = null;
226
228
 
227
- ctx.strokeStyle = this.gridLineColor;
228
- ctx.lineWidth = 1;
229
- aliasPixel = Util.aliasPixel(ctx.lineWidth);
229
+ ctx.strokeStyle = this.gridLineColor;
230
+ ctx.lineWidth = 1;
231
+ aliasPixel = Util.aliasPixel(ctx.lineWidth);
230
232
 
231
- let labelText;
232
- for (let ix = 0; ix <= steps; ix++) {
233
- ctx.beginPath();
234
- ticks[ix] = axisMin + (ix * stepValue);
233
+ let labelText;
234
+ for (let ix = 0; ix <= steps; ix++) {
235
+ ctx.beginPath();
236
+ ticks[ix] = axisMin + (ix * stepValue);
235
237
 
236
- labelCenter = Math.round(startPoint + (labelGap * ix));
237
- linePosition = labelCenter + aliasPixel;
238
- labelText = this.getLabelFormat(Math.min(axisMax, ticks[ix]));
238
+ labelCenter = Math.round(startPoint + (labelGap * ix));
239
+ linePosition = labelCenter + aliasPixel;
240
+ labelText = this.getLabelFormat(Math.min(axisMax, ticks[ix]));
239
241
 
240
- let labelPoint;
242
+ let labelPoint;
241
243
 
242
- if (this.type === 'x') {
243
- labelPoint = this.position === 'top' ? offsetPoint - 10 : offsetPoint + 10;
244
- ctx.fillText(labelText, labelCenter, labelPoint);
245
- if (options?.selectItem?.showLabelTip && hitInfo?.label && !this.options?.horizontal) {
246
- const selectedLabel = this.getLabelFormat(
247
- Math.min(axisMax, hitInfo.label + (0 * stepValue)),
248
- );
249
- if (selectedLabel === labelText) {
250
- const height = Math.round(ctx.measureText(this.labelStyle?.fontSize).width);
251
- Util.showLabelTip({
252
- ctx: this.ctx,
253
- width: Math.round(ctx.measureText(selectedLabel).width) + 10,
254
- height,
255
- x: labelCenter,
256
- y: labelPoint + (height - 2),
257
- borderRadius: 2,
258
- arrowSize: 3,
259
- text: labelText,
260
- backgroundColor: options?.selectItem?.labelTipStyle?.backgroundColor,
261
- textColor: options?.selectItem?.labelTipStyle?.textColor,
262
- });
244
+ if (this.type === 'x') {
245
+ labelPoint = this.position === 'top' ? offsetPoint - 10 : offsetPoint + 10;
246
+ ctx.fillText(labelText, labelCenter, labelPoint);
247
+ if (options?.selectItem?.showLabelTip && hitInfo?.label && !this.options?.horizontal) {
248
+ const selectedLabel = this.getLabelFormat(
249
+ Math.min(axisMax, hitInfo.label + (0 * stepValue)),
250
+ );
251
+ if (selectedLabel === labelText) {
252
+ const height = Math.round(ctx.measureText(this.labelStyle?.fontSize).width);
253
+ Util.showLabelTip({
254
+ ctx: this.ctx,
255
+ width: Math.round(ctx.measureText(selectedLabel).width) + 10,
256
+ height,
257
+ x: labelCenter,
258
+ y: labelPoint + (height - 2),
259
+ borderRadius: 2,
260
+ arrowSize: 3,
261
+ text: labelText,
262
+ backgroundColor: options?.selectItem?.labelTipStyle?.backgroundColor,
263
+ textColor: options?.selectItem?.labelTipStyle?.textColor,
264
+ });
265
+ }
263
266
  }
264
- }
265
- if (ix !== 0 && this.showGrid) {
266
- ctx.moveTo(linePosition, offsetPoint);
267
- ctx.lineTo(linePosition, offsetCounterPoint);
268
- }
269
- } else {
270
- labelPoint = this.position === 'left' ? offsetPoint - 10 : offsetPoint + 10;
271
- ctx.fillText(labelText, labelPoint, labelCenter);
267
+ if (ix !== 0 && this.showGrid) {
268
+ ctx.moveTo(linePosition, offsetPoint);
269
+ ctx.lineTo(linePosition, offsetCounterPoint);
270
+ }
271
+ } else {
272
+ labelPoint = this.position === 'left' ? offsetPoint - 10 : offsetPoint + 10;
273
+ ctx.fillText(labelText, labelPoint, labelCenter);
272
274
 
273
- if (ix === steps) {
274
- linePosition += 1;
275
- }
275
+ if (ix === steps) {
276
+ linePosition += 1;
277
+ }
276
278
 
277
- if (ix !== 0 && this.showGrid) {
278
- ctx.moveTo(offsetPoint, linePosition);
279
- ctx.lineTo(offsetCounterPoint, linePosition);
279
+ if (ix !== 0 && this.showGrid) {
280
+ ctx.moveTo(offsetPoint, linePosition);
281
+ ctx.lineTo(offsetCounterPoint, linePosition);
282
+ }
280
283
  }
281
- }
282
284
 
283
- ctx.stroke();
284
- ctx.closePath();
285
+ ctx.stroke();
286
+ ctx.closePath();
287
+ }
285
288
  }
286
289
 
287
- // Draw plot line
288
- if (this.plotLines?.length) {
290
+ // Draw plot lines and plot bands
291
+ if (this.plotBands?.length || this.plotLines?.length) {
289
292
  const xArea = chartRect.chartWidth - (labelOffset.left + labelOffset.right);
290
293
  const yArea = chartRect.chartHeight - (labelOffset.top + labelOffset.bottom);
291
294
  const padding = aliasPixel + 1;
292
295
  const minX = aPos.x1 + padding;
293
296
  const maxX = aPos.x2;
294
- const minY = aPos.y1 + padding;
295
- const maxY = aPos.y2;
297
+ const minY = aPos.y1 + padding; // top
298
+ const maxY = aPos.y2; // bottom
299
+
300
+ this.plotBands?.forEach((plotBand) => {
301
+ if (!plotBand.from && !plotBand.to) {
302
+ return;
303
+ }
304
+
305
+ const mergedPlotBandOpt = defaultsDeep({}, plotBand, PLOT_BAND_OPTION);
306
+ const { from, to, label: labelOpt } = mergedPlotBandOpt;
307
+
308
+ this.setPlotBandStyle(mergedPlotBandOpt);
309
+
310
+ let fromPos;
311
+ let toPos;
312
+ if (this.type === 'x') {
313
+ fromPos = Canvas.calculateX(from ?? minX, axisMin, axisMax, xArea, minX);
314
+ toPos = Canvas.calculateX(to ?? maxX, axisMin, axisMax, xArea, minX);
315
+ this.drawXPlotBand(fromPos, toPos, minX, maxX, minY, maxY);
316
+ } else {
317
+ fromPos = Canvas.calculateY(from ?? axisMin, axisMin, axisMax, yArea, maxY);
318
+ toPos = Canvas.calculateY(to ?? axisMax, axisMin, axisMax, yArea, maxY);
319
+ this.drawYPlotBand(fromPos, toPos, minX, maxX, minY, maxY);
320
+ }
321
+
322
+ if (labelOpt.show) {
323
+ const labelOptions = this.getNormalizedLabelOptions(chartRect, labelOpt);
324
+ const textXY = this.getPlotBandLabelPosition(fromPos, toPos, labelOptions, maxX, minY);
325
+ this.drawPlotLabel(labelOptions, textXY);
326
+ }
296
327
 
297
- this.plotLines.forEach((plotLine) => {
328
+ ctx.restore();
329
+ });
330
+
331
+ this.plotLines?.forEach((plotLine) => {
298
332
  if (!plotLine.value) {
299
333
  return;
300
334
  }
@@ -304,12 +338,19 @@ class Scale {
304
338
 
305
339
  this.setPlotLineStyle(mergedPlotLineOpt);
306
340
 
341
+ let dataPos;
307
342
  if (this.type === 'x') {
308
- const dataX = Canvas.calculateX(value, axisMin, axisMax, xArea, minX);
309
- this.drawXPlotLine(dataX, minX, maxX, minY, maxY, labelOpt);
343
+ dataPos = Canvas.calculateX(value, axisMin, axisMax, xArea, minX);
344
+ this.drawXPlotLine(dataPos, minX, maxX, minY, maxY);
310
345
  } else {
311
- const dataY = Canvas.calculateY(value, axisMin, axisMax, yArea, maxY);
312
- this.drawYPlotLine(dataY, minX, maxX, minY, maxY, labelOpt);
346
+ dataPos = Canvas.calculateY(value, axisMin, axisMax, yArea, maxY);
347
+ this.drawYPlotLine(dataPos, minX, maxX, minY, maxY);
348
+ }
349
+
350
+ if (labelOpt.show) {
351
+ const labelOptions = this.getNormalizedLabelOptions(chartRect, labelOpt);
352
+ const textXY = this.getPlotLineLabelPosition(dataPos, labelOptions, maxX, minY);
353
+ this.drawPlotLabel(labelOptions, textXY);
313
354
  }
314
355
 
315
356
  ctx.restore();
@@ -337,6 +378,55 @@ class Scale {
337
378
  }
338
379
  }
339
380
 
381
+ /**
382
+ * Set plot band style
383
+ * @param {object} plotBand plotBand Options
384
+ *
385
+ * @returns {undefined}
386
+ */
387
+ setPlotBandStyle(plotBand) {
388
+ const ctx = this.ctx;
389
+ const { color } = plotBand;
390
+
391
+ ctx.beginPath();
392
+ ctx.save();
393
+ ctx.fillStyle = color;
394
+ }
395
+
396
+ /**
397
+ * Draw X Plot band
398
+ * @param {number} fromDataX From data's X Position
399
+ * @param {number} toDataX To data's X Position
400
+ * @param {number} minX Min X Position
401
+ * @param {number} maxX Max X Position
402
+ * @param {number} minY Min Y Position
403
+ * @param {number} maxY Max Y Position
404
+ *
405
+ * @returns {undefined}
406
+ */
407
+ drawXPlotBand(fromDataX, toDataX, minX, maxX, minY, maxY) {
408
+ const ctx = this.ctx;
409
+
410
+ const checkValidPosition = x => x || x > minX || x < maxX;
411
+
412
+ if (!checkValidPosition(fromDataX) || !checkValidPosition(toDataX)) {
413
+ ctx.closePath();
414
+ ctx.restore();
415
+ return;
416
+ }
417
+
418
+ ctx.moveTo(fromDataX, minY);
419
+ ctx.lineTo(fromDataX, maxY);
420
+ ctx.lineTo(toDataX, maxY);
421
+ ctx.lineTo(toDataX, minY);
422
+ ctx.lineTo(fromDataX, minY);
423
+
424
+ ctx.stroke();
425
+ ctx.fill();
426
+ ctx.restore();
427
+ ctx.closePath();
428
+ }
429
+
340
430
  /**
341
431
  * Draw X Plot line
342
432
  * @param {object} dataX Data's X Position
@@ -344,11 +434,10 @@ class Scale {
344
434
  * @param {number} maxX Max X Position
345
435
  * @param {number} minY Min Y Position
346
436
  * @param {number} maxY Max Y Position
347
- * @param {object} labelOpt plotLine Options
348
437
  *
349
438
  * @returns {undefined}
350
439
  */
351
- drawXPlotLine(dataX, minX, maxX, minY, maxY, labelOpt) {
440
+ drawXPlotLine(dataX, minX, maxX, minY, maxY) {
352
441
  const ctx = this.ctx;
353
442
 
354
443
  if (!dataX || dataX < minX || dataX > maxX) {
@@ -363,51 +452,6 @@ class Scale {
363
452
  ctx.stroke();
364
453
  ctx.restore();
365
454
  ctx.closePath();
366
-
367
- if (labelOpt) {
368
- const mergedLabelOpt = defaultsDeep({}, labelOpt, PLOT_LINE_LABEL_OPTION);
369
-
370
- ctx.save();
371
- ctx.beginPath();
372
- ctx.font = Util.getLabelStyle(mergedLabelOpt);
373
-
374
- const {
375
- fontSize,
376
- labelBoxPadding,
377
- labelHalfWidth,
378
- } = this.getLabelParameters(mergedLabelOpt);
379
-
380
- if (fontSize <= 0) {
381
- return;
382
- }
383
-
384
- let textX;
385
- switch (mergedLabelOpt.textAlign) {
386
- case 'left':
387
- textX = dataX - labelHalfWidth - labelBoxPadding;
388
- break;
389
-
390
- case 'right':
391
- textX = dataX + labelHalfWidth + labelBoxPadding;
392
- break;
393
-
394
- case 'center':
395
- default:
396
- textX = dataX;
397
- break;
398
- }
399
-
400
- const textY = minY - labelBoxPadding - fontSize;
401
-
402
- this.drawPlotLineLabel(mergedLabelOpt, {
403
- top: minY - (labelBoxPadding * 2) - fontSize,
404
- bottom: minY - labelBoxPadding,
405
- left: textX - labelHalfWidth - labelBoxPadding,
406
- right: textX + labelHalfWidth + labelBoxPadding,
407
- x: textX,
408
- y: textY,
409
- });
410
- }
411
455
  }
412
456
 
413
457
  /**
@@ -417,11 +461,10 @@ class Scale {
417
461
  * @param {number} maxX Max X Position
418
462
  * @param {number} minY Min Y Position
419
463
  * @param {number} maxY Max Y Position
420
- * @param {object} labelOpt plotLine Options
421
464
  *
422
465
  * @returns {undefined}
423
466
  */
424
- drawYPlotLine(dataY, minX, maxX, minY, maxY, labelOpt) {
467
+ drawYPlotLine(dataY, minX, maxX, minY, maxY) {
425
468
  const ctx = this.ctx;
426
469
 
427
470
  if (!dataY || dataY > maxY || dataY < minY) {
@@ -436,91 +479,263 @@ class Scale {
436
479
  ctx.stroke();
437
480
  ctx.restore();
438
481
  ctx.closePath();
482
+ }
483
+
484
+ /**
485
+ * Draw Y Plot band
486
+ * @param {number} fromDataY From data's Y Position (bottom)
487
+ * @param {number} toDataY To data's Y Position (top)
488
+ * @param {number} minX Min X Position
489
+ * @param {number} maxX Max X Position
490
+ * @param {number} minY Min Y Position
491
+ * @param {number} maxY Max Y Position
492
+ *
493
+ * @returns {undefined}
494
+ */
495
+ drawYPlotBand(fromDataY, toDataY, minX, maxX, minY, maxY) {
496
+ const ctx = this.ctx;
439
497
 
440
- if (labelOpt) {
441
- const mergedLabelOpt = defaultsDeep({}, labelOpt, PLOT_LINE_LABEL_OPTION);
498
+ const checkValidPosition = y => y || y > minY || y < maxY;
442
499
 
443
- ctx.save();
444
- ctx.beginPath();
445
- ctx.font = Util.getLabelStyle(mergedLabelOpt);
500
+ if (!checkValidPosition(fromDataY) || !checkValidPosition(toDataY)) {
501
+ ctx.closePath();
502
+ ctx.restore();
503
+ return;
504
+ }
505
+
506
+ ctx.moveTo(minX, fromDataY);
507
+ ctx.lineTo(minX, toDataY);
508
+ ctx.lineTo(maxX, toDataY);
509
+ ctx.lineTo(maxX, fromDataY);
510
+ ctx.lineTo(minX, fromDataY);
511
+
512
+ ctx.fill();
513
+ ctx.restore();
514
+ ctx.closePath();
515
+ }
516
+
517
+ /**
518
+ * get normalized options for plot label
519
+ * @param {object} chartRect chartRect
520
+ * @param {object} labelOpt plotLine Options
521
+ *
522
+ * @returns {object}
523
+ */
524
+ getNormalizedLabelOptions(chartRect, labelOpt) {
525
+ const mergedLabelOpt = defaultsDeep({}, labelOpt, PLOT_LINE_LABEL_OPTION);
526
+
527
+ const ctx = this.ctx;
528
+ const { maxWidth } = mergedLabelOpt;
529
+ const fontSize = mergedLabelOpt.fontSize > 20 ? 20 : mergedLabelOpt.fontSize;
530
+ let label = mergedLabelOpt.text;
531
+ let labelWidth = maxWidth ?? ctx.measureText(label).width;
532
+
533
+ const plotLabelAreaWidth = this.type === 'y'
534
+ ? chartRect.width - chartRect.chartWidth
535
+ : maxWidth ?? chartRect.width;
536
+
537
+ if (plotLabelAreaWidth < ctx.measureText(label).width && mergedLabelOpt.textOverflow === 'ellipsis') {
538
+ label = Util.truncateLabelWithEllipsis(mergedLabelOpt.text, plotLabelAreaWidth, ctx);
539
+ labelWidth = ctx.measureText(label).width;
540
+ }
541
+
542
+ return {
543
+ label,
544
+ fontSize,
545
+ labelWidth,
546
+ labelBoxPadding: fontSize / 4,
547
+ labelHalfWidth: labelWidth / 2,
548
+ labelHalfHeight: fontSize / 2,
549
+ ...mergedLabelOpt,
550
+ };
551
+ }
552
+
553
+ /**
554
+ * Calculate position of plot band's label
555
+ * @param {object} fromPos from data position
556
+ * @param {object} toPos to data position
557
+ * @param {object} labelOpt label options
558
+ * @param {object} maxX max x position
559
+ * @param {object} minY min y position
560
+ *
561
+ * @returns {object}
562
+ */
563
+ getPlotBandLabelPosition(fromPos, toPos, labelOpt, maxX, minY) {
564
+ const {
565
+ fontSize,
566
+ labelWidth,
567
+ labelHalfWidth,
568
+ labelHalfHeight,
569
+ labelBoxPadding,
570
+ textAlign,
571
+ verticalAlign,
572
+ } = labelOpt;
573
+
574
+ if (fontSize <= 0) {
575
+ return { textX: 0, textY: 0 };
576
+ }
577
+
578
+ let textX;
579
+ let textY;
580
+
581
+ if (this.type === 'x') {
582
+ textY = minY - labelBoxPadding - fontSize;
583
+
584
+ switch (textAlign) {
585
+ case 'left':
586
+ textX = fromPos + labelHalfWidth + labelBoxPadding;
587
+ break;
446
588
 
447
- const {
448
- fontSize,
449
- labelWidth,
450
- labelHalfHeight,
451
- labelBoxPadding,
452
- } = this.getLabelParameters(mergedLabelOpt);
589
+ case 'right':
590
+ textX = toPos - labelHalfWidth - labelBoxPadding;
591
+ break;
453
592
 
454
- if (fontSize <= 0) {
455
- return;
593
+ case 'center':
594
+ default:
595
+ textX = ((toPos - fromPos) / 2) + fromPos;
596
+ break;
456
597
  }
598
+ } else {
599
+ textX = maxX + labelWidth + labelBoxPadding;
457
600
 
458
- let textY;
459
- switch (mergedLabelOpt.verticalAlign) {
601
+ switch (verticalAlign) {
460
602
  case 'top':
461
- textY = dataY - labelHalfHeight - labelBoxPadding;
603
+ textY = toPos + labelHalfHeight + labelBoxPadding;
462
604
  break;
463
605
 
464
606
  case 'bottom':
465
- textY = dataY + labelHalfHeight + labelBoxPadding;
607
+ textY = fromPos - labelHalfHeight - labelBoxPadding;
466
608
  break;
467
609
 
468
610
  case 'middle':
469
611
  default:
470
- textY = dataY;
612
+ textY = ((fromPos - toPos) / 2) + toPos;
471
613
  break;
472
614
  }
473
-
474
- const textX = maxX + labelWidth + labelBoxPadding;
475
-
476
- this.drawPlotLineLabel(mergedLabelOpt, {
477
- top: textY - labelHalfHeight - labelBoxPadding,
478
- bottom: textY + labelHalfHeight + labelBoxPadding,
479
- left: textX - labelWidth - (labelBoxPadding / 2),
480
- right: textX + labelBoxPadding,
481
- x: textX,
482
- y: textY,
483
- });
484
615
  }
616
+
617
+ return { textX, textY };
485
618
  }
486
619
 
487
620
  /**
488
- * Calculate Values for drawing label
489
- * @param {object} labelOpt plotLine Options
621
+ * Calculate position of plot line's label
622
+ * @param {object} dataPos data position
623
+ * @param {object} labelOpt label options
624
+ * @param {object} maxX max x position
625
+ * @param {object} minY min y position
490
626
  *
491
- * @returns {object}
627
+ * @returns {undefined}
492
628
  */
493
- getLabelParameters(labelOpt) {
494
- const ctx = this.ctx;
495
- const fontSize = labelOpt.fontSize > 20 ? 20 : labelOpt.fontSize;
496
- const labelBoxPadding = fontSize / 4;
497
- const labelWidth = ctx.measureText(labelOpt.text).width;
498
- const labelHalfWidth = labelWidth / 2;
499
- const labelHalfHeight = fontSize / 2;
500
-
501
- return {
629
+ getPlotLineLabelPosition(dataPos, labelOpt, maxX, minY) {
630
+ const {
502
631
  fontSize,
503
- labelBoxPadding,
504
632
  labelWidth,
505
633
  labelHalfWidth,
506
634
  labelHalfHeight,
507
- };
635
+ labelBoxPadding,
636
+ } = labelOpt;
637
+
638
+ if (fontSize <= 0) {
639
+ return { textX: 0, textY: 0 };
640
+ }
641
+
642
+ let textX;
643
+ let textY;
644
+
645
+ if (this.type === 'x') {
646
+ textY = minY - labelBoxPadding - fontSize;
647
+
648
+ switch (labelOpt.textAlign) {
649
+ case 'left':
650
+ textX = dataPos - labelHalfWidth - labelBoxPadding;
651
+ break;
652
+
653
+ case 'right':
654
+ textX = dataPos + labelHalfWidth + labelBoxPadding;
655
+ break;
656
+
657
+ case 'center':
658
+ default:
659
+ textX = dataPos;
660
+ break;
661
+ }
662
+ } else {
663
+ textX = maxX + labelWidth + labelBoxPadding;
664
+
665
+ switch (labelOpt.verticalAlign) {
666
+ case 'top':
667
+ textY = dataPos - labelHalfHeight - labelBoxPadding;
668
+ break;
669
+
670
+ case 'bottom':
671
+ textY = dataPos + labelHalfHeight + labelBoxPadding;
672
+ break;
673
+
674
+ case 'middle':
675
+ default:
676
+ textY = dataPos;
677
+ break;
678
+ }
679
+ }
680
+
681
+ return { textX, textY };
508
682
  }
509
683
 
510
684
  /**
511
685
  * Calculate Values for drawing label
512
- * @param {object} labelOpt plot line Label Options
513
- * @param {object} positions label positions
686
+ * @param {object} labelOptions plot line Label Options
687
+ * @param {object} positions x, y Position
514
688
  *
515
689
  * @returns {undefined}
516
690
  */
517
- drawPlotLineLabel(labelOpt, positions) {
691
+ drawPlotLabel(labelOptions, positions) {
692
+ if (!positions) {
693
+ return;
694
+ }
695
+
696
+ const { textX, textY } = positions;
697
+ const {
698
+ label,
699
+ fontSize,
700
+ fontColor,
701
+ fillColor,
702
+ lineColor,
703
+ lineWidth,
704
+ labelBoxPadding,
705
+ labelWidth,
706
+ labelHalfWidth,
707
+ labelHalfHeight,
708
+ } = labelOptions;
709
+
710
+ if (fontSize <= 0) {
711
+ return;
712
+ }
713
+
518
714
  const ctx = this.ctx;
519
- const { top, bottom, left, right, x, y } = positions;
715
+ ctx.save();
716
+ ctx.beginPath();
717
+ ctx.font = Util.getLabelStyle(labelOptions);
718
+
719
+ let top = 0;
720
+ let bottom = 0;
721
+ let left = 0;
722
+ let right = 0;
520
723
 
521
- ctx.fillStyle = labelOpt.fillColor;
522
- ctx.strokeStyle = labelOpt.lineColor;
523
- ctx.lineWidth = labelOpt.lineWidth;
724
+ if (this.type === 'x') {
725
+ top = textY - labelBoxPadding;
726
+ bottom = textY + fontSize;
727
+ left = textX - labelHalfWidth - labelBoxPadding;
728
+ right = textX + labelHalfWidth + labelBoxPadding;
729
+ } else {
730
+ top = textY - labelHalfHeight - labelBoxPadding;
731
+ bottom = textY + labelHalfHeight + labelBoxPadding;
732
+ left = textX - labelWidth;
733
+ right = textX + labelBoxPadding;
734
+ }
735
+
736
+ ctx.fillStyle = fillColor;
737
+ ctx.strokeStyle = lineColor;
738
+ ctx.lineWidth = lineWidth;
524
739
  ctx.moveTo(left, bottom);
525
740
  ctx.lineTo(left, top);
526
741
  ctx.lineTo(right, top);
@@ -528,12 +743,13 @@ class Scale {
528
743
  ctx.lineTo(left, bottom);
529
744
  ctx.fill();
530
745
 
531
- if (labelOpt.lineWidth > 0) {
746
+ if (lineWidth > 0) {
532
747
  ctx.stroke();
533
748
  }
534
749
 
535
- ctx.fillStyle = labelOpt.fontColor;
536
- ctx.fillText(labelOpt.text, x, y);
750
+ ctx.fillStyle = fontColor;
751
+
752
+ ctx.fillText(label, textX, textY);
537
753
  ctx.closePath();
538
754
  }
539
755
  }