Skip to content

Wrong series name on legend when using splitSeriesAccessors with a single series #420

@markov00

Description

@markov00

Describe the bug
When a chart is configured with a split series accessor, but the data has only one series with one accessor value, the name of the series in the legend and in the tooltip is equal to the name or to the Id of the Series.

To Reproduce
Steps to reproduce the behavior:

Use the following playground
import React, { Fragment } from 'react';
import { Axis, Chart, getAxisId, getSpecId, Position, ScaleType, BarSeries, Settings } from '../src';

export class Playground extends React.Component<{}, { dataLimit: boolean }> {
  state = {
    dataLimit: false,
  };
  changeData = () => {
    this.setState((prevState) => {
      return {
        dataLimit: !prevState.dataLimit,
      };
    });
  };
  render() {
    const data = [
      {
        g: 'authentication_failure',
        i: 'aa',
        x: 1571212800000,
        y: 16,
        y1: 2,
      },
      {
        x: 1571290200000,
        y: 1,
        y1: 5,
        g: 'authentication_success',
      },
    ];
    return (
      <Fragment>
        <div>
          <button onClick={this.changeData}>Reduce data</button>
        </div>
        <div className="chart">
          <Chart>
            <Settings showLegend />
            <Axis id={getAxisId('top')} position={Position.Bottom} title={'Top axis'} />
            <Axis
              id={getAxisId('left2')}
              title={'Left axis'}
              position={Position.Left}
              tickFormat={(d: any) => Number(d).toFixed(2)}
            />

            <BarSeries
              id={getSpecId('bars1')}
              xScaleType={ScaleType.Linear}
              yScaleType={ScaleType.Linear}
              xAccessor="x"
              yAccessors={['y']}
              splitSeriesAccessors={['g']}
              stackAccessors={['x']}
              data={data.slice(0, this.state.dataLimit ? 1 : 2)}
            />
          </Chart>
        </div>
      </Fragment>
    );
  }
}

and click on the button

Expected behavior
If the series is configured with splitSeriesAccessors and we rely on this accessors values to define the name of the series, for consistency we should keep the same behaviour also when we have just one series in the data.

Screenshots

Current behaviour:

Oct-17-2019 12-30-12

Version (please complete the following information):

  • Elastic Charts: all

Additional context
Was discovered by SIEM team when adding an histogram

Errors in browser console
n/a

Kibana Cross Issues
elastic/kibana#48260

Checklist

  • every related Kibana issue is listed under Kibana Cross Issues list
  • kibana cross issue tag is associated to the issue if any kibana cross issue is present

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingkibana cross issueHas a Kibana issue counterpartreleasedIssue released publicly

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions