Skip to content

Commit

Permalink
Fix #250 : add a grey rectangle to visually explain that the measurem…
Browse files Browse the repository at this point in the history
…ent does not have data for some low frequency range. Also fix the annoying version parameters not being taken into account in the URL
  • Loading branch information
pierreaubert committed Feb 20, 2024
1 parent 55afae8 commit 20b2316
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 32 deletions.
45 changes: 45 additions & 0 deletions src/website/assets/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,23 @@ function computeDims(windowWidth, windowHeight, is_vertical, is_compact, nb_grap
return [width, height];
}

function showMinMaxMeasurements(datas) {
let results = new Map();
for (let i in datas) {
if (datas[i].legendgrouptitle != null && datas[i].legendgrouptitle.text != null) {
const speaker_name = datas[i].legendgrouptitle.text;
if (datas[i].x != null && datas[i].x.length > 0) {
if (results.has(speaker_name)) {
results.set(speaker_name, Math.min(results.get(speaker_name), datas[i].x[0]));
} else {
results.set(speaker_name, datas[i].x[0]);
}
}
}
}
return results;
}

function setGraphOptions(spin, windowWidth, windowHeight, nb_graphs) {
let datas = null;
let layout = null;
Expand Down Expand Up @@ -362,6 +379,33 @@ function setGraphOptions(spin, windowWidth, windowHeight, nb_graphs) {
fontDelta = Math.round(windowWidth / 300);
}

function displayMeasurementsLimits(datas) {
let shapes = [];
const mins = showMinMaxMeasurements(datas);
mins.forEach((min_freq, speaker_name) => {
if (min_freq > 40) {
shapes.push({
type: 'rect',
xref: 'x',
yref: 'y',
x0: 20,
y0: -45,
x1: min_freq,
y1: 5,
fillcolor: '#d3d3d3',
opacity: 0.2,
line: { width: 2 },
label: {
text: 'No data below ' + Math.round(min_freq) + 'Hz for' + speaker_name,
font: { size: 10, color: 'green' },
textposition: 'top center',
},
});
}
});
return shapes;
}

function computeXaxis() {
if (layout.xaxis && layout.xaxis.title) {
layout.xaxis.title.text = 'SPL (dB) v.s. Frequency (Hz)';
Expand Down Expand Up @@ -668,6 +712,7 @@ function setGraphOptions(spin, windowWidth, windowHeight, nb_graphs) {
computeModbar();
computeColorbar();
computePolar();
layout.shapes = displayMeasurementsLimits(datas);
computeMargin(); // must be last
} else {
// should be a pop up
Expand Down
73 changes: 42 additions & 31 deletions src/website/assets/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {

function updateVersion(metaSpeakers, speaker, selector, origin, version) {
// update possible version(s) for matching speaker and origin
// console.log('update version for ' + speaker + ' origin=' + origin + ' version=' + version)
console.log('update version for ' + speaker + ' origin=' + origin + ' version=' + version);
const versions = Object.keys(metaSpeakers[speaker].measurements);
let matches = new Set();
versions.forEach((val) => {
Expand All @@ -58,8 +58,8 @@ function updateVersion(metaSpeakers, speaker, selector, origin, version) {
assignOptions(Array.from(matches), selector, correct_version);
}

function updateOrigin(metaSpeakers, speaker, originSelector, versionSelector, origin, version) {
// console.log('updateOrigin for ' + speaker + ' with origin ' + origin + ' version=' + version)
function updateOriginAndVersion(metaSpeakers, speaker, originSelector, versionSelector, origin, version) {
console.log('updateOrigin for ' + speaker + ' with origin ' + origin + ' version=' + version);
const measurements = Object.keys(metaSpeakers[speaker].measurements);
const origins = new Set();
for (const key in measurements) {
Expand Down Expand Up @@ -258,14 +258,14 @@ getMetadata()

function updateSpeakerPos(pos) {
// console.log('updateSpeakerPos(' + pos + ')')
updateOrigin(metaSpeakers, speakersSelector[pos].value, originsSelector[pos], versionsSelector[pos]);
updateOriginAndVersion(metaSpeakers, speakersSelector[pos].value, originsSelector[pos], versionsSelector[pos]);
urlParams.set('speaker' + pos, speakersSelector[pos].value);
updateOriginPos(pos);
}

function updateOriginPos(pos) {
// console.log('updateOriginPos(' + pos + ')')
updateOrigin(
updateOriginAndVersion(
metaSpeakers,
speakersSelector[pos].value,
originsSelector[pos],
Expand Down Expand Up @@ -299,35 +299,46 @@ getMetadata()
window.history.pushState({ page: 1 }, 'Compare speakers', urlCompare + urlParams.toString());
}

// initial setup
for (let pos = 0; pos < nbSpeakers; pos++) {
const tpos = pos.toString();
speakersSelector[pos] = formContainer.querySelector('#compare-select-speaker' + tpos);
originsSelector[pos] = formContainer.querySelector('#compare-select-origin' + tpos);
versionsSelector[pos] = formContainer.querySelector('#compare-select-version' + tpos);
fieldsetOriginsSelector[pos] = formContainer.querySelector('#compare-fieldset-origin' + tpos);
fieldsetVersionsSelector[pos] = formContainer.querySelector('#compare-fieldset-version' + tpos);
}
const initDatas = [];

for (let pos = 0; pos < nbSpeakers; pos++) {
assignOptions(speakers, speakersSelector[pos], initSpeakers[pos]);
}
assignOptions(knownMeasurements, graphsSelector, initMeasurement);
if (initDatas.length === 0) {
for (let pos = 0; pos < nbSpeakers; pos++) {
// read selectors
const tpos = pos.toString();
speakersSelector[pos] = formContainer.querySelector('#compare-select-speaker' + tpos);
originsSelector[pos] = formContainer.querySelector('#compare-select-origin' + tpos);
versionsSelector[pos] = formContainer.querySelector('#compare-select-version' + tpos);
fieldsetOriginsSelector[pos] = formContainer.querySelector('#compare-fieldset-origin' + tpos);
fieldsetVersionsSelector[pos] = formContainer.querySelector('#compare-fieldset-version' + tpos);

// assign initial values
assignOptions(speakers, speakersSelector[pos], initSpeakers[pos]);

// update associated origin and version
updateOriginAndVersion(
metaSpeakers,
speakersSelector[pos].value,
originsSelector[pos],
versionsSelector[pos],
initOrigins[pos],
initVersions[pos]
);

const initDatas = [];
for (let pos = 0; pos < nbSpeakers; pos++) {
updateOrigin(metaSpeakers, initSpeakers[pos], originsSelector[pos], versionsSelector[pos], null, null);
updateSpeakerPos(pos);
// console.log('DEBUG: ' + originsSelector[pos].options[0])
initDatas[pos] = getSpeakerData(
metaSpeakers,
initMeasurement,
initSpeakers[pos],
initOrigins[pos],
initVersions[pos]
);
// get data
initDatas[pos] = getSpeakerData(
metaSpeakers,
initMeasurement,
initSpeakers[pos],
initOrigins[pos],
initVersions[pos]
);
}

// update list of graphs in the form
assignOptions(knownMeasurements, graphsSelector, initMeasurement);
} else {
updateSpeakers();
}
updateSpeakers();

// add listeners
function windowChanges(event) {
Expand Down
2 changes: 1 addition & 1 deletion src/website/assets/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function sortMetadata2(metadata, sorter) {
const def = spk.default_measurement;
const msr = spk.measurements[def];
if ('sensitivity' in msr && 'sensitivity_1m' in msr.sensitivity) {
return spk.measurements[def].sensitivity.sensitivity_1m;
return spk.measurements[def].sensitivity.sensitivity_1m;
}
return 0.0;
}
Expand Down

0 comments on commit 20b2316

Please sign in to comment.