2022-08-30 15:36:33 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021-present The maxGraph project Contributors
|
|
|
|
Copyright (c) 2006-2020, JGraph Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-12-17 08:16:26 +00:00
|
|
|
import { Graph, Perimeter, Point } 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);
|
|
|
|
|
2022-12-17 08:16:26 +00:00
|
|
|
// Returns a special label for edges. Note: This does a super call 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;
|
2022-12-17 08:16:26 +00:00
|
|
|
if (cell.isEdge()) {
|
2021-04-25 03:39:40 +00:00
|
|
|
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
|
2022-12-17 08:16:26 +00:00
|
|
|
/** @type {import('@maxgraph/core').CellStyle} */
|
|
|
|
const defaultVertexStyle = {
|
|
|
|
align: 'center',
|
|
|
|
fillColor: '#EEEEEE',
|
|
|
|
fontColor: '#774400',
|
|
|
|
fontSize: 12,
|
|
|
|
fontStyle: 1,
|
|
|
|
gradientColor: 'white',
|
|
|
|
perimeter: Perimeter.RectanglePerimeter,
|
|
|
|
rounded: true,
|
|
|
|
shape: 'rectangle',
|
|
|
|
strokeColor: 'gray',
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
};
|
|
|
|
graph.getStylesheet().putDefaultVertexStyle(defaultVertexStyle);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Creates the default style for edges
|
2022-12-17 08:16:26 +00:00
|
|
|
/** @type {import('@maxgraph/core').CellStyle} */
|
|
|
|
const defaultEdgeStyle = {
|
|
|
|
align: 'center',
|
|
|
|
edgeStyle: 'elbowEdgeStyle',
|
|
|
|
endArrow: 'classic',
|
|
|
|
fontSize: 10,
|
|
|
|
shape: 'connector',
|
|
|
|
strokeColor: '#6482B9',
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
};
|
|
|
|
graph.getStylesheet().putDefaultEdgeStyle(defaultEdgeStyle);
|
|
|
|
|
|
|
|
// Additional styles
|
|
|
|
const redColor = '#f10d0d';
|
|
|
|
/** @type {import('@maxgraph/core').CellStyle} */
|
|
|
|
const edgeImportantStyle = {
|
|
|
|
fontColor: redColor,
|
|
|
|
fontSize: 14,
|
|
|
|
fontStyle: 3,
|
|
|
|
strokeColor: redColor,
|
|
|
|
};
|
|
|
|
graph.getStylesheet().putCellStyle('importantEdge', edgeImportantStyle);
|
|
|
|
|
|
|
|
/** @type {import('@maxgraph/core').CellStyle} */
|
|
|
|
const shapeImportantStyle = { strokeColor: redColor };
|
|
|
|
graph.getStylesheet().putCellStyle('importantShape', shapeImportantStyle);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// 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
|
2022-01-08 01:49:35 +00:00
|
|
|
graph.batchUpdate(() => {
|
2022-12-17 08:16:26 +00:00
|
|
|
const v1 = graph.insertVertex({
|
|
|
|
parent,
|
|
|
|
value: 'Interval 1',
|
|
|
|
position: [20, 20],
|
|
|
|
size: [180, 30],
|
|
|
|
style: { baseStyleNames: ['importantShape'] },
|
|
|
|
});
|
2021-08-30 14:20:26 +00:00
|
|
|
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);
|
2022-12-17 08:16:26 +00:00
|
|
|
e1.getGeometry().points = [new Point(160, 60)];
|
|
|
|
const e2 = graph.insertEdge({
|
|
|
|
parent,
|
|
|
|
value: '2',
|
|
|
|
source: v1,
|
|
|
|
target: v5,
|
|
|
|
style: { baseStyleNames: ['importantEdge'] },
|
|
|
|
});
|
|
|
|
e2.getGeometry().points = [new Point(80, 60)];
|
2021-04-25 03:39:40 +00:00
|
|
|
const e3 = graph.insertEdge(parent, null, '3', v2, v3);
|
2022-12-17 08:16:26 +00:00
|
|
|
e3.getGeometry().points = [new Point(280, 120)];
|
2021-04-25 03:39:40 +00:00
|
|
|
const e4 = graph.insertEdge(parent, null, '4', v3, v4);
|
2022-12-17 08:16:26 +00:00
|
|
|
e4.getGeometry().points = [new Point(500, 180)];
|
2021-04-25 03:39:40 +00:00
|
|
|
const e5 = graph.insertEdge(parent, null, '5', v3, v5);
|
2022-12-17 08:16:26 +00:00
|
|
|
e5.getGeometry().points = [new Point(380, 180)];
|
2022-01-08 01:49:35 +00:00
|
|
|
});
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
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({});
|