@vaadin/charts 23.1.0-alpha2 → 23.1.0-alpha3

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/vaadin-chart.js +56 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/charts",
3
- "version": "23.1.0-alpha2",
3
+ "version": "23.1.0-alpha3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -34,15 +34,15 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@polymer/polymer": "^3.0.0",
37
- "@vaadin/component-base": "23.1.0-alpha2",
37
+ "@vaadin/component-base": "23.1.0-alpha3",
38
38
  "@vaadin/vaadin-license-checker": "^2.1.0",
39
- "@vaadin/vaadin-themable-mixin": "23.1.0-alpha2",
39
+ "@vaadin/vaadin-themable-mixin": "23.1.0-alpha3",
40
40
  "highcharts": "9.2.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@esm-bundle/chai": "^4.3.4",
44
44
  "@vaadin/testing-helpers": "^0.3.2",
45
- "sinon": "^9.2.4"
45
+ "sinon": "^13.0.2"
46
46
  },
47
- "gitHead": "6842dcb8b163d4512fae8d3d12a6559077a4aee6"
47
+ "gitHead": "8c9e64e8dfa158dd52a9bf6da351ff038c88ca85"
48
48
  }
@@ -62,6 +62,10 @@ export function deepMerge(target, source) {
62
62
  /* eslint-enable no-invalid-this */
63
63
  });
64
64
 
65
+ // Init Highcharts global language defaults
66
+ // No data message should be empty by default
67
+ Highcharts.setOptions({ lang: { noData: '' } });
68
+
65
69
  /**
66
70
  * `<vaadin-chart>` is a Web Component for creating high quality charts.
67
71
  *
@@ -428,7 +432,6 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
428
432
  */
429
433
  emptyText: {
430
434
  type: String,
431
- value: ' ',
432
435
  reflectToAttribute: true
433
436
  },
434
437
 
@@ -532,9 +535,17 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
532
535
  this._jsonConfigurationBuffer = null;
533
536
  this.__initChart(options);
534
537
  this.__addChildObserver();
538
+ this.__checkTurboMode();
535
539
  });
536
540
  }
537
541
 
542
+ /** @protected */
543
+ ready() {
544
+ super.ready();
545
+
546
+ this.addEventListener('chart-redraw', this.__onRedraw.bind(this));
547
+ }
548
+
538
549
  /**
539
550
  * @return {!Options}
540
551
  */
@@ -1032,13 +1043,7 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
1032
1043
  // Best effort to make chart display custom empty-text messages when series are removed.
1033
1044
  // This is needed because Highcharts currently doesn't react. A condition not catered for is
1034
1045
  // when all points are removed from all series without removing any series.
1035
- const isEmpty =
1036
- this.configuration.series.length === 0 ||
1037
- this.configuration.series.map((e) => e.data.length === 0).reduce((e1, e2) => e1 && e2, true);
1038
- if (isEmpty) {
1039
- this.configuration.hideNoData();
1040
- this.configuration.showNoData(this.emptyText);
1041
- }
1046
+ this.__updateNoDataElement(this.configuration);
1042
1047
  }
1043
1048
 
1044
1049
  /** @private */
@@ -1664,8 +1669,21 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
1664
1669
  noData: emptyText
1665
1670
  }
1666
1671
  });
1667
- config.hideNoData();
1668
- config.showNoData(emptyText);
1672
+ this.__updateNoDataElement(config);
1673
+ }
1674
+
1675
+ /**
1676
+ * Force the no data text element to become visible if the chart has no data.
1677
+ * This is necessary in cases where Highcharts does not update the element
1678
+ * automatically, for example when setting the language config
1679
+ * @private
1680
+ */
1681
+ __updateNoDataElement(config) {
1682
+ const isEmpty = config.series.every((e) => e.data.length === 0);
1683
+ if (isEmpty) {
1684
+ config.hideNoData();
1685
+ config.showNoData(this.emptyText);
1686
+ }
1669
1687
  }
1670
1688
 
1671
1689
  /** @private */
@@ -1771,6 +1789,34 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
1771
1789
  __showWarn(propertyName, acceptedValues) {
1772
1790
  console.warn('<vaadin-chart> Acceptable values for "' + propertyName + '" are ' + acceptedValues);
1773
1791
  }
1792
+
1793
+ /** @private */
1794
+ __onRedraw() {
1795
+ this.__checkTurboMode();
1796
+ }
1797
+
1798
+ /** @private */
1799
+ __checkTurboMode() {
1800
+ const isDevelopmentMode = !!window.Vaadin.developmentMode;
1801
+
1802
+ if (!this.configuration || !isDevelopmentMode || this.__turboModeWarningAlreadyLogged) {
1803
+ return;
1804
+ }
1805
+
1806
+ const exceedsTurboThreshold = this.configuration.series.some((series) => {
1807
+ const threshold = (series.options && series.options.turboThreshold) || 0;
1808
+ const dataLength = series.data.length;
1809
+
1810
+ return threshold > 0 && dataLength > threshold;
1811
+ });
1812
+
1813
+ if (exceedsTurboThreshold) {
1814
+ this.__turboModeWarningAlreadyLogged = true;
1815
+ console.warn(
1816
+ '<vaadin-chart> Turbo mode has been enabled for one or more series, because the number of data items exceeds the configured threshold. Turbo mode improves the performance of charts with lots of data, but is not compatible with every type of series. Please consult the documentation on compatibility, or how to disable turbo mode.'
1817
+ );
1818
+ }
1819
+ }
1774
1820
  }
1775
1821
 
1776
1822
  customElements.define(Chart.is, Chart);