Skip to content

Commit

Permalink
round result numbers (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
madil4 authored Sep 21, 2023
1 parent 941cb2b commit 7eb07e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Viewer/objects/ElementResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function ElementResult(props: ElementResultProps) {

// text
const textPosition = start.clone().add(end).multiplyScalar(0.5).toArray();
const textValue = `${Math.round(props.result * 10000) / 10000}`;

onCleanup(() => {
plane.geometry.dispose();
Expand All @@ -81,7 +82,7 @@ export function ElementResult(props: ElementResultProps) {
{plane}
<Text
position={convertAxesToThreeJS(textPosition)}
text={`${props.result}`}
text={textValue}
size={props.size}
></Text>
</>
Expand Down
9 changes: 6 additions & 3 deletions src/Viewer/objects/NodeResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export function NodeResult(props: NodeResultProps) {
zArrow.dispose();
});

const roundTo5 = (number: number): number =>
Math.round(number * 10000) / 10000;

const textScale = 0.04 / 0.07;

return (
Expand All @@ -91,7 +94,7 @@ export function NodeResult(props: NodeResultProps) {
{xArrow}
{
<Text
text={`${props.result[0]}`}
text={`${roundTo5(props.result[0])}`}
position={xTextPosition()}
size={props.size * textScale}
/>
Expand All @@ -103,7 +106,7 @@ export function NodeResult(props: NodeResultProps) {
{yArrow}
{
<Text
text={`${props.result[1]}`}
text={`${roundTo5(props.result[1])}`}
position={yTextPosition()}
size={props.size * textScale}
/>
Expand All @@ -115,7 +118,7 @@ export function NodeResult(props: NodeResultProps) {
{zArrow}
{
<Text
text={`${props.result[2]}`}
text={`${roundTo5(props.result[2])}`}
position={zTextPosition()}
size={props.size * textScale}
/>
Expand Down

0 comments on commit 7eb07e6

Please sign in to comment.