zrender & svg

window.prompt

double click

https://codepen.io/xgqfrms/pen/jOEGNvw

// https://cdn.xgqfrms.xyz/svg/zrender/zrender.min.js

window.onload = () => {
const log = console.log;
const default_pts = {
renderer: 'canavs',// 渲染方式,支持:'canavs'、'svg'、'vml'
devicePixelRatio: 2, // 画布大小与容器大小之比,仅当 renderer 为 'canvas' 时有效。
width: 'auto',// 画布宽度,设为 'auto' 则根据 devicePixelRatio 与容器宽度自动计算。
height: 'auto', // 画布高度,设为 'auto' 则根据 devicePixelRatio 与容器高度自动计算。
};
const opts = {
renderer: 'svg',
width: 400,
height: 400,// 画布大小
};
const zr = zrender.init(document.getElementById('app'), opts);
// log(`zr`, zr);
const version = zrender.version;
log(`zr version`, version);
// version 4.1.2 let w = zr.getWidth();
let h = zr.getHeight(); log(`w / h`, w, h);
let text = null; const boundingRect = new zrender.Rect({
shape: {
r: 0,
// r: 1,
// r: 10,
// r: [1],
// cx: 0,
// cy: 0,
x: 100,
y: 100,
// x: 0,
// y: 0,
width: 200,
height: 200,
},
style: {
fill: '#0f0',
// fill: 'none',
stroke: '#666',
},
color: "abc",
});
// boundingRect.on(`click`, function(e) {
// // log(`click e`, e);
// log(`click this`, this,);
// log(`click this.color`, this.color);
// this.color = "xyz";
// log(`click new this.color`, this.color);
// // boundingRect
// }, boundingRect);
boundingRect.on(`dblclick`, function(e) {
// log(`click e`, e);
log(`dblclick this`, this);
// log(`dblclick this.style`, this.style);
let rect = this.getBoundingRect();
log(`dblclick rect\n%c ${JSON.stringify(rect, null, 4)}`, `color: #0f0`);
const x = rect.width / 2 + rect.x;
const y = rect.height / 2 + rect.y;
log(`x, y`, x, y);
// let msg = window.confirm(`请输入选区的名称?`);
let msg = window.prompt(`请输入选区的名称?`);
// prompt([string message], [string defaultValue]);
if(text){
zr.remove(text);
// zr.clear(text);
}
log(`text`, text);
text = new zrender.Text({
style: {
text: msg || 'A 区',
textAlign: 'center',
textVerticalAlign: 'middle',
fontSize: 18,
fontFamily: 'Lato',
fontWeight: 'bolder',
textFill: '#f0f',
blend: 'lighten',
},
position: [x, y],
});
log(`text`, text);
zr.add(text);
}, boundingRect);
// boundingRect.on(`click`, (e) => {
// // log(`click e`, e);
// log(`click this`, this);
// this bind bug
// log(`click this`, boundingRect);
// // boundingRect
// }, boundingRect); zr.add(boundingRect); };

最新文章

  1. Node.js入门
  2. ​Linux下的SVN服务器搭建
  3. BUAA_OVERWATCH第一次行动前战略部署
  4. MySQL建表规范与常见问题
  5. ImFire即时通讯系统构建(需求)
  6. discuz数据库表
  7. 转:Android 判断用户2G/3G/4G移动数据网络
  8. c programming language ___ 5_2.c
  9. B. Berland Bingo
  10. Qt 富文本处理(QTextDocument和QTextBlock和QTextFrame和QTextTable和QTextList和QTextDocument)
  11. BC 2015在百度之星程序设计大赛 - 预赛(1)(系列转换-二分法答案贪婪)
  12. tastypie Django REST API developement 1)
  13. 王爽汇编语言(第三版)环境搭建(附PDF及工具下载)
  14. java开发注解总结笔记
  15. H5上传图片之canvas
  16. 【XSY1519】彩灯节 DP 数学 第二类斯特林数
  17. P3613 睡觉困难综合征(LCT + 位运算)
  18. linux free命令
  19. 回文串 --- 动态dp UVA 11584
  20. JQuery下载及选择器总结

热门文章

  1. session和cookie自动登录机制
  2. 【转】DDD-应用架构
  3. LOJ2723
  4. PowerApps画布应用编码规范 和指南
  5. Jenkins入门教程
  6. 使用ganglia 实现监控 hadoop 和 hbase(详细过程总结)
  7. java中的IO处理和使用,API详细介绍(二)
  8. MySQL数据库的逻辑架构和存储引擎
  9. php小程序-文章发布系统(mvc框架)
  10. 13. 从0学ARM-Cortex-A9 RTC裸机程序编写