ST.Plot.NodeTypes定义和提供树节点的形状类型

来源:互联网 发布:php应用 编辑:程序博客网 时间:2024/06/03 10:04


/*  Class: ST.Plot.NodeTypes  This class contains a list of <Graph.Node> built-in types.  Node types implemented are 'none', 'circle', 'rectangle', 'ellipse' and 'square'.  You can add your custom node types, customizing your visualization to the extreme.  Example:  (start code js)    ST.Plot.NodeTypes.implement({      'mySpecialType': {        'render': function(node, canvas) {          //print your custom node to canvas        },        //optional        'contains': function(node, pos) {          //return true if pos is inside the node or false otherwise        }      }    });  (end code)*/$jit.ST.Plot.NodeTypes = new Class({  'none': {    'render': $.empty,    'contains': $.lambda(false)  },  'circle': {    'render': function(node, canvas) {      var dim  = node.getData('dim'),          pos = this.getAlignedPos(node.pos.getc(true), dim, dim),          dim2 = dim/2;      this.nodeHelper.circle.render('fill', {x:pos.x+dim2, y:pos.y+dim2}, dim2, canvas);    },    'contains': function(node, pos) {      var dim  = node.getData('dim'),          npos = this.getAlignedPos(node.pos.getc(true), dim, dim),          dim2 = dim/2;      return this.nodeHelper.circle.contains({x:npos.x+dim2, y:npos.y+dim2}, pos, dim2);    }  },  'square': {    'render': function(node, canvas) {      var dim  = node.getData('dim'),          dim2 = dim/2,          pos = this.getAlignedPos(node.pos.getc(true), dim, dim);      this.nodeHelper.square.render('fill', {x:pos.x+dim2, y:pos.y+dim2}, dim2, canvas);    },    'contains': function(node, pos) {      var dim  = node.getData('dim'),          npos = this.getAlignedPos(node.pos.getc(true), dim, dim),          dim2 = dim/2;      return this.nodeHelper.square.contains({x:npos.x+dim2, y:npos.y+dim2}, pos, dim2);    }  },  'ellipse': {    'render': function(node, canvas) {      var width = node.getData('width'),          height = node.getData('height'),          pos = this.getAlignedPos(node.pos.getc(true), width, height);      this.nodeHelper.ellipse.render('fill', {x:pos.x+width/2, y:pos.y+height/2}, width, height, canvas);    },    'contains': function(node, pos) {      var width = node.getData('width'),          height = node.getData('height'),          npos = this.getAlignedPos(node.pos.getc(true), width, height);      return this.nodeHelper.ellipse.contains({x:npos.x+width/2, y:npos.y+height/2}, pos, width, height);    }  },  'rectangle': {    'render': function(node, canvas) {      var width = node.getData('width'),          height = node.getData('height'),          pos = this.getAlignedPos(node.pos.getc(true), width, height);      this.nodeHelper.rectangle.render('fill', {x:pos.x+width/2, y:pos.y+height/2}, width, height, canvas);    },    'contains': function(node, pos) {      var width = node.getData('width'),          height = node.getData('height'),          npos = this.getAlignedPos(node.pos.getc(true), width, height);      return this.nodeHelper.rectangle.contains({x:npos.x+width/2, y:npos.y+height/2}, pos, width, height);    }  }});





原创粉丝点击