PlotBandSeries.experimental.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* *
  2. * (c) 2010-2019 Torstein Honsi
  3. *
  4. * License: www.highcharts.com/license
  5. */
  6. /* ************************************************************************** *
  7. * Start PlotBand series code *
  8. * ************************************************************************** */
  9. /* This is an experiment of implementing plotBands and plotLines as a series.
  10. It could solve problems with export, updating etc., add tooltip and mouse
  11. events, and provide a more compact and consistent implementation.
  12. Demo: https://jsfiddle.net/highcharts/5Rbf6/ */
  13. 'use strict';
  14. import H from './Globals.js';
  15. import './Utilities.js';
  16. import './Series.js';
  17. import './Options.js';
  18. var seriesType = H.seriesType,
  19. Series = H.Series;
  20. seriesType('plotband', 'column', {
  21. lineWidth: 0,
  22. threshold: null
  23. }, {
  24. // mapping between SVG attributes and the corresponding options
  25. pointAttrToOptions: {
  26. fill: 'color',
  27. stroke: 'lineColor',
  28. 'stroke-width': 'lineWidth'
  29. },
  30. animate: function () {},
  31. translate: function () {
  32. var series = this,
  33. xAxis = series.xAxis,
  34. yAxis = series.yAxis;
  35. Series.prototype.translate.apply(series);
  36. series.points.forEach(function (point) {
  37. var onXAxis = point.onXAxis,
  38. ownAxis = onXAxis ? xAxis : yAxis,
  39. otherAxis = onXAxis ? yAxis : xAxis,
  40. from = ownAxis.toPixels(point.from, true),
  41. to = ownAxis.toPixels(point.to, true),
  42. start = Math.min(from, to),
  43. width = Math.abs(to - from);
  44. point.plotY = 1; // lure ColumnSeries.drawPoints
  45. point.shapeType = 'rect';
  46. point.shapeArgs = ownAxis.horiz ? {
  47. x: start,
  48. y: 0,
  49. width: width,
  50. height: otherAxis.len
  51. } : {
  52. x: 0,
  53. y: start,
  54. width: otherAxis.len,
  55. height: width
  56. };
  57. });
  58. }
  59. });
  60. /* ************************************************************************** *
  61. * End PlotBand series code *
  62. * ************************************************************************** */