2021-09-07 09:07:27 +00:00
|
|
|
import {
|
|
|
|
Graph,
|
|
|
|
mxDomHelpers,
|
|
|
|
mxMorphing,
|
|
|
|
InternalEvent,
|
2021-09-07 12:21:22 +00:00
|
|
|
RubberBand,
|
2021-09-07 09:07:27 +00:00
|
|
|
} from '@maxgraph/core';
|
2021-04-21 04:54:09 +00:00
|
|
|
|
|
|
|
import { globalTypes } from '../.storybook/preview';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Effects/Morph',
|
|
|
|
argTypes: {
|
|
|
|
...globalTypes,
|
|
|
|
contextMenu: {
|
|
|
|
type: 'boolean',
|
2021-08-30 14:20:26 +00:00
|
|
|
defaultValue: false,
|
2021-04-21 04:54:09 +00:00
|
|
|
},
|
|
|
|
rubberBand: {
|
|
|
|
type: 'boolean',
|
2021-08-30 14:20:26 +00:00
|
|
|
defaultValue: true,
|
|
|
|
},
|
|
|
|
},
|
2021-04-21 04:54:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const Template = ({ label, ...args }) => {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
|
|
|
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';
|
|
|
|
div.appendChild(container);
|
|
|
|
|
|
|
|
// Disables the built-in context menu
|
2021-08-30 14:20:26 +00:00
|
|
|
if (!args.contextMenu) InternalEvent.disableContextMenu(container);
|
2021-04-21 04:54:09 +00:00
|
|
|
|
|
|
|
// Creates the graph inside the given container
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph = new Graph(container);
|
2021-04-21 04:54:09 +00:00
|
|
|
|
|
|
|
// Enables rubberband selection
|
2021-09-07 12:21:22 +00:00
|
|
|
if (args.rubberBand) new RubberBand(graph);
|
2021-04-21 04:54:09 +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
|
|
|
|
graph.getModel().beginUpdate();
|
|
|
|
let v1;
|
|
|
|
var v2;
|
|
|
|
try {
|
|
|
|
v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
|
|
|
|
var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
|
|
|
|
const e1 = graph.insertEdge(parent, null, '', v1, v2);
|
|
|
|
} finally {
|
|
|
|
// Updates the display
|
|
|
|
graph.getModel().endUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mult = 1;
|
|
|
|
|
|
|
|
const buttons = document.createElement('div');
|
|
|
|
div.appendChild(buttons);
|
|
|
|
|
|
|
|
buttons.appendChild(
|
2021-08-30 14:20:26 +00:00
|
|
|
mxDomHelpers.button('Morph', function () {
|
2021-04-21 04:54:09 +00:00
|
|
|
graph.clearSelection();
|
|
|
|
|
|
|
|
graph.getModel().beginUpdate();
|
|
|
|
try {
|
|
|
|
let geo = graph.getCellGeometry(v1);
|
|
|
|
geo = geo.clone();
|
|
|
|
geo.x += 180 * mult;
|
|
|
|
graph.getModel().setGeometry(v1, geo);
|
|
|
|
|
|
|
|
geo = graph.getCellGeometry(v2);
|
|
|
|
geo = geo.clone();
|
|
|
|
geo.x -= 180 * mult;
|
|
|
|
graph.getModel().setGeometry(v2, geo);
|
|
|
|
} finally {
|
|
|
|
// Arguments are number of steps, ease and delay
|
|
|
|
const morph = new mxMorphing(graph, 20, 1.2, 20);
|
2021-08-30 14:20:26 +00:00
|
|
|
morph.addListener(InternalEvent.DONE, function () {
|
2021-04-21 04:54:09 +00:00
|
|
|
graph.getModel().endUpdate();
|
|
|
|
});
|
|
|
|
morph.startAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
mult *= -1;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
return div;
|
2021-08-30 14:20:26 +00:00
|
|
|
};
|
2021-04-21 04:54:09 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
export const Default = Template.bind({});
|