maxGraph/packages/html/stories/Animation.stories.js

80 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-09-07 09:07:27 +00:00
import { Graph, Point } from '@maxgraph/core';
2021-04-21 04:54:09 +00:00
import { globalTypes } from '../.storybook/preview';
import './css/animation.css';
export default {
title: 'Effects/Animation',
argTypes: {
...globalTypes,
},
2021-04-21 04:54:09 +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';
const graph = new Graph(container);
2021-04-21 04:54:09 +00:00
graph.setEnabled(false);
const parent = graph.getDefaultParent();
const vertexStyle =
'shape=cylinder;strokeWidth=2;fillColor=#ffffff;strokeColor=black;' +
'gradientColor=#a0a0a0;fontColor=black;fontStyle=1;spacingTop=14;';
/*const vertexStyle = {
shape: 'cylinder',
strokeWidth: 2,
fillColor: '#ffffff',
strokeColor: 'black',
gradientColor: '#a0a0a0',
fontColor: 'black',
fontStyle: 1,
spacingTop: 14,
};*/
let e1;
graph.batchUpdate(() => {
2021-04-21 04:54:09 +00:00
const v1 = graph.insertVertex({
parent,
value: 'Pump',
position: [20, 20],
size: [60, 60],
style: vertexStyle,
});
const v2 = graph.insertVertex({
parent,
value: 'Tank',
position: [200, 150],
size: [60, 60],
style: vertexStyle,
});
e1 = graph.insertEdge({
2021-04-21 04:54:09 +00:00
parent,
source: v1,
target: v2,
style:
'strokeWidth=3;endArrow=block;endSize=2;endFill=1;strokeColor=black;rounded=1;',
});
e1.geometry.points = [new Point(230, 50)];
2021-04-21 04:54:09 +00:00
graph.orderCells(true, [e1]);
});
2021-04-21 04:54:09 +00:00
// Adds animation to edge shape and makes "pipe" visible
const state = graph.view.getState(e1);
state.shape.node.getElementsByTagName('path')[0].removeAttribute('visibility');
state.shape.node.getElementsByTagName('path')[0].setAttribute('stroke-width', '6');
state.shape.node.getElementsByTagName('path')[0].setAttribute('stroke', 'lightGray');
state.shape.node.getElementsByTagName('path')[1].setAttribute('class', 'flow');
2021-04-21 04:54:09 +00:00
return container;
};
2021-04-21 04:54:09 +00:00
export const Default = Template.bind({});