how to change svg polygon size by update it's points in js

matrixTransform

https://stackoverflow.com/questions/40493506/get-updated-polygon-points-after-transformations-svg


function screenPolygon(myPoly){
var sCTM = myPoly.getCTM()
var svgRoot = myPoly.ownerSVGElement var pointsList = myPoly.points;
var n = pointsList.numberOfItems;
for(var m=0;m<n;m++)
{
var mySVGPoint = svgRoot.createSVGPoint();
mySVGPoint.x = pointsList.getItem(m).x
mySVGPoint.y = pointsList.getItem(m).y
mySVGPointTrans = mySVGPoint.matrixTransform(sCTM)
pointsList.getItem(m).x=mySVGPointTrans.x
pointsList.getItem(m).y=mySVGPointTrans.y
}
//---force removal of transform--
myPoly.setAttribute("transform","")
myPoly.removeAttribute("transform")
}

var sCTM = this.poly.getCTM();
// SVGMatrix
var svgRoot = this.poly.ownerSVGElement;
// svg
var mySVGPoint = svgRoot.createSVGPoint();
// SVGPoint {x: 0, y: 0}
log(`sCTM`, sCTM);
log(`svgRoot`, svgRoot);
log(`mySVGPoint`, mySVGPoint);

matrix transforms

https://stackoverflow.com/questions/38525536/svg-polygon-scale-and-set-points-accordingly

Convert SVG polygon points to path

https://stackoverflow.com/questions/16245712/convert-svg-polygon-points-to-path


var points="270,328 270,376 342,376 342,368 358,368 358,320 314,320 298,336 278,336" var p = points.split(/\s+/);
var path = "";
for( var i = 0, len = p.length; i < len; i++ ){
path += (i && "L" || "M") + p[i]
} console.log( path )
=> M270,328L270,376L342,376L342,368L358,368L358,320L314,320L298,336L278,336

C#

https://stackoverflow.com/questions/11263936/changing-a-polygons-points


demo

  getMinPoint() {
const {
x,
y,
} = this.getBoxSize();
return {
x,
y,
};
}
getMaxPoint() {
const {
x,
y,
width,
height,
} = this.getBoxSize();
return {
x: x + width,
y: y + height,
};
}
getSize() {
const {
width,
height,
} = this.getBoxSize();
return {
width,
height,
};
}
zoomWidth(w) {
// 除最小点, 其他点 x 增大
var sCTM = this.poly.getCTM();
// SVGMatrix
var svgRoot = this.poly.ownerSVGElement;
// svg
var mySVGPoint = svgRoot.createSVGPoint();
// SVGPoint {x: 0, y: 0}
log(`sCTM`, sCTM);
log(`svgRoot`, svgRoot);
log(`mySVGPoint`, mySVGPoint);
const box = this.getBoxSize();
const min = this.getMinPoint();
const max = this.getMaxPoint();
log(`box size`, box, min, max);
log(`poly points`, this.poly.points);
// log(`poly points`, this.poly.getAttribute(`points`));
// 放大 width
const points = [];
[...this.poly.points].forEach(point => {
const {
x,
y,
} = point;
const px = (x === min.x) ? x : x + w;
if(x === min.x) {
log(`min point x`, point)
}
const py = y;
points.push(px, py);
});
this.poly.setAttribute(`points`, points.join(` `));
}

d3

https://stackoverflow.com/questions/49261369/update-polygon-when-points-change-in-d3

zrender

mapbox

canvas


最新文章

  1. RecyclerView-------MyAdapter代码
  2. 关于php的开源
  3. Apache Mina 入门实例
  4. WTL 自绘 进度条Progressbar
  5. (转载)无缝滚动图片的js和jquery两种写法
  6. ASP.net与SQLite数据库通过js和ashx交互(连接和操作)
  7. mysql数据迁移
  8. “永恒之蓝&quot;漏洞的紧急应对--毕业生必看
  9. 59、jQuery初识
  10. linux环境手动编译安装Nginx实践过程 附异常解决
  11. Liunx文件解压与压缩
  12. unity插件开发
  13. 图片支持get请求访问
  14. mysql5.5 五种日期
  15. MSSQL DB Replication Error
  16. BZOJ1067 [SCOI2007]降雨量 线段树
  17. python中的list以及list与array相互转换
  18. “全栈2019”Java多线程第三十六章:如何设置线程的等待截止时间
  19. Docker实战(二)之操作Docker容器
  20. Cannot load supported formats: Cannot run program &quot;svn&quot;

热门文章

  1. 系列trick - bitmask
  2. 五:Spring Security 中的角色继承问题
  3. 图的广度优先遍历算法(BFS)
  4. 谷粒商城为什么要选择后天管理用vue前后端分离,而商城页面选择Thymeleaf类?
  5. StringTable---字符串常量池的垃圾回收跟踪案例
  6. Linux上搭建https服务器
  7. Java一些概念
  8. Codeforces Global Round 9 D. Replace by MEX
  9. SCZ 20170812 T1 HKJ
  10. Codeforces Round #672 (Div. 2) A. Cubes Sorting (思维)