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. XCTF-基础Android

    前期工作 查壳,无.打开看是普通的输入注册码然后验证. 逆向分析 这题太简单了,就不贴图了.看Manifest得知MainActivity是启动类,也就是点进去输入注册码那个类.密码不重要,验证成功后 ...

  2. Spring框架——JDBC方式搭建项目

    学习Spring框架,使用JDBC的方式配置方式搭建一个项目,进行项目总结. 首先,采用MVC设计模式思想,搭建项目目录. 然后各个目录文件下面的相关源码附上: controller目录: impor ...

  3. 免费开源的代码审计工具 Gosec 入门使用

    声明: 本教程是在自己的电脑上本地测试Gosec的效果,所以不涉及其他运行模式,如果想要了解其他模式可以关注后期文档,如果想要自定义交流自定义代码扫描规则,可以跟我交流沟通. 背景: Gosec是一个 ...

  4. DEDECMS:解决无法上传图片(在后台插入图片时提示类型不允许)

    在include/uploadsafe.inc.php里把 $imtypes = array ( "image/pjpeg", "image/jpeg", &q ...

  5. Centos8上搭建EMQ MQTT

    layout: post title: Centos8上搭建EMQ MQTT subtitle: 在阿里云Centos8搭建EMQ并配置接入 date: 2020-3-11 author: Dapen ...

  6. Jenkins(5)生成allure报告

    前言 jenkins集成了allure插件,安装插件后运行pytest+allure的脚本即可在jenkins上查看allure报告了. allure安装 在运行代码的服务器本机,我这里是用的dock ...

  7. P3195 [HNOI2008] 玩具装箱(斜率优化DP)

    题目链接 设\(d[i]\)为将前 \(i\) 个玩具装入箱中所需得最小费用 容易得到动态转移方程: \[d[i] = min(d[j] + (s[i]-s[j]+i-j-1-L)^2), (j< ...

  8. CF 666E Forensic Examination 【SAM 倍增 线段树合并】

    CF 666E Forensic Examination 题意: 给出一个串\(s\)和\(n\)个串\(t_i\),\(q\)次询问,每次询问串\(s\)的子串\(s[p_l:p_r]\)在串\(t ...

  9. Codeforces Round #652 (Div. 2) B. AccurateLee(字符串)

    题目链接:https://codeforces.com/contest/1369/problem/B 题意 给出一个长 $n$ 的 二进制串,每次可以选择字符串中的一个 $10$,然后删除其中的一个字 ...

  10. hdu5501 The Highest Mark

    Problem Description The SDOI in 2045 is far from what it was been 30 years ago. Each competition has ...