Skip to content

Commit 7cf4936

Browse files
authored
refactor: declare RubberBandHandler as a plugin (#148)
Also enable `fadeOut` option. Add missing link to the Rsbuild project in the main README.
1 parent 7daa72d commit 7cf4936

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Build the "shared" package:
3131
- [TypeScript with Lit](./projects/lit-ts/README.md)
3232
- [TypeScript with Parcel](./projects/parcel-ts/README.md)
3333
- [TypeScript with Rollup](./projects/rollup-ts/README.md)
34+
- [TypeScript with Rsbuild](./projects/rsbuild-ts/README.md)
3435
- [TypeScript with SvelteKit](./projects/sveltekit-ts/README.md)
3536
- [TypeScript with ViteJs](./projects/vitejs-ts/README.md)
3637

projects/_shared/src/generate-graph.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
constants,
3+
getDefaultPlugins,
34
Graph,
5+
GraphDataModel,
46
InternalEvent,
57
Perimeter,
68
RubberBandHandler,
@@ -11,9 +13,14 @@ export const initializeGraph = (container: HTMLElement) => {
1113
// Disables the built-in context menu
1214
InternalEvent.disableContextMenu(container);
1315

14-
const graph = new Graph(container);
16+
const graph = new Graph(container, new GraphDataModel(), [
17+
...getDefaultPlugins(),
18+
RubberBandHandler, // Enables rubber band selection
19+
]);
1520
graph.setPanning(true); // Use mouse right button for panning
16-
new RubberBandHandler(graph); // Enables rubber band selection
21+
22+
// Customize the rubber band selection
23+
graph.getPlugin<RubberBandHandler>('RubberBandHandler').fadeOut = true;
1724

1825
// shapes and styles
1926
registerCustomShapes();
@@ -66,7 +73,7 @@ export const initializeGraph = (container: HTMLElement) => {
6673
value: 'a custom rectangle',
6774
position: [20, 200],
6875
size: [100, 100],
69-
style: { shape: 'customRectangle' },
76+
style: {shape: 'customRectangle'},
7077
});
7178
// use the new insertVertex method using position and size parameters
7279
const vertex12 = graph.insertVertex({
@@ -87,7 +94,7 @@ export const initializeGraph = (container: HTMLElement) => {
8794
value: 'another edge',
8895
source: vertex11,
8996
target: vertex12,
90-
style: { endArrow: 'block' },
97+
style: {endArrow: 'block'},
9198
});
9299
});
93100
}

0 commit comments

Comments
 (0)