rules.json Example

Refer to this example of the rules.json file.

Example 

1{
2   "constants":[
3      {
4         "name":"ChartType",
5         "value":"pie"
6      }
7   ],
8   "rules":[
9      {
10         "name":"rule1",
11         "appliesTo":[
12            "type":"dashboard",
13            "name":"dashboardOne",
14
15         ],
16         "actions":[
17            {
18               "action":"put",
19               "description":"Put a section back in, but with different attributes",
20               "path":"$.state.widgets.chart_1",
21               "key":"pos",
22               "value":{
23                  "w":"501",
24                  "y":"41",
25                  "h":"121",
26                  "x":"51"
27               }
28            },
29            {
30               "action":"delete",
31               "description":"Delete a section",
32               "path":"$.state.widgets.chart_2"
33            }
34         ]
35      }
36   ]

The corresponding dashboardOne.json file that uses the above rules files looks like:

1{
2    "_type": "dashboardTemplate",
3    "name": "Dashboard From Template With Rules",
4    "edgemarts": {
5        "${Variables.Dataset1.datasetAlias}": {
6            "_type": "edgemart",
7            "_uid": "${Variables.Dataset1.datasetId}"
8        },
9        "${Variables.Dataset2.datasetAlias}": {
10            "_type": "edgemart",
11            "_uid": "${Variables.Dataset2.datasetId}"
12        }
13    },
14    "folder": {
15        "_type": "folder",
16        "_uid": "${App.Folder.Id}"
17    },
18    "tags": [
19
20    ],
21    "state": {
22        "widgets": {
23            "chart_1": {
24                "params": {
25                    "chartType": "${Constants.ChartType}",
26                    "minColumnWidth": 30,
27                    "maxColumnWidth": 200,
28                    "legend": false,
29                    "selectMode": "single",
30                    "sqrt": false,
31                    "legendHideHeader": false,
32                    "legendWidth": 145,
33                    "step": "step_1"
34                },
35                "type": "ChartWidget",
36                "pos": {
37                    "w": "500",
38                    "y": 60,
39                    "h": "120",
40                    "x": 40
41                }
42            },
43            "chart_2": {
44                "params": {
45                    "chartType": "${Constants.ChartType}",
46                    "minColumnWidth": 30,
47                    "maxColumnWidth": 200,
48                    "legend": false,
49                    "selectMode": "single",
50                    "sqrt": false,
51                    "legendHideHeader": false,
52                    "legendWidth": 145,
53                    "step": "step_2"
54                },
55                "type": "ChartWidget",data
56                "pos": {
57                    "w": "500",
58                    "y": 190,
59                    "h": "120",
60                    "x": 40
61                }
62            }
63        },
64        "steps": {
65            "step_1": {
66                "isFacet": true,
67                "start": null,
68                "query": {
69                    "measures": [
70                        [
71                            "count",
72                            "*"
73                        ]
74                    ]
75                },
76                "selectMode": "single",
77                "useGlobal": true,
78                "em": "${Variables.Dataset1.datasetId}",
79                "type": "aggregate",
80                "isGlobal": false
81            },
82            "step_2": {
83                "isFacet": true,
84                "start": null,
85                "query": {
86                    "measures": [
87                        [
88                            "count",
89                            "*"
90                        ]
91                    ]
92                },
93                "selectMode": "single",
94                "useGlobal": true,
95                "em": "${Variables.Dataset2.datasetId}",
96                "type": "aggregate",
97                "isGlobal": false
98            }
99        },
100        "type": "hbar"
101    }
102}

When the rules are applied to the dashboard, the chart_1 widget will have a chartType of “pie” and the “pos” will be updated to w=501, y=41, h=121, and x=51. The chart_2 widget will be removed.