maxGraph/packages/html/stories/Folding.stories.js

139 lines
4.1 KiB
JavaScript
Raw Normal View History

Finish converting core to ts, JSDoc conversion, consistency+convention changes, example bugfixes (#70) * reorganised directories; removed mx prefix * reduced directory hierarchies; removed mx prefix; type fixes * convert remaining javascript to ts * fix/add types * add type defs * type updates; moved codecs to where they're used * reorganise constants into enums+type additions * removed "Function:" and "Variable:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:", "Variable:" and "Class:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:" prefixes from comments, as they aren't needed in JSDoc * minor changes * convert code example blocks to markdown * module casing updates * converted parameter function documentation to JSDoc * documentation+type updates * removed react subdir (for now) * reorganised various `utils` functions into different files * type updates/bugfixes/workarounds * rename Rubberband and CellEditor to be *Handler to match the other plugins * move codec classes to where they're used to reduce cyclic dependencies * move codec classes to where they're used to reduce cyclic dependencies * type updates/reorganize layout file structure * renamed various files for consistency * import fixes * renamed GraphHandler SelectionHander and various fixes * convert EventObject parameters to objects * add basic better-docs config * update better-docs config * bugfix for shared variables in Graph persisting across instances * fixed accessing handlers in examples; renamed Model to GraphModel * fixed accessing handlers in examples; renamed Model to GraphModel * restored selection model * bugfix * renamed getModel to getDataModel * changed to use graph.batchUpdate() to reduce lines of code * changed to use graph.batchUpdate() to reduce lines of code * finished annotations+added TypeDoc * convert remaining Cell[] instances to CellArray * convert NaturalDocs links to JSDoc
2022-01-08 01:49:35 +00:00
import { Graph, constants, EdgeStyle, StackLayout, LayoutManager } from '@maxgraph/core';
import { globalTypes } from '../.storybook/preview';
export default {
title: 'Layouts/Folding',
argTypes: {
...globalTypes,
},
};
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?
// Enables crisp rendering of rectangles in SVG
Finish converting core to ts, JSDoc conversion, consistency+convention changes, example bugfixes (#70) * reorganised directories; removed mx prefix * reduced directory hierarchies; removed mx prefix; type fixes * convert remaining javascript to ts * fix/add types * add type defs * type updates; moved codecs to where they're used * reorganise constants into enums+type additions * removed "Function:" and "Variable:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:", "Variable:" and "Class:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:" prefixes from comments, as they aren't needed in JSDoc * minor changes * convert code example blocks to markdown * module casing updates * converted parameter function documentation to JSDoc * documentation+type updates * removed react subdir (for now) * reorganised various `utils` functions into different files * type updates/bugfixes/workarounds * rename Rubberband and CellEditor to be *Handler to match the other plugins * move codec classes to where they're used to reduce cyclic dependencies * move codec classes to where they're used to reduce cyclic dependencies * type updates/reorganize layout file structure * renamed various files for consistency * import fixes * renamed GraphHandler SelectionHander and various fixes * convert EventObject parameters to objects * add basic better-docs config * update better-docs config * bugfix for shared variables in Graph persisting across instances * fixed accessing handlers in examples; renamed Model to GraphModel * fixed accessing handlers in examples; renamed Model to GraphModel * restored selection model * bugfix * renamed getModel to getDataModel * changed to use graph.batchUpdate() to reduce lines of code * changed to use graph.batchUpdate() to reduce lines of code * finished annotations+added TypeDoc * convert remaining Cell[] instances to CellArray * convert NaturalDocs links to JSDoc
2022-01-08 01:49:35 +00:00
// constants.ENTITY_SEGMENT = 20;
// Creates the graph inside the given container
const graph = new Graph(container);
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();
style.edge = EdgeStyle.EntityRelation;
style.rounded = true;
style = graph.getStylesheet().getDefaultVertexStyle();
style.fillColor = '#ffffff';
style.shape = 'swimlane';
style.startSize = 30;
style = [];
Finish converting core to ts, JSDoc conversion, consistency+convention changes, example bugfixes (#70) * reorganised directories; removed mx prefix * reduced directory hierarchies; removed mx prefix; type fixes * convert remaining javascript to ts * fix/add types * add type defs * type updates; moved codecs to where they're used * reorganise constants into enums+type additions * removed "Function:" and "Variable:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:", "Variable:" and "Class:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:" prefixes from comments, as they aren't needed in JSDoc * minor changes * convert code example blocks to markdown * module casing updates * converted parameter function documentation to JSDoc * documentation+type updates * removed react subdir (for now) * reorganised various `utils` functions into different files * type updates/bugfixes/workarounds * rename Rubberband and CellEditor to be *Handler to match the other plugins * move codec classes to where they're used to reduce cyclic dependencies * move codec classes to where they're used to reduce cyclic dependencies * type updates/reorganize layout file structure * renamed various files for consistency * import fixes * renamed GraphHandler SelectionHander and various fixes * convert EventObject parameters to objects * add basic better-docs config * update better-docs config * bugfix for shared variables in Graph persisting across instances * fixed accessing handlers in examples; renamed Model to GraphModel * fixed accessing handlers in examples; renamed Model to GraphModel * restored selection model * bugfix * renamed getModel to getDataModel * changed to use graph.batchUpdate() to reduce lines of code * changed to use graph.batchUpdate() to reduce lines of code * finished annotations+added TypeDoc * convert remaining Cell[] instances to CellArray * convert NaturalDocs links to JSDoc
2022-01-08 01:49:35 +00:00
style.shape = constants.SHAPE_RECTANGLE;
style.strokeColor = 'none';
style.fillColor = 'none';
style.foldable = false;
graph.getStylesheet().putCellStyle('column', style);
// Installs auto layout for all levels
const layout = new StackLayout(graph, true);
layout.border = graph.border;
const layoutMgr = new LayoutManager(graph);
layoutMgr.getLayout = function (cell) {
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
Finish converting core to ts, JSDoc conversion, consistency+convention changes, example bugfixes (#70) * reorganised directories; removed mx prefix * reduced directory hierarchies; removed mx prefix; type fixes * convert remaining javascript to ts * fix/add types * add type defs * type updates; moved codecs to where they're used * reorganise constants into enums+type additions * removed "Function:" and "Variable:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:", "Variable:" and "Class:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:" prefixes from comments, as they aren't needed in JSDoc * minor changes * convert code example blocks to markdown * module casing updates * converted parameter function documentation to JSDoc * documentation+type updates * removed react subdir (for now) * reorganised various `utils` functions into different files * type updates/bugfixes/workarounds * rename Rubberband and CellEditor to be *Handler to match the other plugins * move codec classes to where they're used to reduce cyclic dependencies * move codec classes to where they're used to reduce cyclic dependencies * type updates/reorganize layout file structure * renamed various files for consistency * import fixes * renamed GraphHandler SelectionHander and various fixes * convert EventObject parameters to objects * add basic better-docs config * update better-docs config * bugfix for shared variables in Graph persisting across instances * fixed accessing handlers in examples; renamed Model to GraphModel * fixed accessing handlers in examples; renamed Model to GraphModel * restored selection model * bugfix * renamed getModel to getDataModel * changed to use graph.batchUpdate() to reduce lines of code * changed to use graph.batchUpdate() to reduce lines of code * finished annotations+added TypeDoc * convert remaining Cell[] instances to CellArray * convert NaturalDocs links to JSDoc
2022-01-08 01:49:35 +00:00
graph.batchUpdate(() => {
const col1 = graph.insertVertex(parent, null, '', 0, 0, 120, 0, {
baseStyleName: 'column',
});
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);
const col2 = graph.insertVertex(parent, null, '', 0, 0, 120, 0, {
baseStyleName: 'column',
});
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);
Finish converting core to ts, JSDoc conversion, consistency+convention changes, example bugfixes (#70) * reorganised directories; removed mx prefix * reduced directory hierarchies; removed mx prefix; type fixes * convert remaining javascript to ts * fix/add types * add type defs * type updates; moved codecs to where they're used * reorganise constants into enums+type additions * removed "Function:" and "Variable:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:", "Variable:" and "Class:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:" prefixes from comments, as they aren't needed in JSDoc * minor changes * convert code example blocks to markdown * module casing updates * converted parameter function documentation to JSDoc * documentation+type updates * removed react subdir (for now) * reorganised various `utils` functions into different files * type updates/bugfixes/workarounds * rename Rubberband and CellEditor to be *Handler to match the other plugins * move codec classes to where they're used to reduce cyclic dependencies * move codec classes to where they're used to reduce cyclic dependencies * type updates/reorganize layout file structure * renamed various files for consistency * import fixes * renamed GraphHandler SelectionHander and various fixes * convert EventObject parameters to objects * add basic better-docs config * update better-docs config * bugfix for shared variables in Graph persisting across instances * fixed accessing handlers in examples; renamed Model to GraphModel * fixed accessing handlers in examples; renamed Model to GraphModel * restored selection model * bugfix * renamed getModel to getDataModel * changed to use graph.batchUpdate() to reduce lines of code * changed to use graph.batchUpdate() to reduce lines of code * finished annotations+added TypeDoc * convert remaining Cell[] instances to CellArray * convert NaturalDocs links to JSDoc
2022-01-08 01:49:35 +00:00
});
return container;
};
export const Default = Template.bind({});