in charts/shared/table.js [94:165]
export async function colourize(headings, userKey, data, columnOrder) {
const desiredOrder = columnOrder.sort((a, b) => a.index - b.index).map(col => col.column);
const pantone = swatches(data, userKey)
const highlighted = userKey.map(item => item.key)
const formating = userKey.map(item => {
if (item.format) {
console.log(item.format)
if (item.format.includes(",")) {
return item.format.split(",")
} else {
return [ item.format.trim() ]
}
} else {
return []
}
})
const hasDate = formating.map(item => contains(item, 'date'))
const graphics = userKey.map(item => {
return (item.graphics) ? item.graphics : undefined ;
})
const outta = userKey.map(item => {
return (item.outta) ? item.outta : undefined ;
})
const colourizer = (value, index) => (!contains(headings[index], highlighted)) ? false : pantone.find(item => item.name === headings[index]).profile.get(value) ;
//const values = data.map((row) => Object.values(row))
const values = reorderValues(data, desiredOrder);
const getFormat = (index) => {
return (highlighted.indexOf(headings[index]) > -1) ? formating[highlighted.indexOf(headings[index])] : [""]
}
const checkDate = (value, index) => {
return (hasDate[index-1]) ? Math.floor(new Date(value).getTime() / 1000) : value
}
const getGraphics = (index) => {
return (highlighted.indexOf(headings[index]) > -1) ? graphics[highlighted.indexOf(headings[index])] : null
}
const getOutta = (index) => {
return (highlighted.indexOf(headings[index]) > -1) ? outta[highlighted.indexOf(headings[index])] : null
}
return await values.map((row, i) => {
return row.map((value, index) => { return { value : value, sort : checkDate(value, index), format: getFormat(index), color : colourizer(value, index), contrast : setContrast(colourizer(value, index)), graphics: getGraphics(index), outta : getOutta(index) }})
})
}