Skip to content

Commit

Permalink
[TSVB] Different field format on different series is ignored (#78138)
Browse files Browse the repository at this point in the history
* [TSVB] Different field format on different series is ignored

Closes #74951

* Replace formatter of Y axis with simple value instead of formatter of the first series

* Add a condition to Y-axis tickFormatter to display formatted value if there's only one series

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
DianaDerevyankina and elasticmachine authored Sep 29, 2020
1 parent d7d96d9 commit 6f2fd54
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,9 @@ export class TimeseriesVisualization extends Component {
const mainAxisGroupId = yAxisIdGenerator('main_group');

const seriesModel = model.series.filter((s) => !s.hidden).map((s) => cloneDeep(s));
const firstSeries = seriesModel.find((s) => s.formatter && !s.separate_axis);

const mainAxisScaleType = TimeseriesVisualization.getAxisScaleType(model);
const mainAxisDomain = TimeseriesVisualization.getYAxisDomain(model);
const tickFormatter = TimeseriesVisualization.getTickFormatter(
firstSeries,
this.props.getConfig
);
const yAxis = [];
let mainDomainAdded = false;

Expand Down Expand Up @@ -203,7 +198,7 @@ export class TimeseriesVisualization extends Component {
series
.filter((r) => startsWith(r.id, seriesGroup.id))
.forEach((seriesDataRow) => {
seriesDataRow.tickFormatter = seriesGroupTickFormatter;
seriesDataRow.tickFormat = seriesGroupTickFormatter;
seriesDataRow.groupId = groupId;
seriesDataRow.yScaleType = yScaleType;
seriesDataRow.hideInLegend = Boolean(seriesGroup.hide_in_legend);
Expand All @@ -224,7 +219,7 @@ export class TimeseriesVisualization extends Component {
});
} else if (!mainDomainAdded) {
TimeseriesVisualization.addYAxis(yAxis, {
tickFormatter,
tickFormatter: series.length === 1 ? undefined : (val) => val,
id: yAxisIdGenerator('main'),
groupId: mainAxisGroupId,
position: model.axis_position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function AreaSeriesDecorator({
sortIndex,
y1AccessorFormat,
y0AccessorFormat,
tickFormat,
}) {
const id = seriesId;
const groupId = seriesGroupId;
Expand All @@ -67,6 +68,7 @@ export function AreaSeriesDecorator({
enableHistogramMode,
useDefaultGroupDomain,
sortIndex,
tickFormat,
...areaSeriesStyle,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function BarSeriesDecorator({
sortIndex,
y1AccessorFormat,
y0AccessorFormat,
tickFormat,
}) {
const id = seriesId;
const groupId = seriesGroupId;
Expand All @@ -66,6 +67,7 @@ export function BarSeriesDecorator({
enableHistogramMode,
useDefaultGroupDomain,
sortIndex,
tickFormat,
...barSeriesStyle,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const TimeSeries = ({
useDefaultGroupDomain,
y1AccessorFormat,
y0AccessorFormat,
tickFormat,
},
sortIndex
) => {
Expand Down Expand Up @@ -207,6 +208,7 @@ export const TimeSeries = ({
sortIndex={sortIndex}
y1AccessorFormat={y1AccessorFormat}
y0AccessorFormat={y0AccessorFormat}
tickFormat={tickFormat}
/>
);
}
Expand All @@ -233,6 +235,7 @@ export const TimeSeries = ({
sortIndex={sortIndex}
y1AccessorFormat={y1AccessorFormat}
y0AccessorFormat={y0AccessorFormat}
tickFormat={tickFormat}
/>
);
}
Expand Down

0 comments on commit 6f2fd54

Please sign in to comment.