forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisual.ts
142 lines (127 loc) · 4.01 KB
/
visual.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
import * as service from './service';
import * as embed from './embed';
import * as models from 'powerbi-models';
import { Report } from './report'
import { Page } from './page';
/**
* The Power BI Visual embed component
*
* @export
* @class Visual
*/
export class Visual extends Report {
static type = "visual";
static GetFiltersNotSupportedError = "Getting visual level filters is not supported.";
static SetFiltersNotSupportedError = "Setting visual level filters is not supported.";
static GetPagesNotSupportedError = "Get pages is not supported while embedding a visual.";
static SetPageNotSupportedError = "Set page is not supported while embedding a visual.";
/**
* Creates an instance of a Power BI Single Visual.
*
* @param {service.Service} service
* @param {HTMLElement} element
* @param {embed.IEmbedConfiguration} config
*/
constructor(service: service.Service, element: HTMLElement, baseConfig: embed.IEmbedConfigurationBase, phasedRender?: boolean, iframe?: HTMLIFrameElement) {
super(service, element, baseConfig, phasedRender, iframe);
}
load(baseConfig: embed.IEmbedConfigurationBase, phasedRender?: boolean): Promise<void> {
var config = <embed.IVisualEmbedConfiguration>baseConfig;
if (typeof config.pageName !== 'string' || config.pageName.length === 0) {
throw new Error(`Page name is required when embedding a visual.`);
}
if (typeof config.visualName !== 'string' || config.visualName.length === 0) {
throw new Error(`Visual name is required, but it was not found. You must provide a visual name as part of embed configuration.`);
}
// calculate custom layout settings and override config.
let width = config.width ? config.width : this.iframe.offsetWidth;
let height = config.height ? config.height : this.iframe.offsetHeight;
const pageSize: models.ICustomPageSize = {
type: models.PageSizeType.Custom,
width: width,
height: height,
};
let pagesLayout: models.PagesLayout = {};
pagesLayout[config.pageName] = {
defaultLayout: {
displayState: {
mode: models.VisualContainerDisplayMode.Hidden
}
},
visualsLayout: {}
};
pagesLayout[config.pageName].visualsLayout[config.visualName] = {
displayState: {
mode: models.VisualContainerDisplayMode.Visible
},
x: 1,
y: 1,
z: 1,
width: pageSize.width,
height: pageSize.height
}
config.settings = config.settings || {};
config.settings.filterPaneEnabled = false;
config.settings.navContentPaneEnabled = false;
config.settings.layoutType = models.LayoutType.Custom;
config.settings.customLayout = {
displayOption: models.DisplayOption.FitToPage,
pageSize: pageSize,
pagesLayout: pagesLayout
};
return super.load(config, phasedRender);
}
/**
* Gets the list of pages within the report - not supported in visual embed.
*
* @returns {Promise<Page[]>}
*/
getPages(): Promise<Page[]> {
throw Visual.GetPagesNotSupportedError;
}
/**
* Sets the active page of the report - not supported in visual embed.
*
* @param {string} pageName
* @returns {Promise<void>}
*/
setPage(pageName: string): Promise<void> {
throw Visual.SetPageNotSupportedError;
}
/**
* Gets filters that are applied at the visual level.
*
* ```javascript
* // Get filters applied at visual level
* visual.getFilters()
* .then(filters => {
* ...
* });
* ```
*
* @returns {Promise<models.IFilter[]>}
*/
getFilters(): Promise<models.IFilter[]> {
throw Visual.GetFiltersNotSupportedError;
}
/**
* Sets filters at the visual level.
*
* ```javascript
* const filters: [
* ...
* ];
*
* visual.setFilters(filters)
* .catch(errors => {
* ...
* });
* ```
*
* @param {(models.IFilter[])} filters
* @returns {Promise<void>}
*/
setFilters(filters: models.IFilter[]): Promise<void> {
throw Visual.SetFiltersNotSupportedError;
}
}