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

[v5] render spec 用法 #4560

Closed
visiky opened this issue Jan 9, 2023 · 3 comments · Fixed by #4661
Closed

[v5] render spec 用法 #4560

visiky opened this issue Jan 9, 2023 · 3 comments · Fixed by #4661

Comments

@visiky
Copy link
Member

visiky commented Jan 9, 2023

现状

使用 render spec 用法时,目前需要增加 type: 'view' 的节点,期望可以增加语法糖,简化用法

render({
  type: 'view',
  children: [{
    type: 'line',
    encode: {},
    style: {},
  }]
})

期望

render({
  type: 'line',
  encode: {},
  style: {},
})
@pearmini
Copy link
Member

pearmini commented Jan 9, 2023

@visiky
Copy link
Member Author

visiky commented Jan 9, 2023

import { render } from '@antv/g2';

function Composite({ data, encode }) {
  return () => {
    return [{
      type: 'line',
      data,
      encode
    }, {
      type: 'point',
      data,
      encode: {
        ...encode,
        shape: 'point'
      }
    }]
  }
}

Composite.props = { composite: true }

const c1 = render({
  type: Composite,
  height: 200,
  data: [{ type: '分类1', value: 10 }, { type: '分类2', value: 12 }],
  encode: { x: 'type', y: 'value' }
});

const c2 = render({
  type: 'view',
  height: 200,
  children: [{
    type: Composite,
    data: [{ type: '分类1', value: 10 }, { type: '分类2', value: 12 }],
    encode: { x: 'type', y: 'value' }
  }]
});

document.getElementById('container').replaceChildren(c1, c2);

image

控制台有报错

@pearmini
Copy link
Member

大概2月份重构的时候会解决这个问题

@pearmini pearmini linked a pull request Feb 17, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants