dojox/gfx/path.js

  • Provides:

    • dojox.gfx.path
  • Requires:

    • dojox.gfx.matrix in common
    • dojox.gfx.shape in common
  • dojox.gfx.path.Path

    • type
      Function
    • chains:
      • dojox.gfx.shape.Shape: (prototype)
      • dojox.gfx.shape.Shape: (call)
    • summary
      a path constructor
    • parameters:
      • rawNode: (typeof Node)
        a DOM node to be used by this path object
    • source: [view]
        this.shape = dojo.clone(dojox.gfx.defaultPath);
        this.segments = [];
        this.tbbox = null;
        this.absolute = true;
        this.last = {};
        this.rawNode = rawNode;
        this.segmented = false;
  • dojox.gfx.path.Path.setAbsoluteMode

    • type
      Function
    • parameters:
      • mode: (typeof Boolean)
        true/false or "absolute"/"relative" to specify the mode
    • source: [view]
        this._confirmSegmented();
        this.absolute = typeof mode == "string" ? (mode == "absolute") : mode;
        return this; // self
    • summary
      sets an absolute or relative mode for path points
    • returns
      self
  • dojox.gfx.path.Path.getAbsoluteMode

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        return this.absolute; // Boolean
    • summary
      returns a current value of the absolute mode
    • returns
      Boolean
  • dojox.gfx.path.Path.getBoundingBox

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        return (this.bbox && ("l" in this.bbox)) ? {x: this.bbox.l, y: this.bbox.t, width: this.bbox.r - this.bbox.l, height: this.bbox.b - this.bbox.t} : null; // dojox.gfx.Rectangle
    • summary
      returns the bounding box {x, y, width, height} or null
    • returns
      dojox.gfx.Rectangle
  • dojox.gfx.path.Path._getRealBBox

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        if(this.tbbox){
         return this.tbbox; // Array
        }
        var bbox = this.bbox, matrix = this._getRealMatrix();
        this.bbox = null;
        for(var i = 0, len = this.segments.length; i < len; ++i){
         this._updateWithSegment(this.segments[i], matrix);
        }
        var t = this.bbox;
        this.bbox = bbox;
        this.tbbox = t ? [
         {x: t.l, y: t.t},
         {x: t.r, y: t.t},
         {x: t.r, y: t.b},
         {x: t.l, y: t.b}
        ] : null;
        return this.tbbox; // Array
    • summary
      returns an array of four points or null
      four points represent four corners of the untransformed bounding box
    • returns
      Array
  • dojox.gfx.path.Path.getLastPosition

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        return "x" in this.last ? this.last : null; // Object
    • summary
      returns the last point in the path, or null
    • returns
      Object
  • dojox.gfx.path.Path._applyTransform

    • type
      Function
    • source: [view]
        this.tbbox = null;
        return this.inherited(arguments);
    • summary
  • dojox.gfx.path.Path._updateBBox

    • type
      Function
    • parameters:
      • x: (typeof Number)
        an x coordinate
      • y: (typeof Number)
        a y coordinate
      • matrix: (typeof )
    • source: [view]
        if(matrix){
         var t = dojox.gfx.matrix.multiplyPoint(matrix, x, y);
         x = t.x;
         y = t.y;
        }


        // we use {l, b, r, t} representation of a bbox
        if(this.bbox && ("l" in this.bbox)){
         if(this.bbox.l > x) this.bbox.l = x;
         if(this.bbox.r < x) this.bbox.r = x;
         if(this.bbox.t > y) this.bbox.t = y;
         if(this.bbox.b < y) this.bbox.b = y;
        }else{
         this.bbox = {l: x, b: y, r: x, t: y};
        }
    • summary
      updates the bounding box of path with new point
  • dojox.gfx.path.Path._updateWithSegment

    • type
      Function
    • parameters:
      • segment: (typeof Object)
        a segment
      • matrix: (typeof )
    • source: [view]
        var n = segment.args, l = n.length;
        // update internal variables: bbox, absolute, last
        switch(segment.action){
         case "M":
         case "L":
         case "C":
         case "S":
         case "Q":
         case "T":
          for(var i = 0; i < l; i += 2){
           this._updateBBox(n[i], n[i + 1], matrix);
          }
          this.last.x = n[l - 2];
          this.last.y = n[l - 1];
          this.absolute = true;
          break;
         case "H":
          for(var i = 0; i < l; ++i){
           this._updateBBox(n[i], this.last.y, matrix);
          }
          this.last.x = n[l - 1];
          this.absolute = true;
          break;
         case "V":
          for(var i = 0; i < l; ++i){
           this._updateBBox(this.last.x, n[i], matrix);
          }
          this.last.y = n[l - 1];
          this.absolute = true;
          break;
         case "m":
          var start = 0;
          if(!("x" in this.last)){
           this._updateBBox(this.last.x = n[0], this.last.y = n[1], matrix);
           start = 2;
          }
          for(var i = start; i < l; i += 2){
           this._updateBBox(this.last.x += n[i], this.last.y += n[i + 1], matrix);
          }
          this.absolute = false;
          break;
         case "l":
         case "t":
          for(var i = 0; i < l; i += 2){
           this._updateBBox(this.last.x += n[i], this.last.y += n[i + 1], matrix);
          }
          this.absolute = false;
          break;
         case "h":
          for(var i = 0; i < l; ++i){
           this._updateBBox(this.last.x += n[i], this.last.y, matrix);
          }
          this.absolute = false;
          break;
         case "v":
          for(var i = 0; i < l; ++i){
           this._updateBBox(this.last.x, this.last.y += n[i], matrix);
          }
          this.absolute = false;
          break;
         case "c":
          for(var i = 0; i < l; i += 6){
           this._updateBBox(this.last.x + n[i], this.last.y + n[i + 1], matrix);
           this._updateBBox(this.last.x + n[i + 2], this.last.y + n[i + 3], matrix);
           this._updateBBox(this.last.x += n[i + 4], this.last.y += n[i + 5], matrix);
          }
          this.absolute = false;
          break;
         case "s":
         case "q":
          for(var i = 0; i < l; i += 4){
           this._updateBBox(this.last.x + n[i], this.last.y + n[i + 1], matrix);
           this._updateBBox(this.last.x += n[i + 2], this.last.y += n[i + 3], matrix);
          }
          this.absolute = false;
          break;
         case "A":
          for(var i = 0; i < l; i += 7){
           this._updateBBox(n[i + 5], n[i + 6], matrix);
          }
          this.last.x = n[l - 2];
          this.last.y = n[l - 1];
          this.absolute = true;
          break;
         case "a":
          for(var i = 0; i < l; i += 7){
           this._updateBBox(this.last.x += n[i + 5], this.last.y += n[i + 6], matrix);
          }
          this.absolute = false;
          break;
        }
        // add an SVG path segment
        var path = [segment.action];
        for(var i = 0; i < l; ++i){
         path.push(dojox.gfx.formatNumber(n[i], true));
        }
        if(typeof this.shape.path == "string"){
         this.shape.path += path.join("");
        }else{
         Array.prototype.push.apply(this.shape.path, path); //FIXME: why not simple push()?
        }
    • summary
      updates the bounding box of path with new segment
    • chains:
      • Array.prototype.push: (call)
  • dojox.gfx.path.Path._validSegments

    • type
      Object
    • summary
  • dojox.gfx.path.Path._pushSegment

    • type
      Function
    • parameters:
      • action: (typeof String)
        valid SVG code for a segment's type
      • args: (typeof Array)
        a list of parameters for this segment
    • source: [view]
        this.tbbox = null;
        var group = this._validSegments[action.toLowerCase()];
        if(typeof group == "number"){
         if(group){
          if(args.length >= group){
           var segment = {action: action, args: args.slice(0, args.length - args.length % group)};
           this.segments.push(segment);
           this._updateWithSegment(segment);
          }
         }else{
          var segment = {action: action, args: []};
          this.segments.push(segment);
          this._updateWithSegment(segment);
         }
        }
    • summary
      adds a segment
  • dojox.gfx.path.Path._collectArgs

    • type
      Function
    • parameters:
      • array: (typeof Array)
        an output argument (array of numbers)
      • args: (typeof Array)
        an input argument (can be values of Boolean, Number, dojox.gfx.Point, or an embedded array of them)
    • source: [view]
        for(var i = 0; i < args.length; ++i){
         var t = args[i];
         if(typeof t == "boolean"){
          array.push(t ? 1 : 0);
         }else if(typeof t == "number"){
          array.push(t);
         }else if(t instanceof Array){
          this._collectArgs(array, t);
         }else if("x" in t && "y" in t){
          array.push(t.x, t.y);
         }
        }
    • summary
      converts an array of arguments to plain numeric values
  • dojox.gfx.path.Path.moveTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "M" : "m", args);
        return this; // self
    • summary
      formes a move segment
    • returns
      self
  • dojox.gfx.path.Path.lineTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "L" : "l", args);
        return this; // self
    • summary
      formes a line segment
    • returns
      self
  • dojox.gfx.path.Path.hLineTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "H" : "h", args);
        return this; // self
    • summary
      formes a horizontal line segment
    • returns
      self
  • dojox.gfx.path.Path.vLineTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "V" : "v", args);
        return this; // self
    • summary
      formes a vertical line segment
    • returns
      self
  • dojox.gfx.path.Path.curveTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "C" : "c", args);
        return this; // self
    • summary
      formes a curve segment
    • returns
      self
  • dojox.gfx.path.Path.smoothCurveTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "S" : "s", args);
        return this; // self
    • summary
      formes a smooth curve segment
    • returns
      self
  • dojox.gfx.path.Path.qCurveTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "Q" : "q", args);
        return this; // self
    • summary
      formes a quadratic curve segment
    • returns
      self
  • dojox.gfx.path.Path.qSmoothCurveTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "T" : "t", args);
        return this; // self
    • summary
      formes a quadratic smooth curve segment
    • returns
      self
  • dojox.gfx.path.Path.arcTo

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        var args = [];
        this._collectArgs(args, arguments);
        this._pushSegment(this.absolute ? "A" : "a", args);
        return this; // self
    • summary
      formes an elliptic arc segment
    • returns
      self
  • dojox.gfx.path.Path.closePath

    • type
      Function
    • source: [view]
        this._confirmSegmented();
        this._pushSegment("Z", []);
        return this; // self
    • summary
      closes a path
    • returns
      self
  • dojox.gfx.path.Path._confirmSegmented

    • type
      Function
    • source: [view]
        if (!this.segmented) {
         var path = this.shape.path;
         // switch to non-updating version of path building
         this.shape.path = [];
         this._setPath(path);
         // switch back to the string path
         this.shape.path = this.shape.path.join("");
         // become segmented
         this.segmented = true;
        }
    • summary
  • dojox.gfx.path.Path._setPath

    • type
      Function
    • parameters:
      • path: (typeof String)
        an SVG path string
    • source: [view]
        var p = dojo.isArray(path) ? path : path.match(dojox.gfx.pathSvgRegExp);
        this.segments = [];
        this.absolute = true;
        this.bbox = {};
        this.last = {};
        if(!p) return;
        // create segments
        var action = "", // current action
         args = [],  // current arguments
         l = p.length;
        for(var i = 0; i < l; ++i){
         var t = p[i], x = parseFloat(t);
         if(isNaN(x)){
          if(action){
           this._pushSegment(action, args);
          }
          args = [];
          action = t;
         }else{
          args.push(x);
         }
        }
        this._pushSegment(action, args);
    • summary
      forms a path using an SVG path string
  • dojox.gfx.path.Path.setShape

    • type
      Function
    • parameters:
      • newShape: (typeof Object)
        an SVG path string or a path object (see dojox.gfx.defaultPath)
    • source: [view]
        this.inherited(arguments, [typeof newShape == "string" ? {path: newShape} : newShape]);

        
        this.segmented = false;
        this.segments = [];
        if(!dojox.gfx.lazyPathSegmentation){
         this._confirmSegmented();
        }
        return this; // self
    • summary
      forms a path using a shape
    • returns
      self
  • dojox.gfx.path.Path._2PI

    • summary
  • dojox.gfx.path.Path.absolute

    • summary
  • dojox.gfx.path.Path.bbox

    • summary
  • dojox.gfx.path.Path.tbbox

    • summary
  • dojox.gfx.path.Path.bbox.l

    • summary
  • dojox.gfx.path.Path.bbox.r

    • summary
  • dojox.gfx.path.Path.bbox.t

    • summary
  • dojox.gfx.path.Path.bbox.b

    • summary
  • dojox.gfx.path.Path.last.x

    • summary
  • dojox.gfx.path.Path.last.y

    • summary
  • dojox.gfx.path.Path.shape.path

    • summary
  • dojox.gfx.path.Path._validSegments.m

    • summary
  • dojox.gfx.path.Path._validSegments.l

    • summary
  • dojox.gfx.path.Path._validSegments.h

    • summary
  • dojox.gfx.path.Path._validSegments.v

    • summary
  • dojox.gfx.path.Path._validSegments.c

    • summary
  • dojox.gfx.path.Path._validSegments.s

    • summary
  • dojox.gfx.path.Path._validSegments.q

    • summary
  • dojox.gfx.path.Path._validSegments.t

    • summary
  • dojox.gfx.path.Path._validSegments.a

    • summary
  • dojox.gfx.path.Path._validSegments.z

    • summary
  • dojox.gfx.path.Path.segmented

    • summary
  • dojox.gfx.path.Path.segments

    • summary
  • dojox.gfx.path.Path.last

    • summary
  • dojox.gfx.path.Path.shape

    • summary
  • dojox.gfx.path.Path.rawNode

    • type
      Node
    • summary
      a DOM node to be used by this path object
  • dojox.gfx.path.TextPath

    • type
      Function
    • chains:
      • dojox.gfx.path.Path: (prototype)
      • dojox.gfx.path.Path: (call)
    • summary
      a TextPath shape constructor
    • parameters:
      • rawNode: (typeof Node)
        a DOM node to be used by this TextPath object
    • source: [view]
        if(!("text" in this)){
         this.text = dojo.clone(dojox.gfx.defaultTextPath);
        }
        if(!("fontStyle" in this)){
         this.fontStyle = dojo.clone(dojox.gfx.defaultFont);
        }
  • dojox.gfx.path.TextPath.getText

    • type
      Function
    • source: [view]
        return this.text; // Object
    • summary
      returns the current text object or null
    • returns
      Object
  • dojox.gfx.path.TextPath.setText

    • type
      Function
    • parameters:
      • newText: (typeof )
    • source: [view]
        this.text = dojox.gfx.makeParameters(this.text,
         typeof newText == "string" ? {text: newText} : newText);
        this._setText();
        return this; // self
    • summary
      sets a text to be drawn along the path
    • returns
      self
  • dojox.gfx.path.TextPath.getFont

    • type
      Function
    • source: [view]
        return this.fontStyle; // Object
    • summary
      returns the current font object or null
    • returns
      Object
  • dojox.gfx.path.TextPath.setFont

    • type
      Function
    • parameters:
      • newFont: (typeof )
    • source: [view]
        this.fontStyle = typeof newFont == "string" ?
         dojox.gfx.splitFontString(newFont) :
         dojox.gfx.makeParameters(dojox.gfx.defaultFont, newFont);
        this._setFont();
        return this; // self
    • summary
      sets a font for text
    • returns
      self
  • dojox.gfx.path.TextPath.text

    • summary
  • dojox.gfx.path.TextPath.fontStyle

    • summary
  • dojox.gfx.path

    • type
      Object
    • summary
  • dojox.gfx

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary