diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9106560f..224442ac 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,8 @@ { - "recommendations": ["Vue.volar", "streetsidesoftware.code-spell-checker", "dbaeumer.vscode-eslint"] + "recommendations": [ + "Vue.volar", + "streetsidesoftware.code-spell-checker", + "dbaeumer.vscode-eslint", + "aaron-bond.better-comments" + ] } diff --git a/packages/graph/src/base/types.ts b/packages/graph/src/base/types.ts index 784d7266..997c022e 100644 --- a/packages/graph/src/base/types.ts +++ b/packages/graph/src/base/types.ts @@ -105,8 +105,11 @@ export const MOVE_NODE_OPTIONS_DEFAULTS: MoveNodeOptions = { broadcast: true, }; -export const BULK_MOVE_NODE_OPTIONS_DEFAULTS: MoveNodeOptions = { +export type BulkMoveNodeOptions = BroadcastOption & AnimateOption; + +export const BULK_MOVE_NODE_OPTIONS_DEFAULTS: BulkMoveNodeOptions = { broadcast: true, + animate: false, }; export type EditEdgeLabelOptions = BroadcastOption & HistoryOption; diff --git a/packages/graph/src/base/useGraphCRUD.ts b/packages/graph/src/base/useGraphCRUD.ts index 21ef2db7..1945edba 100644 --- a/packages/graph/src/base/useGraphCRUD.ts +++ b/packages/graph/src/base/useGraphCRUD.ts @@ -12,6 +12,7 @@ import { getConnectedEdges } from '../helpers'; import { nodeLetterLabelGetter } from '../labels'; import type { GraphSettings } from '../settings'; import type { GEdge, GNode } from '../types'; +import { AnimationKeyframe } from './../../../shapes/src/animation/interpolation/types'; import type { GraphAnimations } from './animations'; import { ADD_EDGE_DEFAULTS, @@ -27,6 +28,7 @@ import { import type { AddEdgeOptions, AddNodeOptions, + BulkMoveNodeOptions, EditEdgeLabelOptions, MoveNodeOptions, RemoveEdgeOptions, @@ -166,6 +168,7 @@ export const useGraphCRUD = ({ focus: false, broadcast: false, history: false, + animate: fullOptions.animate, }); if (!newNode) continue; createdNodes.push(newNode); @@ -292,22 +295,22 @@ export const useGraphCRUD = ({ const bulkMoveNode = ( nodeMovements: GNodeMoveInstruction[], - options: Partial = {}, + options: Partial = {}, ) => { const fullOptions = { ...BULK_MOVE_NODE_OPTIONS_DEFAULTS, ...options, }; - const finalizeFrame = autoAnimate.captureFrame(() => - draw(getCtx(magicCanvas.canvas)), - ); + const animate = fullOptions.animate + ? autoAnimate.captureFrame(() => draw(getCtx(magicCanvas.canvas))) + : null; for (const { nodeId, coords } of nodeMovements) { moveNode(nodeId, coords, fullOptions); } - finalizeFrame(); + animate?.(); }; const editEdgeLabel = ( diff --git a/packages/graph/src/schematics/edge.ts b/packages/graph/src/schematics/edge.ts index 42f252c3..fcc3edb3 100644 --- a/packages/graph/src/schematics/edge.ts +++ b/packages/graph/src/schematics/edge.ts @@ -22,19 +22,19 @@ export const getEdgeSchematic = ( ): Omit | undefined => { const { displayEdgeLabels, isGraphDirected } = graph.settings.value; - const [from, to] = getConnectedNodes(edge.id, graph); - const edgesAlongPath = getEdgesAlongPath(from.id, to.id, graph); + const [fromNode, toNode] = getConnectedNodes(edge.id, graph); + const edgesAlongPath = getEdgesAlongPath(fromNode.id, toNode.id, graph); const multipleEdgesInPath = edgesAlongPath.length > 1; - const isSelfDirected = to === from; + const isSelfDirected = toNode.id === fromNode.id; - const fromNodeBorderWidth = graph.getTheme('nodeBorderWidth', from); - const toNodeBorderWidth = graph.getTheme('nodeBorderWidth', to); + const fromNodeBorderWidth = graph.getTheme('nodeBorderWidth', fromNode); + const toNodeBorderWidth = graph.getTheme('nodeBorderWidth', toNode); - const fromNodeSize = graph.getTheme('nodeSize', from); - const toNodeSize = graph.getTheme('nodeSize', to); + const fromNodeSize = graph.getTheme('nodeSize', fromNode); + const toNodeSize = graph.getTheme('nodeSize', toNode); - const angle = Math.atan2(to.y - from.y, to.x - from.x); + const angle = Math.atan2(toNode.y - fromNode.y, toNode.x - fromNode.x); const arrowHeadSpacingAwayFromNode = toNodeBorderWidth / 2 + WHITESPACE_BETWEEN_ARROW_TIP_AND_NODE; @@ -43,10 +43,10 @@ export const getEdgeSchematic = ( y: (toNodeSize + arrowHeadSpacingAwayFromNode) * Math.sin(angle), }; - const edgeStart = { x: from.x, y: from.y }; + const edgeStart = { x: fromNode.x, y: fromNode.y }; const edgeEnd = { - x: to.x - (isGraphDirected ? arrowDrawOffset.x : 0), - y: to.y - (isGraphDirected ? arrowDrawOffset.y : 0), + x: toNode.x - (isGraphDirected ? arrowDrawOffset.x : 0), + y: toNode.y - (isGraphDirected ? arrowDrawOffset.y : 0), }; const edgeWidth = graph.getTheme('edgeWidth', edge); @@ -74,10 +74,13 @@ export const getEdgeSchematic = ( * from causing angle issues when no other edges are present */ graph.edges.value - .filter((e) => (e.from === from.id || e.to === to.id) && e.from !== e.to) + .filter( + (e) => + (e.from === fromNode.id || e.to === toNode.id) && e.from !== e.to, + ) .map((e) => { const [fromNode, toNode] = getConnectedNodes(e.id, graph); - return from.id === fromNode.id ? toNode : fromNode; + return fromNode.id === fromNode.id ? toNode : fromNode; }) .filter( (point, index, self) => @@ -117,7 +120,7 @@ export const getEdgeSchematic = ( const shape = graph.shapes.uturn({ id: edge.id, spacing: edgeWidth * 1.2, - at: { x: from.x, y: from.y }, + at: { x: fromNode.x, y: fromNode.y }, upDistance, downDistance, rotation: largestAngularSpace, @@ -136,7 +139,7 @@ export const getEdgeSchematic = ( const sumOfToAndFromNodeSize = fromNodeSize + fromNodeBorderWidth / 2 + toNodeSize + toNodeBorderWidth / 2; const distanceSquaredBetweenNodes = - (from.x - to.x) ** 2 + (from.y - to.y) ** 2; + (fromNode.x - toNode.x) ** 2 + (fromNode.y - toNode.y) ** 2; const areNodesTouching = sumOfToAndFromNodeSize ** 2 > distanceSquaredBetweenNodes; diff --git a/packages/products/src/abstract-syntax-trees/MainView.vue b/packages/products/src/abstract-syntax-trees/MainView.vue index 98438e0b..18fe0b24 100644 --- a/packages/products/src/abstract-syntax-trees/MainView.vue +++ b/packages/products/src/abstract-syntax-trees/MainView.vue @@ -1,5 +1,6 @@ @@ -99,9 +119,9 @@