Skip to content

Instantly share code, notes, and snippets.

@AndyCross
Created April 30, 2016 19:07
Show Gist options
  • Save AndyCross/41713d85455e2829c524a4a1ff7c6b37 to your computer and use it in GitHub Desktop.
Save AndyCross/41713d85455e2829c524a4a1ff7c6b37 to your computer and use it in GitHub Desktop.
Loads a random image from loremFlickr.com where the image is fluffy
module powerbi.visuals {
export class LoremFlickr implements IVisual {
public static capabilities: VisualCapabilities = {
// This is what will appear in the 'Field Wells' in reports
dataRoles: [
{
name: 'Category',
kind: powerbi.VisualDataRoleKind.Grouping,
},
{
name: 'Y',
kind: powerbi.VisualDataRoleKind.Measure,
},
],
// This tells power bi how to map your roles above into the dataview you will receive
dataViewMappings: [{
categorical: {
categories: {
for: { in: 'Category' },
dataReductionAlgorithm: { top: {} }
},
values: {
select: [{ bind: { to: 'Y' } }]
},
}
}],
// Objects light up the formatting pane
objects: {
general: {
displayName: data.createDisplayNameGetter('Visual_General'),
properties: {
formatString: {
type: { formatting: { formatString: true } },
},
},
},
}
};
private _img:JQuery;
private _ele:JQuery;
/** This is called once when the visual is initialially created */
public init(options: VisualInitOptions): void {
this._ele = options.element;
this.drawFluffy(options.viewport);
}
/** Update is called for data updates, resizes & formatting changes */
public update(options: VisualUpdateOptions) {
this.drawFluffy(options.viewport);
}
private drawFluffy(viewport : IViewport)
{
if (this._img != null)
{
this._ele.empty();
}
this._img = this._ele.html("<img src='https://loremflickr.com/"+Math.floor(viewport.width)+"/"+Math.floor(viewport.height)+"/fluffy'>");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment