echarts [RFC] Resize correctly when the charts are laid out with CSS grid or flex.

jaxagkaj  于 5个月前  发布在  Echarts
关注(0)|答案(1)|浏览(44)

Here are some issues that report incorrect resizing in the CSS grid or flex layout.

This problem may be caused by the width/height set previously on the root element of the instances. The specified value will affect the final height of their parent element. So we may need to hide first other instances before resizing to solve this issue. But I'm not quite sure that we should do this in zrender or by the developer.

If just by the developer, please refer to the following demos.

Otherwise, some changes need to be applied to the resize function of zrender.

Proposed Changes

/**
* Resize the canvas.
* Should be invoked when container size is changed
*/
  resize(opts?: {
      width?: number| string
      height?: number | string
  }) {
      opts = opts || {};
+     let rootDisplay: {[index: number]: string} = {};
+     // if there are multiple instances, hide other instances first.
+     zrUtil.each(instances, zr => {
+       if (zr !== this) {
+         const style = zr.painter.getViewportRoot().style;
+         rootDisplay[zr.id] = style.display;
+         style.display = 'none';
+       }
+     });
      this.painter.resize(opts.width, opts.height);
      this.handler.resize();
+     // restore the previous display
+     zrUtil.each(instances, zr => {
+       zr !== this && (zr.painter.getViewportRoot().style.display = rootDisplay[zr.id]);
+     });
  }

For #11791

1.mp4

Any idea is appreciated. Thanks.

62lalag4

62lalag41#

Indeed a really annoying bug, quite impossible to use echarts inside flexbox :(

相关问题