-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1316] Support a new parametric SVG node style
bug: #1316 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
- Loading branch information
Showing
85 changed files
with
7,204 additions
and
2,148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
= ADR-070 - Contribute a diagram node style | ||
|
||
== Context | ||
|
||
Currently, the diagram styles are hardcoded and known by the sirius-component core in the backend and in the frontend. | ||
|
||
The aim of this ADR is to explain how to contribute a new diagram style from an additional project and what changes are needed in the sirius-component projects to support the contributed style. | ||
|
||
=== Current state | ||
On the backend, style are managed specifically for | ||
* the rendering in `sirius-components-diagrams` | ||
* the layout in `sirius-components-diagrams-layout` | ||
** ELK layout | ||
** Incremental layout | ||
* the service called by the front end | ||
|
||
On the frontend, styles are managed with a dedicated sprotty inherited view. | ||
|
||
== Enhancement == | ||
|
||
For the rest of this ADR, let's consider that the contributed style is a parametric SVG style node. | ||
See `ADR-071 - Add parametric SVG node style` to have more explanation on this style. | ||
|
||
=== Use cases | ||
|
||
*Specifier* | ||
|
||
When defining the diagram description with the web view modeler, the specifier should be able to select the contributed style as well as hardcoded existing style (such as node or image styles) | ||
|
||
*Developper* | ||
|
||
On the backend, the developper will provide spring bean to allow | ||
* defining the new nodestyle | ||
* adding the node style as part of the view modeler | ||
* the style rendering when rendering the diagram | ||
* Optional (customizing the layout) | ||
|
||
On the front end, the developper needs to provide a specific sprotty view to render the style on the frontend | ||
|
||
=== Code changes | ||
|
||
The code needs to evolve so that it is able to manage the contributed style without having any direct dependency of its definition. | ||
Everywhere, the specific node styles are used, the code should adapt to get bean contribution that implement the right API: | ||
|
||
* Diagram rendering: A new API `INodeStyleProvider` has been created to provide a node type and to instanciate the nodeStyle inheriting from `INodeStyle` | ||
* Incremental and ELK layout: A new API `ICustomNodeLabelPositionProvider` has been defined to customize the position of the node Label. This API is used for both ELK and incremental layout | ||
|
||
|
||
* Front end: the code must be able to render the new node style by adding a new sprotty view. In our example `node:parametric-svg` node type and `ParametricSVGView` have been added. | ||
Currently, delegating the creation of the sprotty pojo is not yet supported. So the digram convertion from the data returned by the server to data managed by sprotty is hardcoded. | ||
The link between the node type and the sprotty view capable of rendering the node is done `dependencyInjection` | ||
``` | ||
configureModelElement(context, 'node:parametric-svg', Node, ParametricSVGView); | ||
``` | ||
|
||
== Developper guide | ||
|
||
=== backend | ||
|
||
* View model: contribute an extension of the `view.ecore` and add a subtype of `NodeStyleDescription` | ||
* Diagram rendering : Create a diagram node style | ||
** Add a new POJO class representing the node style. It must implements `INodeStyle` | ||
** Add a `INodeStyleProvider` to provide a node type and to instanciate the nodeStyle inheriting from `INodeStyle` | ||
|
||
* ELK layout: If the default configuration from `LayoutConfiguratorRegistry` is not sufficient, it is possible to provide a bean implementing `IDiagramLayoutConfiguratorProvider` to customize the ELK configuration. | ||
* Incremental and ELK layout: | ||
** (Optional) Provide a bean implementing `ICustomNodeLabelPositionProvider` to customize the position of the node Label. | ||
|
||
* Service: Add a graphqls file that contains `extend union INodeStyle = `<new Node Style>`` and the declaration of the new node type itself For example: | ||
``` | ||
extend union INodeStyle = SVGNodeStyle | ||
|
||
type SVGNodeStyle { | ||
svgURL: String! | ||
backgroundColor: String! | ||
borderColor: String! | ||
borderRadius: Int! | ||
borderSize: Int! | ||
borderStyle: LineStyle! | ||
} | ||
``` | ||
|
||
=== frontend | ||
* Add a new diagram node style type that implements `INodeStyle` | ||
* Add a new diagram node style type that extends `GQLINodeStyle` | ||
* update the diagramEventSubscription | ||
* Add a specific sprotty view that is able to render the style and configure the node style for sprotty | ||
|
||
== Status | ||
|
||
Work in progress |
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,31 @@ | ||
= ADR-071 - Add parametric SVG node style | ||
|
||
== Context | ||
|
||
Parametric SVG node style is a new node style that allows to display, as a node image, a svg that is dynamically computed. | ||
Refer to `ADR-070 - Contribute a diagram node style ` to see how to contribute a new node style. | ||
|
||
== Current state | ||
|
||
Currently there is an image node style that allows to display a node with an image as background. | ||
|
||
== Proposal | ||
The parametric SVG node style has the `node:parametric-svg` node type. | ||
|
||
=== On the back-end | ||
The svg template is contributed with `ParametricSVGImageRegistry` beans. This APi allows to get the id, label and the template svg image path. | ||
A bean implementing `ParametricSVGImageFactory` is contributed to build the svg from the provided template svg and various styling and geometric parameter. | ||
|
||
This parametric svg is available with the shape attribute in the `ImageNodeStyleDescription` in the `view` model. | ||
|
||
During the diagram render, a `ParametricSVGNodeStyle` is instanciated to hold the style attributes as any other node style. | ||
This node style holds a particular attribute : the `url. | ||
|
||
=== On the front | ||
A new `ParametricSVGImageView` will manage the `node:paramtric-svg` node type. | ||
It will call a service on the back-end with the `ParametricSVGNodeStyle.url` and with style and geometric caracteristics of the node as parameters. | ||
It will returns a svg built dynamically. | ||
|
||
== Status | ||
|
||
Work in progress |
2 changes: 1 addition & 1 deletion
2
...nts-graphql-api/src/main/java/org/eclipse/sirius/components/graphql/api/URLConstants.java
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
26 changes: 26 additions & 0 deletions
26
.../org/eclipse/sirius/components/collaborative/diagrams/api/IParametricSVGImageFactory.java
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,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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 | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.diagrams.api; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Factory used to compute dynamically the svg image of node. | ||
* | ||
* @author lfasani | ||
*/ | ||
public interface IParametricSVGImageFactory { | ||
|
||
Optional<byte[]> createSvg(String svgType, EnumMap<SVGAttribute, String> attributesValues); | ||
} |
51 changes: 51 additions & 0 deletions
51
...org/eclipse/sirius/components/collaborative/diagrams/api/IParametricSVGImageRegistry.java
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,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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 | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.diagrams.api; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.sirius.components.annotations.PublicApi; | ||
|
||
/** | ||
* Interface of the service used to get the path of the parametric svg images accessible from the jars used in the | ||
* application.</br> | ||
* The specifier must provide an implementation of this API as a {@link @Service} to provide available images. | ||
* | ||
* @author lfasani | ||
*/ | ||
@PublicApi | ||
public interface IParametricSVGImageRegistry { | ||
/** | ||
* Get the paths of the svg images than can be parameterized.</br> | ||
* The images are those in the jar. | ||
* <p> | ||
* Warning: <b>The path must be unique</b>. Indeed, the images are contained in a jar but the system does not know | ||
* about the jars. Then if an image is contained in the same folder structure in many jars, then the result to read | ||
* the image will be unpredictable. | ||
* </p> | ||
* | ||
* The folder must be of the form: | ||
* | ||
* <pre> | ||
* (/ADDITIONAL_FOLDER1/.../ADDITIONAL_FOLDERn)/IMAGE | ||
* </pre> | ||
* | ||
* <p> | ||
* Path examples:</br> | ||
* "/myparametricsvgfolder/myImage.svg", "/myParametricImage.svg" | ||
* </p> | ||
* | ||
* @return a list a paths. | ||
*/ | ||
List<ParametricSVGImage> getImages(); | ||
} |
54 changes: 54 additions & 0 deletions
54
...ain/java/org/eclipse/sirius/components/collaborative/diagrams/api/ParametricSVGImage.java
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,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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 | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.diagrams.api; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
/** | ||
* POJO representing a parametric svg image. | ||
* | ||
* @author lfasani | ||
*/ | ||
public class ParametricSVGImage { | ||
private final UUID id; | ||
|
||
private final String label; | ||
|
||
private final String path; | ||
|
||
public ParametricSVGImage(UUID id, String label, String path) { | ||
this.id = Objects.requireNonNull(id); | ||
this.label = Objects.requireNonNull(label); | ||
this.path = Objects.requireNonNull(path); | ||
} | ||
|
||
public UUID getId() { | ||
return this.id; | ||
} | ||
|
||
public String getLabel() { | ||
return this.label; | ||
} | ||
|
||
public String getPath() { | ||
return this.path; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{' id: {1}, label: {2}, path: {3} '}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.label, this.path); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../src/main/java/org/eclipse/sirius/components/collaborative/diagrams/api/SVGAttribute.java
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,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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 | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.diagrams.api; | ||
|
||
/** | ||
* Attributes of the SVG that will be used to build the SVG. | ||
* | ||
* @author lfasani | ||
*/ | ||
public enum SVGAttribute { | ||
WIDTH("width"), //$NON-NLS-1$ | ||
HEIGHT("height"), //$NON-NLS-1$ | ||
LABELWIDTH("labelWidth"), //$NON-NLS-1$ | ||
LABELHEIGHT("labelHeight"), //$NON-NLS-1$ | ||
COLOR("color"), //$NON-NLS-1$ | ||
BORDERCOLOR("borderColor"), //$NON-NLS-1$ | ||
BORDERSTYLE("borderStyle"), //$NON-NLS-1$ | ||
BORDERSIZE("borderSize"); //$NON-NLS-1$ | ||
|
||
private String label; | ||
|
||
SVGAttribute(String label) { | ||
this.label = label; | ||
} | ||
|
||
public String getLabel() { | ||
return this.label; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../sirius-components-collaborative-diagrams/src/main/resources/schema/svgNodeStyle.graphqls
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,10 @@ | ||
extend union INodeStyle = ParametricSVGNodeStyle | ||
|
||
type ParametricSVGNodeStyle { | ||
svgURL: String! | ||
backgroundColor: String! | ||
borderColor: String! | ||
borderRadius: Int! | ||
borderSize: Int! | ||
borderStyle: LineStyle! | ||
} |
Oops, something went wrong.