Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2288] Make IconLabel a react flow node
Bug: #2288 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
- Loading branch information
Showing
19 changed files
with
360 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...nd/sirius-components-diagrams-reactflow/src/renderer/layout/IconLabelNodeLayoutHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
import { Node } from 'reactflow'; | ||
import { Diagram, NodeData } from '../DiagramRenderer.types'; | ||
import { IconLabelNodeData } from '../node/IconsLabelNode.types'; | ||
import { DiagramNodeType } from '../node/NodeTypes.types'; | ||
import { ILayoutEngine, INodeLayoutHandler } from './LayoutEngine.types'; | ||
|
||
export class IconLabelNodeLayoutHandler implements INodeLayoutHandler<IconLabelNodeData> { | ||
canHandle(node: Node<NodeData, DiagramNodeType>) { | ||
return node.type === 'iconLabelNode'; | ||
} | ||
handle( | ||
_layoutEngine: ILayoutEngine, | ||
_previousDiagram: Diagram | null, | ||
node: Node<IconLabelNodeData>, | ||
visibleNodes: Node<NodeData, DiagramNodeType>[], | ||
_directChildren: Node<NodeData, DiagramNodeType>[] | ||
) { | ||
const nodeIndex = this.findNodeIndex(visibleNodes, node.id); | ||
const labelElement = document.getElementById(`${node.id}-label-${nodeIndex}`); | ||
|
||
node.width = labelElement?.getBoundingClientRect().width; | ||
node.height = labelElement?.getBoundingClientRect().height; | ||
} | ||
|
||
private findNodeIndex(nodes: Node<NodeData>[], nodeId: string): number { | ||
return nodes.findIndex((node) => node.id === nodeId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.