You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/06/01 09:00:14 UTC
[GitHub] [echarts] plainheart opened a new issue #15062: [SVG] Allow adding DOM to the chart in SVG renderer through `foreignObject`
plainheart opened a new issue #15062:
URL: https://github.com/apache/echarts/issues/15062
### What problem does this feature solve?
For SVG renderer, it would be flexible and creative if allow adding DOM to the chart through [`foreignObject`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject).
### What does the proposed API look like?
Currently no good idea about how to design the API in ECharts. Here is the proposed usage in zrender.
**DOM string**
```ts
// DOM string
const dom = new zrender.ForeignObject({
style: {
x: 600,
y: 250,
width: 200,
height: 400
},
rotation: -60 * Math.PI / 180,
originX: 600 + 200 / 2,
originY: 250 + 400 / 2,
// scaleX: 2,
// scaleY: 2,
html: `
<h1 class="hover-change-color" style="color:#F72C5B">Apache ECharts</h1>
<h4>一个基于 JavaScript 的开源可视化图表库</h3>
<img height="150" src="https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/zh/images/index-home-pie.png?_v_=20200710_1" />
`
});
zr.add(dom);
```
**DOM Array**
```ts
// DOM array
const h1 = document.createElement('h1');
h1.className = 'hover-change-color';
h1.innerText = 'Created Element';
const p = document.createElement('p');
p.innerText = new Date().toLocaleString();
setInterval(() => p.innerText = new Date().toLocaleString(), 1e3);
const dom2 = new zrender.ForeignObject({
style: {
x: 600,
y: 150,
width: 200,
height: 200
},
originX: 600 + 200 / 2,
originY: 150 + 200 / 2,
scaleX: 0.8,
scaleY: 0.8,
html: [h1, p]
});
zr.add(dom2);
```
**Video**
```ts
// video
const video = document.createElement('video');
video.src = 'https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/v4/zh/video/index.mp4';
video.poster = 'https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/v4/zh/video/index-4.jpg';
video.muted = true;
video.autoplay = true;
video.controls = true;
video.loop = true;
video.style.objectFit = 'contain';
video.style.maxWidth = '100%';
const videoDom = new zrender.ForeignObject({
style: {
x: 50,
y: 250,
width: 400,
height: 400
},
html: video
});
zr.add(videoDom);
```
### Screenshot

<!-- This issue is generated by echarts-issue-helper. DO NOT REMOVE -->
<!-- This issue is in English. DO NOT REMOVE -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] pissang edited a comment on issue #15062: [SVG] Allow adding DOM to the chart in SVG renderer through `foreignObject`
Posted by GitBox <gi...@apache.org>.
pissang edited a comment on issue #15062:
URL: https://github.com/apache/echarts/issues/15062#issuecomment-852007778
It's a very promising feature! But I think we should try not to break the consistency between SVG and Canvas renderer as much as possible. So this should be a feature that canvas also can have.
For API design, since ForeignObject is a concept that only SVG has. It's better to use a more general API like `zrender.HTMLElement`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] pissang edited a comment on issue #15062: [SVG] Allow adding DOM to the chart in SVG renderer through `foreignObject`
Posted by GitBox <gi...@apache.org>.
pissang edited a comment on issue #15062:
URL: https://github.com/apache/echarts/issues/15062#issuecomment-852007778
It's a very attractive feature! But I think we should try not to break the consistency between SVG and Canvas renderer as much as possible. So this should be a feature that canvas also can have.
For API design, since ForeignObject is a concept that only SVG has. It's better to use a more general API like `zrender.HTMLElement`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] pissang commented on issue #15062: [SVG] Allow adding DOM to the chart in SVG renderer through `foreignObject`
Posted by GitBox <gi...@apache.org>.
pissang commented on issue #15062:
URL: https://github.com/apache/echarts/issues/15062#issuecomment-852007778
IMO we should try not to break the consistency between SVG and Canvas renderer as much as possible. So this should be a feature that canvas also can have.
For API design, since ForeignObject is a concept that only SVG has. It's better to use a more general API like `zrender.HTMLElement`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org