diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e84cf18..54145c8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Custom [getHoverSounding](https://chird.github.io/meteoJS/doc/module-meteoJS_thermodynamicDiagram_plotDataArea.html#~getHoverSounding) + function for + [PlotAltitudeDataArea](https://chird.github.io/meteoJS/doc/module-meteoJS_thermodynamicDiagram_plotAltitudeDataArea.PlotAltitudeDataArea.html), + [TDDiagram](https://chird.github.io/meteoJS/doc/module-meteoJS_thermodynamicDiagram_tdDiagram.TDDiagram.html), + [WindspeedProfile](https://chird.github.io/meteoJS/doc/module-meteoJS_thermodynamicDiagram_windspeedProfile.WindspeedProfile.html) and + [Hodograph](https://chird.github.io/meteoJS/doc/module-meteoJS_thermodynamicDiagram_hodograph.Hodograph.html). ## [1.16.0] - 2021-07-30 ### Added diff --git a/src/meteoJS/thermodynamicDiagram/Hodograph.js b/src/meteoJS/thermodynamicDiagram/Hodograph.js index adb56558..95980a2c 100644 --- a/src/meteoJS/thermodynamicDiagram/Hodograph.js +++ b/src/meteoJS/thermodynamicDiagram/Hodograph.js @@ -224,7 +224,7 @@ export class Hodograph extends PlotDataArea { origin = undefined, filterDataPoint = undefined, minDataPointsDistance = 0 - }) { + } = {}) { super({ svgNode, coordinateSystem, @@ -501,6 +501,7 @@ export class Hodograph extends PlotDataArea { nearestLevelData = {}; return nearestLevelData; }, + getHoverSounding = undefined, hodograph = {} }) { if (!('visible' in hodograph)) @@ -525,7 +526,8 @@ export class Hodograph extends PlotDataArea { type, maxDistance, insertLabelsFunc, - getLevelData + getLevelData, + getHoverSounding }); } diff --git a/src/meteoJS/thermodynamicDiagram/PlotAltitudeDataArea.js b/src/meteoJS/thermodynamicDiagram/PlotAltitudeDataArea.js index c9e7b8d1..295f6bd7 100644 --- a/src/meteoJS/thermodynamicDiagram/PlotAltitudeDataArea.js +++ b/src/meteoJS/thermodynamicDiagram/PlotAltitudeDataArea.js @@ -125,7 +125,8 @@ export class PlotAltitudeDataArea extends PlotDataArea { return {}; const sounding = hoverLabelsSounding.sounding; return sounding.getData(sounding.getNearestLevel(e.diagramPres)); - } + }, + getHoverSounding = undefined }) { this._isHoverLabelsRemote = remote; @@ -134,7 +135,8 @@ export class PlotAltitudeDataArea extends PlotDataArea { type, maxDistance, insertLabelsFunc, - getLevelData + getLevelData, + getHoverSounding }); } } diff --git a/src/meteoJS/thermodynamicDiagram/TDDiagram.js b/src/meteoJS/thermodynamicDiagram/TDDiagram.js index f699f52d..da2b1c29 100644 --- a/src/meteoJS/thermodynamicDiagram/TDDiagram.js +++ b/src/meteoJS/thermodynamicDiagram/TDDiagram.js @@ -1009,6 +1009,7 @@ export class TDDiagram extends PlotAltitudeDataArea { maxDistance = undefined, remote = true, insertLabelsFunc = undefined, + getHoverSounding = undefined, pres = {}, temp = {}, dewp = {}, @@ -1089,7 +1090,8 @@ export class TDDiagram extends PlotAltitudeDataArea { type, maxDistance, remote, - insertLabelsFunc + insertLabelsFunc, + getHoverSounding, }); } diff --git a/src/meteoJS/thermodynamicDiagram/WindspeedProfile.js b/src/meteoJS/thermodynamicDiagram/WindspeedProfile.js index 57c703ce..f5b1cf2d 100644 --- a/src/meteoJS/thermodynamicDiagram/WindspeedProfile.js +++ b/src/meteoJS/thermodynamicDiagram/WindspeedProfile.js @@ -63,11 +63,12 @@ import PlotAltitudeDataArea from './PlotAltitudeDataArea.js'; * * @typedef {module:meteoJS/thermodynamicDiagram/plotAltitudeDataArea~options} * module:meteoJS/thermodynamicDiagram/windspeedProfile~options + * @property {number} [windspeedMax=77.17] - Maximum visible windspeed, in m/s. * @property {Object} [grid] - Options for grid. * @property {module:meteoJS/thermodynamicDiagram/windspeedProfile~isotachsOptions} - * [isotachs] - Options for isotach grid. By default, the lines are grey and dashed. + * [grid.isotachs] - Options for isotach grid. By default, the lines are grey and dashed. * @property {module:meteoJS/thermodynamicDiagram/windspeedProfile~isobarsOptions} - * [isobars] - Options for isobar grid. By default, the lines are grey and dashed. + * [grid.isobars] - Options for isobar grid. By default, the lines are grey and dashed. */ /** @@ -117,7 +118,7 @@ export class WindspeedProfile extends PlotAltitudeDataArea { grid = {}, filterDataPoint = undefined, minDataPointsDistance = 0 - }) { + } = {}) { super({ svgNode, coordinateSystem, @@ -208,6 +209,7 @@ export class WindspeedProfile extends PlotAltitudeDataArea { maxDistance = undefined, remote = true, insertLabelsFunc = undefined, + getHoverSounding = undefined, windspeed = {} }) { if (!('visible' in windspeed)) @@ -236,7 +238,8 @@ export class WindspeedProfile extends PlotAltitudeDataArea { type, maxDistance, remote, - insertLabelsFunc + insertLabelsFunc, + getHoverSounding }); } diff --git a/test/meteoJS/thermodynamicDiagram/hodograph.test.js b/test/meteoJS/thermodynamicDiagram/hodograph.test.js index 7e2ebeb3..7eb4a3a6 100644 --- a/test/meteoJS/thermodynamicDiagram/hodograph.test.js +++ b/test/meteoJS/thermodynamicDiagram/hodograph.test.js @@ -962,6 +962,57 @@ describe('Hodograph class, import via default', () => { assert.equal(hodograph._hoverLabelsGroup.children()[0].attr('r'), 10, 'circle width in hoverLabelsGroup'); }); }); + it('default getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const plotArea = new Hodograph(); + assert.ok(plotArea._getHoverSounding !== undefined, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[0], 'all visible: hover first sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'first invisible: hover second sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'only second visible: hover second sounding'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'second and third visible: hover second sounding'); + }); + it('custom getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const getHoverSounding = s => { + for (const sounding of s) { + if (sounding == soundings[2]) + return sounding + } + return undefined; + }; + const plotArea = new Hodograph({ + hoverLabels: { + getHoverSounding + } + }); + assert.equal(plotArea._getHoverSounding, getHoverSounding, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'all visible: hover third sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'first invisible: hover third sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'only second visible: hover nothing'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'second and third visible: hover third sounding'); + }); }); }); describe('Hodograph class, import via name', () => { diff --git a/test/meteoJS/thermodynamicDiagram/plotAltitudeDataArea.test.js b/test/meteoJS/thermodynamicDiagram/plotAltitudeDataArea.test.js index d25a2f04..7d1c5675 100644 --- a/test/meteoJS/thermodynamicDiagram/plotAltitudeDataArea.test.js +++ b/test/meteoJS/thermodynamicDiagram/plotAltitudeDataArea.test.js @@ -41,6 +41,57 @@ describe('PlotAltitudeDataArea class, import via default', () => { s2.visible = false; assert.equal(plotArea.hoverLabelsSounding, s3, 'hoverLabelsSounding'); }); + it('default getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const plotArea = new PlotAltitudeDataArea(); + assert.ok(plotArea._getHoverSounding !== undefined, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[0], 'all visible: hover first sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'first invisible: hover second sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'only second visible: hover second sounding'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'second and third visible: hover second sounding'); + }); + it('custom getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const getHoverSounding = s => { + for (const sounding of s) { + if (sounding == soundings[2]) + return sounding + } + return undefined; + }; + const plotArea = new PlotAltitudeDataArea({ + hoverLabels: { + getHoverSounding + } + }); + assert.equal(plotArea._getHoverSounding, getHoverSounding, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'all visible: hover third sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'first invisible: hover third sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'only second visible: hover nothing'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'second and third visible: hover third sounding'); + }); it('empty construction', () => { const svgNode = SVG().size(300,300); const coordinateSystem = new SkewTlogPDiagram(); diff --git a/test/meteoJS/thermodynamicDiagram/tdDiagram.test.js b/test/meteoJS/thermodynamicDiagram/tdDiagram.test.js index 5d5288b8..24a854c5 100644 --- a/test/meteoJS/thermodynamicDiagram/tdDiagram.test.js +++ b/test/meteoJS/thermodynamicDiagram/tdDiagram.test.js @@ -161,6 +161,57 @@ describe('TDDiagram class, import via default', () => { assert.equal(diagram._hoverLabelsGroup.children()[6].children()[1].attr('font-size'), 50, 'font-size'); assert.equal(diagram._hoverLabelsGroup.children()[6].children()[1].attr('color'), 'yellow', 'color'); }); + it('default getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const plotArea = new TDDiagram(); + assert.ok(plotArea._getHoverSounding !== undefined, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[0], 'all visible: hover first sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'first invisible: hover second sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'only second visible: hover second sounding'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'second and third visible: hover second sounding'); + }); + it('custom getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const getHoverSounding = s => { + for (const sounding of s) { + if (sounding == soundings[2]) + return sounding + } + return undefined; + }; + const plotArea = new TDDiagram({ + hoverLabels: { + getHoverSounding + } + }); + assert.equal(plotArea._getHoverSounding, getHoverSounding, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'all visible: hover third sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'first invisible: hover third sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'only second visible: hover nothing'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'second and third visible: hover third sounding'); + }); it('parcels', () => { const diagram = new TDDiagram(); assert.equal(diagram._soundings.size, 0, 'soundings size'); diff --git a/test/meteoJS/thermodynamicDiagram/windspeedProfile.test.js b/test/meteoJS/thermodynamicDiagram/windspeedProfile.test.js index 0ca3b2ca..92c2ba6f 100644 --- a/test/meteoJS/thermodynamicDiagram/windspeedProfile.test.js +++ b/test/meteoJS/thermodynamicDiagram/windspeedProfile.test.js @@ -334,6 +334,57 @@ describe('WindspeedProfile class, import via default', () => { assert.equal(windprofile._hoverLabelsGroup.children()[0].attr().r, 3.5, 'circle'); assert.equal(windprofile._hoverLabelsGroup.children()[0].attr().fill, 'red', 'circle'); }); + it('default getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const plotArea = new WindspeedProfile(); + assert.ok(plotArea._getHoverSounding !== undefined, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[0], 'all visible: hover first sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'first invisible: hover second sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'only second visible: hover second sounding'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[1], 'second and third visible: hover second sounding'); + }); + it('custom getHoverSounding', () => { + const soundings = Array.from({length: 3}, () => { + const s = new Sounding(); + return new DiagramSounding(s); + }); + const getHoverSounding = s => { + for (const sounding of s) { + if (sounding == soundings[2]) + return sounding + } + return undefined; + }; + const plotArea = new WindspeedProfile({ + hoverLabels: { + getHoverSounding + } + }); + assert.equal(plotArea._getHoverSounding, getHoverSounding, 'internal getHoverSounding function'); + soundings.map(s => plotArea.addSounding(s)); + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'all visible: hover third sounding'); + soundings[0].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'first invisible: hover third sounding'); + soundings[1].visible = false; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'only third visible: hover third sounding'); + soundings[2].visible = false; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'no visible sounding'); + soundings[1].visible = true; + assert.equal(plotArea.hoverLabelsSounding, undefined, 'only second visible: hover nothing'); + soundings[2].visible = true; + assert.equal(plotArea.hoverLabelsSounding, soundings[2], 'second and third visible: hover third sounding'); + }); }); describe('WindspeedProfile class, import via name', () => { it('empty object', () => {