diff options
author | wout <wout@impinc.co.uk> | 2014-01-22 12:48:49 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-01-22 12:48:49 +0100 |
commit | b27d01e9f91bff6145170ebd46857cd703480fec (patch) | |
tree | aca9a0b30423ec4f7db769969ae5f3b25c7893df /src | |
parent | df8db4b03df6740e47851907a4b901362634c50b (diff) | |
download | svg.js-b27d01e9f91bff6145170ebd46857cd703480fec.tar.gz svg.js-b27d01e9f91bff6145170ebd46857cd703480fec.zip |
Bumped to v0.33
Diffstat (limited to 'src')
-rwxr-xr-x[-rw-r--r--] | src/arrange.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/array.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/bbox.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/clip.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/color.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/container.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/default.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/defs.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/doc.js | 29 | ||||
-rwxr-xr-x[-rw-r--r--] | src/element.js | 16 | ||||
-rwxr-xr-x[-rw-r--r--] | src/ellipse.js | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | src/event.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/fx.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/gradient.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/group.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/image.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/line.js | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | src/loader.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/mask.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/memory.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/nested.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/number.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/parent.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/path.js | 52 | ||||
-rw-r--r-- | src/plotable.js | 42 | ||||
-rwxr-xr-x[-rw-r--r--] | src/poly.js | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | src/rbox.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/rect.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/regex.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/set.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/shape.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/sugar.js | 9 | ||||
-rwxr-xr-x[-rw-r--r--] | src/svg.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/text.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/textpath.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/use.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/viewbox.js | 0 |
37 files changed, 130 insertions, 56 deletions
diff --git a/src/arrange.js b/src/arrange.js index 0eb2830..0eb2830 100644..100755 --- a/src/arrange.js +++ b/src/arrange.js diff --git a/src/array.js b/src/array.js index b51d740..b51d740 100644..100755 --- a/src/array.js +++ b/src/array.js diff --git a/src/bbox.js b/src/bbox.js index 603b6c9..603b6c9 100644..100755 --- a/src/bbox.js +++ b/src/bbox.js diff --git a/src/clip.js b/src/clip.js index 54f9d37..54f9d37 100644..100755 --- a/src/clip.js +++ b/src/clip.js diff --git a/src/color.js b/src/color.js index 57a4d64..57a4d64 100644..100755 --- a/src/color.js +++ b/src/color.js diff --git a/src/container.js b/src/container.js index 60f62c4..60f62c4 100644..100755 --- a/src/container.js +++ b/src/container.js diff --git a/src/default.js b/src/default.js index e8eeecd..e8eeecd 100644..100755 --- a/src/default.js +++ b/src/default.js diff --git a/src/defs.js b/src/defs.js index 48a8f28..48a8f28 100644..100755 --- a/src/defs.js +++ b/src/defs.js diff --git a/src/doc.js b/src/doc.js index 0a60f99..462fd84 100644..100755 --- a/src/doc.js +++ b/src/doc.js @@ -19,7 +19,11 @@ SVG.Doc = function(element) { /* create the <defs> node */ this._defs = new SVG.Defs + this._defs.parent = this this.node.appendChild(this._defs.node) + + /* turno of sub pixel offset by default */ + this.doSubPixelOffsetFix = false /* ensure correct rendering */ if (this.parent.nodeName != 'svg') @@ -61,11 +65,11 @@ SVG.extend(SVG.Doc, { element.parent.appendChild(element.node) /* after wrapping is done, fix sub-pixel offset */ - element.fixSubPixelOffset() + element.subPixelOffsetFix() /* make sure sub-pixel offset is fixed every time the window is resized */ SVG.on(window, 'resize', function() { - element.fixSubPixelOffset() + element.subPixelOffsetFix() }) }, 5) @@ -86,12 +90,23 @@ SVG.extend(SVG.Doc, { // Fix for possible sub-pixel offset. See: // https://bugzilla.mozilla.org/show_bug.cgi?id=608812 +, subPixelOffsetFix: function() { + if (this.doSubPixelOffsetFix) { + var pos = this.node.getScreenCTM() + + if (pos) + this + .style('left', (-pos.e % 1) + 'px') + .style('top', (-pos.f % 1) + 'px') + } + + return this + } + , fixSubPixelOffset: function() { - var pos = this.node.getScreenCTM() - - this - .style('left', (-pos.e % 1) + 'px') - .style('top', (-pos.f % 1) + 'px') + this.doSubPixelOffsetFix = true + + return this } })
\ No newline at end of file diff --git a/src/element.js b/src/element.js index 630b4a8..dafb9b9 100644..100755 --- a/src/element.js +++ b/src/element.js @@ -53,8 +53,16 @@ SVG.extend(SVG.Element, { , center: function(x, y) { return this.cx(x).cy(y) } + // Set width of element +, width: function(width) { + return this.attr('width', width) + } + // Set height of element +, height: function(height) { + return this.attr('height', height) + } // Set element size to given width and height -, size: function(width, height) { +, size: function(width, height) { return this.attr({ width: new SVG.Number(width) , height: new SVG.Number(height) @@ -100,6 +108,12 @@ SVG.extend(SVG.Element, { return this } + // Replace element +, replace: function(element) { + this.after(element).remove() + + return element + } // Get parent document , doc: function(type) { return this._parent(type || SVG.Doc) diff --git a/src/ellipse.js b/src/ellipse.js index ea019e0..86186c9 100644..100755 --- a/src/ellipse.js +++ b/src/ellipse.js @@ -24,6 +24,14 @@ SVG.extend(SVG.Ellipse, { , cy: function(y) { return y == null ? this.attr('cy') : this.attr('cy', new SVG.Number(y).divide(this.trans.scaleY)) } + // Set width of element +, width: function(width) { + return width == null ? this.attr('rx') * 2 : this.attr('rx', new SVG.Number(width).divide(2)) + } + // Set height of element +, height: function(height) { + return height == null ? this.attr('ry') * 2 : this.attr('ry', new SVG.Number(height).divide(2)) + } // Custom size function , size: function(width, height) { return this.attr({ diff --git a/src/event.js b/src/event.js index 2fc14bb..2fc14bb 100644..100755 --- a/src/event.js +++ b/src/event.js diff --git a/src/fx.js b/src/fx.js index fdcfa0f..fdcfa0f 100644..100755 --- a/src/fx.js +++ b/src/fx.js diff --git a/src/gradient.js b/src/gradient.js index c5c51d1..c5c51d1 100644..100755 --- a/src/gradient.js +++ b/src/gradient.js diff --git a/src/group.js b/src/group.js index 84eed54..84eed54 100644..100755 --- a/src/group.js +++ b/src/group.js diff --git a/src/image.js b/src/image.js index d0a1b40..d0a1b40 100644..100755 --- a/src/image.js +++ b/src/image.js diff --git a/src/line.js b/src/line.js index 2c9034e..a5a9b09 100644..100755 --- a/src/line.js +++ b/src/line.js @@ -35,13 +35,21 @@ SVG.extend(SVG.Line, { var half = this.bbox().height / 2 return y == null ? this.y() + half : this.y(y - half) } + // Set width of element +, width: function(width) { + var b = this.bbox() + + return width == null ? b.width : this.attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', b.x + width) + } + // Set height of element +, height: function(height) { + var b = this.bbox() + + return height == null ? b.height : this.attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', b.y + height) + } // Set line size by width and height , size: function(width, height) { - var b = this.bbox() - - return this - .attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', b.x + width) - .attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', b.y + height) + return this.width(width).height(height) } // Set path data , plot: function(x1, y1, x2, y2) { diff --git a/src/loader.js b/src/loader.js index 80644d8..80644d8 100644..100755 --- a/src/loader.js +++ b/src/loader.js diff --git a/src/mask.js b/src/mask.js index 2aa53d7..2aa53d7 100644..100755 --- a/src/mask.js +++ b/src/mask.js diff --git a/src/memory.js b/src/memory.js index 9b6f308..9b6f308 100644..100755 --- a/src/memory.js +++ b/src/memory.js diff --git a/src/nested.js b/src/nested.js index d42abf9..d42abf9 100644..100755 --- a/src/nested.js +++ b/src/nested.js diff --git a/src/number.js b/src/number.js index 2b3b147..2b3b147 100644..100755 --- a/src/number.js +++ b/src/number.js diff --git a/src/parent.js b/src/parent.js index 8b11f5f..8b11f5f 100644..100755 --- a/src/parent.js +++ b/src/parent.js diff --git a/src/path.js b/src/path.js index 3a50703..e9f4735 100644..100755 --- a/src/path.js +++ b/src/path.js @@ -8,8 +8,58 @@ SVG.Path = function(unbiased) { SVG.Path.prototype = new SVG.Shape SVG.extend(SVG.Path, { + // Move over x-axis + x: function(x) { + return x == null ? this.bbox().x : this.transform('x', x) + } + // Move over y-axis +, y: function(y) { + return y == null ? this.bbox().y : this.transform('y', y) + } + // Set width of element +, width: function(width) { + var b = this.bbox() + + return width == null ? b.width : this.size(width, b.height) + } + // Set height of element +, height: function(height) { + var b = this.bbox() + + return height == null ? b.height : this.size(b.width, height) + } + // Set the actual size in pixels +, size: function(width, height) { + var scale = width / this._offset.width + + return this.transform({ + scaleX: scale + , scaleY: height != null ? height / this._offset.height : scale + }) + } + // Set path data +, plot: function(data) { + var x = this.trans.scaleX + , y = this.trans.scaleY + + /* native plot */ + this._plot(data) + + /* store offset */ + this._offset = this.transform({ scaleX: 1, scaleY: 1 }).bbox() + + /* get and store the actual offset of the element */ + if (this.unbiased) { + this._offset.x = this._offset.y = 0 + } else { + this._offset.x -= this.trans.x + this._offset.y -= this.trans.y + } + + return this.transform({ scaleX: x, scaleY: y }) + } // Private: Native plot - _plot: function(data) { +, _plot: function(data) { return this.attr('d', data || 'M0,0') } diff --git a/src/plotable.js b/src/plotable.js deleted file mode 100644 index 6386f13..0000000 --- a/src/plotable.js +++ /dev/null @@ -1,42 +0,0 @@ - -SVG.extend(SVG.Path, { - // Move over x-axis - x: function(x) { - return x == null ? this.bbox().x : this.transform('x', x) - } - // Move over y-axis -, y: function(y) { - return y == null ? this.bbox().y : this.transform('y', y) - } - // Set the actual size in pixels -, size: function(width, height) { - var scale = width / this._offset.width - - return this.transform({ - scaleX: scale - , scaleY: height != null ? height / this._offset.height : scale - }) - } - // Set path data -, plot: function(data) { - var x = this.trans.scaleX - , y = this.trans.scaleY - - /* native plot */ - this._plot(data) - - /* store offset */ - this._offset = this.transform({ scaleX: 1, scaleY: 1 }).bbox() - - /* get and store the actual offset of the element */ - if (this.unbiased) { - this._offset.x = this._offset.y = 0 - } else { - this._offset.x -= this.trans.x - this._offset.y -= this.trans.y - } - - return this.transform({ scaleX: x, scaleY: y }) - } - -})
\ No newline at end of file diff --git a/src/poly.js b/src/poly.js index 937960d..93a40fd 100644..100755 --- a/src/poly.js +++ b/src/poly.js @@ -32,6 +32,18 @@ SVG.extend(SVG.Polyline, SVG.Polygon, { , y: function(y) { return y == null ? this.bbox().y : this.move(this.bbox().x, y) } + // Set width of element +, width: function(width) { + var b = this.bbox() + + return width == null ? b.width : this.size(width, b.height) + } + // Set height of element +, height: function(height) { + var b = this.bbox() + + return height == null ? b.height : this.size(b.width, height) + } // Set element size to given width and height , size: function(width, height) { return this.attr('points', this.points.size(width, height)) diff --git a/src/rbox.js b/src/rbox.js index 95cc1e2..95cc1e2 100644..100755 --- a/src/rbox.js +++ b/src/rbox.js diff --git a/src/rect.js b/src/rect.js index 583556d..583556d 100644..100755 --- a/src/rect.js +++ b/src/rect.js diff --git a/src/regex.js b/src/regex.js index 602d2c7..602d2c7 100644..100755 --- a/src/regex.js +++ b/src/regex.js diff --git a/src/set.js b/src/set.js index 4c42efc..4c42efc 100644..100755 --- a/src/set.js +++ b/src/set.js diff --git a/src/shape.js b/src/shape.js index 0594ed7..0594ed7 100644..100755 --- a/src/shape.js +++ b/src/shape.js diff --git a/src/sugar.js b/src/sugar.js index 9577d94..5d7f5aa 100644..100755 --- a/src/sugar.js +++ b/src/sugar.js @@ -72,6 +72,15 @@ SVG.extend(SVG.Element, SVG.FX, { }) +// +SVG.extend(SVG.Rect, SVG.Ellipse, { + // Add x and y radius + radius: function(x, y) { + return this.attr({ rx: x, ry: y || x }) + } + +}) + if (SVG.Text) { SVG.extend(SVG.Text, SVG.FX, { diff --git a/src/svg.js b/src/svg.js index 89c23e4..89c23e4 100644..100755 --- a/src/svg.js +++ b/src/svg.js diff --git a/src/text.js b/src/text.js index 4acd236..4acd236 100644..100755 --- a/src/text.js +++ b/src/text.js diff --git a/src/textpath.js b/src/textpath.js index 04d7bde..04d7bde 100644..100755 --- a/src/textpath.js +++ b/src/textpath.js diff --git a/src/use.js b/src/use.js index 0a8bb90..0a8bb90 100644..100755 --- a/src/use.js +++ b/src/use.js diff --git a/src/viewbox.js b/src/viewbox.js index dfafed4..dfafed4 100644..100755 --- a/src/viewbox.js +++ b/src/viewbox.js |