Refactor generate hex function to take explicit options

Also sets he default color to grey text if the cell is a table
(This prevents null values showing up as blue)
pull/10616/head
Alex P 2018-03-21 14:10:48 -07:00
parent 32acc3cc09
commit c5bce2ae7f
3 changed files with 15 additions and 10 deletions

View File

@ -33,11 +33,11 @@ class SingleStat extends PureComponent {
const precision = 100.0
const roundedValue = Math.round(+lastValue * precision) / precision
const {bgColor, textColor} = generateThresholdsListHexs(
const {bgColor, textColor} = generateThresholdsListHexs({
colors,
lastValue,
lineGraph
)
containsLineGraph: lineGraph,
})
const backgroundColor = bgColor
const color = textColor

View File

@ -180,10 +180,11 @@ class TableGraph extends Component {
let cellStyle = style
if (!isFixedRow && !isFixedColumn && !isFixedCorner) {
const {bgColor, textColor} = generateThresholdsListHexs(
const {bgColor, textColor} = generateThresholdsListHexs({
colors,
data[rowIndex][columnIndex]
)
lastValue: data[rowIndex][columnIndex],
cellType: 'table',
})
cellStyle = {
...style,

View File

@ -46,12 +46,16 @@ export const stringifyColorValues = colors => {
return colors.map(color => ({...color, value: `${color.value}`}))
}
export const generateThresholdsListHexs = (
export const generateThresholdsListHexs = ({
colors,
lastValue,
containsLineGraph
) => {
const defaultColoring = {bgColor: null, textColor: THRESHOLD_COLORS[11].hex}
containsLineGraph,
cellType,
}) => {
const defaultColoring = {
bgColor: null,
textColor: cellType === 'table' ? '#BEC2CC' : THRESHOLD_COLORS[11].hex,
}
const lastValueNumber = Number(lastValue) || 0
if (!colors.length || !lastValue) {