Skip to content

Commit 1a53632

Browse files
author
Ivo Sonderegger
committed
DiagramSounding: Define segments with different style for the hodograph
Relates to #39
1 parent 10035c1 commit 1a53632

File tree

2 files changed

+119
-3
lines changed

2 files changed

+119
-3
lines changed

src/meteoJS/thermodynamicDiagram/DiagramSounding.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,27 @@ function updateWindprofileOptions(options, updateOptions) {
373373
}
374374

375375
/**
376-
* Style/visibility options for a sounding in the hodograph.
376+
* Options for a line-segment of a sounding in the hodograph.
377+
*
378+
* @typedef {module:meteoJS/thermodynamicDiagram~lineOptions}
379+
* module:meteoJS/thermodynamicDiagram/diagramSounding~hodographSegmentOptions
380+
* @property {number|undefined}
381+
* [minPressure] - Minimum pressure level of the segment. Unit: hPa.
382+
* @property {number|undefined}
383+
* [maxPressure] - Maximum pressure level of the segment. Unit: hPa.
384+
*/
385+
386+
/**
387+
* Options for a sounding in the hodograph.
377388
*
378389
* @typedef {module:meteoJS/thermodynamicDiagram~lineOptions}
379390
* module:meteoJS/thermodynamicDiagram/diagramSounding~hodographOptions
380391
* @property {number|undefined}
381392
* [minPressure] - Minimum pressure level to plot in the hodograph. Unit: hPa.
382393
* @property {number|undefined}
383394
* [maxPressure] - Maximum pressure level to plot in the hodograph. Unit: hPa.
395+
* @property {module:meteoJS/thermodynamicDiagram/diagramSounding~hodographSegmentOptions[]}
396+
* [segments] - Array of segment definitions.
384397
*/
385398

