Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/client/app/components/CompareLineChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ export default function CompareLineChartComponent() {
}

// Adding information to the shifted data so that it can be plotted on the same graph with current data
const shiftedLabel = translate('shifted');
const updateDataNew = dataNew.map(item => ({
...item,
name: 'Shifted ' + item.name,
name: `${shiftedLabel} ${item.name}`,
line: { ...item.line, color: '#1AA5F0' },
xaxis: 'x2',
text: Array.isArray(item.text)
? item.text.map(text => text.replace('<br>', '<br>Shifted '))
: item.text?.replace('<br>', '<br>Shifted ')
? item.text.map(text => text.replace('<br>', `<br>${shiftedLabel} `))
: item.text?.replace('<br>', `<br>${shiftedLabel} `)
}));

return (
Expand Down Expand Up @@ -194,19 +195,21 @@ export default function CompareLineChartComponent() {
* @param shiftedReading shifted data to compare
*/
function checkReceivedData(originalReading: any, shiftedReading: any) {
const translate = useTranslate();
Comment thread
Nespina24 marked this conversation as resolved.
Outdated
let numberPointsSame = true;
if (originalReading.length !== shiftedReading.length) {
// If the number of points vary then then scales will not line up point by point. Warn the user.
numberPointsSame = false;
showWarnNotification(
`The original line has ${originalReading.length} readings but the shifted line has ${shiftedReading.length}`
+ ' readings which means the points will not align horizontally.'
`${translate('compare.line.original.shifted.count.a')} ${originalReading.length} ` +
`${translate('compare.line.original.shifted.count.b')} ${shiftedReading.length} ` +
`${translate('compare.line.original.shifted.count.c')}`
);
}
// Now see if the original and shifted lines overlap.
if (moment(shiftedReading.at(-1).toString()) > moment(originalReading.at(0).toString())) {
showInfoNotification(
`The shifted line overlaps the original line starting at ${originalReading[0]}`,
`${translate('compare.line.shifted.overlaps.start.prefix')} ${originalReading[0]}`,
toast.POSITION.TOP_RIGHT,
15000
);
Expand All @@ -217,7 +220,7 @@ function checkReceivedData(originalReading: any, shiftedReading: any) {
const firstOriginReadingDay = moment(originalReading.at(0)?.toString());
const firstShiftedReadingDay = moment(shiftedReading.at(0)?.toString());
if (numberPointsSame && firstOriginReadingDay.day() === firstShiftedReadingDay.day()) {
showInfoNotification('Days of week align (unless missing readings)',
showInfoNotification(translate('compare.line.days.align'),
toast.POSITION.TOP_RIGHT,
15000
);
Expand All @@ -227,12 +230,12 @@ function checkReceivedData(originalReading: any, shiftedReading: any) {
if (numberPointsSame && monthDateSame(firstOriginReadingDay, firstShiftedReadingDay)) {
// Loop over all readings but the first. Really okay to do first but just checked that one.
// Note length of original and shifted same so just use original.
let message = 'The month and day of the month align for the original and shifted readings';
let message = translate('compare.line.month.day.align');
for (let i = 1; i < originalReading.length; i++) {
if (!monthDateSame(moment(originalReading.at(i)?.toString()), moment(shiftedReading.at(i)?.toString()))) {
// Mismatch so inform user. Should be due to leap year crossing and differing leap year.
// Only tell first mistmatch
message += ` until original reading at date ${moment(originalReading.at(i)?.toString()).format('ll')}`;
message += `${translate('compare.line.month.day.align.until.prefix')} ${moment(originalReading.at(i)?.toString()).format('ll')}`;
break;
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/client/app/translations/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ const LocaleTranslationData = {
"select.unit": "Select Unit",
"shift.date.interval": "Shift Date Interval",
"shifted.data.crosses.leap.year.to.non.leap.year": "Shifted data crosses a leap year so the graph might not align appropriately",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find where this is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, this line of code has been here since before I was working on it. Regardless, I deleted it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I missed that you did not make the change.

"shifted": "Shifted",
"compare.line.original.shifted.count": "The original line has {original} readings but the shifted line has {shifted}, which means the points will not align horizontally.",
Comment thread
Nespina24 marked this conversation as resolved.
Outdated
"compare.line.original.shifted.count.a": "The original line has ",
Comment thread
Nespina24 marked this conversation as resolved.
Outdated
"compare.line.original.shifted.count.b": " readings but the shifted line has ",
"compare.line.original.shifted.count.c": ", which means the points will not align horizontally.",
"compare.line.shifted.overlaps.start": "The shifted line overlaps the original line starting at {start}",
Comment thread
Nespina24 marked this conversation as resolved.
Outdated
"compare.line.shifted.overlaps.start.prefix": "The shifted line overlaps the original line starting at ",
"compare.line.days.align": "Days of week align (unless missing readings)",
"compare.line.month.day.align": "The month and day of the month align for the original and shifted readings",
"compare.line.month.day.align.until": " until original reading at date {date}",
Comment thread
Nespina24 marked this conversation as resolved.
Outdated
"show": "Show",
"show.all.logs": "Show All Logs ",
"show.grid": "Show grid",
Expand Down Expand Up @@ -1074,6 +1084,16 @@ const LocaleTranslationData = {
"select.unit": "Select Unit\u{26A1}",
"shift.date.interval": "Shift Date Interval\u{26A1}",
"shifted.data.crosses.leap.year.to.non.leap.year": "Shifted data crosses a leap year so the graph might not align appropriately\u{26A1}",
"shifted": "Décalé\u{26A1}",
Comment thread
Nespina24 marked this conversation as resolved.
Outdated
"compare.line.original.shifted.count": "La courbe originale a {original} lectures mais la courbe décalée en a {shifted}, ce qui signifie que les points ne s'aligneront pas horizontalement.",
"compare.line.original.shifted.count.a": "La courbe originale a ",
"compare.line.original.shifted.count.b": " lectures mais la courbe décalée en a ",
"compare.line.original.shifted.count.c": ", ce qui signifie que les points ne s'aligneront pas horizontalement.",
"compare.line.shifted.overlaps.start": "La courbe décalée chevauche la courbe originale à partir de {start}",
"compare.line.shifted.overlaps.start.prefix": "La courbe décalée chevauche la courbe originale à partir de ",
"compare.line.days.align": "Les jours de la semaine s'alignent (sauf si des lectures manquent)",
"compare.line.month.day.align": "Le mois et le jour du mois s'alignent pour les lectures originales et décalées",
"compare.line.month.day.align.until": " jusqu'à la lecture originale à la date {date}",
"show": "Montrer",
"show.all.logs": "Show All Logs\u{26A1} ",
"show.grid": "Show grid\u{26A1}",
Expand Down Expand Up @@ -1662,6 +1682,16 @@ const LocaleTranslationData = {
"select.unit": "Seleccionar unidad",
"shift.date.interval": "Shift Date Interval\u{26A1}",
"shifted.data.crosses.leap.year.to.non.leap.year": "Shifted data crosses a leap year so the graph might not align appropriately\u{26A1}",
"shifted": "Desplazado\u{26A1}",
"compare.line.original.shifted.count": "La línea original tiene {original} lecturas pero la línea desplazada tiene {shifted}, lo que significa que los puntos no se alinearán horizontalmente.",
"compare.line.original.shifted.count.a": "La línea original tiene ",
"compare.line.original.shifted.count.b": " lecturas pero la línea desplazada tiene ",
"compare.line.original.shifted.count.c": ", lo que significa que los puntos no se alinearán horizontalmente.",
"compare.line.shifted.overlaps.start": "La línea desplazada se superpone a la línea original empezando en {start}",
"compare.line.shifted.overlaps.start.prefix": "La línea desplazada se superpone a la línea original empezando en ",
"compare.line.days.align": "Los días de la semana coinciden (a menos que falten lecturas)",
"compare.line.month.day.align": "El mes y el día del mes coinciden para las lecturas originales y desplazadas",
"compare.line.month.day.align.until": " hasta la lectura original con fecha {date}",
"show": "Mostrar",
"show.all.logs": "Show All Logs\u{26A1} ",
"show.grid": "Mostrar rejilla",
Expand Down
Loading