in src/dataConversion.ts [84:176]
function convertToRowObjs(dataView: DataView, settings, roles = null): CardBrowserDocument[] {
const result = [];
// const columns = dataView.metadata.columns;
let rowObj: any;
let firstRoleIndexMap = [];
const categorical =
dataView &&
dataView.categorical;
const categories =
categorical &&
dataView.categorical.categories;
const columnValues =
categorical &&
dataView.categorical.values;
function parseColumn(column: powerbi.DataViewMetadataColumn, colValue: any, colIdx: number) {
const colRoles = Object.keys(column.roles);
const columnValue = colValue && (column.type.dateTime ?
moment(colValue as any).format(settings.presentation.dateFormat) : colValue);
colRoles.forEach((role) => {
if (rowObj[role] === undefined) {
rowObj[role] = assignValue(role, column.displayName, columnValue);
firstRoleIndexMap[role] = colIdx;
return;
}
if (!Array.isArray(rowObj[role])) {
const firstRoleValue = rowObj[role];
rowObj[role] = [];
assignRole(rowObj, role, firstRoleValue, roles, firstRoleIndexMap[role]);
}
assignRole(rowObj, role, assignValue(role, column.displayName, columnValue), roles, colIdx);
});
}
if (categories && categories.length > 0 && categories[0].values && categories[0].values.length > 0) {
// We can get duplicated categories if the user passes in the same column for multiple fields
const uniqueCategories = dedupeCategories(categories);
const idValues = categories[0].values;
for (let rowIdx = 0; rowIdx < idValues.length; rowIdx++) {
rowObj = {
index: rowIdx,
};
for (const cat of uniqueCategories) {
parseColumn(cat.source, cat.values[rowIdx], 0);
}
if (columnValues && columnValues.length > 0) {
columnValues.forEach((valueCol, colIdx) => {
const column = valueCol.source;
const colValue = valueCol.values[rowIdx];
parseColumn(column, colValue, colIdx + 1);
});
}
if (rowObj.metadata) {
rowObj.metadata = flattenMetaData(rowObj.metadata);
}
if (rowObj.subtitle) {
if (Array.isArray(rowObj.subtitle)) {
rowObj.subtitle = rowObj.subtitle.filter(item => item);
}
else {
rowObj.subtitle = [rowObj.subtitle];
}
}
if (rowObj.imageUrl && Array.isArray(rowObj.imageUrl)) {
const cleanArray = [];
for (let i = 0; i < rowObj.imageUrl.length; i++) {
if (rowObj.imageUrl[i]) {
cleanArray.push(rowObj.imageUrl[i]);
}
}
rowObj.imageUrl = cleanArray;
}
if (rowObj.content) {
rowObj.content = utils.sanitizeHTML(rowObj.content, HTML_WHITELIST_CONTENT);
if (!rowObj.summary) {
rowObj.summary = utils.sanitizeHTML(rowObj.content, HTML_WHITELIST_SUMMARY);
}
}
if (rowObj.title && Array.isArray(rowObj.title)) {
rowObj.title = rowObj.title.join(' ');
}
result.push(rowObj);
}
}
return result;
}