private static converter()

in src/visual.ts [812:923]


    private static converter(dataView: DataView, localizationManager: ILocalizationManager, colorHelper: ColorHelper): IDualKpiData {
        let data = {} as IDualKpiData;
        let topValueFormatSymbol = "";
        let bottomValueFormatSymbol = "";
        data.settings = DualKpi.parseSettings(dataView, localizationManager, colorHelper);

        if (data.settings.dualKpiColorsBottom.matchTopChartOptions) {
            data.settings.dualKpiColorsBottom.dataColor = data.settings.dualKpiColors.dataColor;
            data.settings.dualKpiColorsBottom.opacity = data.settings.dualKpiColors.opacity;
            data.settings.dualKpiColorsBottom.textColor = data.settings.dualKpiColors.textColor;
        }

        data.topValues = [];
        data.bottomValues = [];

        let axisCol = -1, topValuesCol = -1, bottomValuesCol = -1, warningStateCol = -1,
            topPercentDateCol = -1, bottomPercentDateCol = -1;

        const categories = dataView.categorical.categories;
        for (let i: number = 0; i < categories.length; i++) {
            let col: DataViewCategoryColumn = categories[i];
            if (col.source && col.source.roles) {
                if (col.source.roles["axis"]) {
                    axisCol = i;
                }
                if (col.source.roles["toppercentdate"]) {
                    topPercentDateCol = i;
                }
                if (col.source.roles["bottompercentdate"]) {
                    bottomPercentDateCol = i;
                }
            }
        }

        const values = dataView.categorical.values;
        for (let i: number = 0; i < values.length; i++) {
            let col: DataViewValueColumn = values[i];
            if (col.source && col.source.roles) {
                if (col.source.roles["topvalues"]) {
                    topValuesCol = i;
                    data.topChartName = col.source.displayName;
                    topValueFormatSymbol = this.getFormatSymbol(col.source.format);
                }
                if (col.source.roles["bottomvalues"]) {
                    bottomValuesCol = i;
                    data.bottomChartName = col.source.displayName;
                    bottomValueFormatSymbol = this.getFormatSymbol(col.source.format);
                }
                if (col.source.roles["warningstate"]) {
                    warningStateCol = i;
                }
            }
        }

        const rowsLength = categories.length > 0 ? categories[0].values.length : (values.length > 0 ? values[0].values.length : 0);

        data.topValueAsPercent = topValueFormatSymbol === "%" ? true : false;
        data.bottomValueAsPercent = bottomValueFormatSymbol === "%" ? true : false;

        // if percent dates are in data use that, otherwise get from formatting pane/default values
        data.topPercentCalcDate = topPercentDateCol > -1 && categories[topPercentDateCol].values[0] ? new Date(<any>categories[topPercentDateCol].values[0]) : new Date(data.settings.dualKpiProperties.topPercentCalcDate);
        data.bottomPercentCalcDate = bottomPercentDateCol > -1 && categories[bottomPercentDateCol].values[0] ? new Date(<any>categories[bottomPercentDateCol].values[0]) : new Date(data.settings.dualKpiProperties.bottomPercentCalcDate);

        for (let i: number = 0; i < rowsLength; i++) {
            let date = null;

            if (axisCol > -1) {
                let timestamp: number = Date.parse(<any>categories[axisCol].values[i]);

                if (!isNaN(timestamp)) {
                    date = new Date(timestamp);
                } else {
                    continue;
                }
            } else {
                date = new Date();
            }

            let topValue = topValuesCol > -1 ? <any>values[topValuesCol].values[i] : 0;
            let bottomValue = bottomValuesCol > -1 ? <any>values[bottomValuesCol].values[i] : 0;

            if (data.topValueAsPercent) {
                topValue *= 100;
            }

            if (data.bottomValueAsPercent) {
                bottomValue *= 100;
            }

            data.topValues.push({
                date: date,
                value: topValue
            });

            data.bottomValues.push({
                date: date,
                value: bottomValue
            });
        }

        if ((warningStateCol > -1) && (rowsLength > 0)) {
            data.warningState = <any>values[warningStateCol].values[rowsLength - 1];
        }

        const sortBy = (key) => {
            return (a, b) => (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0);
        };

        data.topValues.sort(sortBy("date"));
        data.bottomValues.sort(sortBy("date"));
        return data;
    }