我使用PowerBI的可视化工具(https://github.com/Microsoft/PowerBI-visuals-tools)创建了一个新项目,然后我手动安装了d3(@ ^ 3.5.5)及其类型定义(@ types / d3 @ ^ 3.5.5)。令我困惑的是visual.ts
文件夹的src
内,我可以使用d3而不进行任何导入,是否有人可以解释原因?
module powerbi.extensibility.visual {
"use strict";
export class Visuall implements IVisual {
private target: HTMLElement;
private updateCount: number;
private settings: VisualSettings;
constructor(options: VisualConstructorOptions) {
console.log('Visual constructor', options);
this.target = options.element;
this.updateCount = 0;
}
public update(options: VisualUpdateOptions) {
this.settings = Visual.parseSettings(options && options.dataViews && options.dataViews[0]);
console.log('Visual update', options);
this.target.innerHTML = `<p>Update count: <em>${(this.updateCount++)}</em></p>`;
console.log(d3); // no error whatsoever
}
private static parseSettings(dataView: DataView): VisualSettings {
return VisualSettings.parse(dataView) as VisualSettings;
}
/**
* This function gets called for each of the objects defined in the capabilities files and allows you to select which of the
* objects and properties you want to expose to the users in the property pane.
*
*/
public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject {
return VisualSettings.enumerateObjectInstances(this.settings || VisualSettings.getDefault(), options);
}
}
}
答案 0 :(得分:0)
我当然不会在这个问题上发表任何形式的权威,但似乎Power BI Visuals API团队所做的工作是将链接文件的责任转移到构建过程。如果你查看pbiviz.json文件,有一个属性为&#34; externalJS&#34;这应该包含你将使用的任何js参考。由于它们在那里被引用,我相信它是为了排除你需要在你的打字稿文件中做到这一点。