|
1 | | -# @patternfly/react-topology |
2 | | - |
3 | | -This package provides Topology View components based on [PatternFly 4][patternfly-4] |
4 | | - |
5 | | -Based from https://github.com/patternfly/patternfly-react version 4.91.40 |
| 1 | +# PatternFly Topology |
6 | 2 |
|
7 | | -### Prerequisites |
| 3 | +This package provides the resources necessary to use PatternFly Topology, an open source utility that you can use to create a visual representation of all the applications within your project, their build status, and the components and services associated with them. |
8 | 4 |
|
9 | | -#### Node Environment |
| 5 | +Topology utilizes some of PatternFly's React components https://github.com/patternfly/patternfly-react. |
10 | 6 |
|
11 | | -This project currently supports Node [Active LTS](https://github.com/nodejs/Release#release-schedule) releases. Please stay current with Node Active LTS when developing patternfly-react. |
| 7 | +Documentation for Topology and its features is available on [the PatternFly website.](www.patternfly.org/topology/about-topology) |
12 | 8 |
|
13 | | -For example, to develop with Node 8, use the following: |
| 9 | +## Table of contents |
| 10 | +- [Prerequisites](#prerequisites) |
| 11 | +- [Installing Topology](#installing-topology) |
| 12 | +- [Initial setup and usage](#initial-setup-and-usage) |
| 13 | +- [Example](#example) |
| 14 | +- [Demo app](#demo-app) |
14 | 15 |
|
15 | | -``` |
16 | | -nvm install 8 |
17 | | -nvm use 8 |
18 | | -``` |
| 16 | +## Prerequisites |
19 | 17 |
|
20 | | -This project also requires a Yarn version of >=1.6.0. The latest version can be installed [here](https://yarnpkg.com/). |
| 18 | +To use Topology, you will need to have both [Node Active LTS](https://github.com/nodejs/Release#release-schedule) and [Yarn](https://yarnpkg.com/) installed. |
21 | 19 |
|
22 | | -### Installing |
| 20 | +1. Install and develop with the most up-to-date version of Node Active LTS. For example, to develop with Node 8, you would use the following commands: |
23 | 21 |
|
24 | | -``` |
25 | | -yarn add @patternfly/react-topology |
26 | | -``` |
| 22 | + ``` |
| 23 | + nvm install 8 |
| 24 | + nvm use 8 |
| 25 | + ``` |
| 26 | +1. Install and use version 1.6.0 or later of Yarn. |
27 | 27 |
|
28 | | -or |
| 28 | +## Installing Topology |
29 | 29 |
|
30 | | -``` |
31 | | -npm install @patternfly/react-topology --save |
32 | | -``` |
| 30 | +Once you have all of the prequisites, you can install the Topology package with Yarn or npm: |
| 31 | +
|
| 32 | +1. Using Yarn: |
33 | 33 |
|
34 | | -## Basic Usage |
| 34 | + ``` |
| 35 | + yarn add @patternfly/react-topology |
| 36 | + ``` |
| 37 | +1. Using npm: |
35 | 38 |
|
36 | | -To use React Topology out-of-the-box, you will first need to transform your back-end data into a [Model](https://github.com/patternfly/patternfly-react/blob/main/packages/react-topology/src/types.ts#L16-L20). These model objects contain the information needed to display the nodes and edges. Each node and edge has a set of properties used by PF Topology as well as a data field which can be used to customize the nodes and edges by the application. |
| 39 | + ``` |
| 40 | + npm install @patternfly/react-topology --save |
| 41 | + ``` |
37 | 42 |
|
38 | | -You will then need to declare a controller, which can be initialized via the `useVisualizationController()` method. |
| 43 | +## Initial setup and usage |
39 | 44 |
|
40 | | -The `fromModel` method must be called on the controller to create the nodes. `fromModel` will take your data model as a parameter. Your data model should include a `graph` object, on which you will need to set `id` , `type` and `layout`. |
| 45 | +To use Topology out of the box, follow these steps: |
41 | 46 |
|
42 | | -To create your topology view component, you can use `TopologyView` to Wrap `<VisualizationSurface>` which can accept `state` as a parameter. The state is application specific. It can be any data the application wants to store/retrieve from the controller. Adding state to the surface allows hooks to update when state changes. The state is useful to keep graph state such as selected elements. |
| 47 | +1. First transform your back-end data into a [Model](https://github.com/patternfly/react-topology/blob/main/packages/module/src/types.ts) object. This will contain the information needed to display the nodes and edges in your Topology view. Each node and edge contains a set of properties used by Topology, as well as a data field, which Topology can be used to customize the nodes and edges. |
43 | 48 |
|
44 | | -Use a controller to wrap your topology view component. In the example below, this is done via the `VisualizationProvider` which consumes the `Controller` via context. |
| 49 | +1. Declare a controller, which can be initialized via the `useVisualizationController()` method. |
45 | 50 |
|
46 | | -Three `register` methods are accessed by the controller. |
| 51 | +1. Create nodes by calling the `fromModel` method on the controller you initialized. `fromModel` will take the `Model` that you created as a parameter. Your data model should include a `graph` object, on which you will need to set `id` , `type`, and `layout`. |
47 | 52 |
|
48 | | -The following two must be declared explicitly\: |
| 53 | +1. To create your Topology view component, wrap `TopologyView` around `<VisualizationSurface>`, which can accept a `state` parameter. |
| 54 | + - The value of state is application specific and should include any data the application wants to store/retrieve from the controller. |
| 55 | + - Adding state to `<VisualizationSurface>` allows hooks to update when state changes. |
| 56 | + - State can also be used to keep track of your graph state, such as selected elements. |
49 | 57 |
|
50 | | -- `registerLayoutFactory`\: This method sets the layout of your topology view (e.g. Force, Dagre, Cola, etc.). You can use `defaultLayoutFactory` as a parameter if your application supports all layouts. You can also update `defaultLayout` to a custom implementation if you only want to support a subset of the available layout options. |
| 58 | +1. Wrap your `TopologyView` with your controller. In the example below, this is done via the `VisualizationProvider` which consumes the `Controller` via context. |
51 | 59 |
|
52 | | -- `registerComponentFactory`\: This method lets you customize the components in your topology view (e.g. nodes, groups, and edges). You can use `defaultComponentFactory` as a parameter. |
| 60 | +1. There are 3 `register` methods that the controller accesses. |
53 | 61 |
|
54 | | -The register method below is initialized in `Visualization.ts`, therefore it doesn't need to be declared unless you want to support a custom implementation which modifies the types. |
| 62 | + These 2 must be declared explicitly: |
55 | 63 |
|
56 | | -- `registerElementFactory`\: This method sets the types of the elements being used (e.g. graphs, nodes, edges). `defaultElementFactory` uses types from `ModelKind` and is exported in `index.ts`. |
| 64 | + 1. **`registerLayoutFactory`:** Sets the layout of your topology view (e.g. Force, Dagre, Cola, etc.). You can use `defaultLayoutFactory` as a parameter if your application supports all layouts. You can also update `defaultLayout` to a custom implementation if you only want to support a subset of the available layout options. |
| 65 | + 1. **`registerComponentFactory`:** Lets you customize the components in your topology view (e.g. nodes, groups, and edges). You can use `defaultComponentFactory` as a parameter. |
| 66 | + |
| 67 | + The remaining method is initialized in `Visualization.ts`, so it doesn't need to be declared unless you want to support a custom implementation that modifies the types: |
57 | 68 |
|
58 | | -#### Example Component Usage |
| 69 | + 3. **`registerElementFactory`:** Sets the types of the elements being used (e.g. graphs, nodes, edges). `defaultElementFactory` uses types from `ModelKind` and is exported in `index.ts`. |
| 70 | +
|
| 71 | +## Example |
59 | 72 |
|
60 | 73 | ```ts |
61 | 74 | import * as React from 'react'; |
@@ -185,3 +198,42 @@ export const TopologyBaselineDemo = React.memo(() => { |
185 | 198 | }); |
186 | 199 | ``` |
187 | 200 |
|
| 201 | +## Demo app |
| 202 | + |
| 203 | +To help you better understand and visualize the different Topology components, we have created an interactive demo, [which is contained here.](https://github.com/patternfly/react-topology/tree/main/packages/demo-app-ts) |
| 204 | + |
| 205 | +Continue reading for instructions on how to build and run the demo app. |
| 206 | + |
| 207 | +### Prerequisites |
| 208 | + |
| 209 | +In order to run the demo app, you need to make sure the following prerequisites are met. |
| 210 | + |
| 211 | +1. Make sure that you have yarn installed, as outlined in [the general Topology prerequisites.](#prerequisites) |
| 212 | +1. If you haven’t already, [fork the Topology project.](https://github.com/patternfly/react-topology) |
| 213 | + |
| 214 | +### Running the demo app |
| 215 | + |
| 216 | +Once you’ve set up the prerequisites, you can follow these steps to run the docs workspace or the demo app on your local machine |
| 217 | + |
| 218 | +1. In a terminal, type the following commands to start the docs workspace: |
| 219 | + |
| 220 | +``` |
| 221 | +yarn install |
| 222 | +yarn start |
| 223 | +``` |
| 224 | + |
| 225 | +2. In a terminal, type the following commands to navigate to demo-app-ts and launch the demo app: |
| 226 | + |
| 227 | +``` |
| 228 | +cd packages/demo-app-ts |
| 229 | +yarn start:demo-app:hot |
| 230 | +``` |
| 231 | + |
| 232 | +3. You will receive a message confirming that the app is running. To view the locally running workspace, visit http://localhost:8008/. |
| 233 | + |
| 234 | +4. Explore the demo app in your browser: |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | +## Need help? |
| 239 | +If you find a bug, have a request, or have any questions about Topology that aren't answered in our documentation, please [reach out to us on Slack.](https://patternfly.slack.com/archives/CK7URGJ2W) |
0 commit comments