From 61d26a7a2b30804f1e5b1d1df5c44d710f2ce688 Mon Sep 17 00:00:00 2001 From: Pierre Tilak Date: Wed, 6 Dec 2023 16:06:37 +0100 Subject: [PATCH] Use exponent or decimal scale based on y rage --- src/components/Graph.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/components/Graph.js b/src/components/Graph.js index b287f95..39499db 100644 --- a/src/components/Graph.js +++ b/src/components/Graph.js @@ -10,6 +10,7 @@ function Graph({ id, initialKeys, updateKeys, removeGraph }) { const [selectedOptions, setSelectedOptions] = useState([]); const [inputValue, setInputValue] = useState(""); const [data, setData] = useState([]); + const [exponentformat, setExponentformat] = useState('e'); useEffect(() => { getInitialData(); @@ -117,6 +118,7 @@ function Graph({ id, initialKeys, updateKeys, removeGraph }) { ) { plotData.autoScaleVerticalAxis(event); } + updateYAxisLayout(event); }; const handleInput = (value, event) => { @@ -153,6 +155,27 @@ function Graph({ id, initialKeys, updateKeys, removeGraph }) { return labels.includes(option.label); }; + const updateYAxisLayout = (event) => { + + const plot = document.getElementById(`plot-${id}`); + console.log(plot); + const range = plot.layout.yaxis.range; + console.log(plot.layout.yaxis.range); + + if(range.length>0){ + const yMax = Math.max(Math.abs(range[0]),Math.abs(range[1])); + console.log(yMax); + if(yMax<1000.){ + setExponentformat("none"); + } + else{ + setExponentformat("e"); + } + } + console.log(exponentformat); + } + + return (