2021-09-07 09:07:27 +00:00
|
|
|
import { Graph, Perimeter, Constants, EdgeStyle } from '@maxgraph/core';
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
import { globalTypes } from '../.storybook/preview';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Styles/Stylesheet',
|
|
|
|
argTypes: {
|
2021-08-30 14:20:26 +00:00
|
|
|
...globalTypes,
|
|
|
|
},
|
2021-04-25 03:39:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const Template = ({ label, ...args }) => {
|
|
|
|
const container = document.createElement('div');
|
|
|
|
container.style.position = 'relative';
|
|
|
|
container.style.overflow = 'hidden';
|
|
|
|
container.style.width = `${args.width}px`;
|
|
|
|
container.style.height = `${args.height}px`;
|
|
|
|
container.style.background = 'url(/images/grid.gif)';
|
|
|
|
container.style.cursor = 'default';
|
|
|
|
|
|
|
|
// Creates the graph inside the DOM node.
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph = new Graph(container);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Disables basic selection and cell handling
|
|
|
|
graph.setEnabled(false);
|
|
|
|
|
|
|
|
// Returns a special label for edges. Note: This does
|
|
|
|
// a supercall to use the default implementation.
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.getLabel = function (cell) {
|
|
|
|
const label = Graph.prototype.getLabel.apply(this, arguments);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
if (cell.isEdge()) {
|
|
|
|
return `Transfer ${label}`;
|
|
|
|
}
|
|
|
|
return label;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Installs a custom global tooltip
|
|
|
|
graph.setTooltips(true);
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.getTooltip = function (state) {
|
2021-04-25 03:39:40 +00:00
|
|
|
const { cell } = state;
|
|
|
|
const model = this.getModel();
|
|
|
|
|
|
|
|
if (modcellel.isEdge()) {
|
|
|
|
const source = this.getLabel(cell.getTerminal(true));
|
|
|
|
const target = this.getLabel(cell.getTerminal(false));
|
|
|
|
|
|
|
|
return `${source} -> ${target}`;
|
|
|
|
}
|
|
|
|
return this.getLabel(cell);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates the default style for vertices
|
|
|
|
let style = [];
|
2021-08-30 14:20:26 +00:00
|
|
|
style.shape = Constants.SHAPE_RECTANGLE;
|
|
|
|
style.perimiter = Perimeter.RectanglePerimeter;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeColor = 'gray';
|
|
|
|
style.rounded = true;
|
|
|
|
style.fillColor = '#EEEEEE';
|
|
|
|
style.gradientColor = 'white';
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = '#774400';
|
2021-08-30 14:20:26 +00:00
|
|
|
style.align = Constants.ALIGN_CENTER;
|
|
|
|
style.verticalAlign = Constants.ALIGN_MIDDLE;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fontSize = '12';
|
|
|
|
style.fontStyle = 1;
|
2021-04-25 03:39:40 +00:00
|
|
|
graph.getStylesheet().putDefaultVertexStyle(style);
|
|
|
|
|
|
|
|
// Creates the default style for edges
|
|
|
|
style = [];
|
2021-08-30 14:20:26 +00:00
|
|
|
style.shape = Constants.SHAPE_CONNECTOR;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeColor = '#6482B9';
|
2021-08-30 14:20:26 +00:00
|
|
|
style.align = Constants.ALIGN_CENTER;
|
|
|
|
style.verticalAlign = Constants.ALIGN_MIDDLE;
|
|
|
|
style.edge = EdgeStyle.ElbowConnector;
|
|
|
|
style.endArrow = Constants.ARROW_CLASSIC;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fontSize = '10';
|
2021-04-25 03:39:40 +00:00
|
|
|
graph.getStylesheet().putDefaultEdgeStyle(style);
|
|
|
|
|
|
|
|
// Gets the default parent for inserting new cells. This
|
|
|
|
// is normally the first child of the root (ie. layer 0).
|
|
|
|
const parent = graph.getDefaultParent();
|
|
|
|
|
|
|
|
// Adds cells to the model in a single step
|
|
|
|
graph.getModel().beginUpdate();
|
|
|
|
try {
|
2021-08-30 14:20:26 +00:00
|
|
|
const v1 = graph.insertVertex(parent, null, 'Interval 1', 20, 20, 180, 30);
|
|
|
|
const v2 = graph.insertVertex(parent, null, 'Interval 2', 140, 80, 280, 30);
|
|
|
|
const v3 = graph.insertVertex(parent, null, 'Interval 3', 200, 140, 360, 30);
|
|
|
|
const v4 = graph.insertVertex(parent, null, 'Interval 4', 480, 200, 120, 30);
|
|
|
|
const v5 = graph.insertVertex(parent, null, 'Interval 5', 60, 260, 400, 30);
|
2021-04-25 03:39:40 +00:00
|
|
|
const e1 = graph.insertEdge(parent, null, '1', v1, v2);
|
|
|
|
e1.getGeometry().points = [{ x: 160, y: 60 }];
|
|
|
|
const e2 = graph.insertEdge(parent, null, '2', v1, v5);
|
|
|
|
e2.getGeometry().points = [{ x: 80, y: 60 }];
|
|
|
|
const e3 = graph.insertEdge(parent, null, '3', v2, v3);
|
|
|
|
e3.getGeometry().points = [{ x: 280, y: 120 }];
|
|
|
|
const e4 = graph.insertEdge(parent, null, '4', v3, v4);
|
|
|
|
e4.getGeometry().points = [{ x: 500, y: 180 }];
|
|
|
|
const e5 = graph.insertEdge(parent, null, '5', v3, v5);
|
|
|
|
e5.getGeometry().points = [{ x: 380, y: 180 }];
|
|
|
|
} finally {
|
|
|
|
// Updates the display
|
|
|
|
graph.getModel().endUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
2021-08-30 14:20:26 +00:00
|
|
|
};
|
2021-04-25 03:39:40 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
export const Default = Template.bind({});
|