Skip to content

Commit

Permalink
fixed tooltip showing wrong q, better naming (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasmllr authored Mar 2, 2024
1 parent 1d2420b commit 7b959e5
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,8 @@
callbacks: {
label: function(context) {
var label = context.dataset.label || '';
let h_field = context.parsed.y
let q_field = context.parsed.x

// get toggle state of toggle_detailed_tooltip
var toggle_detailed_tooltip = document.getElementById("toggle_detailed_tooltip").checked
Expand All @@ -1270,7 +1272,7 @@
label = [];
if (toggle_detailed_tooltip == true) {
for (var idx in fielddatacsv.stage) {
if (fielddatacsv.stage[idx] == context.parsed.y && fielddatacsv.discharge[idx] == context.parsed.x) {
if (fielddatacsv.stage[idx] == h_field && fielddatacsv.discharge[idx] == q_field) {

// find discharge from rating curve for this stage
let q_model = null
Expand All @@ -1281,18 +1283,18 @@
for (var j in residualData[seg].data){
if (residualData[seg].data[j][0] == fielddatacsv.stage[idx]){
q_model = residualData[seg].data[j][1]
h_model = calc_h_model(context.parsed.x, rcParam[seg - 1].const, rcParam[seg - 1].exp, rcParam[seg - 1].offset)
r_percent = calc_residual_percent(context.parsed.y, context.parsed.x, rcParam[seg - 1].const, rcParam[seg - 1].exp, rcParam[seg - 1].offset)
r_volumetric = r_percent/100 * context.parsed.x
h_model = calc_h_model(q_field, rcParam[seg - 1].const, rcParam[seg - 1].exp, rcParam[seg - 1].offset)
r_percent = calc_residual_percent(h_field, q_field, rcParam[seg - 1].const, rcParam[seg - 1].exp, rcParam[seg - 1].offset)
r_volumetric = r_percent/100 * q_field
}
}
}
label.push(['H: ' + context.parsed.y.toFixed(2) + ' m']);
label.push(['Q: ' + context.parsed.x.toFixed(2) + ' m³/s']);
label.push(['H: ' + h_field.toFixed(2) + ' m']);
label.push(['Q: ' + q_field.toFixed(2) + ' m³/s']);
label.push(['date: ' + fielddatacsv.datetime[idx]]);
if (h_model !== null) {
label.push(['H shift: ' + (h_model - context.parsed.y).toFixed(2) + ' m'])
label.push(['H shift: ' + (h_model - context.parsed.y).toFixed(2) + ' m'])
label.push(['H shift: ' + (h_model - h_field).toFixed(2) + ' m'])
label.push(['H shift: ' + (h_model - h_field).toFixed(2) + ' m'])
}
//if (q_model !== null){
// label.push(['Q model: ' + q_model.toFixed(2) + ' m³/s']);
Expand All @@ -1310,8 +1312,8 @@
}
}
} else {
if (context.parsed.y !== null) {
label.push(['stage: ' + context.parsed.y.toFixed(2) + ' m, discharge: ' + context.parsed.x.toFixed(2) + ' m³/s']);
if (h_field !== null) {
label.push(['stage: ' + h_field.toFixed(2) + ' m, discharge: ' + q_field.toFixed(2) + ' m³/s']);
}
}
}
Expand Down Expand Up @@ -1506,11 +1508,11 @@

for (var idx in fielddatacsv.stage) {
if (fielddatacsv.stage[idx] == h_field && fielddatacsv.discharge[idx] == q_field_rounded) {
label.push(['H: ' + context.parsed.y.toFixed(2) + ' m']);
label.push(['Q: ' + context.parsed.x.toFixed(2) + ' m³/s']);
label.push(['H: ' + h_field.toFixed(2) + ' m']);
label.push(['Q: ' + q_field.toFixed(2) + ' m³/s']);
label.push(['date: ' + fielddatacsv.datetime[idx]]);
if (h_model !== null) {
label.push(['H shift: ' + (h_model - context.parsed.y).toFixed(2) + ' m'])
label.push(['H shift: ' + (h_model - h_field).toFixed(2) + ' m'])
}
//if (q_model !== null){
// label.push(['Q model: ' + q_model.toFixed(2) + ' m³/s']);
Expand Down

0 comments on commit 7b959e5

Please sign in to comment.