Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: declare RubberBandHandler as a plugin #148

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Build the "shared" package:
- [TypeScript with Lit](./projects/lit-ts/README.md)
- [TypeScript with Parcel](./projects/parcel-ts/README.md)
- [TypeScript with Rollup](./projects/rollup-ts/README.md)
- [TypeScript with Rsbuild](./projects/rsbuild-ts/README.md)
- [TypeScript with SvelteKit](./projects/sveltekit-ts/README.md)
- [TypeScript with ViteJs](./projects/vitejs-ts/README.md)

Expand Down
15 changes: 11 additions & 4 deletions projects/_shared/src/generate-graph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
constants,
getDefaultPlugins,
Graph,
GraphDataModel,
InternalEvent,
Perimeter,
RubberBandHandler,
Expand All @@ -11,9 +13,14 @@ export const initializeGraph = (container: HTMLElement) => {
// Disables the built-in context menu
InternalEvent.disableContextMenu(container);

const graph = new Graph(container);
const graph = new Graph(container, new GraphDataModel(), [
...getDefaultPlugins(),
RubberBandHandler, // Enables rubber band selection
]);
graph.setPanning(true); // Use mouse right button for panning
new RubberBandHandler(graph); // Enables rubber band selection

// Customize the rubber band selection
graph.getPlugin<RubberBandHandler>('RubberBandHandler').fadeOut = true;

// shapes and styles
registerCustomShapes();
Expand Down Expand Up @@ -66,7 +73,7 @@ export const initializeGraph = (container: HTMLElement) => {
value: 'a custom rectangle',
position: [20, 200],
size: [100, 100],
style: { shape: 'customRectangle' },
style: {shape: 'customRectangle'},
});
// use the new insertVertex method using position and size parameters
const vertex12 = graph.insertVertex({
Expand All @@ -87,7 +94,7 @@ export const initializeGraph = (container: HTMLElement) => {
value: 'another edge',
source: vertex11,
target: vertex12,
style: { endArrow: 'block' },
style: {endArrow: 'block'},
});
});
}