AnyChart / AnyChart-React

Intuitive and easy to use React plugin that allows you to create and work with AnyChart JavaScript Charts
https://www.anychart.com
Apache License 2.0
39 stars 30 forks source link

Strange component behavior #11

Closed BEGEMOT9I closed 2 years ago

BEGEMOT9I commented 5 years ago

Hi. I conduct a comparative analysis of visualization tools and one of the tools on my list is AnyChart. Since I use React adapters whenever possible, I also took your implementation. But I ran into one very strange problem. It consists in the fact that if it is necessary to draw a dataset from several series, I have to draw an adapter component with the initial settings without a dataset and when redrawing (re-rendering) already set it. For example:

interface Props {}
interface State {
  isMounted: boolean
}

const dataset = [
  ['2018', 1, 2, 3],
  ['2017', 10, 20, 30],
  ['2016', 100, 200, 300],
]

class LineChart extends PureComponent<Props, State> {
  public static displayName = 'LineChart'
  public state: State = {
    isMounted: false
  }

  componentDidMount() {
    this.setState({ isMounted: true })
  }

  public render() {
    const { width, height } = this.props

    if (this.state.isMounted) {
      const chartDataSet = anychart.data.set(dataset)

      return <AnyChart data={chartDataSet} />
    }

    return <AnyChart width={width} height={height} type="line" legend />
  }
}

I analyzed the adapter code a bit and paid attention to this part:

  // ...
  createInstance(props) {
    if (props.instance) {
      // ...
    } else if (props.type) {
      this.removeInstance();
      this.disposeInstance = true;
      this.instance = anychart[props.type](props.data);
      this.isStage = false;
      delete props.type;
      delete props.data;
    }
    // ...
  }
  // ...

I understand that, for example, the method anychart.line and the method chart.data take different input parameters. Does it make sense to separate these two properties and rename at least one of them at least in the adapter, so that there is no need to re-render the chart?

Shestac92 commented 5 years ago

@BEGEMOT9I This plugin was designed a while ago so it can require some optimizations. We will look into it and consider your report. Thank you for your report!

BEGEMOT9I commented 5 years ago

Thank you too.