Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ the following properties:
| `colorHover` | Color | string | Node background color on mouse hover event. If not defined `color` is used. |
| `colorSelected` | Color | string | Node background color on mouse click event. If not defined `color` is used. |
| `fontBackgroundColor` | Color | string | Node text (label) background color. |
| `fontBackgroundBorderWidth` | number | Node text (label) background border width. |
| `fontBackgroundBorderColor` | Color | string | Node text (label) background border color. |
| `fontBackgroundBorderRadius` | number | Node text (label) background border radius. |
| `fontBackgroundPadding` | number | Node text (label) background padding. |
| `fontColor` | Color | string | Node text (label) font color. The default is `#000000`. |
| `fontFamily` | string | Node text (label) font family. The default is `"Roboto, sans-serif"`. |
| `fontSize` | number | Node text (label) font size. The default is `4`. |
Expand Down
48 changes: 38 additions & 10 deletions examples/example-custom-styled-graph.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<!DOCTYPE html>
<html lang='en' type="module">

<head>
<base href=".">
<meta charset='UTF-8'>
<title>Orb | Simple graph with custom default style on default canvas</title>
<script type="text/javascript" src="./orb.js"></script>
</head>
<style>
html, body {
html,
body {
height: 100%;
margin: 0;
}
</style>

<body>
<div style="display: flex; flex-direction: column; align-items: center; height: 100%;">
<h1>Example 2 - Basic + Custom default style</h1>
Expand All @@ -30,13 +33,13 @@ <h1>Example 2 - Basic + Custom default style</h1>

const nodes = [
{ id: 0, label: 'Node A' },
{ id: 1, label: 'Node B' },
{ id: 1, label: 'Node B - A Special Node\nWith Some Special\nProperties' },
{ id: 2, label: 'Node C' },
];
const edges = [
{ id: 0, start: 0, end: 0, label: 'A -> A' },
{ id: 1, start: 0, end: 1, label: 'A -> B' },
{ id: 2, start: 0, end: 2, label: 'A -> C' },
{ id: 2, start: 0, end: 2, label: 'New Property\nA -> C' },
{ id: 3, start: 1, end: 2, label: 'B -> C' },
{ id: 4, start: 2, end: 2, label: 'C -> C' },
{ id: 5, start: 0, end: 1, label: 'A -> B' },
Expand All @@ -54,7 +57,7 @@ <h1>Example 2 - Basic + Custom default style</h1>
getNodeStyle(node) {
const basicStyle = {
borderColor: '#1d1d1d',
borderWidth: 0.6,
borderWidth: 0.1,
color: '#DD2222',
colorHover: '#e7644e',
colorSelected: '#e7644e',
Expand All @@ -63,12 +66,20 @@ <h1>Example 2 - Basic + Custom default style</h1>
size: 6,
};

if (node.data.label === 'Node A') {
if (node.data.id === 1) {
return {
...basicStyle,
size: 10,
size: 4,
borderWidth: 0.3,
color: '#00FF2B',
borderColor: "purple",
zIndex: 1,
fontBackgroundColor: 'rgb(0, 255, 0)',
fontBackgroundBorderWidth: 0.3,
fontBackgroundBorderColor: 'purple',
fontBackgroundBorderRadius: 1.5,
fontBackgroundPadding: 1,
fontSize: 1.5,
};
}

Expand All @@ -77,16 +88,30 @@ <h1>Example 2 - Basic + Custom default style</h1>
};
},
getEdgeStyle(edge) {
return {
const basicStyles = {
color: '#999999',
colorHover: '#1d1d1d',
colorSelected: '#1d1d1d',
fontSize: 3,
fontSize: 2,
width: 0.3,
widthHover: 0.9,
widthSelected: 0.9,
label: edge.data.label,
};
}

if (edge.data.id === 2) {
return {
...basicStyles,
fontBackgroundColor: 'rgb(0, 255, 0)',
fontBackgroundBorderWidth: 0.2,
fontBackgroundBorderColor: 'grey',
fontBackgroundBorderRadius: 10,
fontBackgroundPadding: 1,
fontSize: 1.5,
}
}

else return { ...basicStyles };
},
});

Expand All @@ -96,6 +121,9 @@ <h1>Example 2 - Basic + Custom default style</h1>
orb.view.render(() => {
orb.view.recenter();
});


</script>
</body>
</html>

</html>
4 changes: 4 additions & 0 deletions src/models/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export type IEdgeStyle = Partial<{
colorHover: Color | string;
colorSelected: Color | string;
fontBackgroundColor: Color | string;
fontBackgroundBorderWidth: number;
fontBackgroundBorderColor: Color | string;
fontBackgroundBorderRadius: number;
fontBackgroundPadding: number;
fontColor: Color | string;
fontFamily: string;
fontSize: number;
Expand Down
4 changes: 4 additions & 0 deletions src/models/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export type INodeStyle = Partial<{
colorHover: Color | string;
colorSelected: Color | string;
fontBackgroundColor: Color | string;
fontBackgroundBorderWidth: number;
fontBackgroundBorderColor: Color | string;
fontBackgroundBorderRadius: number;
fontBackgroundPadding: number;
fontColor: Color | string;
fontFamily: string;
fontSize: number;
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/canvas/edge/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ const drawEdgeLabel = <N extends INodeBase, E extends IEdgeBase>(
textBaseline: LabelTextBaseline.MIDDLE,
properties: {
fontBackgroundColor: edge.style.fontBackgroundColor,
fontBackgroundBorderWidth: edge.style.fontBackgroundBorderWidth,
fontBackgroundBorderColor: edge.style.fontBackgroundBorderColor,
fontBackgroundBorderRadius: edge.style.fontBackgroundBorderRadius,
fontBackgroundPadding: edge.style.fontBackgroundPadding,
fontColor: edge.style.fontColor,
fontFamily: edge.style.fontFamily,
fontSize: edge.style.fontSize,
},
});
drawLabel(context, label);
drawLabel(context, label, 'edge');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check that one other comment, this 'edge' part can be removed.

};

const drawLine = <N extends INodeBase, E extends IEdgeBase>(context: CanvasRenderingContext2D, edge: IEdge<N, E>) => {
Expand Down
Loading