Socket
Socket
Sign inDemoInstall

workflow-svg.js

Package Overview
Dependencies
5
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    workflow-svg.js

*workflow-svg.js* is a JS Library to present and edit workflows as SVG. You can move entities and define connections between them. It is simple to include and configure it for your project. Take a look at a real example on [https://thomaswruss.github.io/w


Version published
Weekly downloads
6
increased by100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

workflow-svg.js

workflow-svg.js is a JS Library to present and edit workflows as SVG. You can move entities and define connections between them. It is simple to include and configure it for your project. Take a look at a real example on https://thomaswruss.github.io/workflow-svg.js/.

How to include

Install the library with npm i workflow-svg.js. That is all.

With the installation, two additional libraries will be installed. Import them first:

  • svg.js: <script src="./node_modules/@svgdotjs/svg.js/dist/svg.min.js"></script>
  • svg.draggable.js <script src="./node_modules/@svgdotjs/svg.draggable.js/dist/svg.draggable.js"></script>

If you want to be compatible with IE11 you have to import svg.js Polyfills too:

  • <script src="./node_modules/@svgdotjs/svg.js/dist/polyfills.js"></script>
  • <script src="./node_modules/@svgdotjs/svg.js/dist/polyfillsIE.js"></script>

And of course you have to import the library itself:

<script src="./node_modules/workflow-svg.js/dist/workflow-svg.minified.js"></script>

In ./docs/index.html you can find examples how to include, call and work with the library.

How to use

Create a new workflow-svg.js instance with new WorkflowSVG();. The object has the following methods.

MethodDescription
initalize(id, width, height)Has to be called to initalize the SVG. 'id' is the <div> Element where the SVG should be rendered with the defined 'width' and 'height'
update(json)Update the SVG with the defined 'json'
register(eventname, callback)Register your callback for some event (eventname).
get()Get the JSON configuration of your workflow-svg.js instance
EventnameDescription
entity:movedEvent when some entity was moved
entity:clickedEvent when some entity was clicked
line:addedEvent when a line was added between some entity
line:clickedEvent when some line was clicked
label:movedEvent when some label was moved

You always get the ID of the related entity/line.

JSON

The JSON contains of three fields.

FieldTypeDescription
entitiesarrayEntities of a workflow.
linesarrayLines between the entities.
labelsarraySome labels to display.
configurationobjectDefines some configuration that will be applied to the whole chart.

The fields are explained now into more detail.

entities

One entity in the array contains the following attributes:

AttributeTypeDescription
idstringUnique id of the entity
textstringText of the entity
typestringType of entity. Default is 'entity'. For workflow operations use: 'operation'
xintegerX coordinate of the entity
yintegerY coordinate of the entity
background_colorstring(hex)Background Color of the entity
colorstring(hex)Font Color of the entity
fa_unicodestringUnicode for FontAwesome Icon (note: don't forget to specify which version of FontAwesome you use - see )
radiusintegerRadius of the corners of the entity
classstringClass Name for css styling

lines

One line in the array contains the following attributes:

AttributeTypeDescription
idstringUnique id of the line
fromobjectObject that contains:
- 'element' - the id from the source entity,
- 'point' - where the line starts at this entity (top, right, bottom, left)
toobjectObject that contains:
- 'element' - the id from the target entity,
- 'point' - where the line ends at this entity (top, right, bottom, left)

labels

One label in the array contains the following attributes:

AttributeTypeDescription
idstringUnique id of the label
valuestringThe text of the label
xintegerX coordinate of the label
yintegerY coordinate of the label
colorstring(hex)Font Color of the label

configuration

The configuration contains the following attributes:

AttributeTypeDescriptionDefault value
line_colorstring(hex)Color of all lines'#000000' (=black)
arrow_type'default' or 'none'At the moment there are only two arrow type: default or none'default'
read_onlybooleanIf true, the chart will be read_onlyfalse
font_awesomeintegerVersion of Font Awesome that you want to use: 4 or 5 are allowedundefined
grid_type'static' or 'dynamic'If 'static' - grid lines will always be shown. Otherwise the grid line will only be shown if the dragged entity is near enough -tjis is called 'dynamic'.'dynamic'
grid_xarrayArray of objects
- 'value': the x coordinate of the line
- 'width': width of the line
- 'color': color of the line
[]
grid_yarrayArray of objects
- 'value': the y coordinate of the line
- 'width': width of the line
- 'color': color of the line
[]

The configuration is completely optional. All non-existent values ​​are set automatically.

Use FontAwesome icons

workflow-svg.js support FontAwesome Icons in Version 4 and 5. What you need to do:

  • import FontAwesome CSS, e.g.: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0/css/all.min.css">
  • provide in the JSON (see chapter above) in the config part font_awesome: 5 (or 4 if you imported version 4)
  • add on the entities the unicode of the FontAwesome Icon you want to use, e.g.: fa_unicode:'f256'

Keywords

FAQs

Last updated on 30 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc