1. /**
  2. * @module meteoJS/thermodynamicDiagram/plotAltitudeDataArea
  3. */
  4. import PlotDataArea from './PlotDataArea.js';
  5. /**
  6. * Options for labels on hovering the diagram. Extended by the "remote" option.
  7. *
  8. * @typedef {module:meteoJS/thermodynamicDiagram/plotDataArea~hoverLabelsOptions}
  9. * module:meteoJS/thermodynamicDiagram/plotAltitudeDataArea~hoverLabelsOptions
  10. * @property {boolean} [remote=true]
  11. * Show labels relative to the mouse position on the diagram, even when the
  12. * pointer isn't directly on the plot area.
  13. */
  14. /**
  15. * Options for the constructor.
  16. *
  17. * @typedef {module:meteoJS/thermodynamicDiagram/plotDataArea~options}
  18. * module:meteoJS/thermodynamicDiagram/plotAltitudeDataArea~options
  19. * @property {module:meteoJS/thermodynamicDiagram/plotAltitudeDataArea~hoverLabelsOptions}
  20. * [hoverLabels] - Hover labels options.
  21. */
  22. /**
  23. * Abstract class to define an area on the SVG with sounding data, plotted with
  24. * pressure on the y-axis.
  25. *
  26. * <pre><code>import PlotAltitudeDataArea from 'meteojs/thermodynamicDiagram/PlotAltitudeDataArea';</code></pre>
  27. *
  28. * @extends module:meteoJS/thermodynamicDiagram/plotDataArea.PlotDataArea
  29. */
  30. export class PlotAltitudeDataArea extends PlotDataArea {
  31. /**
  32. * @param {module:meteoJS/thermodynamicDiagram/plotAltitudeDataArea~options}
  33. * options - Options.
  34. */
  35. constructor({
  36. svgNode = undefined,
  37. coordinateSystem = undefined,
  38. x = 0,
  39. y = 0,
  40. width = 100,
  41. height = 100,
  42. style = {},
  43. visible = true,
  44. events = {},
  45. hoverLabels = {},
  46. getSoundingVisibility = sounding => sounding.visible,
  47. dataGroupIds = undefined,
  48. getCoordinatesByLevelData = undefined,
  49. insertDataGroupInto = undefined,
  50. filterDataPoint = undefined,
  51. minDataPointsDistance = 0
  52. } = {}) {
  53. super({
  54. svgNode,
  55. coordinateSystem,
  56. x,
  57. y,
  58. width,
  59. height,
  60. style,
  61. visible,
  62. events,
  63. hoverLabels,
  64. getSoundingVisibility,
  65. dataGroupIds,
  66. getCoordinatesByLevelData,
  67. insertDataGroupInto,
  68. filterDataPoint,
  69. minDataPointsDistance
  70. });
  71. /**
  72. * @type boolean
  73. * @private
  74. */
  75. this._isHoverLabelsRemote;
  76. }
  77. /**
  78. * Extend an event with pressure.
  79. *
  80. * @override
  81. */
  82. getExtendedEvent(e, p) {
  83. e = super.getExtendedEvent(e, p);
  84. e.diagramPres = undefined;
  85. if (this.coordinateSystem !== undefined)
  86. e.diagramPres =
  87. this.coordinateSystem.getPByXY(0,
  88. this.coordinateSystem.height - e.elementY);
  89. return e;
  90. }
  91. /**
  92. * Show also hover labels when mouse isn't over the area.
  93. *
  94. * @type boolean
  95. * @readonly
  96. */
  97. get isHoverLabelsRemote() {
  98. return this._isHoverLabelsRemote;
  99. }
  100. /**
  101. * Initialize hover labels options.
  102. *
  103. * @param {module:meteoJS/thermodynamicDiagram/plotAltitudeDataArea~hoverLabelsOptions}
  104. * options - Hover labels options.
  105. * @override
  106. */
  107. _initHoverLabels({
  108. visible = true,
  109. type = 'mousemove',
  110. maxDistance = undefined,
  111. remote = true,
  112. insertLabelsFunc = undefined,
  113. getLevelData = ({ hoverLabelsSounding, e }) => {
  114. if (!e.diagramPres)
  115. return {};
  116. const sounding = hoverLabelsSounding.sounding;
  117. return sounding.getData(sounding.getNearestLevel(e.diagramPres));
  118. },
  119. getHoverSounding = undefined
  120. }) {
  121. this._isHoverLabelsRemote = remote;
  122. super._initHoverLabels({
  123. visible,
  124. type,
  125. maxDistance,
  126. insertLabelsFunc,
  127. getLevelData,
  128. getHoverSounding
  129. });
  130. }
  131. }
  132. export default PlotAltitudeDataArea;