Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

aight shims for d3

  • Loading branch information...
commit bc711275d220af37c47c36226f001eb4e09bd961 1 parent acf1c59
Shawn Allen authored
Showing with 57 additions and 0 deletions.
  1. +57 −0 aight.d3.js
View
57 aight.d3.js
@@ -0,0 +1,57 @@
+(function(exports) {
+
+ aight.d3 = {};
+
+ if (aight.browser.ie8) {
+ function mapped(property, format, parse) {
+ var read = function(p) {
+ var value = this.node().style[property];
+ return parse
+ ? parse.call(this, value, p)
+ : value;
+ },
+ write = function(p, value) {
+ return this.each(function() {
+ var v = (typeof value === "function")
+ ? value.apply(this, arguments)
+ : value;
+ this.style[property] = format
+ ? format.call(this, v, p)
+ : v;
+ });
+ };
+ return function() {
+ return arguments.length > 1
+ ? write.apply(this, arguments)
+ : read.call(this);
+ };
+ }
+
+ var aight_d3_style = {
+ "background-image": mapped("backgroundImage"),
+ "background-repeat": mapped("backgroundRepeat"),
+ "background-position": mapped("backgroundPosition"),
+ "background-color": mapped("backgroundColor"),
+
+ "opacity": mapped("filter",
+ function opacity_to_filter(opacity) {
+ return ["alpha(opacity=", Math.round(opacity * 100), ")"].join("");
+ },
+ function filter_to_opacity(filter) {
+ var opacity = (filter || "").match(/opacity=(\d+)/)[1] || 100;
+ return opacity / 100;
+ })
+ };
+
+ aight.d3.style = aight_d3_style;
+
+ var d3_style = d3.selection.prototype.style;
+ d3.selection.prototype.style = function(prop) {
+ var style = aight_d3_style.hasOwnProperty(prop)
+ ? aight_d3_style[prop]
+ : d3_style;
+ return style.apply(this, arguments);
+ };
+ }
+
+})(this);
Please sign in to comment.
Something went wrong with that request. Please try again.