2021-09-07 09:07:27 +00:00
|
|
|
import { Graph } from '@maxgraph/core';
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
import { globalTypes } from '../.storybook/preview';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Labels/LabelPosition',
|
|
|
|
argTypes: {
|
2021-08-30 14:20:26 +00:00
|
|
|
...globalTypes,
|
|
|
|
},
|
2021-04-24 12:30:27 +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 given container
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph = new Graph(container);
|
2021-04-24 12:30:27 +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();
|
|
|
|
|
|
|
|
// Defines the common part of all cell styles as a string-prefix
|
|
|
|
const prefix = 'shape=image;image=images/icons48/keys.png;';
|
|
|
|
|
|
|
|
// Adds cells to the model in a single step and set the vertex
|
|
|
|
// label positions using the label position styles. Vertical
|
|
|
|
// and horizontal label position styles can be combined.
|
|
|
|
// Note: Alternatively, vertex labels can be set be overriding
|
2021-08-30 14:20:26 +00:00
|
|
|
// CellRenderer.getLabelBounds.
|
2022-01-08 01:49:35 +00:00
|
|
|
graph.batchUpdate(() => {
|
2021-04-24 12:30:27 +00:00
|
|
|
graph.insertVertex(
|
|
|
|
parent,
|
|
|
|
null,
|
|
|
|
'Bottom',
|
|
|
|
60,
|
|
|
|
60,
|
|
|
|
60,
|
|
|
|
60,
|
|
|
|
`${prefix}verticalLabelPosition=bottom;verticalAlign=top`
|
|
|
|
);
|
|
|
|
graph.insertVertex(
|
|
|
|
parent,
|
|
|
|
null,
|
|
|
|
'Top',
|
|
|
|
140,
|
|
|
|
60,
|
|
|
|
60,
|
|
|
|
60,
|
|
|
|
`${prefix}verticalLabelPosition=top;verticalAlign=bottom`
|
|
|
|
);
|
|
|
|
graph.insertVertex(
|
|
|
|
parent,
|
|
|
|
null,
|
|
|
|
'Left',
|
|
|
|
60,
|
|
|
|
160,
|
|
|
|
60,
|
|
|
|
60,
|
|
|
|
`${prefix}labelPosition=left;align=right`
|
|
|
|
);
|
|
|
|
graph.insertVertex(
|
|
|
|
parent,
|
|
|
|
null,
|
|
|
|
'Right',
|
|
|
|
140,
|
|
|
|
160,
|
|
|
|
60,
|
|
|
|
60,
|
|
|
|
`${prefix}labelPosition=right;align=left`
|
|
|
|
);
|
2022-01-08 01:49:35 +00:00
|
|
|
});
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
return container;
|
2021-08-30 14:20:26 +00:00
|
|
|
};
|
2021-04-24 12:30:27 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
export const Default = Template.bind({});
|