@@ -10,12 +10,13 @@ Visualizes the state tree and transitions in UI-Router 1.0+.
10
10
11
11
This script augments your app with two components:
12
12
13
- 1 ) State Visualizer: Your UI-Router state tree, showing the active state and its active ancestors (green nodes)
13
+ 1 . State Visualizer: Your UI-Router state tree, showing the active state and its active ancestors (green nodes)
14
+
14
15
- Clicking a state will transition to that state.
15
16
- If your app is large, state trees can be collapsed by double-clicking a state.
16
- - Supports different layouts and zoom.
17
+ - Supports different layouts and zoom.
17
18
18
- 2 ) Transition Visualizer: A list of each transition (from one state to another)
19
+ 2 . Transition Visualizer: A list of each transition (from one state to another)
19
20
20
21
- Color coded Transition status (success/error/ignored/redirected)
21
22
- Hover over a Transition to show which states were entered/exited, or retained during the transition.
@@ -28,37 +29,37 @@ Register the plugin with the `UIRouter` object.
28
29
29
30
### Locate the Plugin
30
31
31
- - Using a ` <script> ` tag
32
-
33
- Add the script as a tag in your HTML.
34
-
35
- ``` html
36
- <script src =" //unpkg.com/@uirouter/visualizer@4" ></script >
37
- ```
38
-
39
- The visualizer Plugin can be found (as a global variable) on the window object.
40
-
41
- ```js
42
- var Visualizer = window['@uirouter/visualizer'].Visualizer;
43
- ```
44
-
45
- - Using `require` or `import` (SystemJS, Webpack, etc)
46
-
47
- Add the npm package to your project
48
-
49
- ```
50
- npm install --save @uirouter/visualizer
51
- ```
52
-
53
- - Use `require` or ES6 `import`:
54
-
55
- ```js
56
- var Visualizer = require('@uirouter/visualizer').Visualizer;
57
- ```
58
-
59
- ```js
60
- import { Visualizer } from '@uirouter/visualizer';
61
- ```
32
+ - Using a ` <script> ` tag
33
+
34
+ Add the script as a tag in your HTML.
35
+
36
+ ``` html
37
+ <script src =" //unpkg.com/@uirouter/visualizer@4" ></script >
38
+ ```
39
+
40
+ The visualizer Plugin can be found (as a global variable) on the window object.
41
+
42
+ ``` js
43
+ var Visualizer = window [' @uirouter/visualizer' ].Visualizer ;
44
+ ```
45
+
46
+ - Using ` require ` or ` import ` (SystemJS, Webpack, etc)
47
+
48
+ Add the npm package to your project
49
+
50
+ ```
51
+ npm install --save @uirouter/visualizer
52
+ ```
53
+
54
+ - Use ` require ` or ES6 ` import ` :
55
+
56
+ ``` js
57
+ var Visualizer = require (' @uirouter/visualizer' ).Visualizer ;
58
+ ```
59
+
60
+ ``` js
61
+ import { Visualizer } from ' @uirouter/visualizer' ;
62
+ ```
62
63
63
64
### Register the plugin
64
65
@@ -79,18 +80,52 @@ var pluginInstance = uiRouterInstance.plugin(Visualizer);
79
80
80
81
### Configuring the plugin
81
82
82
- Optionally you can pass configuration to how the visualizer displays the state tree and the transitions.
83
+ You can pass a configuration object when registering the plugin.
84
+ The configuration object may have the following fields:
85
+
86
+ - ` state ` : (boolean) State Visualizer is not rendered when this is ` false `
87
+ - ` transition ` : (boolean) Transition Visualizer is not rendered when this is ` false `
88
+ - ` stateVisualizer.node.label ` : (function) A function that returns the label for a node
89
+ - ` stateVisualizer.node.classes ` : (function) A function that returns classnames to apply to a node
90
+
91
+ #### ` stateVisualizer.node.label `
92
+
93
+ The labels for tree nodes can be customized.
94
+
95
+ Provide a function that accepts the node object and the default label and returns a string:
96
+
97
+ ```
98
+ function(node, defaultLabel) { return "label"; }
99
+ ```
100
+
101
+ This example adds ` (future) ` to future states.
102
+ _ Note: ` node.self ` contains a reference to the state declaration object._
103
+
104
+ ``` js
105
+ var options = {
106
+ stateVisualizer: {
107
+ node: {
108
+ label : function (node , defaultLabel ) {
109
+ return node .self .name .endsWith (' .**' ) ? defaultLabel + ' (future)' : defaultLabel;
110
+ },
111
+ },
112
+ },
113
+ };
83
114
84
- The state tree visualizer can be configured to style each node specifically.
115
+ var pluginInstance = uiRouterInstance .plugin (Visualizer, options);
116
+ ```
85
117
86
- Example below marks every node with angular.js view with is-ng1 class.
118
+ #### ` stateVisualizer.node.classes `
119
+
120
+ The state tree visualizer can be configured to add additional classes to nodes.
121
+ Example below marks every node with angular.js view with ` is-ng1 ` class.
87
122
88
123
``` js
89
124
var options = {
90
125
stateVisualizer: {
91
126
node: {
92
127
classes (node ) {
93
- return Object .entries (node .views || {}).some (routeView => routeView[1 ] && routeView[1 ].$type === ' ng1' )
128
+ return Object .entries (node .views || {}).some (( routeView ) => routeView[1 ] && routeView[1 ].$type === ' ng1' )
94
129
? ' is-ng1'
95
130
: ' ' ;
96
131
},
@@ -109,8 +144,8 @@ Inject the `$uiRouter` router instance in a run block.
109
144
110
145
``` js
111
146
// inject the router instance into a `run` block by name
112
- app .run (function ($uiRouter ) {
113
- var pluginInstance = $uiRouter .plugin (Visualizer);
147
+ app .run (function ($uiRouter ) {
148
+ var pluginInstance = $uiRouter .plugin (Visualizer);
114
149
});
115
150
```
116
151
@@ -124,7 +159,7 @@ import { Visualizer } from "@uirouter/visualizer";
124
159
125
160
...
126
161
127
- export function configRouter (router : UIRouter ) {
162
+ export function configRouter (router : UIRouter ) {
128
163
var pluginInstance = router .plugin (Visualizer);
129
164
}
130
165
@@ -137,7 +172,6 @@ export function configRouter(router: UIRouter) {
137
172
138
173
#### React (Imperative)
139
174
140
-
141
175
Create the UI-Router instance manually by calling ` new UIRouterReact ();`
142
176
143
177
` ` ` js
@@ -147,7 +181,7 @@ var pluginInstance = router.plugin(Visualizer);
147
181
` ` `
148
182
149
183
#### React (Declarative)
150
-
184
+
151
185
Add the plugin to your ` UIRouter` component
152
186
153
187
` ` ` js
0 commit comments