/* 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. */ import { Graph, RubberBandHandler, Rectangle, constants, utils, LabelShape, } from '@maxgraph/core'; import { globalTypes } from '../.storybook/preview'; export default { title: 'Icon_Images/FixedIcons', argTypes: { ...globalTypes, rubberBand: { type: 'boolean', defaultValue: true, }, }, }; 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 LabelShape.prototype.getImageBounds = function (x, y, w, h) { const iw = utils.getValue(this.style, 'imageWidth', constants.DEFAULT_IMAGESIZE); const ih = utils.getValue(this.style, 'imageHeight', constants.DEFAULT_IMAGESIZE); // Places the icon const ix = (w - iw) / 2; const iy = h - ih; return new Rectangle(x + ix, y + iy, iw, ih); }; // Should we allow overriding constants? // Makes the shadow brighter //constants.SHADOWCOLOR = '#C0C0C0'; // Creates the graph inside the given container const graph = new Graph(container); // Uncomment the following if you want the container // to fit the size of the graph // graph.setResizeContainer(true); // Enables rubberband selection if (args.rubberBand) new RubberBandHandler(graph); // 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.batchUpdate(() => { 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, }); }); return container; }; export const Default = Template.bind({});