npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@essex/visual-settings

v3.0.0

Published

A library to parse and enumerate powerbi visual settings.

Downloads

33

Readme

Essex PBI Base -- Visual Settings

A library to parse/enumerate PowerBI formatting pane settings in a simple way.

Building

See the root README on how to build this project.

Usage

Create a Visual Settings class that extends from the visual-settings/HasSettings class, and mark each of your settings that you want to persist into powerbi, with an appropriate setting decorator.

import { HasSettings, boolSetting, numberSetting, textSetting, colorSetting } from "visual-settings";
class MyVisualSettings extends HasSettings {

    @boolSetting({ // Represents a boolean setting (a toggle switch)
        category: "Formatting", // This is the top level grouping within PowerBI's formatting pane
        displayName: "My Bool Setting", // This is the text that gets displayed in the formatting pane for this setting
        description: "Who's setting is it?", // This is the description of this setting, it will be displayed to the users.
        defaultValue: true, // *Optional* This is the default value for this setting if the user hits the reset button.
        enumerable: true, // *Optional* (default: true) If true, the setting will be displayed in the formatting pane, and the user can modify it. If false, it will be a hidden setting that your visual can update, but the user cannot
        persist: true, // *Optional* (default: true) If true, when this settings value has changed, it will be persisted to powerbi.  This config option is handy if you only want to read setting values from PowerBI but not update them.
    })
    public bool myBoolSetting = true;

    @numberSetting({ // Represents a numeric setting
        ...
    })
    public number myNumberSetting;

    @textSetting({ // Represents a text/string setting
        ...
    })
    public string myTextSetting;

    @colorSetting({ // Represents a color setting (shows a color pallette)
        ...
    })
    public string myColorSetting; // This is a hex code string i.e. #cfcfcf
}

Instantiate your settings class within your visual, and store the current dataView

import MyVisualSettings from "./visualSettings";

class MyVisual implements IVisual {
    private dataView: powerbi.DataView;
    private visualSettings: MyVisualSettings;

    constructor() {
        this.visualSettings = MyVisualSettings.create<MyVisualSettings>();
    }

    public update(options: VisualUpdateOptions) {
        if (options.dataViews && options.dataViews[0]) {
            this.dataView = options.dataViews[0];
        }

        const oldSettings = this.visualSettings; // A reference to the old settings
        this.visualSettings = this.visualSettings.receiveFromPBI(this.dataView); // Parse the new settings from PowerBI
    }
}

Update your enumerateObjectInstances to return the values from your settings.

import MyVisualSettings from "./visualSettings";

class MyVisual implements IVisual {

    private dataView: powerbi.DataView;
    private visualSettings: MyVisualSettings;

     * The IVisual.enumerateObjectInstances function
     * Enumerates the instances for the objects that appear in the power bi panel
     */
    public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] {
        return this.visualSettings.buildEnumerationObjects(options.objectName, this.dataView, false);
    }
}

If you change a settings value and want to persist it back to powerbi

import MyVisualSettings from "./visualSettings";

class MyVisual implements IVisual {
    private visualSettings: MyVisualSettings;
    private host: IVisualHost;
    private dataView: powerbi.DataView;

    public void onUpdateSettingValue(value: string) {
        this.visualSettings.myTextSetting = value;

        const pbiObjects = this.visualSettings.buildPersistObjects(this.dataView);
        this.host.persistProperties(pbiObjects); // Persist them off to powerbi
    }
}