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 {
|
2023-10-12 21:41:37 +00:00
|
|
|
Client,
|
|
|
|
DomHelpers,
|
2021-09-07 09:07:27 +00:00
|
|
|
EdgeStyle,
|
2023-10-12 21:41:37 +00:00
|
|
|
Graph,
|
|
|
|
MaxWindow,
|
2021-09-07 09:07:27 +00:00
|
|
|
Point,
|
2023-10-12 21:41:37 +00:00
|
|
|
RubberBandHandler,
|
|
|
|
xmlUtils,
|
2021-09-07 09:07:27 +00:00
|
|
|
} from '@maxgraph/core';
|
2021-04-20 12:22:55 +00:00
|
|
|
|
2023-10-12 21:41:37 +00:00
|
|
|
import {
|
|
|
|
globalTypes,
|
|
|
|
globalValues,
|
|
|
|
rubberBandTypes,
|
|
|
|
rubberBandValues,
|
|
|
|
} from './shared/args.js';
|
|
|
|
// style required by RubberBand
|
|
|
|
import '@maxgraph/core/css/common.css';
|
2021-04-20 12:22:55 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Connections/HelloPort',
|
|
|
|
argTypes: {
|
2021-04-21 04:54:09 +00:00
|
|
|
...globalTypes,
|
2023-10-12 21:41:37 +00:00
|
|
|
...rubberBandTypes,
|
|
|
|
},
|
|
|
|
args: {
|
|
|
|
...globalValues,
|
|
|
|
...rubberBandValues,
|
2021-08-30 14:20:26 +00:00
|
|
|
},
|
2021-04-20 12:22:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const Template = ({ label, ...args }) => {
|
2022-01-08 01:49:35 +00:00
|
|
|
Client.setImageBasePath('/images');
|
2021-04-25 03:39:40 +00:00
|
|
|
|
2021-04-20 12:22:55 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
// Creates the graph inside the given container
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph = new Graph(container);
|
2021-04-20 12:22:55 +00:00
|
|
|
graph.setConnectable(true);
|
|
|
|
graph.setTooltips(true);
|
|
|
|
|
|
|
|
// Sets the default edge style
|
|
|
|
const style = graph.getStylesheet().getDefaultEdgeStyle();
|
2021-08-30 14:20:26 +00:00
|
|
|
style.edge = EdgeStyle.ElbowConnector;
|
2021-04-20 12:22:55 +00:00
|
|
|
|
|
|
|
// Ports are not used as terminals for edges, they are
|
|
|
|
// only used to compute the graphical connection point
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.isPort = function (cell) {
|
2021-09-10 05:17:59 +00:00
|
|
|
const geo = cell.getGeometry();
|
2021-04-20 12:22:55 +00:00
|
|
|
|
|
|
|
return geo != null ? geo.relative : false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implements a tooltip that shows the actual
|
|
|
|
// source and target of an edge
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.getTooltipForCell = function (cell) {
|
2021-04-25 03:39:40 +00:00
|
|
|
if (cell.isEdge()) {
|
2021-04-20 12:22:55 +00:00
|
|
|
return `${this.convertValueToString(
|
2021-04-25 03:39:40 +00:00
|
|
|
cell.getTerminal(true)
|
2021-08-30 14:20:26 +00:00
|
|
|
)} => ${this.convertValueToString(cell.getTerminal(false))}`;
|
2021-04-20 12:22:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
return Graph.prototype.getTooltipForCell.apply(this, arguments);
|
2021-04-20 12:22:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Removes the folding icon and disables any folding
|
2021-08-30 14:20:26 +00:00
|
|
|
graph.isCellFoldable = function (cell) {
|
2021-04-20 12:22:55 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Enables rubberband selection
|
2022-01-08 01:49:35 +00:00
|
|
|
if (args.rubberBand) new RubberBandHandler(graph);
|
2021-04-20 12:22:55 +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(() => {
|
2021-04-20 12:22:55 +00:00
|
|
|
const v1 = graph.insertVertex(parent, null, 'Hello', 20, 80, 80, 30);
|
|
|
|
v1.setConnectable(false);
|
|
|
|
const v11 = graph.insertVertex(v1, null, '', 1, 1, 10, 10);
|
2021-08-30 14:20:26 +00:00
|
|
|
v11.geometry.offset = new Point(-5, -5);
|
2021-04-20 12:22:55 +00:00
|
|
|
v11.geometry.relative = true;
|
|
|
|
const v12 = graph.insertVertex(v1, null, '', 1, 0, 10, 10);
|
2021-08-30 14:20:26 +00:00
|
|
|
v12.geometry.offset = new Point(-5, -5);
|
2021-04-20 12:22:55 +00:00
|
|
|
v12.geometry.relative = true;
|
|
|
|
const v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
|
|
|
|
const v3 = graph.insertVertex(parent, null, 'World2', 200, 20, 80, 30);
|
|
|
|
var e1 = graph.insertEdge(parent, null, '', v11, v2);
|
|
|
|
var e1 = graph.insertEdge(parent, null, '', v12, v3);
|
2022-01-08 01:49:35 +00:00
|
|
|
});
|
2021-04-20 12:22:55 +00:00
|
|
|
|
|
|
|
const controller = document.createElement('div');
|
|
|
|
div.appendChild(controller);
|
|
|
|
|
2022-01-08 01:49:35 +00:00
|
|
|
const button = DomHelpers.button('View XML', function () {
|
|
|
|
const encoder = new Codec();
|
|
|
|
const node = encoder.encode(graph.getDataModel());
|
2023-10-12 21:41:37 +00:00
|
|
|
MaxWindow.popup(xmlUtils.getPrettyXml(node), true);
|
2021-04-20 12:22:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
controller.appendChild(button);
|
|
|
|
|
|
|
|
return div;
|
2021-08-30 14:20:26 +00:00
|
|
|
};
|
2021-04-20 12:22:55 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
export const Default = Template.bind({});
|