public update()

in packages/timebrush-powerbi/src/TimeBrushVisual.ts [117:156]


    public update(options: powerbi.extensibility.visual.VisualUpdateOptions, vm?: any, type?: UpdateType) {
        const updateType = type !== undefined ? type : calcUpdateType(this.prevUpdateOptions, options);
        this.prevUpdateOptions = options;
        const dataView = this.dataView = options.dataViews && options.dataViews[0];
        if (updateType !== UpdateType.Resize) {
            const newState = this._internalState.receiveFromPBI(dataView);

            if (dataView) {
                const hasDataChanged = !!(updateType & UpdateType.Data);
                this.loadLegendFromPowerBI(newState);
                this.loadDataFromPowerBI(dataView, hasDataChanged, newState);
                this.loadSelectedRangeFromPowerBI(dataView, hasDataChanged, newState);

                // Safari for some reason will not repaint after an dynamically added class, so we are adding this here
                // to ensure that safari repaints after an update
                this.element.addClass("SAFARI_HACK").removeClass("SAFARI_HACK");
            }

            if (updateType & UpdateType.Settings) {
                if (newState.barWidth !== this._internalState.barWidth) {
                    this.timeBrush.barWidth = newState.barWidth;
                }
                if (!isEqual(newState.yAxisSettings, this._internalState.yAxisSettings)) {
                    this.timeBrush.showYAxis = newState.yAxisSettings.show;
                    this.timeBrush.yAxisPosition = newState.yAxisSettings.yAxisPosition;
                    this.timeBrush.showYAxisReferenceLines = newState.yAxisSettings.showReferenceLines;
                }
            }

            const newRange = this.boundRangeByItemDates((<any>newState.selectedRange || []).map((v: string) => new Date(v)));

            newState.selectedRange = newRange;

            // Update the Time Brush
            this.timeBrush.selectedRange = newRange;

            // Update the internal state
            this._internalState = this._internalState.receive(newState);
        }
    }