├── LICENSE
├── README.md
├── app
├── index.html
└── scripts
│ └── app.js
├── package.json
└── webpack.config.js
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 yWorks GmbH
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # yfiles-neo4j-basic-demo
2 | Shows how to use yFiles for HTML and Neo4j in a web based single page app to visualize database contents.
3 |
4 | This repository serves as a reference for a demo that can be used as a guideline for creating single page web application that render a visualization of [Neo4j](https://www.neo4j.com) database contents using the [yFiles for HTML JavaScript graph drawing library](https://www.yworks.com/yfileshtml). __You cannot run or test the demo without a yFiles for HTML library or without a Neo4j database just by cloning this repository. This repository was originally meant as a reference for the sources in [this outdated posting](https://medium.com/neo4j/neo4j-graph-visualization-like-a-pro-18651963ebd4) and [the corresponding (also slightly outdated) YouTube screencast](https://youtu.be/ABixtyDjcKc), only.__ If you are evaluating yFiles for HTML today, be sure to stick to the sources in this repository which uses the now (at the time of writing) current version of yFiles, which is 2.4.
5 |
6 | For a much easier way to get started with yFiles for HTML and Neo4j, be sure to check out the [App-Generator](https://www.yworks.com/products/app-generator) which has several Neo4j related examples that you can adjust to your needs with low-code techniques. It also allows you to scaffold yFiles/Neo4j powered applications with your choice of UI framework and programming language, supporting VueJS, Angular, React, Plain Old HTML, with both JavaScript and TypeScript and a set of additional options like tooltips, search fields, overview, image and PDF export, etc.
7 |
8 | The current demo was scaffolded using the [yeoman generator for yFiles apps](https://www.npmjs.com/package/generator-yfiles-app) for yFiles for HTML 2.3 using the following settings:
9 |
10 | ```
11 | ? Which framework do you want to use? No framework
12 | ? Application name Yfiles_neo4j_basic_demo_2
13 | ? Path of yFiles for HTML package C:\Path\to\your\yFilesForHTMLPackage
14 | ? Path of license file (e.g. 'path/to/license.json') C:\Path\to\your\yFilesForHTMLPackage\lib\license.json
15 | ? Which kind of yFiles modules do you want to use? Local NPM dependency (recommended)
16 | ? Which language variant do you want to use? ES6
17 | ? What else do you want? Use development library
18 | ? Which package manager would you like to use? npm
19 | ```
20 | See [this updated YouTube screencast](https://youtu.be/fgY4ezIfVjI) on how to get started with yFiles and scaffold a yFiles for HTML powered application with yeoman.
21 |
22 | In order to run this demo, you should first obtain a current version of yFiles for HTML from [here](https://www.yworks.com/products/yfiles-for-html/evaluate).
23 | Then run the yeoman generator and replace the contents of the scaffolded `app.js` file with the ones from this repository and install neo4j using npm.
24 | For a *generic* introduction to yFiles for HTML see [this YouTube screencast](https://youtu.be/QITNGXNGM3w)
25 |
26 | If you are new to yFiles for HTML, you might also consider the approach shown in [this webinar recording](https://youtu.be/_Gz773u-TBQ) to get your first app up and running, quickly.
27 |
--------------------------------------------------------------------------------
/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Neo_yFiles
5 |
6 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/scripts/app.js:
--------------------------------------------------------------------------------
1 | import 'yfiles/yfiles.css'
2 |
3 | import {
4 | License,
5 | GraphComponent,
6 | Class,
7 | LayoutExecutor,
8 | GraphViewerInputMode,
9 | RadialLayout,
10 | RadialLayoutData,
11 | Size,
12 | GraphBuilder,
13 | ShapeNodeStyle,
14 | EdgePathLabelModel,
15 | PolylineEdgeStyle,
16 | INode,
17 | DefaultLabelStyle,
18 | GraphItemTypes,
19 | Reachability,
20 | } from 'yfiles'
21 |
22 | // Tell the library about the license contents
23 | License.value = {
24 | /* put the license contents here - the yeoman generator does this automatically for you */
25 | }
26 |
27 | import neo4j, { Node as NeoNode } from 'neo4j-driver'
28 |
29 | // setup the driver
30 | const neo4jDriver = neo4j.driver('bolt://1.2.3.4/', neo4j.auth.basic('username', 'TheS3cr3t'))
31 |
32 | // We need to load the yfiles/view-layout-bridge module explicitly to prevent the webpack
33 | // tree shaker from removing this dependency which is needed for 'morphLayout' in this demo.
34 | Class.ensure(LayoutExecutor)
35 |
36 | // hook up the graph control to the div in the page
37 | const graphComponent = new GraphComponent('#graphComponent')
38 |
39 | // make it interactive - we don't allow editing (creating new elements)
40 | // but are generally interested in viewing, only
41 | const inputMode = new GraphViewerInputMode()
42 | graphComponent.inputMode = inputMode
43 |
44 | // display a tooltip when the mouse hovers over an item
45 | inputMode.addQueryItemToolTipListener((sender, args) => {
46 | // the neo4j data is stored in the "tag" property of the item
47 | // if it contains "properties" - show them in a simple HTML list
48 | if (args.item?.tag?.properties) {
49 | // we can use a string, or set an HTML Element (e.g. when we do cannot trust the data)
50 | args.toolTip = `