386399
/**
@@ -395,11 +408,22 @@ function updateWindprofileOptions(options, updateOptions) {
395408
function getNormalizedHodographOptions({
396409
minPressure = undefined,
397410
maxPressure = undefined,
411+
segments = [],
398412
...result
399413
} = {}) {
400414
result = getNormalizedLineOptions(result);
401415
result.minPressure = minPressure;
402416
result.maxPressure = maxPressure;
417+
result.segments = segments.map(({
418+
minPressure = undefined,
419+
maxPressure = undefined,
420+
...segment
421+
}) => {
422+
segment = getNormalizedLineOptions(segment);
423+
segment.minPressure = minPressure;
424+
segment.maxPressure = maxPressure;
425+
return segment;
426+
});
403427
return result;
404428
}
405429

@@ -420,6 +444,17 @@ function updateHodographOptions(options, updateOptions) {
420444
if (styleKey in updateOptions)
421445
options[styleKey] = updateOptions[styleKey];
422446
});
447+
if ('segments' in updateOptions)
448+
options.segments = updateOptions.segments.map(({
449+
minPressure = undefined,
450+
maxPressure = undefined,
451+
...segment
452+
}) => {
453+
segment = getNormalizedLineOptions(segment);
454+
segment.minPressure = minPressure;
455+
segment.maxPressure = maxPressure;
456+
return segment;
457+
});
423458
return options;
424459
}
425460

test/meteoJS/thermodynamicDiagram/diagramSounding.test.js

+83-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ describe('DiagramSounding class, import via default', () => {
5454
assert.ok(Object.keys(s.options.hodograph.style).length > 1, 'style');
5555
assert.equal(s.options.hodograph.minPressure, undefined, 'hodograph.minPressure');
5656
assert.equal(s.options.hodograph.maxPressure, undefined, 'hodograph.maxPressure');
57+
assert.ok(s.options.hodograph.segments instanceof Array, 'hodograph.segments');
58+
assert.equal(s.options.hodograph.segments.length, 0, 'hodograph.segments');
5759
assert.equal(Object.keys(s.options.parcels).length, 2, 'length parcels options');
5860
assert.ok('default' in s.options.parcels, 'default');
5961
assert.equal(Object.keys(s.options.parcels.default).length, 3, 'length default options');
@@ -84,7 +86,16 @@ describe('DiagramSounding class, import via default', () => {
8486
width: 2
8587
},
8688
minPressure: 300,
87-
maxPressure: 900
89+
maxPressure: 900,
90+
segments: [{
91+
visible: false,
92+
minPressure: 500,
93+
maxPressure: 800,
94+
style: {
95+
color: 'red',
96+
width: 3
97+
}
98+
}]
8899
},
89100
parcels: {
90101
default: {
@@ -142,6 +153,14 @@ describe('DiagramSounding class, import via default', () => {
142153
assert.equal(s.options.hodograph.maxPressure, 900, 'hodograph.maxPressure');
143154
assert.equal(s.options.hodograph.style.color, 'black', 'color');
144155
assert.equal(s.options.hodograph.style.width, 2, 'width');
156+
assert.ok(s.options.hodograph.segments instanceof Array, 'hodograph.segments');
157+
assert.equal(s.options.hodograph.segments.length, 1, 'hodograph.segments');
158+
assert.equal(s.options.hodograph.segments[0].minPressure, 500, 'hodograph.segments[0].minPressure');
159+
assert.equal(s.options.hodograph.segments[0].maxPressure, 800, 'hodograph.segments[0].maxPressure');
160+
assert.equal(s.options.hodograph.segments[0].visible, false, 'hodograph.segments[0].visible');
161+
assert.equal(Object.keys(s.options.hodograph.segments[0].style).length, 2, 'keys hodograph.segments[0].style');
162+
assert.equal(s.options.hodograph.segments[0].style.color, 'red', 'hodograph.segments[0].style.color');
163+
assert.equal(s.options.hodograph.segments[0].style.width, 3, 'hodograph.segments[0].style.width');
145164
assert.equal(Object.keys(s.options.parcels).length, 3, 'length parcels options');
146165
assert.ok(!s.options.parcels.default.visible, 'default.visible');
147166
assert.equal(Object.keys(s.options.parcels.default).length, 3, 'length default parcels options');
@@ -208,7 +227,20 @@ describe('DiagramSounding class, import via default', () => {
208227
hodograph: {
209228
visible: true,
210229
style: { color: 'green' },
211-
minPressure: 200
230+
minPressure: 200,
231+
segments: [{
232+
minPressure: 300,
233+
maxPressure: 500,
234+
style: {
235+
color: 'orange'
236+
}
237+
}, {
238+
minPressure: 500,
239+
maxPressure: 700,
240+
style: {
241+
color: 'pink'
242+
}
243+
}]
212244
},
213245
parcels: {
214246
visible: true,
@@ -247,6 +279,14 @@ describe('DiagramSounding class, import via default', () => {
247279
assert.equal(s.options.hodograph.style.width, '1', 'width');
248280
assert.equal(s.options.hodograph.minPressure, 200, 'hodograph.minPressure');
249281
assert.equal(s.options.hodograph.maxPressure, undefined, 'hodograph.maxPressure');
282+
assert.ok(s.options.hodograph.segments instanceof Array, 'hodograph.segments');
283+
assert.equal(s.options.hodograph.segments.length, 2, 'hodograph.segments');
284+
assert.equal(s.options.hodograph.segments[0].minPressure, 300, 'hodograph.segments[0].minPressure');
285+
assert.equal(s.options.hodograph.segments[0].maxPressure, 500, 'hodograph.segments[0].maxPressure');
286+
assert.equal(s.options.hodograph.segments[0].visible, true, 'hodograph.segments[0].visible');
287+
assert.equal(Object.keys(s.options.hodograph.segments[0].style).length, 2, 'keys hodograph.segments[0].style');
288+
assert.equal(s.options.hodograph.segments[0].style.color, 'orange', 'hodograph.segments[0].style.color');
289+
assert.equal(s.options.hodograph.segments[0].style.width, 1, 'hodograph.segments[0].style.width');
250290
assert.ok(!s.options.parcels.default.visible, 'visible');
251291
assert.equal(s.options.parcels.default.temp.style.color, 'gray', 'color');
252292
assert.ok(!s.options.parcels.default.dewp.visible, 'visible');
@@ -258,6 +298,47 @@ describe('DiagramSounding class, import via default', () => {
258298
assert.ok(s.visible, 'visible');
259299
assert.equal(changeOptionsCounter, 2, 'changeOptionsCounter');
260300
assert.equal(changeVisibleCounter, 2, 'changeVisibleCounter');
301+
s.update({
302+
hodograph: {
303+
segments: [{
304+
minPressure: 850,
305+
maxPressure: 1000,
306+
style: {
307+
color: 'violet'
308+
}
309+
}]
310+
}
311+
});
312+
assert.equal(s.options.hodograph.style.color, 'green', 'color');
313+
assert.equal(s.options.hodograph.style.width, '1', 'width');
314+
assert.equal(s.options.hodograph.minPressure, 200, 'hodograph.minPressure');
315+
assert.equal(s.options.hodograph.maxPressure, undefined, 'hodograph.maxPressure');
316+
assert.ok(s.options.hodograph.segments instanceof Array, 'hodograph.segments');
317+
assert.equal(s.options.hodograph.segments.length, 1, 'hodograph.segments');
318+
assert.equal(s.options.hodograph.segments[0].minPressure, 850, 'hodograph.segments[0].minPressure');
319+
assert.equal(s.options.hodograph.segments[0].maxPressure, 1000, 'hodograph.segments[0].maxPressure');
320+
assert.equal(s.options.hodograph.segments[0].visible, true, 'hodograph.segments[0].visible');
321+
assert.equal(Object.keys(s.options.hodograph.segments[0].style).length, 2, 'keys hodograph.segments[0].style');
322+
assert.equal(s.options.hodograph.segments[0].style.color, 'violet', 'hodograph.segments[0].style.color');
323+
assert.equal(s.options.hodograph.segments[0].style.width, 1, 'hodograph.segments[0].style.width');
324+
s.update({
325+
hodograph: {
326+
minPressure: undefined,
327+
maxPressure: undefined
328+
}
329+
});
330+
assert.equal(s.options.hodograph.style.color, 'green', 'color');
331+
assert.equal(s.options.hodograph.style.width, '1', 'width');
332+
assert.equal(s.options.hodograph.minPressure, undefined, 'hodograph.minPressure');
333+
assert.equal(s.options.hodograph.maxPressure, undefined, 'hodograph.maxPressure');
334+
assert.ok(s.options.hodograph.segments instanceof Array, 'hodograph.segments');
335+
assert.equal(s.options.hodograph.segments.length, 1, 'hodograph.segments');
336+
assert.equal(s.options.hodograph.segments[0].minPressure, 850, 'hodograph.segments[0].minPressure');
337+
assert.equal(s.options.hodograph.segments[0].maxPressure, 1000, 'hodograph.segments[0].maxPressure');
338+
assert.equal(s.options.hodograph.segments[0].visible, true, 'hodograph.segments[0].visible');
339+
assert.equal(Object.keys(s.options.hodograph.segments[0].style).length, 2, 'keys hodograph.segments[0].style');
340+
assert.equal(s.options.hodograph.segments[0].style.color, 'violet', 'hodograph.segments[0].style.color');
341+
assert.equal(s.options.hodograph.segments[0].style.width, 1, 'hodograph.segments[0].style.width');
261342
});
262343
it('getParcelOptions()', () => {
263344
const sounding = new Sounding();

0 commit comments

Comments
 (0)