From 486a3568e93fa7bb748cc48fbeae48dc1c9835b4 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Sun, 16 Jun 2019 22:31:21 +0200 Subject: [PATCH] Allow plotting edge-case values --- app/src/components/Sidebar/CodeDiff/util.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/components/Sidebar/CodeDiff/util.tsx b/app/src/components/Sidebar/CodeDiff/util.tsx index ab71b47..0815366 100644 --- a/app/src/components/Sidebar/CodeDiff/util.tsx +++ b/app/src/components/Sidebar/CodeDiff/util.tsx @@ -49,6 +49,19 @@ export function toPlottableValue(value: any): number | undefined { if (isNumber && !isNaN(intVal)) { return intVal } + + // Convert "on" / "off" to int 1 / 0 + if (typeof value === 'string') { + if (/^(on$)|(off$)/i.test(value)) { + return value.toLowerCase() === 'on' ? 1 : 0 + } + if (/^[0-9]*,[0-9]+$/.test(value)) { + let parsedFloat = parseFloat(value.replace(',', '.')) + if (!isNaN(parsedFloat)) { + return parsedFloat + } + } + } } export function isPlottable(value: any) {