Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis Labels not always updating #699

Closed
iffy opened this issue Aug 7, 2017 · 5 comments · Fixed by FormidableLabs/victory-chart#529
Closed

Axis Labels not always updating #699

iffy opened this issue Aug 7, 2017 · 5 comments · Fixed by FormidableLabs/victory-chart#529
Assignees

Comments

@iffy
Copy link

iffy commented Aug 7, 2017

I have some area charts in which the X-axis labels are not always being updated.

<V.VictoryChart
    domain={{y: [0, max_bal * 1.25]}}
    height={200}
    width={800}
  >
    <V.VictoryAxis
      standalone={false}
      tickValues={tickValues}
    />
    <V.VictoryAxis
      dependentAxis
      tickFormat={x => cents2decimal(x)}
    />
    <V.VictoryArea
      data={data}
      interpolation="catmullRom"
      x="month"
      y="end_balance" />
</V.VictoryChart>

For example, when tickValues changes from the first to the second line

["Aug 2016", "Sep", "Oct", "Nov", "Dec", "Jan 2017", "Feb", "Mar", "Apr", "May", "Jun", "Jul"]
["Sep 2016", "Oct", "Nov", "Dec", "Jan 2017", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug"]

The chart still shows Aug 2016 ... Jul as the labels.

The data/lines/area is changing, just not the labels. I'd submit a PR if I could find the responsible code.

@iffy
Copy link
Author

iffy commented Aug 7, 2017

I've found out why, but not sure of the fix.

Here's VictoryChart.render with inline comments. (https://github.com/FormidableLabs/victory-chart/blob/master/src/components/victory-chart/victory-chart.js#L229):

function render() {
  const props = this.state && this.state.nodesWillExit ?
    this.state.oldProps || this.props : this.props;
  //
  // At this point, props.children[0].props.tickValues
  // is an array of string like this:
  // ["Sep 2016", "Oct", "Nov", "Dec", "Jan 2017", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug"]
  //
  const modifiedProps = Helpers.modifyProps(props, fallbackProps, "chart");
  const { eventKey, containerComponent } = modifiedProps;
  const axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes;
  const childComponents = ChartHelpers.getChildComponents(modifiedProps, axes);

  //
  // At this point, childComponents[0].props.tickValues is
  // still that list
  //

  const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);

  //
  // At this point, calculatedProps introduces a mapping of tickValues
  // rather than the actual values.
  //
  // > calculatedProps.categories.x
  // ["Sep 2016", "Oct", ...]
  //
  // > calculatedProps.domain.x
  // [0, 12]
  //
  // > calculatedProps.stringMap.x
  // { Apr: 8, Aug: 12, Dec: 4, ... }
  //

  const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);

  //
  // And now newChildren[0].props.tickValues is an array of numbers
  // rather than an array of strings:
  //
  // > newChildren[0].props.tickValues
  // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  //
  const containerProps = this.getContainerProps(modifiedProps, calculatedProps);
  const container = this.renderContainer(containerComponent, containerProps);
  if (this.events) {
    return (
      <VictorySharedEvents events={this.events} eventKey={eventKey} container={container}>
        {newChildren}
      </VictorySharedEvents>
    );
  }
  return React.cloneElement(container, container.props, newChildren);
}

The problem is that the tickValues are always [1...12] even though the labels change.

@boygirl boygirl self-assigned this Aug 8, 2017
@omeid
Copy link

omeid commented Sep 22, 2017

Hitting this issue, I have labels that change based on the other dimension of the data but the 'tickValues' remain the same.

@SamSamskies
Copy link

SamSamskies commented Oct 3, 2017

I just hit this issue as well. Used this as a hack in my component containing the VictoryAxis to fix it for now:

constructor(props) {
  super()
  this.state = { tickValues: props.tickValues }
}

componentWillReceiveProps(nextProps) {
  // TODO: Remove once VictoryAxis not updating bug is fixed
  // https://github.com/FormidableLabs/victory/issues/699
  if (!isEqual(nextProps.tickValues, this.state.tickValues)) {
    this.setState(
      { tickValues: [] },
      () => this.setState({ tickValues: nextProps.tickValues })
    )
  }
}

@SamSamskies
Copy link

@boygirl I upgraded to 0.24 and this issue is still not resolved for me. When I pass new tickValues to VictoryAxis it still doesn't re-render with the new values.

@nicolasrenon
Copy link

Same issue here with 0.25.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants