FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: restore remaining non-"Editor" examples to Storybook by mcyph · Pull Request #150 · maxGraph/maxGraph · GitHub

forked from jgraph/mxgraph
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (13) .ts  (3) All 2 file types selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 6 additions & 4 deletions packages/core/src/gui/MaxPopupMenu.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class MaxPopupMenu extends EventSource implements Partial<PopupMenuItem> {
) {
super();

this.factoryMethod = factoryMethod;
if (factoryMethod) {
this.factoryMethod = factoryMethod;
}

// Adds the inner table
this.table = document.createElement('table');
Expand Down Expand Up @@ -189,9 +191,9 @@ class MaxPopupMenu extends EventSource implements Partial<PopupMenuItem> {
funct: Function,
parent: PopupMenuItem | null = null,
iconCls: string | null = null,
enabled: boolean | null = null,
active: boolean | null = null,
noHover: boolean | null = null
enabled = true,
active = true,
noHover = false
) {
parent = (parent ?? this) as PopupMenuItem;
this.itemCount++;
Expand Down
150 changes: 90 additions & 60 deletions packages/core/src/view/Graph.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class Graph extends EventSource {
foldingEnabled: null | boolean = null;
isConstrainedMoving = false;

/*****************************************************************************
* Group: Variables (that maybe should be in the mixins, but need to be created for each new class instance)
*****************************************************************************/
// ===================================================================================================================
// Group: Variables (that maybe should be in the mixins, but need to be created for each new class instance)
// ===================================================================================================================

cells: Cell[] = [];

Expand All @@ -111,10 +111,6 @@ class Graph extends EventSource {
*/
multiplicities: Multiplicity[] = [];

/*****************************************************************************
* Group: Variables
*****************************************************************************/

/**
* Holds the {@link GraphDataModel} that contains the cells to be displayed.
*/
Expand Down Expand Up @@ -407,6 +403,89 @@ class Graph extends EventSource {
containsValidationErrorsResource: string =
Client.language != 'none' ? 'containsValidationErrors' : '';

// ===================================================================================================================
// Group: "Create Class Instance" factory functions.
// These can be overridden in subclasses of Graph to allow the Graph to instantiate user-defined implementations with
// custom behavior.
// ===================================================================================================================

/**
* Creates a new {@link CellRenderer} to be used in this graph.
*/
createCellRenderer(): CellRenderer {
return new CellRenderer();
}

/**
* Hooks to create a new {@link EdgeHandler} for the given {@link CellState}.
*
* @param state {@link CellState} to create the handler for.
*/
createEdgeHandlerInstance(state: CellState): EdgeHandler {
// Note this method not being called createEdgeHandler to keep compatibility
// with older code which overrides/calls createEdgeHandler
return new EdgeHandler(state);
}

/**
* Hooks to create a new {@link EdgeSegmentHandler} for the given {@link CellState}.
*
* @param state {@link CellState} to create the handler for.
*/
createEdgeSegmentHandler(state: CellState) {
return new EdgeSegmentHandler(state);
}

/**
* Hooks to create a new {@link ElbowEdgeHandler} for the given {@link CellState}.
*
* @param state {@link CellState} to create the handler for.
*/
createElbowEdgeHandler(state: CellState) {
return new ElbowEdgeHandler(state);
}

/**
* Creates a new {@link GraphDataModel} to be used in this graph.
*/
createGraphDataModel(): GraphDataModel {
return new GraphDataModel();
}

/**
* Creates a new {@link GraphView} to be used in this graph.
*/
createGraphView(): GraphView {
return new GraphView(this);
}

/**
* Creates a new {@link GraphSelectionModel} to be used in this graph.
*/
createSelectionModel() {
return new GraphSelectionModel(this);
}

/**
* Creates a new {@link Stylesheet} to be used in this graph.
*/
createStylesheet(): Stylesheet {
return new Stylesheet();
}

/**
* Hooks to create a new {@link VertexHandler} for the given {@link CellState}.
*
* @param state {@link CellState} to create the handler for.
*/
createVertexHandler(state: CellState): VertexHandler {
return new VertexHandler(state);
}

// ===================================================================================================================
// Group: Main graph constructor and functions
// ===================================================================================================================

constructor(
container: HTMLElement,
model?: GraphDataModel,
Expand All @@ -416,10 +495,10 @@ class Graph extends EventSource {
super();

this.container = container ?? document.createElement('div');
this.model = model ?? new GraphDataModel();
this.model = model ?? this.createGraphDataModel();
this.plugins = plugins;
this.cellRenderer = this.createCellRenderer();
this.setStylesheet(stylesheet != null ? stylesheet : this.createStylesheet());
this.setStylesheet(stylesheet ?? this.createStylesheet());
this.view = this.createGraphView();

// Adds a graph model listener to update the view
Expand All @@ -437,15 +516,14 @@ class Graph extends EventSource {
// Set the selection model
this.setSelectionModel(this.createSelectionModel());

// Initiailzes plugins
// Initializes plugins
this.plugins.forEach((p: GraphPluginConstructor) => {
this.pluginsMap[p.pluginId] = new p(this);
});

this.view.revalidate();
}

createSelectionModel = () => new GraphSelectionModel(this);
getContainer = () => this.container;
getPlugin = (id: string) => this.pluginsMap[id] as unknown;
getCellRenderer = () => this.cellRenderer;
Expand Down Expand Up @@ -489,27 +567,6 @@ class Graph extends EventSource {
this.getDataModel().batchUpdate(fn);
}

/**
* Creates a new {@link Stylesheet} to be used in this graph.
*/
createStylesheet(): Stylesheet {
return new Stylesheet();
}

/**
* Creates a new {@link GraphView} to be used in this graph.
*/
createGraphView() {
return new GraphView(this);
}

/**
* Creates a new {@link CellRenderer} to be used in this graph.
*/
createCellRenderer(): CellRenderer {
return new CellRenderer();
}

/**
* Returns the {@link GraphDataModel} that contains the cells.
*/
Expand Down Expand Up @@ -960,15 +1017,6 @@ class Graph extends EventSource {
return result;
}

/**
* Hooks to create a new {@link VertexHandler} for the given {@link CellState}.
*
* @param state {@link CellState} to create the handler for.
*/
createVertexHandler(state: CellState): VertexHandler {
return new VertexHandler(state);
}

/**
* Hooks to create a new {@link EdgeHandler} for the given {@link CellState}.
*
Expand All @@ -989,30 +1037,12 @@ class Graph extends EventSource {
) {
result = this.createEdgeSegmentHandler(state);
} else {
result = new EdgeHandler(state);
result = this.createEdgeHandlerInstance(state);
}

return result as EdgeHandler;
}

/**
* Hooks to create a new {@link EdgeSegmentHandler} for the given {@link CellState}.
*
* @param state {@link CellState} to create the handler for.
*/
createEdgeSegmentHandler(state: CellState) {
return new EdgeSegmentHandler(state);
}

/**
* Hooks to create a new {@link ElbowEdgeHandler} for the given {@link CellState}.
*
* @param state {@link CellState} to create the handler for.
*/
createElbowEdgeHandler(state: CellState) {
return new ElbowEdgeHandler(state);
}

/*****************************************************************************
* Group: Drilldown
*****************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/animate/Morphing.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { Graph } from '../Graph';
* @param delay Optional delay between the animation steps. Passed to <Animation>.
*/
class Morphing extends Animation {
constructor(graph: Graph, steps = 6, ease = 1.5, delay: number) {
constructor(graph: Graph, steps = 6, ease = 1.5, delay?: number) {
super(delay);
this.graph = graph;
this.steps = steps;
Expand Down
Loading

Back | FazBrowse Home | New Git URL