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.
|
|
|
|
*/
|
|
|
|
|
2022-01-08 01:49:35 +00:00
|
|
|
import { Graph, constants, EdgeStyle, StackLayout, LayoutManager } from '@maxgraph/core';
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
import { globalTypes } from '../.storybook/preview';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Layouts/Folding',
|
|
|
|
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';
|
|
|
|
|
2021-09-10 05:17:59 +00:00
|
|
|
// Should we allow overriding constant values?
|
2021-04-24 12:30:27 +00:00
|
|
|
// Enables crisp rendering of rectangles in SVG
|
2022-01-08 01:49:35 +00:00
|
|
|
// constants.ENTITY_SEGMENT = 20;
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
graph.setDropEnabled(true);
|
|
|
|
|
|
|
|
// Disables global features
|
|
|
|
graph.collapseToPreferredSize = false;
|
|
|
|
graph.constrainChildren = false;
|
|
|
|
graph.cellsSelectable = false;
|
|
|
|
graph.extendParentsOnAdd = false;
|
|
|
|
graph.extendParents = false;
|
|
|
|
graph.border = 10;
|
|
|
|
|
|
|
|
// Sets global styles
|
|
|
|
let style = graph.getStylesheet().getDefaultEdgeStyle();
|
2021-08-30 14:20:26 +00:00
|
|
|
style.edge = EdgeStyle.EntityRelation;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.rounded = true;
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
style = graph.getStylesheet().getDefaultVertexStyle();
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fillColor = '#ffffff';
|
|
|
|
style.shape = 'swimlane';
|
|
|
|
style.startSize = 30;
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
style = [];
|
2022-01-08 01:49:35 +00:00
|
|
|
style.shape = constants.SHAPE_RECTANGLE;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeColor = 'none';
|
|
|
|
style.fillColor = 'none';
|
|
|
|
style.foldable = false;
|
2021-04-24 12:30:27 +00:00
|
|
|
graph.getStylesheet().putCellStyle('column', style);
|
|
|
|
|
|
|
|
// Installs auto layout for all levels
|
2021-08-30 14:20:26 +00:00
|
|
|
const layout = new StackLayout(graph, true);
|
2021-04-24 12:30:27 +00:00
|
|
|
layout.border = graph.border;
|
2021-08-30 14:20:26 +00:00
|
|
|
const layoutMgr = new LayoutManager(graph);
|
|
|
|
layoutMgr.getLayout = function (cell) {
|
2021-04-24 12:30:27 +00:00
|
|
|
if (!cell.collapsed) {
|
|
|
|
if (cell.parent !== graph.model.root) {
|
|
|
|
layout.resizeParent = true;
|
|
|
|
layout.horizontal = false;
|
|
|
|
layout.spacing = 10;
|
|
|
|
} else {
|
|
|
|
layout.resizeParent = true;
|
|
|
|
layout.horizontal = true;
|
|
|
|
layout.spacing = 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Resizes the container
|
|
|
|
graph.setResizeContainer(true);
|
|
|
|
|
|
|
|
// 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 col1 = graph.insertVertex(parent, null, '', 0, 0, 120, 0, {
|
2022-05-08 09:18:53 +00:00
|
|
|
baseStyleNames: ['column'],
|
2022-04-17 06:58:35 +00:00
|
|
|
});
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
const v1 = graph.insertVertex(col1, null, '1', 0, 0, 100, 30);
|
|
|
|
v1.collapsed = true;
|
|
|
|
|
|
|
|
const v11 = graph.insertVertex(v1, null, '1.1', 0, 0, 80, 30);
|
|
|
|
v11.collapsed = true;
|
|
|
|
|
|
|
|
const v111 = graph.insertVertex(v11, null, '1.1.1', 0, 0, 60, 30);
|
|
|
|
const v112 = graph.insertVertex(v11, null, '1.1.2', 0, 0, 60, 30);
|
|
|
|
|
|
|
|
const v12 = graph.insertVertex(v1, null, '1.2', 0, 0, 80, 30);
|
|
|
|
|
2022-04-17 06:58:35 +00:00
|
|
|
const col2 = graph.insertVertex(parent, null, '', 0, 0, 120, 0, {
|
2022-05-08 09:18:53 +00:00
|
|
|
baseStyleNames: ['column'],
|
2022-04-17 06:58:35 +00:00
|
|
|
});
|
2021-04-24 12:30:27 +00:00
|
|
|
|
|
|
|
const v2 = graph.insertVertex(col2, null, '2', 0, 0, 100, 30);
|
|
|
|
v2.collapsed = true;
|
|
|
|
|
|
|
|
const v21 = graph.insertVertex(v2, null, '2.1', 0, 0, 80, 30);
|
|
|
|
v21.collapsed = true;
|
|
|
|
|
|
|
|
const v211 = graph.insertVertex(v21, null, '2.1.1', 0, 0, 60, 30);
|
|
|
|
const v212 = graph.insertVertex(v21, null, '2.1.2', 0, 0, 60, 30);
|
|
|
|
|
|
|
|
const v22 = graph.insertVertex(v2, null, '2.2', 0, 0, 80, 30);
|
|
|
|
|
|
|
|
const v3 = graph.insertVertex(col2, null, '3', 0, 0, 100, 30);
|
|
|
|
v3.collapsed = true;
|
|
|
|
|
|
|
|
const v31 = graph.insertVertex(v3, null, '3.1', 0, 0, 80, 30);
|
|
|
|
v31.collapsed = true;
|
|
|
|
|
|
|
|
const v311 = graph.insertVertex(v31, null, '3.1.1', 0, 0, 60, 30);
|
|
|
|
const v312 = graph.insertVertex(v31, null, '3.1.2', 0, 0, 60, 30);
|
|
|
|
|
|
|
|
const v32 = graph.insertVertex(v3, null, '3.2', 0, 0, 80, 30);
|
|
|
|
|
|
|
|
graph.insertEdge(parent, null, '', v111, v211);
|
|
|
|
graph.insertEdge(parent, null, '', v112, v212);
|
|
|
|
graph.insertEdge(parent, null, '', v112, v22);
|
|
|
|
|
|
|
|
graph.insertEdge(parent, null, '', v12, v311);
|
|
|
|
graph.insertEdge(parent, null, '', v12, v312);
|
|
|
|
graph.insertEdge(parent, null, '', v12, v32);
|
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({});
|