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


how to change svg polygon size by update it's points in js的更多相关文章

  1. A workaround to change shared memory size for Docker containers in AWS ECS

    Issue Because of not supporting to specify the following docker run parameter, containers in ECS can ...

  2. svg学习(七)polygon

    <polygon> 标签用来创建含有不少于三个边的图形. <?xml version="1.0" standalone="no"?> & ...

  3. 1. Change the emulator screen size

    1. "Windows" ==> "Android Virtual Device Manager" ==> Select one emulator ...

  4. SVG & convert polygon/polyline to path

    SVG & convert polygon/polyline to path SVG Polygon/Polyline to Path Converter https://codepen.io ...

  5. 【MySQL 5.7 Reference Manual】15.4.2 Change Buffer(变更缓冲)

    15.4.2 Change Buffer(变更缓冲)   The change buffer is a special data structure that caches changes to se ...

  6. SVG.js Marker标记和自定义标签

    一.SVG.Marker 添加标记 SVG.Marker 标记可以被添加到一个线,折线的各点,多边形和路径.有三种类型的标记:开始,中间和结束.如果开始表示第一个点,则结束中间的最后一点和中间点. v ...

  7. SVG.js 图案使用和use引用

    一.SVG.Pattern 图案设置 var draw = SVG('svg1').size(300, 300); //SVG.Pattern 图案设置 var pattern = draw.patt ...

  8. SVG.js 颜色渐变使用

    一.SVG.Gradient 1.线性渐变.径向渐变,设置渐变的起始点,设置径向渐变的外层半径 var draw = SVG('svg1').size(300, 300); //SVG.Gradien ...

  9. SVG.js 基础图形绘制整理(二)

    一.折线 var draw = SVG('svg1').size(300, 300); //画折线 //使用字符串点 // var polyline=draw.polyline('0,0 100,50 ...

随机推荐

  1. 固定学习率梯度下降法的Python实现方案

    应用场景 优化算法经常被使用在各种组合优化问题中.我们可以假定待优化的函数对象\(f(x)\)是一个黑盒,我们可以给这个黑盒输入一些参数\(x_0, x_1, ...\),然后这个黑盒会给我们返回其计 ...

  2. Node.js 安全指南

    当项目周期快结束时,开发人员会越来越关注应用的"安全性"问题.一个安全的应用程序并不是一种奢侈,而是必要的.你应该在开发的每个阶段都考虑应用程序的安全性,例如系统架构.设计.编码, ...

  3. fastHttp服务端处理请求的过程

    Github 地址 https://github.com/valyala/fasthttp fastHttp 服务端的处理请求的过程 工作过程 主要代码 设置监听地址 server.go func ( ...

  4. (九)整合 ElasticSearch框架,实现高性能搜索引擎

    整合 ElasticSearch框架,实现高性能搜索引擎 1.SpringBoot整合ElasticSearch 1.1 核心依赖 1.2 配置文件 1.3 实体类配置 1.4 数据交互层 1.5 演 ...

  5. 渗透测试流程&mdash;&mdash;渗透测试的9个步骤(转)

    目录 明确目标 分析风险,获得授权 信息收集 漏洞探测(手动&自动) 漏洞验证 信息分析 利用漏洞,获取数据 信息整理 形成报告 1.明确目标 1)确定范围:测试的范围,如:IP.域名.内外网 ...

  6. linux 用户、用户组及相关命令(useradd 、passwd、userdel 、groupadd 、groupdel、usermod 、gpasswd 、 id、su)

    linux是一个多用户系统,用于权限管理(权限最小化); 相关命令: 7 8 9 10 11 12 13 14 15 useradd passwd userdel groupadd groupdel ...

  7. Pytest(6)重复运行用例pytest-repeat

    前言 平常在做功能测试的时候,经常会遇到某个模块不稳定,偶然会出现一些bug,对于这种问题我们会针对此用例反复执行多次,最终复现出问题来. 自动化运行用例时候,也会出现偶然的bug,可以针对单个用例, ...

  8. 各个复位标志解析,让我们对MCU的程序的健康更有把控

    作者:良知犹存 转载授权以及围观:欢迎添加微信公众号:Conscience_Remains 总述 曾经开发的时候遇到这样情况,我们开发的设备需要长时间工作上报信息,但是我们在后台查看上报数据,发现设备 ...

  9. BZOJ2882 工艺【SAM】 最小循环串

    BZOJ2882 工艺 给出一个串,要求其循环同构串中字典序最小的那个 串翻倍建\(SAM\)然后从起点开始贪心的跑\(n\)次即可 当然也能用最小表示法来做 #include<bits/std ...

  10. linux搭建网站

    CentOS 1.安装 yum -y install nginx *或者安装指定版本,版本网址:http://nginx.org/packages/centos/7/x86_64/RPMS/ rpm ...