Giter Site home page Giter Site logo

flow-renderer's Introduction

FlowFuse Flow Renderer

A library to render Node-RED flows in a web page.

Installation

npm install @flowfuse/flow-renderer

development

All client-side code is in the index.js file for easy inclusion in a web page.

Run npm run demo to test the flow renderer in a browser.

Run npm run build to build a minimised version of the flow renderer. This will output the file index.min.js.

IMPORTANT: The minified version of the flow renderer should be built before committing changes to the repository.

Usage

Add the following script tag to your HTML file:

<script type="module" src="public/flow-renderer/index.min.js"></script>

or wherever the script is located in your project

Next, add a container element to your HTML file and call the flowRenderer function with the flow data and options. NOTE: flow-renderer is an ES Module and requires a modern browser to run. Script tags must have the type="module" attribute.

By default, the flow renderer will render the flow with gridLines, images, labels, zoom, autoZoom, and autoScroll enabled. linkLines are disabled by default.

To operate the zoom, use the mouse wheel + Ctrl or โŒ˜ key. To scroll the container vertically, use the mouse wheel without the Shift key. To scroll the container horizontally, use the mouse wheel + Shift key.

Basic example

<div id="nr-flow-1" class="flow-renderer" style="height: 300px"></div>
<script type="module">
  const renderer = new FlowRenderer()
  const container1 = document.getElementById('nr-flow-1');
  const flow = [{"id": "1001", "type": "inject", "x": 100, "y": 40, "wires": [["1002"]]}, {"id": "1002", "type": "debug", "x":300, "y": 40}]
  renderer.renderFlows(flow, { container: container1 })
</script>

Inline Options example

Options can be set by data attributes scope, grid-lines, zoom, images, link-lines, labels, auto-zoom, auto-scroll.

NOTE: To SET and option, the data attribute can simply be present on the container element. To UNSET an option, the data attribute must be set to false.

<div id="nr-flow-2" style="height: 300px" 
    data-scope="custom-css-scope"
    data-grid-lines
    data-zoom
    data-images
    data-link-lines="false"
    data-labels
    data-auto-zoom
    data-auto-scroll
></div>
<script type="module">
  const renderer = new FlowRenderer()
  const container2 = document.getElementById('nr-flow-2');
  const flow = [{"id": "1001", "type": "inject", "x": 100, "y": 40, "wires": [["1002"]]}, {"id": "1002", "type": "debug", "x":300, "y": 40}]
  renderer.renderFlows(flow, { container: container2 })
</script>

Full Options example

<div id="nr-flow-3" class="my-scope" style="height: 300px"></div>
const renderer = new FlowRenderer()
const container3 = document.getElementById('nr-flow-3');
const flow = [{"id": "1001", "type": "inject", "x": 100, "y": 40, "wires": [["1002"]]}, {"id": "1002", "type": "debug", "x":300, "y": 40}]
renderer.renderFlows(flow, {
    container: container3,
    scope: 'custom-css-scope', // scope for CSS
    gridLines: true, // show gridLines
    images: true, // show images
    linkLines: false, // show link lines
    labels: true, // show labels
    zoom: true, // enable zoom within the container
    autoZoom: true, // auto zoom to fit the flow within the container upon rendering (best fit, limited to 20% min, 100% max zoom)
    autoScroll: true, // auto scroll the leftmost node to the left of the container and the topmost node to the top of the container upon rendering
    flowId: undefined // Id of flow to display
})

Vue example

    <div id="app">
        <div ref="f1" class="flow-renderer"></div>
    </div>

    <script type="module">
        import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
        import FlowRenderer from './index.js'
        createApp({
            mounted() {
                const flow = [{"id": "1001", "type": "inject", "x": 100, "y": 40, "wires": [["1002"]]}, {"id": "1002", "type": "debug", "x":300, "y": 40}]
                const renderer = new FlowRenderer()
                renderer.renderFlows(flow, { container: this.$refs.f1 })
            }
        }).mount('#app')
    </script>

Acknowledgements

This project owes a huge thanks to Gerrit Riessen for his original works on node-red-flowviewer. It was this great contribution that started the ball rolling. Gerrit kindly allowed us relicense the parts we needed to use in this project.

Limitations

  • Only client-side rendering is currently supported
  • Mobile pinch zoom is not yet implemented
  • The flow renderer does not support the full range of contributed Node-RED nodes however they will render as a generic node type complete with the node's label.
  • The flow renderer does not always render the flows and nodes exactly as they appear in the Node-RED editor. This is due in part to being a client-side render with no server-side component to provide full context and partly due to the current limitations of the renderer itself.

