Skip to content
Snippets Groups Projects
Commit 43ad9ac8 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[dome] styling DOT diagrams

parent 64f3e438
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,8 @@ import './style.css'; ...@@ -35,6 +35,8 @@ import './style.css';
export type Direction = 'LR' | 'TD'; export type Direction = 'LR' | 'TD';
export type Font = 'serif' | 'sans' | 'mono';
export type Color = export type Color =
| 'white' | 'grey' | 'dark' | 'white' | 'grey' | 'dark'
| 'primary' | 'selected' | 'primary' | 'selected'
...@@ -45,7 +47,7 @@ export type Shape = ...@@ -45,7 +47,7 @@ export type Shape =
| 'point' | 'box' | 'point' | 'box'
| 'diamond' | 'hexagon' | 'diamond' | 'hexagon'
| 'circle' | 'ellipse' | 'circle' | 'ellipse'
| 'note' | 'tab' | 'folder'; | 'note' | 'tab' | 'folder' | 'cds';
export type Arrow = 'none' | 'arrow' | 'tee' | 'box' | 'dot'; export type Arrow = 'none' | 'arrow' | 'tee' | 'box' | 'dot';
...@@ -64,6 +66,8 @@ export interface Node { ...@@ -64,6 +66,8 @@ export interface Node {
label?: string; label?: string;
/** Node tooltip */ /** Node tooltip */
title?: string; title?: string;
/** Node font (label) */
font?: Font;
/** Node color (filled background) */ /** Node color (filled background) */
color?: Color; color?: Color;
/** /**
...@@ -94,6 +98,8 @@ export interface Edge { ...@@ -94,6 +98,8 @@ export interface Edge {
head?: Arrow; head?: Arrow;
/** Default is `none` */ /** Default is `none` */
tail?: Arrow; tail?: Arrow;
/** Label font */
font?: Font;
/** Label */ /** Label */
label?: string; label?: string;
/** Tooltip */ /** Tooltip */
...@@ -148,9 +154,15 @@ export interface DiagramProps { ...@@ -148,9 +154,15 @@ export interface DiagramProps {
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* --- Color Model --- */ /* --- CSS Model --- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
const FONTNAME = {
'serif': 'Times',
'sans': 'sans-serif',
'mono': 'Courier',
};
// node background colors // node background colors
const BGCOLOR = { const BGCOLOR = {
'white': '#fff', 'white': '#fff',
...@@ -340,7 +352,8 @@ class Builder { ...@@ -340,7 +352,8 @@ class Builder {
.print(' ') .print(' ')
.port(n.id) .port(n.id)
.print(' [') .print(' [')
.attr('id', n.id); .attr('id', n.id)
.attr('fontname', n.font ? FONTNAME[n.font] : undefined);
if (typeof n.shape === 'object') { if (typeof n.shape === 'object') {
this this
.attr('shape', 'record') .attr('shape', 'record')
...@@ -399,6 +412,7 @@ class Builder { ...@@ -399,6 +412,7 @@ class Builder {
.port(e.target, e.targetPort) .port(e.target, e.targetPort)
.print(' [') .print(' [')
.attr('label', e.label) .attr('label', e.label)
.attr('fontname', e.font ? FONTNAME[e.font] : undefined)
.attr('headlabel', e.headLabel) .attr('headlabel', e.headLabel)
.attr('taillabel', e.tailLabel) .attr('taillabel', e.tailLabel)
.attr('labeltooltip', e.label ? tooltip : undefined) .attr('labeltooltip', e.label ? tooltip : undefined)
...@@ -476,7 +490,7 @@ function GraphvizView(props: GraphvizProps): JSX.Element { ...@@ -476,7 +490,7 @@ function GraphvizView(props: GraphvizProps): JSX.Element {
setError(undefined); setError(undefined);
graphviz(href, { graphviz(href, {
useWorker: false, useWorker: false,
fit: true, zoom: true, width, height, fit: false, zoom: true, width, height,
}).onerror(setError) }).onerror(setError)
.renderDot(model).on('end', function () { .renderDot(model).on('end', function () {
if (onSelection) { if (onSelection) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment