2021-09-07 12:21:22 +00:00
|
|
|
import {
|
|
|
|
Graph,
|
2022-01-08 01:49:35 +00:00
|
|
|
RubberBandHandler,
|
2021-09-07 12:21:22 +00:00
|
|
|
Rectangle,
|
2022-01-08 01:49:35 +00:00
|
|
|
constants,
|
2021-09-07 12:21:22 +00:00
|
|
|
utils,
|
|
|
|
LabelShape,
|
|
|
|
} from '@maxgraph/core';
|
2021-04-21 11:36:38 +00:00
|
|
|
|
|
|
|
import { globalTypes } from '../.storybook/preview';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Icon_Images/FixedIcons',
|
|
|
|
argTypes: {
|
|
|
|
...globalTypes,
|
|
|
|
rubberBand: {
|
|
|
|
type: 'boolean',
|
2021-08-30 14:20:26 +00:00
|
|
|
defaultValue: true,
|
|
|
|
},
|
|
|
|
},
|
2021-04-21 11:36:38 +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';
|
|
|
|
|
|
|
|
// Overrides the image bounds code to change the position
|
2021-09-07 12:21:22 +00:00
|
|
|
LabelShape.prototype.getImageBounds = function (x, y, w, h) {
|
2022-01-08 01:49:35 +00:00
|
|
|
const iw = utils.getValue(this.style, 'imageWidth', constants.DEFAULT_IMAGESIZE);
|
|
|
|
const ih = utils.getValue(this.style, 'imageHeight', constants.DEFAULT_IMAGESIZE);
|
2021-04-21 11:36:38 +00:00
|
|
|
|
|
|
|
// Places the icon
|
|
|
|
const ix = (w - iw) / 2;
|
|
|
|
const iy = h - ih;
|
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
return new Rectangle(x + ix, y + iy, iw, ih);
|
2021-04-21 11:36:38 +00:00
|
|
|
};
|
|
|
|
|
2021-09-10 05:17:59 +00:00
|
|
|
// Should we allow overriding constants?
|
2021-04-21 11:36:38 +00:00
|
|
|
// Makes the shadow brighter
|
2022-01-08 01:49:35 +00:00
|
|
|
//constants.SHADOWCOLOR = '#C0C0C0';
|
2021-04-21 11:36:38 +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 11:36:38 +00:00
|
|
|
|
|
|
|
// Uncomment the following if you want the container
|
|
|
|
// to fit the size of the graph
|
|
|
|
// graph.setResizeContainer(true);
|
|
|
|
|
|
|
|
// Enables rubberband selection
|
2022-01-08 01:49:35 +00:00
|
|
|
if (args.rubberBand) new RubberBandHandler(graph);
|
2021-04-21 11:36:38 +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-04-17 06:58:35 +00:00
|
|
|
const v1 = graph.insertVertex(parent, null, 'Fixed icon', 20, 20, 80, 50, {
|
|
|
|
shape: 'label',
|
|
|
|
image: 'images/plus.png',
|
|
|
|
imageWidth: 16,
|
|
|
|
imageHeight: 16,
|
|
|
|
spacingBottom: 10,
|
|
|
|
fillColor: '#adc5ff',
|
|
|
|
gradientColor: '#7d85df',
|
|
|
|
glass: true,
|
|
|
|
rounded: true,
|
|
|
|
shadow: true,
|
|
|
|
});
|
2022-01-08 01:49:35 +00:00
|
|
|
});
|
2021-04-21 11:36:38 +00:00
|
|
|
|
|
|
|
return container;
|
2021-08-30 14:20:26 +00:00
|
|
|
};
|
2021-04-21 11:36:38 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
export const Default = Template.bind({});
|