-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: share common code in a dedicated package (#55)
Introduce a "shared" package that contains all the initialization code for the Graph example used in all projects. The projects only implement the glue code between the shared code and the specific framework. Also share the common assets (style).
- Loading branch information
Showing
26 changed files
with
195 additions
and
527 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# maxgraph-examples-shared | ||
|
||
This package contains the code and assets that are shared between all projects. | ||
|
||
It mainly includes the code calling `@maxGraph/core` to initialize the `Graph`. | ||
|
||
## Setup | ||
|
||
From the repository root, run `npm install`. For more details, see the [root README](../../README.md#setup). | ||
|
||
## Develop | ||
|
||
From the repository root, run `npm run dev -w projects/_shared`. The package will be continuously built making any change | ||
available in other projects using it. | ||
|
||
To build a static version of the "shared" package, run `npm run build -w projects/_shared`. |
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* For rubber band selection, override maxGraph defaults */ | ||
div.mxRubberband { | ||
border-color: #b18426; | ||
background: #db9b0b; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "maxgraph-examples-shared", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "tsc --watch", | ||
"build": "tsc" | ||
}, | ||
"module": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"files": [ | ||
"css", | ||
"lib" | ||
] | ||
} |
16 changes: 4 additions & 12 deletions
16
...cts/sveltekit-ts/src/lib/custom-shapes.ts → projects/_shared/src/custom-shapes.ts
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { | ||
Graph, | ||
InternalEvent, | ||
Perimeter, | ||
RubberBandHandler, | ||
} from '@maxgraph/core'; | ||
import {registerCustomShapes} from "./custom-shapes"; | ||
|
||
export const initializeGraph = (container: HTMLElement) => { | ||
// Disables the built-in context menu | ||
InternalEvent.disableContextMenu(container); | ||
|
||
const graph = new Graph(container); | ||
graph.setPanning(true); // Use mouse right button for panning | ||
new RubberBandHandler(graph); // Enables rubber band selection | ||
|
||
// shapes and styles | ||
registerCustomShapes(); | ||
// create a dedicated style for "ellipse" to share properties | ||
graph.getStylesheet().putCellStyle('myEllipse', { | ||
perimeter: Perimeter.EllipsePerimeter, | ||
shape: 'ellipse', | ||
verticalAlign: 'top', | ||
verticalLabelPosition: 'bottom', | ||
}); | ||
|
||
// 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(() => { | ||
// use the legacy insertVertex method | ||
const vertex01 = graph.insertVertex( | ||
parent, | ||
null, | ||
'a regular rectangle', | ||
10, | ||
10, | ||
100, | ||
100 | ||
); | ||
const vertex02 = graph.insertVertex( | ||
parent, | ||
null, | ||
'a regular ellipse', | ||
350, | ||
90, | ||
50, | ||
50, | ||
{ | ||
baseStyleNames: ['myEllipse'], | ||
fillColor: 'orange', | ||
} | ||
); | ||
// use the legacy insertEdge method | ||
graph.insertEdge(parent, null, 'an orthogonal style edge', vertex01, vertex02, { | ||
// TODO cannot use constants.EDGESTYLE.ORTHOGONAL | ||
// TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided. | ||
// See https://github.com/maxGraph/maxGraph/issues/205 | ||
edgeStyle: 'orthogonalEdgeStyle', | ||
rounded: true, | ||
}); | ||
|
||
// insert vertex using custom shapes using the new insertVertex method | ||
const vertex11 = graph.insertVertex({ | ||
parent, | ||
value: 'a custom rectangle', | ||
position: [20, 200], | ||
size: [100, 100], | ||
style: { shape: 'customRectangle' }, | ||
}); | ||
// use the new insertVertex method using position and size parameters | ||
const vertex12 = graph.insertVertex({ | ||
parent, | ||
value: 'a custom ellipse', | ||
x: 150, | ||
y: 350, | ||
width: 70, | ||
height: 70, | ||
style: { | ||
baseStyleNames: ['myEllipse'], | ||
shape: 'customEllipse', | ||
}, | ||
}); | ||
// use the new insertEdge method | ||
graph.insertEdge({ | ||
parent, | ||
value: 'another edge', | ||
source: vertex11, | ||
target: vertex12, | ||
style: { endArrow: 'block' }, | ||
}); | ||
}); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export {initializeGraph} from './generate-graph'; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"lib": ["ESNext", "DOM"], | ||
"moduleResolution": "Node", | ||
"strict": true, | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"noEmit": false, | ||
"declaration": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true | ||
}, | ||
"include": ["src"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.