summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-04-26 21:27:46 +0200
committerwout <wout@impinc.co.uk>2013-04-26 21:27:46 +0200
commit6afb0006730768d03b787e840f6a71249c4a051e (patch)
tree7e3f54893bbdb4c01c9385ca203bdc96f16a2e89 /src
parent11ded2fe8fabf4392633fcdb3713a49e084746a1 (diff)
downloadsvg.js-6afb0006730768d03b787e840f6a71249c4a051e.tar.gz
svg.js-6afb0006730768d03b787e840f6a71249c4a051e.zip
Bumped to v0.15, removed hsb color support
Diffstat (limited to 'src')
-rw-r--r--src/color.js84
-rw-r--r--src/element.js11
-rw-r--r--src/regex.js8
-rw-r--r--src/sugar.js2
4 files changed, 16 insertions, 89 deletions
diff --git a/src/color.js b/src/color.js
index bd4b6b0..57a4d64 100644
--- a/src/color.js
+++ b/src/color.js
@@ -14,9 +14,9 @@ SVG.Color = function(color) {
match = SVG.regex.rgb.exec(color.replace(/\s/g,''))
/* parse numeric values */
- this.r = parseInt(m[1])
- this.g = parseInt(m[2])
- this.b = parseInt(m[3])
+ this.r = parseInt(match[1])
+ this.g = parseInt(match[2])
+ this.b = parseInt(match[3])
} else if (SVG.regex.isHex.test(color)) {
/* get hex values */
@@ -26,22 +26,14 @@ SVG.Color = function(color) {
this.r = parseInt(match[1], 16)
this.g = parseInt(match[2], 16)
this.b = parseInt(match[3], 16)
-
- } else if (SVG.regex.isHsb.test(color)) {
- /* get hsb values */
- match = SVG.regex.hsb.exec(color.replace(/\s/g,''))
-
- /* convert hsb to rgb */
- color = this._hsbToRgb(match[1], match[2], match[3])
+
}
} else if (typeof color == 'object') {
- if (SVG.Color.isHsb(color))
- color = this._hsbToRgb(color.h, color.s, color.b)
-
this.r = color.r
this.g = color.g
this.b = color.b
+
}
}
@@ -68,66 +60,6 @@ SVG.extend(SVG.Color, {
+ (this.g / 255 * 0.59)
+ (this.b / 255 * 0.11)
}
- // Private: convert hsb to rgb
-, _hsbToRgb: function(h, s, v) {
- var vs, vsf
-
- /* process hue */
- h = parseInt(h) % 360
- if (h < 0) h += 360
-
- /* process saturation */
- s = parseInt(s)
- s = s > 100 ? 100 : s
-
- /* process brightness */
- v = parseInt(v)
- v = (v < 0 ? 0 : v > 100 ? 100 : v) * 255 / 100
-
- /* compile rgb */
- vs = v * s / 100
- vsf = (vs * ((h * 256 / 60) % 256)) / 256
-
- switch (Math.floor(h / 60)) {
- case 0:
- r = v
- g = v - vs + vsf
- b = v - vs
- break
- case 1:
- r = v - vsf
- g = v
- b = v - vs
- break
- case 2:
- r = v - vs
- g = v
- b = v - vs + vsf
- break
- case 3:
- r = v - vs
- g = v - vsf
- b = v
- break
- case 4:
- r = v - vs + vsf
- g = v - vs
- b = v
- break
- case 5:
- r = v
- g = v - vs
- b = v - vsf
- break
- }
-
- /* parse values */
- return {
- r: Math.floor(r + 0.5)
- , g: Math.floor(g + 0.5)
- , b: Math.floor(b + 0.5)
- }
- }
// Private: ensure to six-based hex
, _fullHex: function(hex) {
return hex.length == 4 ?
@@ -150,15 +82,9 @@ SVG.Color.test = function(color) {
color += ''
return SVG.regex.isHex.test(color)
|| SVG.regex.isRgb.test(color)
- || SVG.regex.isHsb.test(color)
}
// Test if given value is a rgb object
SVG.Color.isRgb = function(color) {
return color && typeof color.r == 'number'
-}
-
-// Test if given value is a hsb object
-SVG.Color.isHsb = function(color) {
- return color && typeof color.h == 'number'
} \ No newline at end of file
diff --git a/src/element.js b/src/element.js
index df3f82a..3149d22 100644
--- a/src/element.js
+++ b/src/element.js
@@ -152,7 +152,7 @@ SVG.extend(SVG.Element, {
this._stroke = v
/* ensure hex color */
- if (SVG.Color.test(v) || SVG.Color.isRgb(v) || SVG.Color.isHsb(v))
+ if (SVG.Color.test(v) || SVG.Color.isRgb(v))
v = new SVG.Color(v).toHex()
/* set give attribute on node */
@@ -311,7 +311,14 @@ SVG.extend(SVG.Element, {
}
} else {
- this.attr('data-' + a, v === null ? null : r === true ? v : JSON.stringify(v))
+ this.attr(
+ 'data-' + a
+ , v === null ?
+ null :
+ r === true || typeof v === 'string' || typeof v === 'number' ?
+ v :
+ JSON.stringify(v)
+ )
}
return this
diff --git a/src/regex.js b/src/regex.js
index 7b268f6..4cd74ae 100644
--- a/src/regex.js
+++ b/src/regex.js
@@ -12,10 +12,7 @@ SVG.regex = {
, hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i
/* parse rgb value */
-, rgb: /rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/
-
- /* parse hsb value */
-, hsb: /hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/
+, rgb: /rgb\((\d+),(\d+),(\d+)\)/
/* test hex value */
, isHex: /^#[a-f0-9]{3,6}$/i
@@ -23,9 +20,6 @@ SVG.regex = {
/* test rgb value */
, isRgb: /^rgb\(/
- /* test hsb value */
-, isHsb: /^hsb\(/
-
/* test css declaration */
, isCss: /[^:]+:[^;]+;?/
diff --git a/src/sugar.js b/src/sugar.js
index 27b0537..d063207 100644
--- a/src/sugar.js
+++ b/src/sugar.js
@@ -15,7 +15,7 @@ var _colorPrefix = function(type, attr) {
extension[method] = function(o) {
var indexOf
- if (typeof o == 'string' || SVG.Color.isRgb(o) || SVG.Color.isHsb(o))
+ if (typeof o == 'string' || SVG.Color.isRgb(o))
this.attr(method, o)
else