From 9a98499cbc3463f70f1d842c12c87f6519749540 Mon Sep 17 00:00:00 2001 From: Piotr Rogowski Date: Mon, 31 Oct 2022 20:52:16 +0100 Subject: [PATCH] Small rusEFI fixes --- src/components/Logs/LogCanvas.tsx | 4 ++-- src/components/Tune/Dialog.tsx | 5 +++++ src/components/Tune/Dialog/SmartNumber.tsx | 6 ++++-- src/utils/numbers.ts | 7 ++++--- src/utils/tune/expression.ts | 3 ++- src/utils/tune/table.ts | 4 +++- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/components/Logs/LogCanvas.tsx b/src/components/Logs/LogCanvas.tsx index 10d8b9f..1b53e1c 100644 --- a/src/components/Logs/LogCanvas.tsx +++ b/src/components/Logs/LogCanvas.tsx @@ -8,7 +8,7 @@ import UplotReact from 'uplot-react'; import uPlot from 'uplot'; import { colorHsl, - formatNumber, + formatNumberMs, } from '../../utils/numbers'; import LandscapeNotice from '../Tune/Dialog/LandscapeNotice'; import { Colors } from '../../utils/colors'; @@ -88,7 +88,7 @@ const LogCanvas = ({ data, width, height, selectedFields1, selectedFields2, show stroke: hsl(index, selectedFieldsLength), scale: field.units, width: 2, - value: (_self, val) => `${(isNumber(val) ? formatNumber(val, field.format) : 0)}${field.units}`, + value: (_self, val) => `${(isNumber(val) ? formatNumberMs(val, field.format) : 0)}${field.units}`, }); data.forEach((entry) => { diff --git a/src/components/Tune/Dialog.tsx b/src/components/Tune/Dialog.tsx index f96eafd..3b9a1ff 100644 --- a/src/components/Tune/Dialog.tsx +++ b/src/components/Tune/Dialog.tsx @@ -145,6 +145,11 @@ const Dialog = ({ const y = tune.constants[table.yBins[0]]; const z = tune.constants[table.zBins[0]]; + if (!x || !y) { + // TODO: handle this (rusEFI: fuel/lambdaTableTbl) + return null; + } + return
{renderHelp(table.help)} { // eslint-disable-next-line prefer-template export const round = (value: number, digits: number | string = 0) => +(Math.round(value + `e+${digits}` as any) + `e-${digits}`); -// TODO: move this or rename to MS -export const formatNumber = (value: number, format: string): string => { +export const formatNumberMs = (value: number, format: string): string => { if (format === '%d') { return `${Math.round(value)}`; } @@ -60,5 +59,7 @@ export const formatNumber = (value: number, format: string): string => { const { digits } = match.groups!; - return round(value, digits).toFixed(digits as any); + return round(value, digits).toFixed(digits as unknown as number); }; + +export const formatNumber = (value: number, digits: number): string => round(value, digits).toFixed(digits); diff --git a/src/utils/tune/expression.ts b/src/utils/tune/expression.ts index eebc445..c49ac50 100644 --- a/src/utils/tune/expression.ts +++ b/src/utils/tune/expression.ts @@ -36,7 +36,8 @@ export const prepareConstDeclarations = (tuneConstants: TuneConstantsType, confi // escape string values if (typeof val === 'string') { - val = `'${val}'`; + // eslint-disable-next-line quotes + val = `'${val.replaceAll("'", "\\'")}'`; } // some names may have invalid characters, we can fix it or skip it diff --git a/src/utils/tune/table.ts b/src/utils/tune/table.ts index 3d77af7..c488d16 100644 --- a/src/utils/tune/table.ts +++ b/src/utils/tune/table.ts @@ -1,9 +1,11 @@ +import { round } from '../numbers'; + export const parseXy = (value: string) => value .trim() .split('\n') .map((val) => val.trim()) .filter((val) => val !== '') - .map(Number); + .map((val) => round(Number(val), 2)); export const parseZ = (value: string) => value .trim()