Commit c382d5d3 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

New function: get y-axis measurement unit symbol

Function provides a 'hack' that ensures that the correct phenomenon
symbols are displayed by a scatter plot's tooltip
parent 4b54e638
......@@ -177,6 +177,36 @@ const createSeriesOptionsForScatterPlot = function (
}
};
/**
* Match a scatter plot's y-axis phenomenon name to its corresponding symbol
*
* @param {String} seriesName A string representing a scatter plot's series name. It is made up of two phenomenon names separated by a comma
* @returns {String} The phenomenon's symbol
*/
const getYAxisUnitOfMeasurementSymbol = function (seriesName) {
const phenomenonNameToSymbolMapping = {
temperature: "\u00B0C",
flow: "m\u00B3/h",
power: "kW",
energy: "MWh",
};
// The `series.name` property for the scatter plot is made up of
// two phenomenon names delimited by a comma
// We are interested in the first string
const phenomenonNameYAxis = seriesName.split(",")[0].toLowerCase();
if (phenomenonNameYAxis.includes("temperature")) {
return phenomenonNameToSymbolMapping.temperature;
} else if (phenomenonNameYAxis.includes("flow")) {
return phenomenonNameToSymbolMapping.flow;
} else if (phenomenonNameYAxis.includes("power")) {
return phenomenonNameToSymbolMapping.power;
} else if (phenomenonNameYAxis.includes("energy")) {
return phenomenonNameToSymbolMapping.energy;
}
};
/**
* Draw a scatter plot using Highcharts library
* @param {Array} formattedObsArrayForSeriesOnePlusSeriesTwo Response from SensorThings API formatted for use in a scatter plot
......@@ -217,8 +247,7 @@ const drawScatterPlotHighcharts = function (
);
// The unit of measurement symbols for the x-axis is the first element of the array
// Assume that we will be comparing similar phenomena, so we can reuse this symbol
const UNIT_OF_MEASUREMENT_SYMBOL = unitOfMeasurementSymbolsArr[0];
const unitOfMeasurementXAxisSymbol = unitOfMeasurementSymbolsArr[0];
const MARKER_RADIUS = 2;
......@@ -302,9 +331,9 @@ const drawScatterPlotHighcharts = function (
const pointString = `<b>${this.point.y.toFixed(
2
)} ${UNIT_OF_MEASUREMENT_SYMBOL}, ${this.point.x.toFixed(
2
)} ${UNIT_OF_MEASUREMENT_SYMBOL}</b>`;
)} ${getYAxisUnitOfMeasurementSymbol(
this.series.name
)}, ${this.point.x.toFixed(2)} ${unitOfMeasurementXAxisSymbol}</b>`;
return headerString + pointString;
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment