@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
124 lines • 5.16 kB
JavaScript
import { Data } from 'victory-core';
import { getBulletComparativeErrorMeasureTheme, getBulletComparativeMeasureTheme, getBulletComparativeWarningMeasureTheme, getBulletPrimaryDotMeasureTheme, getBulletPrimaryNegativeMeasureTheme, getBulletPrimarySegmentedMeasureTheme, getBulletQualitativeRangeTheme } from '../../ChartUtils/chart-theme-types';
/**
* Returns comparative measure data
*
* @private Not intended as public API and subject to change
*/
export const getComparativeMeasureData = ({ data, themeColor,
// destructure last
theme = getBulletComparativeMeasureTheme(themeColor), y }) => {
const datum = [];
Data.formatData(data, { y }, ['y']).forEach((dataPoint, index) => {
datum.push(Object.assign(Object.assign({}, dataPoint), { _index: index // Save to sync legend color
}));
});
const computedData = datum.map((dataPoint) => (Object.assign(Object.assign({}, dataPoint), { x: 1, _x: 1, y0: dataPoint._y, _y0: dataPoint._y, _color: theme.bar.style.data.fill // Save to sync legend color
})));
return computedData;
};
/**
* Returns comparative error measure data
*
* @private Not intended as public API and subject to change
*/
export const getComparativeErrorMeasureData = ({ data, themeColor,
// destructure last
theme = getBulletComparativeErrorMeasureTheme(themeColor), y }) => getComparativeMeasureData({
data,
theme,
themeColor,
y
});
/**
* Returns comparative warning data
*
* @private Not intended as public API and subject to change
*/
export const getComparativeWarningMeasureData = ({ data, themeColor,
// destructure last
theme = getBulletComparativeWarningMeasureTheme(themeColor), y }) => getComparativeMeasureData({
data,
theme,
themeColor,
y
});
/**
* Returns primary dot measure data
*
* @private Not intended as public API and subject to change
*/
export const getPrimaryDotMeasureData = ({ data, invert, themeColor,
// destructure last
theme = getBulletPrimaryDotMeasureTheme(themeColor), y, y0 }) => getComparativeMeasureData({
data,
invert,
theme,
themeColor,
y,
y0
});
/**
* Returns primary segment measure data
*
* @private Not intended as public API and subject to change
*/
export const getPrimarySegmentedMeasureData = ({ data, invert, themeColor,
// destructure last
theme = getBulletPrimarySegmentedMeasureTheme(themeColor), negativeMeasureTheme = getBulletPrimaryNegativeMeasureTheme(themeColor), y, y0 }) => {
const negativeDatum = [];
const positiveDatum = [];
Data.formatData(data, { y, y0 }, ['y', 'y0']).forEach((dataPoint, index) => {
if (dataPoint._y < 0) {
negativeDatum.push(Object.assign(Object.assign({}, dataPoint), { _index: index // Save to sync legend color
}));
}
else {
positiveDatum.push(Object.assign(Object.assign({}, dataPoint), { _index: index // Save to sync legend color
}));
}
});
// Instead of relying on colorScale, colors must be added to each measure in ascending order
const negativeComputedData = negativeDatum
.sort((a, b) => b._y - a._y)
.map((dataPoint, index) => (Object.assign(Object.assign({}, dataPoint), { x: 1, _x: 1, _color: invert
? theme.group.colorScale[index % theme.group.colorScale.length]
: negativeMeasureTheme.group.colorScale[index % theme.group.colorScale.length] }))
// Sort descending so largest bar is appears behind others
)
.reverse();
// Instead of relying on colorScale, colors must be added to each measure in ascending order
const positiveComputedData = positiveDatum
.sort((a, b) => a._y - b._y)
.map((dataPoint, index) => (Object.assign(Object.assign({}, dataPoint), { x: 1, _x: 1, _color: invert
? negativeMeasureTheme.group.colorScale[index % theme.group.colorScale.length]
: theme.group.colorScale[index % theme.group.colorScale.length] }))
// Sort descending so largest bar is appears behind others
)
.reverse();
return [...negativeComputedData, ...positiveComputedData];
};
/**
* Returns qualitative range data
*
* @private Not intended as public API and subject to change
*/
export const getQualitativeRangeData = ({ data, invert, themeColor,
// destructure last
theme = getBulletQualitativeRangeTheme(themeColor), y, y0 }) => {
const datum = [];
Data.formatData(data, { y, y0 }, ['y', 'y0']).forEach((dataPoint, index) => {
datum.push(Object.assign(Object.assign({}, dataPoint), { _index: index // Save to sync legend color
}));
});
const computedData = datum
.sort((a, b) => (invert ? b._y - a._y : a._y - b._y))
.map((dataPoint, index) => (Object.assign(Object.assign({}, dataPoint), { x: 1, _x: 1,
// Instead of relying on colorScale, colors must be added to each measure in ascending order
_color: theme.group.colorScale[index % theme.group.colorScale.length] }))
// Sort descending so largest bar is appears behind others
)
.reverse();
return computedData;
};
//# sourceMappingURL=chart-bullet-data.js.map