Files
windmill/frontend/src/lib/components/graph/util.ts
T
Faton Ramadani c483d06e4d feat(frontend): Decision tree (#2812)
* feat(frontend): wip

* feat(frontend): wip

* feat(frontend): wip

* feat(frontend): wip

* feat(frontend): deicision tree v0

* feat(frontend): deicision tree v0

* feat(frontend): fix build

* feat(frontend): fix events

* feat(frontend): add branch

* feat(frontend): interactions done

* feat(frontend): fix graph display

* feat(frontend): fix rendering

* feat(frontend): add end props

* feat(frontend): working empty branches

* feat(frontend): code cleanup

* feat(frontend): code cleanup

* feat(frontend): fix subgrids sync

* feat(frontend): add missing events

* feat(frontend): clean up comments

* feat(frontend): fix inputValue key

* feat(frontend): clean up comments

* feat(frontend): compute first node

* feat(frontend): fix layout

* feat(frontend): fix actions

* feat(frontend): remove console.log

* feat(frontend): fix styling + add debug mode + use label in output panel

* feat(frontend): fix styling

* feat(frontend): fix styling

* feat(frontend): done

* feat(frontend): done

* feat(frontend): done

* feat(frontend): fix add

* feat(frontend): fix delete

* feat(frontend): minor fix

* feat(frontend): fix preivous buttons

* feat(frontend): Fix the eval preview

* feat(frontend): Remove log

* feat(frontend): fix wording

* feat(frontend): select the tab in the app editor when selecting the node
2023-12-15 15:19:59 +01:00

86 lines
2.0 KiB
TypeScript

import { FlowStatusModule, type FlowModule } from '$lib/gen'
import MapItem from '../flows/map/MapItem.svelte'
import type { GraphModuleState } from './model'
export const NODE = {
width: 275,
height: 34,
gap: {
horizontal: 40,
vertical: 50
}
}
export function* createIdGenerator(): Generator<number, number, unknown> {
let id = 0
while (true) {
yield id++
}
}
export function getStateColor(state: FlowStatusModule.type | undefined): string {
const isDark = document.documentElement.classList.contains('dark')
switch (state) {
case FlowStatusModule.type.SUCCESS:
return isDark ? '#059669' : 'rgb(193, 255, 216)'
case FlowStatusModule.type.FAILURE:
return isDark ? '#dc2626' : 'rgb(248 113 113)'
case FlowStatusModule.type.IN_PROGRESS:
return isDark ? '#f59e0b' : 'rgb(253, 240, 176)'
case FlowStatusModule.type.WAITING_FOR_EVENTS:
return isDark ? '#db2777' : 'rgb(229, 176, 253)'
case FlowStatusModule.type.WAITING_FOR_EXECUTOR:
return isDark ? '#ea580c' : 'rgb(255, 208, 193)'
default:
return isDark ? '#2e3440' : '#fff'
}
}
export function flowModuleToNode(
parentIds: string[],
mod: FlowModule,
edgeLabel: string | undefined,
annotation: string | undefined,
loopDepth: number,
insertableEnd: boolean,
branchable: boolean,
modules: FlowModule[],
callbackHandler: (event: string, detail: any) => void,
flowModuleStates: Record<string, GraphModuleState>,
insertable: boolean,
moving: boolean,
disableAi: boolean
) {
return {
type: 'node',
id: mod.id,
position: { x: -1, y: -1 },
data: {
custom: {
component: MapItem,
props: {
trigger: parentIds.length == 0,
mod,
insertable,
insertableEnd,
branchable,
duration_ms: flowModuleStates?.[mod.id]?.duration_ms,
bgColor: getStateColor(flowModuleStates?.[mod.id]?.type),
annotation,
modules,
moving,
disableAi
},
cb: callbackHandler
}
},
width: NODE.width,
height: NODE.height,
parentIds,
sourcePosition: 'bottom',
targetPosition: 'top',
edgeLabel,
loopDepth
}
}