0.0.1 • Published 9 months ago

@lincle/react-web-base v0.0.1

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
gitlab
Last release
9 months ago

lincle generates a reactive graph.

Please see the various testing demos for examples.

If you require an interactive diagram, checkout @lincle/interactive.

Installation & Setup

Install @lincle/react-web-base and the peer dependencies react, react-dom:

npm install react react-dom @lincle/react-web-base

Also include the provided styles file. For example:

import '@lincle/react-web-base/dist/main.min.css';

Simple Example

The following example will generate this diagram:

CodeSandbox

/* styles.css */

.App {
	position: absolute;
	overflow: hidden;
	width: 100%;
	height: 100%;
}

.node {
	display: flex;
	align-items: center;
	justify-content: center;
	width: calc(100% - 2px);
	height: calc(100% - 2px);
	border: 1px solid black;
	background-color: white;
	box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

.node-oval {
	border-radius: 50%;
}
import React, { FunctionComponent, ReactElement } from "react";
import { Edge, Edges, Graph, Node, Nodes } from "@lincle/react-web-base";
import "@lincle/react-web-base/dist/main.min.css";
import "./styles.css";

const App: FunctionComponent = (): ReactElement => {
  return (
    <div className="App">
      <Graph id="SimpleDiagram" key="1" nodeHeight={50} nodeWidth={50}>
        <Nodes>
          <Node id={1} key={1} x={50} y={50}>
            <div className="node">Node 1</div>
          </Node>
          <Node
            height={100}
            id={2}
            key={2}
            shape="oval"
            width={200}
            x={100}
            y={150}
          >
            <div className="node node-oval">Node 2</div>
          </Node>
          <Node id={3} key={3} shape="oval" x={150} y={350}>
            <div className="node node-oval">Node 3</div>
          </Node>
        </Nodes>
        <Edges>
          <Edge id={1} key={1} sourceId={1} targetId={2}>
            <circle fill="white" r="3" stroke="black" strokeWidth={2}>
              <title>Bridge</title>
            </circle>
          </Edge>
          <Edge id={2} key={2} line="direct" sourceId={2} targetId={3} />
        </Edges>
      </Graph>
    </div>
  );
};

export default App;

Component API's

* bolded parameters are required

<Graph>

ParametersTypeDefaultDescription
idstring \| numberThe unique ID of the graph
edgeFrequencynumber16Frequency of edge updates during node movements (in ms)
gridfalse \| [number, number][16, 16]The background grid space; false to disable.
line"curve" \| "direct" \| "step""step"The default curve for the edges
nodeFrequencynumber500Frequency of node movements reported (in ms, aside from edges)
nodeHeightnumber50The default height for nodes (in px)
nodeWidthnumber50The default width for nodes (in px)
shape"oval" \| "rectangle""rectangle"The default shape for nodes

<Nodes>

ParametersTypeDefaultDescription
none

<Node>

ParametersTypeDefaultDescription
idstring \| numberThe unique ID of the node
xnumber0The initial x coordinate of the node
ynumber0The initial y coordinate of the node
The following override the defaults provided by <Graph />
heightnumber50The node height
shape'oval' \| 'rectangle'rectangleThe shape of the node
widthnumber50The node width

<Edges>

ParametersTypeDefaultDescription
dashboolean \| undefinedundefinedWhether dash should be enabled. Defaults to hover only.

<Edge>

ParametersTypeDefaultDescription
idstring \| numberThe unique ID for the edge
dashboolean \| undefinedundefinedWhether dash should be enabled. Defaults to hover only.
line'curve' \| 'direct' \| 'step'directThe line shape (overrides default) and not applicable if custom path generator is used.
markerEndstringPassed to the default path generated <path> SVG
markerStartstringPassed to the default path generated <path> SVG
pathpath function - see belowUse to generate a custom path component.
sourceIdstring \| numberID for the source node
targetIdstring \| numberID for the target node

*Note: The child of <Edge /> is intended to be an element at the center of the path. The child will be inside an <SVG /> element and should be an SVG type or wrapped in a <foreignObject /> element. See examples for details.*

Path function

Instead of using the @lincle/react-web-base provided edges (curve, line, & step), you may opt to generate your own path component:

(
	source: {
		height: number,
		id: string | number,
		shape: 'oval' | 'rectangle',
		width: number,
		x: number,
		y: number
	},
	target: {
		height: number,
		id: string | number,
		shape: 'oval' | 'rectangle',
		width: number,
		x: number,
		y: number
	},
	children?: ReactNode
) => Component<SVG type>

<Grid>

ParametersTypeDefaultDescription
childrenSVG<circle>The repeated SVG
scalenumber1Scales the grid
xOffsetnumber0Translates the grid left/right
yOffsetnumber0Translates the grid up/down

Contexts

<Context>'s can be taken advantage of to extend the functionality of @lincle/react-web-base:

ContextProvidesDescription
<GraphContext>{diagramId: ReactText, nodePosition: NodePositions, edgeSubscriber: EdgeSubscriber, defaultSettings: DefaultSettings}Provides the current diagramId and default settings along with classes to subscribe to <Node> and <Edge> events.
<GridContext>[number, number]Provides the current grid dimensions.
0.4.0-next.12

9 months ago

0.4.0-next.11

9 months ago

0.4.0-next.6

10 months ago

0.4.0-next.7

10 months ago

0.4.0-next.8

10 months ago

0.4.0-next.9

10 months ago

0.4.0-next.2

1 year ago

0.4.0-next.3

11 months ago

0.4.0-next.4

11 months ago

0.4.0-next.5

10 months ago

0.4.0-next.10

10 months ago

0.4.0-next.1

1 year ago

0.0.1

2 years ago