From b27d01e9f91bff6145170ebd46857cd703480fec Mon Sep 17 00:00:00 2001 From: wout Date: Wed, 22 Jan 2014 12:48:49 +0100 Subject: Bumped to v0.33 --- src/arrange.js | 0 src/array.js | 0 src/bbox.js | 0 src/clip.js | 0 src/color.js | 0 src/container.js | 0 src/default.js | 0 src/defs.js | 0 src/doc.js | 29 ++++++++++++++++++++++------- src/element.js | 16 +++++++++++++++- src/ellipse.js | 8 ++++++++ src/event.js | 0 src/fx.js | 0 src/gradient.js | 0 src/group.js | 0 src/image.js | 0 src/line.js | 18 +++++++++++++----- src/loader.js | 0 src/mask.js | 0 src/memory.js | 0 src/nested.js | 0 src/number.js | 0 src/parent.js | 0 src/path.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/plotable.js | 42 ------------------------------------------ src/poly.js | 12 ++++++++++++ src/rbox.js | 0 src/rect.js | 0 src/regex.js | 0 src/set.js | 0 src/shape.js | 0 src/sugar.js | 9 +++++++++ src/svg.js | 0 src/text.js | 0 src/textpath.js | 0 src/use.js | 0 src/viewbox.js | 0 37 files changed, 130 insertions(+), 56 deletions(-) mode change 100644 => 100755 src/arrange.js mode change 100644 => 100755 src/array.js mode change 100644 => 100755 src/bbox.js mode change 100644 => 100755 src/clip.js mode change 100644 => 100755 src/color.js mode change 100644 => 100755 src/container.js mode change 100644 => 100755 src/default.js mode change 100644 => 100755 src/defs.js mode change 100644 => 100755 src/doc.js mode change 100644 => 100755 src/element.js mode change 100644 => 100755 src/ellipse.js mode change 100644 => 100755 src/event.js mode change 100644 => 100755 src/fx.js mode change 100644 => 100755 src/gradient.js mode change 100644 => 100755 src/group.js mode change 100644 => 100755 src/image.js mode change 100644 => 100755 src/line.js mode change 100644 => 100755 src/loader.js mode change 100644 => 100755 src/mask.js mode change 100644 => 100755 src/memory.js mode change 100644 => 100755 src/nested.js mode change 100644 => 100755 src/number.js mode change 100644 => 100755 src/parent.js mode change 100644 => 100755 src/path.js delete mode 100644 src/plotable.js mode change 100644 => 100755 src/poly.js mode change 100644 => 100755 src/rbox.js mode change 100644 => 100755 src/rect.js mode change 100644 => 100755 src/regex.js mode change 100644 => 100755 src/set.js mode change 100644 => 100755 src/shape.js mode change 100644 => 100755 src/sugar.js mode change 100644 => 100755 src/svg.js mode change 100644 => 100755 src/text.js mode change 100644 => 100755 src/textpath.js mode change 100644 => 100755 src/use.js mode change 100644 => 100755 src/viewbox.js (limited to 'src') diff --git a/src/arrange.js b/src/arrange.js old mode 100644 new mode 100755 diff --git a/src/array.js b/src/array.js old mode 100644 new mode 100755 diff --git a/src/bbox.js b/src/bbox.js old mode 100644 new mode 100755 diff --git a/src/clip.js b/src/clip.js old mode 100644 new mode 100755 diff --git a/src/color.js b/src/color.js old mode 100644 new mode 100755 diff --git a/src/container.js b/src/container.js old mode 100644 new mode 100755 diff --git a/src/default.js b/src/default.js old mode 100644 new mode 100755 diff --git a/src/defs.js b/src/defs.js old mode 100644 new mode 100755 diff --git a/src/doc.js b/src/doc.js old mode 100644 new mode 100755 index 0a60f99..462fd84 --- a/src/doc.js +++ b/src/doc.js @@ -19,7 +19,11 @@ SVG.Doc = function(element) { /* create the 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 old mode 100644 new mode 100755 index 630b4a8..dafb9b9 --- 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 old mode 100644 new mode 100755 index ea019e0..86186c9 --- 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 old mode 100644 new mode 100755 diff --git a/src/fx.js b/src/fx.js old mode 100644 new mode 100755 diff --git a/src/gradient.js b/src/gradient.js old mode 100644 new mode 100755 diff --git a/src/group.js b/src/group.js old mode 100644 new mode 100755 diff --git a/src/image.js b/src/image.js old mode 100644 new mode 100755 diff --git a/src/line.js b/src/line.js old mode 100644 new mode 100755 index 2c9034e..a5a9b09 --- 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 old mode 100644 new mode 100755 diff --git a/src/mask.js b/src/mask.js old mode 100644 new mode 100755 diff --git a/src/memory.js b/src/memory.js old mode 100644 new mode 100755 diff --git a/src/nested.js b/src/nested.js old mode 100644 new mode 100755 diff --git a/src/number.js b/src/number.js old mode 100644 new mode 100755 diff --git a/src/parent.js b/src/parent.js old mode 100644 new mode 100755 diff --git a/src/path.js b/src/path.js old mode 100644 new mode 100755 index 3a50703..e9f4735 --- 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 old mode 100644 new mode 100755 index 937960d..93a40fd --- 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 old mode 100644 new mode 100755 diff --git a/src/rect.js b/src/rect.js old mode 100644 new mode 100755 diff --git a/src/regex.js b/src/regex.js old mode 100644 new mode 100755 diff --git a/src/set.js b/src/set.js old mode 100644 new mode 100755 diff --git a/src/shape.js b/src/shape.js old mode 100644 new mode 100755 diff --git a/src/sugar.js b/src/sugar.js old mode 100644 new mode 100755 index 9577d94..5d7f5aa --- 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 old mode 100644 new mode 100755 diff --git a/src/text.js b/src/text.js old mode 100644 new mode 100755 diff --git a/src/textpath.js b/src/textpath.js old mode 100644 new mode 100755 diff --git a/src/use.js b/src/use.js old mode 100644 new mode 100755 diff --git a/src/viewbox.js b/src/viewbox.js old mode 100644 new mode 100755 -- cgit v1.2.3