zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    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' 时有效。
         'auto',// 画布宽度,设为 'auto' 则根据 devicePixelRatio 与容器宽度自动计算。
        height: 'auto', // 画布高度,设为 'auto' 则根据 devicePixelRatio 与容器高度自动计算。
      };
      const opts = {
        renderer: 'svg',
         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,
           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
    %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);
    
    };
    
    
    

  • 相关阅读:
    设计模式(三)原型模式
    PageHelper在Mybatis中的使用
    设计模式(二) 单例模式
    设计模式(一)简单工厂、工厂方法和抽象工厂
    Java网络编程
    循环控制语句if 、for、case、while
    处理海量数据的grep、cut、awk、sed 命令
    shell脚本的输入以及脚本拥有特效地输出
    shell的变量以及常见符号
    shell的使用技巧
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/12319800.html
Copyright © 2011-2022 走看看