Versioning

While the API is in development, the version number of this package will remain at 0.x.y. x will be incremented for breaking changes, y for new features and patches. Once the API is stable, the version number will be updated to 1.0.0 and full SemVer rules will be applied.

License

Apache-2.0

flow-renderer's People

Contributors

steve-mcl avatar joepavitt avatar zjvandeweg avatar hardillb avatar

Stargazers

Douglas Oliveira avatar  avatar Marian avatar  avatar

Watchers

Nick O'Leary avatar  avatar  avatar

flow-renderer's Issues

Add missing icons & colours for core nodes

Current Behavior

for example, core nodes tcp & udp are missing icons (non exhaustive)

Expected Behavior

  • All core nodes to have icon and colour
  • support fa icons (covers most other scenarios)
  • ensure ALL flowfuse nodes are faithfully represented
  • Consider icons and/or colours for the most popular nodes (incl. Modbus, PLC, OPC, Database Nodes)

Steps To Reproduce

import flow with all core nodes - some are rendered in default styling

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

Mobile view cannot pinch to zoom within the flow container

Current Behavior

flows rendered on a mobile (touch screen device) cannot pinch to zoom within the flow container.

Expected Behavior

Ideally, support pinch zoom

MVP: add zoom buttons [+] [o] [-] buttons like Node-RED has at the bottom right of the canvas

Steps To Reproduce

open rendered flows on a mobile touch device

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

Disabled flows are shown as active flows

Current Behavior

If a flow tab is disabled, it is rendered as enabled

Expected Behavior

tabs marked disabled should be shown as disabled (same as node-red)

Steps To Reproduce

import a flow with a tab disabled

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

Nodes set to show no label are rendered full size

Current Behavior

Nodes set to show no label are rendered full size. This typically causes users flows to be badly laid out with overlapping nodes

Expected Behavior

nodes with label hidden should be drawn without a label (same as node-red does)

Steps To Reproduce

import flow with regular core nodes, some of them with the hide label option set

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

CSS overrides scroll bar

Current Behavior

CSS built in overrides scroll bar appearance. This affect the whole site.

Expected Behavior

remove (or condition) scroll bar overrides in the CSS

Steps To Reproduce

No response

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

Add linting

Description

Add standard eslint to the package.

Some of the code (imported directly from Node-RED) will likely need block exceptions e.g.

ESLint supports block comments /* eslint-disable */ to disable all rules for a block of code until /* eslint-enable */ is encountered

Epic/Story

No response

Nodes do not snap to grid like node-red and as such, layout differs

Current Behavior

Nodes do not snap to grid like node-red and as such, layout differs

image

Expected Behavior

Nodes should snap to grid to improve fidelity

Steps To Reproduce

try out the built in demo npm run demo

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

Scrollbars not updated when zoomed in/out

Current Behavior

When zooming scroll bars remain the same.

Expected Behavior

When zooming in, scroll bars should be reduced (more to scoll). When zooming out, scroll bars should be increased (less to scroll)

Steps To Reproduce

Zoom out to max, scrolling reveals whitespace.

Environment

  • version: 0.3.0

Auto scale the rendered canvas

Description

When my flow starts say 150 pixels down, and 300 pixels to the right, the top left part of the SVG / canvas has an open space which is slightly awkward. It would be great of the view would shift the thing down.

Epic/Story

No response

The `labels` option causes odd node size rendering

Current Behavior

Look at this demo rendering the the same flow. Top one has default options, 2nd one has the labels options set false. The computed size of the node is not correct and since Node-RED uses the centerpoint for positioning a node, it looks quite odd.

image

Expected Behavior

the option to not show labels should not affect positioning or size

Steps To Reproduce

run the built in demo npm run demo

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

Support server side rendering

Epic

No response

Description

As an integrator/user of this library:

I want to render flows serverside

So that: we can protect IP, cache flow diagrams, other

Acceptance Criteria

  • can render single flow given an flow TAB ID
  • can render multiple flow tabs
  • can generate CSV scoped to given name

File nodes rendering issues

Current Behavior

image

Expected Behavior

should match Node-RED

Steps To Reproduce

No response

Environment

  • FlowFuse version:
  • Node.js version:
  • npm version:
  • Platform/OS:
  • Browser:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.