2022-08-30 15:36:33 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-09-07 09:07:27 +00:00
|
|
|
import { Graph } from '@maxgraph/core';
|
2023-10-12 21:41:37 +00:00
|
|
|
import { globalTypes, globalValues } from './shared/args.js';
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Labels/Wrapping',
|
|
|
|
argTypes: {
|
2021-08-30 14:20:26 +00:00
|
|
|
...globalTypes,
|
|
|
|
},
|
2023-10-12 21:41:37 +00:00
|
|
|
args: {
|
|
|
|
...globalValues,
|
|
|
|
},
|
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
|
|
|
|
|
|
|
// Enables HTML labels as wrapping is only available for those
|
|
|
|
graph.setHtmlLabels(true);
|
|
|
|
|
|
|
|
// Disables in-place editing for edges
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.isCellEditable = function (cell) {
|
2021-04-25 03:39:40 +00:00
|
|
|
return !cell.isEdge();
|
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();
|
|
|
|
|
|
|
|
// Adds cells to the model in a single step
|
|
|
|
graph.batchUpdate(() => {
|
|
|
|
const v1 = graph.insertVertex({
|
|
|
|
parent,
|
|
|
|
value: 'Cum Caesar vidisset, portum plenum esse, iuxta navigavit.',
|
|
|
|
position: [20, 20],
|
|
|
|
size: [100, 70],
|
2022-04-17 06:58:35 +00:00
|
|
|
style: { whiteSpace: 'wrap' },
|
2021-04-24 12:30:27 +00:00
|
|
|
});
|
|
|
|
const v2 = graph.insertVertex({
|
|
|
|
parent,
|
|
|
|
value: 'Cum Caesar vidisset, portum plenum esse, iuxta navigavit.',
|
|
|
|
position: [220, 150],
|
|
|
|
size: [80, 70],
|
2022-04-17 06:58:35 +00:00
|
|
|
style: { whiteSpace: 'wrap' },
|
2021-04-24 12:30:27 +00:00
|
|
|
});
|
|
|
|
const e1 = graph.insertEdge({
|
|
|
|
parent,
|
|
|
|
value: 'Cum Caesar vidisset, portum plenum esse, iuxta navigavit.',
|
|
|
|
source: v1,
|
|
|
|
target: v2,
|
2022-04-17 06:58:35 +00:00
|
|
|
style: { whiteSpace: 'wrap' },
|
2021-04-24 12:30:27 +00:00
|
|
|
});
|
|
|
|
e1.geometry.width = 100;
|
|
|
|
});
|
|
|
|
|
|
|
|
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({});
|