function ShootDemo()

in stories/chart.map.stories.js [457:521]


function ShootDemo() {
  const log = action('setData');
  const [width, useWidth] = useState(800);
  const [data, setData] = useState([]);
  useEffect(() => {
    const dataLen = shootData.length;
    const changeData = () => {
      const newData = [];
      const len = Math.round(Math.random() * 10) + 10;
      for (let i = 0; i < len; i++) {
        let fIndex = Math.round(Math.random() * (dataLen - 1));
        let tIndex = (fIndex + Math.round(Math.random() * (dataLen / 2)) + 1) % dataLen;
        if (fIndex === tIndex) {
          tIndex = (fIndex + 1) % dataLen;
        }
        newData.push({
          from: Object.assign({}, shootData[fIndex]),
          to: Object.assign({}, shootData[tIndex]),
        });
      }

      log(newData);

      setData(newData);
    };

    changeData();
    const timer = setInterval(() => {
      changeData();
    }, 8000);
    return () => clearInterval(timer);
  }, []);
  return (
    <Wcontainer
      className="demos"
      width={width}
      height={600}
      title="点击右侧测试改变大小"
      operation={
        <button
          onClick={() => {
            const w = width > 700 ? 600 : 800;
            useWidth(w);
            action('resize')(w);
            window.dispatchEvent(new Event('resize'));
          }}
        >
          resize
        </button>
      }
    >
      <Wmap>
        <Wmap.Shoot data={data} />
        <Wmap.Custom
          data={shootData}
          render={(point, index) => (
            <span>
              {index} : {point.name}
            </span>
          )}
        />
      </Wmap>
    </Wcontainer>
  );
}