From 60a8558daf2e5a469d14b0fecd4c7919cc3eaa2d Mon Sep 17 00:00:00 2001 From: Mael Date: Sat, 20 Jul 2019 18:30:42 +0200 Subject: [PATCH] =?UTF-8?q?Affichage=20des=20unit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/evaluation.js | 2 +- source/engine/mecanismViews/Composantes.js | 8 +++++--- source/engine/mecanismViews/Product.js | 3 ++- source/engine/mecanismViews/Somme.js | 15 ++++++++------- source/engine/mecanismViews/Variations.js | 8 +++++--- source/engine/mecanismViews/common.js | 12 ++++++------ source/engine/mecanisms.js | 8 ++++---- source/engine/parse.js | 1 + source/engine/parseReference.js | 20 +++++++++++--------- 9 files changed, 43 insertions(+), 34 deletions(-) diff --git a/source/engine/evaluation.js b/source/engine/evaluation.js index e27bb97f6..ca59b46d3 100644 --- a/source/engine/evaluation.js +++ b/source/engine/evaluation.js @@ -16,7 +16,7 @@ import { export let makeJsx = node => typeof node.jsx == 'function' - ? node.jsx(node.nodeValue, node.explanation, node.lazyEval) + ? node.jsx(node.nodeValue, node.explanation, node.lazyEval, node.unit) : node.jsx export let collectNodeMissing = node => node.missingVariables || {} diff --git a/source/engine/mecanismViews/Composantes.js b/source/engine/mecanismViews/Composantes.js index 26787882e..ba44b47fc 100644 --- a/source/engine/mecanismViews/Composantes.js +++ b/source/engine/mecanismViews/Composantes.js @@ -10,7 +10,8 @@ import withLanguage from 'Components/utils/withLanguage' let Comp = withLanguage(function Composantes({ language, nodeValue, - explanation + explanation, + unit }) { return (

@@ -51,6 +53,6 @@ let Comp = withLanguage(function Composantes({ }) // eslint-disable-next-line -export default (nodeValue, explanation) => ( - +export default (nodeValue, explanation, _, unit) => ( + ) diff --git a/source/engine/mecanismViews/Product.js b/source/engine/mecanismViews/Product.js index b8f74395d..1cb81521a 100644 --- a/source/engine/mecanismViews/Product.js +++ b/source/engine/mecanismViews/Product.js @@ -4,13 +4,14 @@ import { Trans } from 'react-i18next' import { Node } from './common' import './InversionNumérique.css' -export default function ProductView(nodeValue, explanation) { +export default function ProductView(nodeValue, explanation, _, unit) { return ( // The rate and factor and threshold are given defaut neutral values. If there is nothing to explain, don't display them at all ( +const SommeNode = ({ explanation, nodeValue, unit }) => ( } + unit={unit} + child={} /> ) export default SommeNode -let Table = ({ explanation }) => ( +let Table = ({ explanation, unit }) => (
{explanation.map((v, i) => ( - + ))}
@@ -30,7 +31,7 @@ class Row extends Component { folded: true } render() { - let { v, i } = this.props, + let { v, i, unit } = this.props, rowFormula = path(['explanation', 'formule', 'explanation'], v), isSomme = rowFormula && rowFormula.name == 'somme' @@ -50,13 +51,13 @@ class Row extends Component { )}
- +
, ...(isSomme && !this.state.folded ? [
-
+
] : []) diff --git a/source/engine/mecanismViews/Variations.js b/source/engine/mecanismViews/Variations.js index df68bb469..af9f868f4 100644 --- a/source/engine/mecanismViews/Variations.js +++ b/source/engine/mecanismViews/Variations.js @@ -12,7 +12,8 @@ import './Variations.css' let Comp = withLanguage(function Variations({ language, nodeValue, - explanation + explanation, + unit }) { let [expandedVariation, toggleVariation] = useState(null) @@ -23,6 +24,7 @@ let Comp = withLanguage(function Variations({ classes="mecanism variations" name="variations" inline + unit={unit} value={nodeValue} child={ <> @@ -111,6 +113,6 @@ let Comp = withLanguage(function Variations({ ) }) // eslint-disable-next-line -export default (nodeValue, explanation) => ( - +export default (nodeValue, explanation, _, unit) => ( + ) diff --git a/source/engine/mecanismViews/common.js b/source/engine/mecanismViews/common.js index 11853fbd7..51b37dba7 100644 --- a/source/engine/mecanismViews/common.js +++ b/source/engine/mecanismViews/common.js @@ -35,7 +35,7 @@ export let NodeValuePointer = ({ data, unit }) => ( // Un élément du graphe de calcul qui a une valeur interprétée (à afficher) export class Node extends Component { render() { - let { classes, name, value, child, inline } = this.props, + let { classes, name, value, child, inline, unit } = this.props, termDefinition = contains('mecanism', classes) && name return ( @@ -58,7 +58,7 @@ export class Node extends Component { {name ? ( !isNil(value) && (
- +
) ) : ( @@ -66,7 +66,7 @@ export class Node extends Component { {value !== true && value !== false && !isNil(value) && ( = )} - + )} @@ -98,7 +98,7 @@ export const Leaf = compose( classes, dottedName, name, - value, + nodeValue, flatRules, filter, sitePaths, @@ -120,12 +120,12 @@ export const Leaf = compose( {rule.title || capitalise0(name)} {filter} - {!isNil(value) && ( + {!isNil(nodeValue) && ( - + )} diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index aa4441fa9..4c36925fe 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -138,7 +138,8 @@ export let mecanismVariations = (recurse, k, v, devariate) => { jsx: Variations, category: 'mecanism', name: 'variations', - type: 'numeric' + type: 'numeric', + unit: inferUnit('+', explanation.map(r => r.consequence.unit)) } } @@ -497,8 +498,8 @@ export let mecanismSum = (recurse, k, v) => { return { evaluate, // eslint-disable-next-line - jsx: (nodeValue, explanation) => ( - + jsx: (nodeValue, explanation, _, unit) => ( + ), explanation, category: 'mecanism', @@ -620,7 +621,6 @@ export let mecanismProduct = (recurse, k, v) => { } } - export let mecanismContinuousScale = (recurse, k, v) => { let objectShape = { assiette: false, diff --git a/source/engine/parse.js b/source/engine/parse.js index 7eebe2488..663196bb4 100644 --- a/source/engine/parse.js +++ b/source/engine/parse.js @@ -201,6 +201,7 @@ let mecanismOperation = (k, operatorFunction, symbol) => (recurse, k, v) => { diff --git a/source/engine/parseReference.js b/source/engine/parseReference.js index c222c9a4d..879aece22 100644 --- a/source/engine/parseReference.js +++ b/source/engine/parseReference.js @@ -21,7 +21,7 @@ export let parseReference = (rules, rule, parsedRules, filter) => ({ let parsedRule = parsedRules[dottedName] || - // the 'inversion numérique' formula should not exist. The instructions to the evaluation should be enough to infer that an inversion is necessary (assuming it is possible, the client decides this) + // the 'inversion numérique' formula should not exist. The instructions to the evaluation should be enough to infer that an inversion is necessary (assuming it is possible, the client decides this) (!inInversionFormula && parseRule(rules, findRuleByDottedName(rules, dottedName), parsedRules)) @@ -97,14 +97,16 @@ export let parseReference = (rules, rule, parsedRules, filter) => ({ evaluate, //eslint-disable-next-line react/display-name jsx: nodeValue => ( - + <> + + ), name: partialReference,