forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualDescriptor.ts
178 lines (164 loc) · 4.63 KB
/
visualDescriptor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import * as models from 'powerbi-models';
import { IFilterable } from './ifilterable';
import { IPageNode, Page } from './page';
/**
* A Visual node within a report hierarchy
*
* @export
* @interface IVisualNode
*/
export interface IVisualNode {
name: string;
title: string;
type: string;
layout: models.IVisualLayout;
page: IPageNode;
}
/**
* A Power BI visual within a page
*
* @export
* @class VisualDescriptor
* @implements {IVisualNode}
*/
export class VisualDescriptor implements IVisualNode, IFilterable {
/**
* The visual name
*
* @type {string}
*/
name: string;
/**
* The visual title
*
* @type {string}
*/
title: string;
/**
* The visual type
*
* @type {string}
*/
type: string;
/**
* The visual layout: position, size and visiblity.
*
* @type {string}
*/
layout: models.IVisualLayout;
/**
* The parent Power BI page that contains this visual
*
* @type {IPageNode}
*/
page: IPageNode;
constructor(page: IPageNode, name: string, title: string, type: string, layout: models.IVisualLayout) {
this.name = name;
this.title = title;
this.type = type;
this.layout = layout;
this.page = page;
}
/**
* Gets all visual level filters of the current visual.
*
* ```javascript
* visual.getFilters()
* .then(filters => { ... });
* ```
*
* @returns {(Promise<models.IFilter[]>)}
*/
getFilters(): Promise<models.IFilter[]> {
return this.page.report.service.hpm.get<models.IFilter[]>(`/report/pages/${this.page.name}/visuals/${this.name}/filters`, { uid: this.page.report.config.uniqueId }, this.page.report.iframe.contentWindow)
.then(response => response.body,
response => {
throw response.body;
});
}
/**
* Removes all filters from the current visual.
*
* ```javascript
* visual.removeFilters();
* ```
*
* @returns {Promise<void>}
*/
removeFilters(): Promise<void> {
return this.setFilters([]);
}
/**
* Sets the filters on the current visual to 'filters'.
*
* ```javascript
* visual.setFilters(filters);
* .catch(errors => { ... });
* ```
*
* @param {(models.IFilter[])} filters
* @returns {Promise<void>}
*/
setFilters(filters: models.IFilter[]): Promise<void> {
return this.page.report.service.hpm.put<models.IError[]>(`/report/pages/${this.page.name}/visuals/${this.name}/filters`, filters, { uid: this.page.report.config.uniqueId }, this.page.report.iframe.contentWindow)
.catch(response => {
throw response.body;
});
}
/**
* Exports Visual data.
* Can export up to 30K rows.
* @param rows: Optional. Default value is 30K, maximum value is 30K as well.
* @param exportDataType: Optional. Default is models.ExportDataType.Summarized.
* ```javascript
* visual.exportData()
* .then(data => { ... });
* ```
*
* @returns {(Promise<models.ExportDataType>)}
*/
exportData(exportDataType?: models.ExportDataType, rows?: number): Promise<models.ExportDataType> {
let exportDataRequestBody: models.IExportDataRequest = {
rows: rows,
exportDataType: exportDataType
};
return this.page.report.service.hpm.post<models.ExportDataType>(`/report/pages/${this.page.name}/visuals/${this.name}/exportData`, exportDataRequestBody, { uid: this.page.report.config.uniqueId }, this.page.report.iframe.contentWindow)
.then(response => response.body,
response => {
throw response.body;
});
}
/**
* Set slicer state.
* Works only for visuals of type slicer.
* @param state: A new state which contains the slicer filters.
* ```javascript
* visual.setSlicerState()
* .then(() => { ... });
* ```
*/
setSlicerState(state: models.ISlicerState): Promise<void> {
return this.page.report.service.hpm.put<models.IError[]>(`/report/pages/${this.page.name}/visuals/${this.name}/slicer`, state, { uid: this.page.report.config.uniqueId }, this.page.report.iframe.contentWindow)
.catch(response => {
throw response.body;
});
}
/**
* Get slicer state.
* Works only for visuals of type slicer.
*
* ```javascript
* visual.getSlicerState()
* .then(state => { ... });
* ```
*
* @returns {(Promise<models.ISlicerState>)}
*/
getSlicerState(): Promise<models.ISlicerState> {
return this.page.report.service.hpm.get<models.ISlicerState>(`/report/pages/${this.page.name}/visuals/${this.name}/slicer`, { uid: this.page.report.config.uniqueId }, this.page.report.iframe.contentWindow)
.then(response => response.body,
response => {
throw response.body;
});
}
}