Skip to content

Commit

Permalink
Thermodynamic diagram: Bugfix for getHoverSounding option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Sonderegger committed Aug 16, 2021
1 parent 0b304f8 commit b94f951
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/meteoJS/thermodynamicDiagram/Hodograph.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Hodograph extends PlotDataArea {
origin = undefined,
filterDataPoint = undefined,
minDataPointsDistance = 0
}) {
} = {}) {
super({
svgNode,
coordinateSystem,
Expand Down Expand Up @@ -501,6 +501,7 @@ export class Hodograph extends PlotDataArea {
nearestLevelData = {};
return nearestLevelData;
},
getHoverSounding = undefined,
hodograph = {}
}) {
if (!('visible' in hodograph))
Expand All @@ -525,7 +526,8 @@ export class Hodograph extends PlotDataArea {
type,
maxDistance,
insertLabelsFunc,
getLevelData
getLevelData,
getHoverSounding
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/meteoJS/thermodynamicDiagram/PlotAltitudeDataArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -134,7 +135,8 @@ export class PlotAltitudeDataArea extends PlotDataArea {
type,
maxDistance,
insertLabelsFunc,
getLevelData
getLevelData,
getHoverSounding
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/meteoJS/thermodynamicDiagram/TDDiagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ export class TDDiagram extends PlotAltitudeDataArea {
maxDistance = undefined,
remote = true,
insertLabelsFunc = undefined,
getHoverSounding = undefined,
pres = {},
temp = {},
dewp = {},
Expand Down Expand Up @@ -1089,7 +1090,8 @@ export class TDDiagram extends PlotAltitudeDataArea {
type,
maxDistance,
remote,
insertLabelsFunc
insertLabelsFunc,
getHoverSounding,
});
}

Expand Down
11 changes: 7 additions & 4 deletions src/meteoJS/thermodynamicDiagram/WindspeedProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

/**
Expand Down Expand Up @@ -117,7 +118,7 @@ export class WindspeedProfile extends PlotAltitudeDataArea {
grid = {},
filterDataPoint = undefined,
minDataPointsDistance = 0
}) {
} = {}) {
super({
svgNode,
coordinateSystem,
Expand Down Expand Up @@ -208,6 +209,7 @@ export class WindspeedProfile extends PlotAltitudeDataArea {
maxDistance = undefined,
remote = true,
insertLabelsFunc = undefined,
getHoverSounding = undefined,
windspeed = {}
}) {
if (!('visible' in windspeed))
Expand Down Expand Up @@ -236,7 +238,8 @@ export class WindspeedProfile extends PlotAltitudeDataArea {
type,
maxDistance,
remote,
insertLabelsFunc
insertLabelsFunc,
getHoverSounding
});
}

Expand Down
51 changes: 51 additions & 0 deletions test/meteoJS/thermodynamicDiagram/hodograph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
51 changes: 51 additions & 0 deletions test/meteoJS/thermodynamicDiagram/plotAltitudeDataArea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
51 changes: 51 additions & 0 deletions test/meteoJS/thermodynamicDiagram/tdDiagram.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
51 changes: 51 additions & 0 deletions test/meteoJS/thermodynamicDiagram/windspeedProfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit b94f951

Please sign in to comment.