Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion client/src/views/inspector/equation/EquationFieldSet.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useRef } from "react";
import { LuCircleHelp } from "react-icons/lu";

import { Field, FieldLabel, FieldSet } from "@/components/ui/field";
import { Textarea } from "@/components/ui/textarea";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import type { Flow, Node } from "@/models/graph";
import { useEquationController } from "@/utils/useEquationController";
import { useOutsideClickHandler } from "@/utils/useOutsideClickHandler";
Expand Down Expand Up @@ -32,7 +34,45 @@ export function EquationFieldSet({
<>
<FieldSet>
<Field>
<FieldLabel>Equation</FieldLabel>
<FieldLabel>
Equation
<Tooltip>
<TooltipTrigger asChild>
<LuCircleHelp />
</TooltipTrigger>
<TooltipContent className="flex flex-col gap-2 ml-2">
<div className="space-y-1">
<code className="font-semibold">
IF(cond, trueValue, falseValue)
</code>
<p className="text-sm text-background/70">
Returns <code className="text-gray-200">trueValue</code> if{" "}
<code className="text-gray-200">cond</code> is true,
otherwise <code className="text-gray-200">falseValue</code>.
</p>
</div>

<div className="space-y-1">
<code className="font-semibold">STEP(value, targetTime)</code>
<p className="text-sm text-background/70">
Returns <code className="text-gray-200">value</code> when{" "}
<code className="text-gray-200">targetTime</code> ≥ current
time, otherwise 0.
</p>
</div>

<div className="space-y-1">
<code className="font-semibold">
LOOKUP(target, x1, ..., xn, y1, ..., yn)
</code>
<p className="text-sm text-background/70">
Performs piecewise linear interpolation for{" "}
<code className="text-gray-200">target</code>.
</p>
</div>
</TooltipContent>
</Tooltip>
</FieldLabel>
<Textarea
name="equation"
className={`
Expand Down
4 changes: 2 additions & 2 deletions server/sim/functions.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package sim

// IF returns trueValue when cond is true and false otherwise
// IF returns trueValue when cond is true and falseValue otherwise
func IF(cond bool, trueValue float64, falseValue float64) float64 {
if cond {
return trueValue
}
return falseValue
}

// STEP returns the value if targetTime >= the environment's current time
// STEP returns value if targetTime >= the environment's current time
func STEP(value float64, targetTime float64, env RuntimeEnv) float64 {
currentTime, ok := env["currentTime"].(float64)
if !ok {
Expand Down
Loading