zoukankan      html  css  js  c++  java
  • d3.js不支持attr和style像jquery一样传入多个对象,重写attr和style方法

    import * as d3 from 'd3';
    // 重写d3的attr和style支持传入对象
    const oldAttr = d3.selection.prototype.attr;
    d3.selection.prototype.attr = function () {
      if (arguments.length === 1) {
        if (typeof arguments[0] === 'object') {
          for (const item in arguments[0]) {
            oldAttr.call(this, item, arguments[0][item]);
          }
          return this;
        }
        return oldAttr.call(this, arguments[0]);
      } else if (arguments.length === 2) {
        return oldAttr.call(this, arguments[0], arguments[1]);
      }
    };
    const oldStyle = d3.selection.prototype.style;
    d3.selection.prototype.style = function () {
      if (arguments.length === 1) {
        if (typeof arguments[0] === 'object') {
          for (const item in arguments[0]) {
            oldStyle.call(this, item, arguments[0][item]);
          }
          return this;
        }
        return oldStyle.call(this, arguments[0]);
      } else if (arguments.length === 2) {
        return oldStyle.call(this, arguments[0], arguments[1]);
      }
    };

    转载自:http://www.codezd.com/js/271.html

  • 相关阅读:
    输出重定向
    echo带颜色输出
    shell学习视频目录
    css盒模型
    jQuery表格模糊搜索
    mysql基础语法3
    mysql基础语法2
    mysql基础语法1
    pyspider框架的使用
    quill富文本框图片上传重写
  • 原文地址:https://www.cnblogs.com/xiaoyaoweb/p/13274164.html
Copyright © 2011-2022 走看看