Dart SVG翻译对象 [英] Dart SVG Translate an object

查看:131
本文介绍了Dart SVG翻译对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Dart在SVG中翻译椭圆。我没有找到任何解释如何做,除了SetAttribute方式

I'm trying to translate an ellipse in SVG with Dart. I haven't found any explanation on how to do that, other than the SetAttribute way

ellipse.setAttribute('transform', 'translate($acx, $acy)');

我发现EllipseElement有这样的符号:

I have found that the EllipseElement has a notation like this:

ellipse.transform.baseVal[...].setTranslate(acx,acy);

..但它不工作。我完全不知道setTranslate如何工作,我想我必须告诉哪个元素来翻译,但我不知道如何。
是否最好使用setATtribute而不是尝试使用其他方法?

..but it doesn't work. I'm totally not sure how setTranslate works and I suppose I have to tell which element to translate but I have no idea how. Is it better to use setATtribute instead of trying to use the other method?

推荐答案

>



I successfully tried

ellipse.setAttribute('transform', 'translate(150, 150)');



setAttribute 然后下面的工作太少

ellipse.transform.baseVal.first.setTranslate(20, 100);

或者您可以如图所示添加 Transform 在此问题的答案中 Dart创建和转换SVG路径

or you can add a Transform as shown in the answer to this question Dart create and transform an SVG path

Matrix m = new svg.SvgSvgElement().createSvgMatrix();
Matrix m2 = m.translate(50, 50);
Transform tr = ellipse.transform.baseVal.createSvgTransformFromMatrix(m2);
ellipse.transform.baseVal.appendItem(tr);

您可以使用

ellipse.style.setProperty('fill', '#07f');

这篇关于Dart SVG翻译对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