Skip to content

Commit 3273868

Browse files
committed
Demos are a whole lot better now
1 parent ecd7202 commit 3273868

File tree

11 files changed

+137
-108
lines changed

11 files changed

+137
-108
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Checklist
2+
3+
- [] The code has been run through pretty `yarn run pretty`
4+
- [] The PR Template has been filled out (see below)
5+
- [] Had a beer because you are awesome
6+
7+
## What?
8+
9+
(My awesome new feature does this really cool thing.)
10+
11+
## Why?
12+
13+
(Because obviously it could not do it before)
14+
15+
## How?
16+
17+
(Basically I did this and that because im a super 1337 hacker)
18+
19+
## Feel-Good "programming lol" image:
20+
21+
(Add your own one below)
22+
23+
![](https://media.giphy.com/media/13HgwGsXF0aiGY/giphy.gif)
24+
25+

CONTRIBUTING.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contributing
2+
3+
See below for guidelines on house keeping:
4+
5+
### Always add a PR
6+
7+
Since the project runs on GitHub, the best way to contribute is to fork and then submit a PR.
8+
You will find a template that you will need to fill out
9+
10+
### Adding new demos
11+
12+
Add a new folder in the ./demos directory and make sure that it is named correctly like the other demos.
13+
A new demo should conform to the standard of either `demo-simple` in which it contains a markdown file that
14+
clearly explains 'whats going on', or the code sample should have very clear comments that almost always should ready
15+
like an instruction manual such as the simple demo.
16+
17+
Finally, you should link up your demo to the __index.tsx__ file in the __demos__ directory. It should be quite
18+
self explanatory on how it works, but ultimately I have a helper method that makes it easy to link source code
19+
to the demo itself, hence the 'require' statements. The third parameter is if you want to place your demo
20+
inside a markdown guide (again: see simple demo for how that is done).
21+
22+
### Make the demo testable
23+
24+
Similar procedure, except link your demo in the __index.tsx__ file sitting in the __tests__ directory.
25+
Running `yarn run test` will fire up jest (hopefully) and then it will render your demo to a snapshot directory
26+
which when run again (for a second time), should compare the output to the newely generated snapshot. Make sure
27+
to commit the updated snapshot file with your PR!

demos/Helper.tsx renamed to demos/.helpers/Helper.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import * as React from "react";
2+
import {withDocs} from 'storybook-readme';
3+
import {WithCode} from "../../.storybook/addon-code/react.js";
4+
15
export class Helper {
26
/**
37
* Logs the mouse position in the console, but overlays a div that consumes all events
@@ -18,4 +22,16 @@ export class Helper {
1822
console.log(event.clientX, event.clientY);
1923
});
2024
}
25+
26+
static makeDemo(widget, code, markdown?) {
27+
let container = () => <WithCode code={code}>{widget}</WithCode>;
28+
if (markdown) {
29+
return withDocs({
30+
PreviewComponent: ({children}) => {
31+
return <div className="docs-preview-wrapper">{children}</div>
32+
}
33+
})(markdown, container);
34+
}
35+
return container;
36+
}
2137
}

demos/demo.scss renamed to demos/.helpers/demo.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "../src/sass";
1+
@import "../../src/sass";
22

33
.srd-demo-workspace{
44
background: black;
@@ -48,7 +48,7 @@
4848
.storm-diagrams-canvas{
4949
height: 100%;
5050
min-height: 300px;
51-
background-color: rgb(60,60,60);
51+
background-color: rgb(60,60,60) !important;
5252
$color: rgba(white, .05);
5353
background-image:
5454
linear-gradient(0deg,

demos/demo-cloning/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "../../src/main";
1616
import * as _ from "lodash";
1717
import * as React from "react";
18-
import {DemoWorkspaceWidget} from "../DemoWorkspaceWidget";
18+
import {DemoWorkspaceWidget} from "../.helpers/DemoWorkspaceWidget";
1919

2020
/**
2121
* Tests cloning

demos/demo-dagre/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "../../src/main";
1414
import { distributeElements } from "./dagre-utils";
1515
import * as React from "react";
16-
import {DemoWorkspaceWidget} from "../DemoWorkspaceWidget";
16+
import {DemoWorkspaceWidget} from "../.helpers/DemoWorkspaceWidget";
1717

1818
function createNode(name) {
1919
return new DefaultNodeModel(name, "rgb(0,192,255)");

demos/demo-mutate-graph/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
LinkInstanceFactory
1313
} from "../../src/main";
1414
import * as React from "react";
15-
import {DemoWorkspaceWidget} from "../DemoWorkspaceWidget";
15+
import {DemoWorkspaceWidget} from "../.helpers/DemoWorkspaceWidget";
1616

1717
/**
1818
* Tests the grid size

demos/demo-serializing/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
LinkInstanceFactory
1313
} from "../../src/main";
1414
import * as React from "react";
15-
import {DemoWorkspaceWidget} from "../DemoWorkspaceWidget";
15+
import {DemoWorkspaceWidget} from "../.helpers/DemoWorkspaceWidget";
1616
import { action } from '@storybook/addon-actions';
1717
var beautify = require("json-beautify");
1818

demos/demo-zoom-to-fit/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
DiagramWidget
1010
} from "../../src/main";
1111
import * as React from "react";
12-
import {DemoWorkspaceWidget} from "../DemoWorkspaceWidget";
12+
import {DemoWorkspaceWidget} from "../.helpers/DemoWorkspaceWidget";
1313

1414
/**
1515
*

demos/index.tsx

+62-101
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,93 @@
11
import * as React from "react";
2-
import {storiesOf} from "@storybook/react";
3-
import * as storybook from '@storybook/react';
4-
import {action} from "@storybook/addon-actions";
2+
import {storiesOf, addDecorator} from "@storybook/react";
53
import {setOptions} from '@storybook/addon-options';
64
import {Toolkit} from "../src/Toolkit";
75
import { host } from 'storybook-host';
8-
import { withReadme, withDocs } from 'storybook-readme';
9-
import {WithCode} from "../.storybook/addon-code/react.js";
6+
import {Helper} from "./.helpers/Helper";
107

11-
import demo_performance from "./demo-performance/index";
12-
import demo_custom_node1 from "./demo-custom-node1/index";
13-
import demo_locks from "./demo-locks/index";
14-
import demo_drag_and_drop from "./demo-drag-and-drop/index";
15-
import demo_serializing from "./demo-serializing/index";
16-
import demo_grid from "./demo-grid/index";
17-
import demo_limit_points from "./demo-limit-points/index";
18-
import demo_listeners from "./demo-listeners/index";
19-
import demo_mutate_graph from "./demo-mutate-graph/index";
20-
import demo_zoom_to_fit from "./demo-zoom-to-fit/index";
21-
import demo_custom_link1 from "./demo-custom-link1/index";
22-
import demo_cloning from "./demo-cloning/index";
23-
import demo_dagre from "./demo-dagre/index";
24-
25-
import {Helper} from "./Helper";
26-
27-
require("./demo.scss");
8+
//include the SCSS for the demo
9+
require("./.helpers/demo.scss");
2810

2911
// make tests deterministic
3012
Toolkit.TESTING_MODE = true;
3113

32-
// Option defaults:
14+
addDecorator(host({
15+
cropMarks: false,
16+
height: '100%',
17+
width: '100%',
18+
padding: 20
19+
}));
20+
3321
setOptions({
3422
name: 'STORM React Diagrams',
3523
url: 'https://github.com/projectstorm/react-diagrams',
3624
addonPanelInRight: true
3725
});
3826

39-
const withCustomPreview = withDocs({
40-
PreviewComponent: ({ children }) => {
41-
return <div className="docs-preview-wrapper">{children}</div>
42-
}
43-
})
44-
45-
function getDemo(widget, code, markdown?){
46-
let container = () => <WithCode code={code}>{widget}</WithCode>;
47-
if(markdown){
48-
return withCustomPreview(markdown, container);
49-
}
50-
return container;
51-
}
52-
53-
5427
storiesOf("Simple Usage", module)
55-
.addDecorator(host({
56-
cropMarks: false,
57-
height: '100%',
58-
width: '100%',
59-
padding: 20
60-
}))
61-
.add("Simple example", getDemo(
28+
.add("Simple example", Helper.makeDemo(
6229
require("./demo-simple/index").default(),
6330
require('!!raw-loader!./demo-simple/index'),
6431
require("./demo-simple/docs.md")
6532
))
66-
.add("Performance demo", getDemo(
67-
demo_performance(),
33+
.add("Performance demo", Helper.makeDemo(
34+
require("./demo-performance/index").default(),
6835
require('!!raw-loader!./demo-performance/index')
6936
))
70-
.add("Locked widget", () => {
71-
return demo_locks();
72-
})
73-
.add("Grid size", () => {
74-
return demo_grid();
75-
})
76-
.add("Limiting number of points", () => {
77-
return demo_limit_points();
78-
})
79-
.add("Events and listeners", () => {
80-
return demo_listeners();
81-
})
82-
.add("Zoom to fit", () => {
83-
return demo_zoom_to_fit();
84-
})
37+
.add("Locked widget", Helper.makeDemo(
38+
require("./demo-locks/index").default(),
39+
require('!!raw-loader!./demo-locks/index')
40+
))
41+
.add("Canvas grid size", Helper.makeDemo(
42+
require("./demo-grid/index").default(),
43+
require('!!raw-loader!./demo-grid/index')
44+
))
45+
.add("Limiting link points", Helper.makeDemo(
46+
require("./demo-limit-points/index").default(),
47+
require('!!raw-loader!./demo-limit-points/index')
48+
))
49+
.add("Events and listeners", Helper.makeDemo(
50+
require("./demo-listeners/index").default(),
51+
require('!!raw-loader!./demo-listeners/index')
52+
))
53+
.add("Zoom to fit", Helper.makeDemo(
54+
require("./demo-zoom-to-fit/index").default(),
55+
require('!!raw-loader!./demo-zoom-to-fit/index')
56+
))
8557

8658
storiesOf("Advanced Techniques", module)
87-
.addDecorator(host({
88-
cropMarks: false,
89-
height: '100%',
90-
width: '100%',
91-
padding: 20
92-
}))
93-
.add("Clone selected", () => {
94-
return demo_cloning();
95-
})
96-
.add("Serializing and deserializing", () => {
97-
return demo_serializing();
98-
})
99-
.add("Programatically modify graph", () => {
100-
return demo_mutate_graph();
101-
})
102-
.add("Large application example", () => {
103-
return demo_drag_and_drop();
104-
})
59+
.add("Clone Selected", Helper.makeDemo(
60+
require("./demo-cloning/index").default(),
61+
require('!!raw-loader!./demo-cloning/index')
62+
))
63+
.add("Serializing and de-serializing", Helper.makeDemo(
64+
require("./demo-serializing/index").default(),
65+
require('!!raw-loader!./demo-serializing/index')
66+
))
67+
.add("Programatically modifying graph", Helper.makeDemo(
68+
require("./demo-mutate-graph/index").default(),
69+
require('!!raw-loader!./demo-mutate-graph/index')
70+
))
71+
.add("Large application", Helper.makeDemo(
72+
require("./demo-drag-and-drop/index").default(),
73+
require('!!raw-loader!./demo-drag-and-drop/components/BodyWidget')
74+
))
10575

10676
storiesOf("Custom Models", module)
107-
.addDecorator(host({
108-
cropMarks: false,
109-
height: '100%',
110-
width: '100%',
111-
padding: 20
112-
}))
113-
.add("Custom diamond node", () => {
114-
return demo_custom_node1();
115-
})
116-
.add("Custom links", () => {
117-
return demo_custom_link1();
118-
})
77+
.add("Custom diamond node", Helper.makeDemo(
78+
require("./demo-custom-node1/index").default(),
79+
require('!!raw-loader!./demo-custom-node1/index')
80+
))
81+
.add("Custom link sizes", Helper.makeDemo(
82+
require("./demo-custom-link1/index").default(),
83+
require('!!raw-loader!./demo-custom-link1/index')
84+
))
11985

12086
storiesOf("3rd party libraries", module)
121-
.addDecorator(host({
122-
cropMarks: false,
123-
height: '100%',
124-
width: '100%',
125-
padding: 20
126-
}))
127-
.add("Auto distribute - Dagre", () => {
128-
return demo_dagre();
129-
})
87+
.add("Auto Distribute (Dagre)", Helper.makeDemo(
88+
require("./demo-dagre/index").default(),
89+
require('!!raw-loader!./demo-dagre/index')
90+
))
13091

13192

13293
// enable this to log mouse location when writing new puppeteer tests

0 commit comments

Comments
 (0)