Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add borders to sub nodes #276

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions src/factories/border.ts
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to this file fix an issue where if the width/height of the border was smaller than the radius the sprites would overlap. This makes sure the radius is not larger than the width/height.

Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ export function borderFactory() {

async function render(style: BorderStyle): Promise<Container> {
const { radius = 0, color = '#fff', stroke, width, height } = style
const size = radius * 2
const smallest = Math.min(width, height)
const size = radius * 2 > smallest ? smallest / 2 : radius * 2

const cornerStyle: CornerStyle = {
size,
radius,
radius: radius,
stroke,
}

Expand Down Expand Up @@ -110,8 +111,8 @@ export function borderFactory() {
}

function updateBorders({ texture, size, width, height, stroke }: UpdateBorders): void {
const sidesHeight = height - size * 2
const topAndBottomWidth = width - size * 2
const sidesHeight = Math.max(height - size * 2, 0)
const topAndBottomWidth = Math.max(width - size * 2, 0)

top.texture = texture
left.texture = texture
Expand Down
25 changes: 25 additions & 0 deletions src/factories/nodeFlowRun.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Container } from 'pixi.js'
import { DEFAULT_NODE_CONTAINER_NAME } from '@/consts'
import { borderFactory } from '@/factories/border'
import { nodeLabelFactory } from '@/factories/label'
import { nodeArrowButtonFactory } from '@/factories/nodeArrowButton'
import { nodeBarFactory } from '@/factories/nodeBar'
Expand All @@ -18,9 +19,11 @@ export async function flowRunContainerFactory(node: RunGraphNode) {
const { label, render: renderLabelText } = await nodeLabelFactory()
const { container: nodesContainer, render: renderNodes, stop: stopNodes, getHeight: getNodesHeight } = await nodesContainerFactory(node.id)
const { container: arrowButton, render: renderArrowButtonContainer } = await nodeArrowButtonFactory()
const { border, render: renderBorderContainer } = await borderFactory()

let isOpen = false

container.addChild(border)
container.addChild(bar)
container.addChild(label)
container.addChild(nodesContainer)
Expand All @@ -38,6 +41,7 @@ export async function flowRunContainerFactory(node: RunGraphNode) {
await renderBar(node)
await renderArrowButton()
await renderLabel()
await renderBorder()

return container
}
Expand All @@ -50,6 +54,26 @@ export async function flowRunContainerFactory(node: RunGraphNode) {
}
}

async function renderBorder(): Promise<void> {
const { background = '#fff' } = config.styles.node(node)
const offset = 4
const x = isOpen ? -offset : offset
const y = x
const width = isOpen ? bar.width + offset * 2 : bar.width - offset * 2
const height = isOpen ? getNodesHeight() : config.styles.nodeHeight
const stroke = isOpen ? 2 : 1

const border = await renderBorderContainer({
width,
height,
stroke,
radius: config.styles.nodeBorderRadius,
color: background,
})

border.position.set(x, y)
}

async function open(): Promise<void> {
isOpen = true

Expand Down Expand Up @@ -117,6 +141,7 @@ export async function flowRunContainerFactory(node: RunGraphNode) {
}

function resized(): void {
renderBorder()
const height = getHeight()

container.emit('resized', { height })
Expand Down