Skip to content

Instantly share code, notes, and snippets.

@vlandham
Last active December 30, 2015 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlandham/c553c451c49f59261b68 to your computer and use it in GitHub Desktop.
Save vlandham/c553c451c49f59261b68 to your computer and use it in GitHub Desktop.
radial
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define('d3-radial', ['exports'], factory) :
factory((global.d3_radial = {}));
}(this, function (exports) { 'use strict';
function radial() {
var increment = 0;
var width = 500;
var height = 500;
var tapper = 0;
var center = [0,0];
var start = -90;
var current = start;
var radialLocation = function(center, angle, width, height, tapper) {
return {"x":(center[0] + (width * Math.cos(angle * Math.PI / 180) - tapper)),
"y": (center[1] + (height * Math.sin(angle * Math.PI / 180) + tapper))};
};
var place = function(obj) {
var value = radialLocation(center, current, width, height, tapper);
// now it just adds attributes to the object.
obj.x = value.x;
obj.y = value.y;
obj.angle = current;
current += increment;
tapper += increment;
tapper = Math.min(tapper, 0);
return value;
};
var placement = function(objs) {
increment = 360 / objs.length;
objs.forEach(function(obj) {
place(obj);
});
};
placement.center = function(_) {
if (!arguments.length) {
return center;
}
center = _;
return placement;
};
placement.width = function(_) {
if (!arguments.length) {
return width;
}
width = _;
return placement;
};
placement.height = function(_) {
if (!arguments.length) {
return height;
}
height = _;
return placement;
};
placement.start = function(_) {
if (!arguments.length) {
return start;
}
start = _;
return placement;
};
return placement;
}
var version = "0.0.1";
exports.version = version;
exports.radial = radial;
}));
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="./d3-radial.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width:100%; height: 100% }
</style>
</head>
<body>
<script>
var pos = radial();
// Feel free to change or delete any of the code you see!
var svg = d3.select("body").append("svg")
svg.append("rect")
.attr({x: 100, y: 10, width: 700, height: 480})
.style({ fill: "#a72d1a"})
.transition().duration(3000).ease("bounce")
.style({ fill: "#5db9e3"})
console.log("you are now rocking with d3", d3);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment