@progress/kendo-charts 2.10.0-develop.2 → 2.10.0-develop.3

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.
@@ -481,6 +481,75 @@ class Chart {
481
481
  return visual;
482
482
  }
483
483
 
484
+ _toggleCategoryHighlight(index, axis) {
485
+ const plotArea = this._plotArea;
486
+ const categoryAxis = axis || plotArea.categoryAxis;
487
+
488
+ if (this._categoryHighlightIndex === index && this._categoryHighlightAxis === categoryAxis) {
489
+ return;
490
+ }
491
+
492
+ this._categoryHighlightIndex = index;
493
+ this._categoryHighlightAxis = categoryAxis;
494
+
495
+ const highlightOptions = (categoryAxis.options || {}).highlight;
496
+
497
+ if (!highlightOptions || !highlightOptions.visible || index === null) {
498
+ if (this._categoryHighlight) {
499
+ this._categoryHighlight.visible(false);
500
+ }
501
+ return;
502
+ }
503
+
504
+ if (!this._categoryHighlight) {
505
+ this._categoryHighlight = new draw.Path({
506
+ fill: {
507
+ color: highlightOptions.color,
508
+ opacity: highlightOptions.opacity
509
+ },
510
+ stroke: highlightOptions.border || null,
511
+ closed: true
512
+ });
513
+
514
+ this.surface.draw(this._categoryHighlight);
515
+ } else {
516
+ const options = this._categoryHighlight.options;
517
+ options.set("fill", {
518
+ color: highlightOptions.color,
519
+ opacity: highlightOptions.opacity
520
+ });
521
+ options.set("stroke", highlightOptions.border);
522
+ }
523
+
524
+ const slot = categoryAxis.getSlot(index);
525
+ const rect = slot.toRect();
526
+ let plotBox = plotArea.box;
527
+
528
+ if (categoryAxis.pane) {
529
+ plotBox = categoryAxis.pane.chartsBox();
530
+ }
531
+
532
+ if (categoryAxis.options.vertical) {
533
+ rect.origin.x = plotBox.x1;
534
+ rect.size.width = plotBox.width();
535
+ } else {
536
+ rect.origin.y = plotBox.y1;
537
+ rect.size.height = plotBox.height();
538
+ }
539
+
540
+ const newPath = draw.Path.fromRect(rect);
541
+ this._categoryHighlight.segments.elements(newPath.segments.elements());
542
+ this._categoryHighlight.visible(true);
543
+ }
544
+
545
+ _categoryHighlightEnabled() {
546
+ const plotArea = this._plotArea;
547
+ const categoryAxis = plotArea.categoryAxis || {};
548
+ const highlightOptions = (categoryAxis.options || {}).highlight;
549
+
550
+ return plotArea instanceof CategoricalPlotArea && highlightOptions && highlightOptions.visible;
551
+ }
552
+
484
553
  _sharedTooltip() {
485
554
  return this._plotArea instanceof CategoricalPlotArea && this.options.tooltip && this.options.tooltip.shared;
486
555
  }
@@ -1796,6 +1865,22 @@ class Chart {
1796
1865
  if (this._sharedTooltip()) {
1797
1866
  this._trackSharedTooltip(coords, e);
1798
1867
  }
1868
+
1869
+ if (this._categoryHighlightEnabled()) {
1870
+ this._trackCategoryHighlight(coords);
1871
+ }
1872
+ }
1873
+
1874
+ _trackCategoryHighlight(coords) {
1875
+ const { _plotArea: plotArea } = this;
1876
+ const categoryAxis = plotArea.categoryAxisByPoint(coords) || plotArea.categoryAxis;
1877
+
1878
+ if (plotArea.backgroundContainsPoint(coords)) {
1879
+ const index = categoryAxis.pointCategoryIndex(coords);
1880
+ this._toggleCategoryHighlight(index, categoryAxis);
1881
+ } else {
1882
+ this._toggleCategoryHighlight(null);
1883
+ }
1799
1884
  }
1800
1885
 
1801
1886
  _trackCrosshairs(coords) {
@@ -1862,6 +1947,8 @@ class Chart {
1862
1947
  plotArea.hideCrosshairs();
1863
1948
 
1864
1949
  this._unsetActivePoint(options);
1950
+
1951
+ this._toggleCategoryHighlight(null);
1865
1952
  }
1866
1953
 
1867
1954
  _unsetActivePoint(options) {
@@ -2001,7 +2088,7 @@ class Chart {
2001
2088
  }
2002
2089
 
2003
2090
  _shouldAttachMouseMove() {
2004
- return this._plotArea.crosshairs.length || (this._tooltip && this._sharedTooltip()) || this.requiresHandlers([ PLOT_AREA_HOVER, PLOT_AREA_LEAVE ]);
2091
+ return this._plotArea.crosshairs.length || (this._tooltip && this._sharedTooltip()) || this._categoryHighlightEnabled() || this.requiresHandlers([ PLOT_AREA_HOVER, PLOT_AREA_LEAVE ]);
2005
2092
  }
2006
2093
 
2007
2094
  updateMouseMoveHandler() {
@@ -2331,7 +2418,12 @@ setDefaultOptions(Chart, {
2331
2418
  }
2332
2419
  }
2333
2420
  },
2334
- categoryAxis: {},
2421
+ categoryAxis: {
2422
+ highlight: {
2423
+ visible: false,
2424
+ border: null
2425
+ }
2426
+ },
2335
2427
  seriesDefaults: {
2336
2428
  type: COLUMN,
2337
2429
  data: [],
@@ -883,6 +883,21 @@ class CategoricalPlotArea extends PlotAreaBase {
883
883
 
884
884
  return sortableSeries || stackableSeries && point.options.isStacked;
885
885
  }
886
+
887
+ categoryAxisByPoint(point) {
888
+ const axes = this.axes;
889
+ let axis;
890
+
891
+ for (let i = 0; i < axes.length; i++) {
892
+ const current = axes[i];
893
+ if (current instanceof CategoryAxis && current.pane.chartsBox().containsPoint(point)) {
894
+ axis = current;
895
+ break;
896
+ }
897
+ }
898
+
899
+ return axis;
900
+ }
886
901
  }
887
902
 
888
903
  function updateAxisOptions(targetOptions, axis, options) {
@@ -323,6 +323,12 @@ export const chartTheme = (element) => {
323
323
  font: defaultFont(element),
324
324
  }
325
325
  },
326
+ categoryAxis: {
327
+ highlight: {
328
+ color: "#8C9FD9",
329
+ opacity: 0.15
330
+ }
331
+ },
326
332
  chartArea: {
327
333
  background: chartBg,
328
334
  },
@@ -481,6 +481,75 @@ class Chart {
481
481
  return visual;
482
482
  }
483
483
 
484
+ _toggleCategoryHighlight(index, axis) {
485
+ const plotArea = this._plotArea;
486
+ const categoryAxis = axis || plotArea.categoryAxis;
487
+
488
+ if (this._categoryHighlightIndex === index && this._categoryHighlightAxis === categoryAxis) {
489
+ return;
490
+ }
491
+
492
+ this._categoryHighlightIndex = index;
493
+ this._categoryHighlightAxis = categoryAxis;
494
+
495
+ const highlightOptions = (categoryAxis.options || {}).highlight;
496
+
497
+ if (!highlightOptions || !highlightOptions.visible || index === null) {
498
+ if (this._categoryHighlight) {
499
+ this._categoryHighlight.visible(false);
500
+ }
501
+ return;
502
+ }
503
+
504
+ if (!this._categoryHighlight) {
505
+ this._categoryHighlight = new draw.Path({
506
+ fill: {
507
+ color: highlightOptions.color,
508
+ opacity: highlightOptions.opacity
509
+ },
510
+ stroke: highlightOptions.border || null,
511
+ closed: true
512
+ });
513
+
514
+ this.surface.draw(this._categoryHighlight);
515
+ } else {
516
+ const options = this._categoryHighlight.options;
517
+ options.set("fill", {
518
+ color: highlightOptions.color,
519
+ opacity: highlightOptions.opacity
520
+ });
521
+ options.set("stroke", highlightOptions.border);
522
+ }
523
+
524
+ const slot = categoryAxis.getSlot(index);
525
+ const rect = slot.toRect();
526
+ let plotBox = plotArea.box;
527
+
528
+ if (categoryAxis.pane) {
529
+ plotBox = categoryAxis.pane.chartsBox();
530
+ }
531
+
532
+ if (categoryAxis.options.vertical) {
533
+ rect.origin.x = plotBox.x1;
534
+ rect.size.width = plotBox.width();
535
+ } else {
536
+ rect.origin.y = plotBox.y1;
537
+ rect.size.height = plotBox.height();
538
+ }
539
+
540
+ const newPath = draw.Path.fromRect(rect);
541
+ this._categoryHighlight.segments.elements(newPath.segments.elements());
542
+ this._categoryHighlight.visible(true);
543
+ }
544
+
545
+ _categoryHighlightEnabled() {
546
+ const plotArea = this._plotArea;
547
+ const categoryAxis = plotArea.categoryAxis || {};
548
+ const highlightOptions = (categoryAxis.options || {}).highlight;
549
+
550
+ return plotArea instanceof CategoricalPlotArea && highlightOptions && highlightOptions.visible;
551
+ }
552
+
484
553
  _sharedTooltip() {
485
554
  return this._plotArea instanceof CategoricalPlotArea && this.options.tooltip && this.options.tooltip.shared;
486
555
  }
@@ -1796,6 +1865,22 @@ class Chart {
1796
1865
  if (this._sharedTooltip()) {
1797
1866
  this._trackSharedTooltip(coords, e);
1798
1867
  }
1868
+
1869
+ if (this._categoryHighlightEnabled()) {
1870
+ this._trackCategoryHighlight(coords);
1871
+ }
1872
+ }
1873
+
1874
+ _trackCategoryHighlight(coords) {
1875
+ const { _plotArea: plotArea } = this;
1876
+ const categoryAxis = plotArea.categoryAxisByPoint(coords) || plotArea.categoryAxis;
1877
+
1878
+ if (plotArea.backgroundContainsPoint(coords)) {
1879
+ const index = categoryAxis.pointCategoryIndex(coords);
1880
+ this._toggleCategoryHighlight(index, categoryAxis);
1881
+ } else {
1882
+ this._toggleCategoryHighlight(null);
1883
+ }
1799
1884
  }
1800
1885
 
1801
1886
  _trackCrosshairs(coords) {
@@ -1862,6 +1947,8 @@ class Chart {
1862
1947
  plotArea.hideCrosshairs();
1863
1948
 
1864
1949
  this._unsetActivePoint(options);
1950
+
1951
+ this._toggleCategoryHighlight(null);
1865
1952
  }
1866
1953
 
1867
1954
  _unsetActivePoint(options) {
@@ -2001,7 +2088,7 @@ class Chart {
2001
2088
  }
2002
2089
 
2003
2090
  _shouldAttachMouseMove() {
2004
- return this._plotArea.crosshairs.length || (this._tooltip && this._sharedTooltip()) || this.requiresHandlers([ PLOT_AREA_HOVER, PLOT_AREA_LEAVE ]);
2091
+ return this._plotArea.crosshairs.length || (this._tooltip && this._sharedTooltip()) || this._categoryHighlightEnabled() || this.requiresHandlers([ PLOT_AREA_HOVER, PLOT_AREA_LEAVE ]);
2005
2092
  }
2006
2093
 
2007
2094
  updateMouseMoveHandler() {
@@ -2331,7 +2418,12 @@ setDefaultOptions(Chart, {
2331
2418
  }
2332
2419
  }
2333
2420
  },
2334
- categoryAxis: {},
2421
+ categoryAxis: {
2422
+ highlight: {
2423
+ visible: false,
2424
+ border: null
2425
+ }
2426
+ },
2335
2427
  seriesDefaults: {
2336
2428
  type: COLUMN,
2337
2429
  data: [],
@@ -883,6 +883,21 @@ class CategoricalPlotArea extends PlotAreaBase {
883
883
 
884
884
  return sortableSeries || stackableSeries && point.options.isStacked;
885
885
  }
886
+
887
+ categoryAxisByPoint(point) {
888
+ const axes = this.axes;
889
+ let axis;
890
+
891
+ for (let i = 0; i < axes.length; i++) {
892
+ const current = axes[i];
893
+ if (current instanceof CategoryAxis && current.pane.chartsBox().containsPoint(point)) {
894
+ axis = current;
895
+ break;
896
+ }
897
+ }
898
+
899
+ return axis;
900
+ }
886
901
  }
887
902
 
888
903
  function updateAxisOptions(targetOptions, axis, options) {
@@ -323,6 +323,12 @@ export const chartTheme = (element) => {
323
323
  font: defaultFont(element),
324
324
  }
325
325
  },
326
+ categoryAxis: {
327
+ highlight: {
328
+ color: "#8C9FD9",
329
+ opacity: 0.15
330
+ }
331
+ },
326
332
  chartArea: {
327
333
  background: chartBg,
328
334
  },