[TSVB] Add option to stack globally or within series (#31417)
* Add a check for the same series metric * Replace logic to the nodejs side * Add 'Stack within series' option
This commit is contained in:
parent
a382b49744
commit
7559941e26
|
@ -62,6 +62,13 @@ const TimeseriesConfig = injectI18n(function (props) {
|
|||
const stackedOptions = [
|
||||
{ label: intl.formatMessage({ id: 'tsvb.timeSeries.noneLabel', defaultMessage: 'None' }), value: 'none' },
|
||||
{ label: intl.formatMessage({ id: 'tsvb.timeSeries.stackedLabel', defaultMessage: 'Stacked' }), value: 'stacked' },
|
||||
{
|
||||
label: intl.formatMessage({
|
||||
id: 'tsvb.timeSeries.stackedWithinSeriesLabel',
|
||||
defaultMessage: 'Stacked within series'
|
||||
}),
|
||||
value: 'stacked_within_series'
|
||||
},
|
||||
{ label: intl.formatMessage({ id: 'tsvb.timeSeries.percentLabel', defaultMessage: 'Percent' }), value: 'percent' }
|
||||
];
|
||||
const selectedStackedOption = stackedOptions.find(option => {
|
||||
|
|
|
@ -22,6 +22,45 @@ import getDefaultDecoration from '../../helpers/get_default_decoration';
|
|||
|
||||
describe('getDefaultDecoration', () => {
|
||||
|
||||
describe('stack option', () => {
|
||||
|
||||
it('should set a stack option to false', () => {
|
||||
const series = {
|
||||
id: 'test_id'
|
||||
};
|
||||
expect(getDefaultDecoration(series))
|
||||
.to.have.property('stack', false);
|
||||
|
||||
series.stacked = 'none';
|
||||
expect(getDefaultDecoration(series))
|
||||
.to.have.property('stack', false);
|
||||
});
|
||||
|
||||
it('should set a stack option to true', () => {
|
||||
const series = {
|
||||
stacked: 'stacked',
|
||||
id: 'test_id'
|
||||
};
|
||||
|
||||
expect(getDefaultDecoration(series))
|
||||
.to.have.property('stack', true);
|
||||
|
||||
series.stacked = 'percent';
|
||||
expect(getDefaultDecoration(series))
|
||||
.to.have.property('stack', true);
|
||||
});
|
||||
|
||||
it('should set a stack option to be series id', () => {
|
||||
const series = {
|
||||
stacked: 'stacked_within_series',
|
||||
id: 'test_id'
|
||||
};
|
||||
|
||||
expect(getDefaultDecoration(series))
|
||||
.to.have.property('stack', series.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lines', () => {
|
||||
it('return decoration for lines', () => {
|
||||
const series = {
|
||||
|
|
|
@ -20,8 +20,21 @@
|
|||
export default series => {
|
||||
const pointSize = series.point_size != null ? Number(series.point_size) : Number(series.line_width);
|
||||
const showPoints = series.chart_type === 'line' && pointSize !== 0;
|
||||
let stack;
|
||||
switch (series.stacked) {
|
||||
case 'stacked':
|
||||
case 'percent':
|
||||
stack = true;
|
||||
break;
|
||||
case 'stacked_within_series':
|
||||
stack = series.id;
|
||||
break;
|
||||
default:
|
||||
stack = false;
|
||||
}
|
||||
|
||||
return {
|
||||
stack: series.stacked && series.stacked !== 'none' || false,
|
||||
stack,
|
||||
lines: {
|
||||
show: series.chart_type === 'line' && series.line_width !== 0,
|
||||
fill: Number(series.fill),
|
||||
|
|
Loading…
Reference in a new issue