RenderUtil.js 647 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import {
  2. attr as svgAttr,
  3. create as svgCreate
  4. } from 'tiny-svg';
  5. export function componentsToPath(elements) {
  6. return elements.join(',').replace(/,?([A-z]),?/g, '$1');
  7. }
  8. export function toSVGPoints(points) {
  9. var result = '';
  10. for (var i = 0, p; (p = points[i]); i++) {
  11. result += p.x + ',' + p.y + ' ';
  12. }
  13. return result;
  14. }
  15. export function createLine(points, attrs) {
  16. var line = svgCreate('polyline');
  17. svgAttr(line, { points: toSVGPoints(points) });
  18. if (attrs) {
  19. svgAttr(line, attrs);
  20. }
  21. return line;
  22. }
  23. export function updateLine(gfx, points) {
  24. svgAttr(gfx, { points: toSVGPoints(points) });
  25. return gfx;
  26. }