forked from jamster/nvd3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removing old fishey code from scatter, and updating to new fisheye
- Loading branch information
1 parent
7c44710
commit cf8f7ca
Showing
5 changed files
with
80 additions
and
83 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,12 @@ | |
margin: 0; | ||
} | ||
|
||
|
||
/* | ||
#offsetDiv { | ||
margin-left: 100px; | ||
margin-top: 100px; | ||
} | ||
|
||
*/ | ||
|
||
#test1 { | ||
margin: 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,86 @@ | ||
(function() { | ||
d3.fisheye = function() { | ||
var radius = 200, | ||
power = 2, | ||
k0, | ||
k1, | ||
center = [0, 0]; | ||
|
||
function fisheye(d) { | ||
var dx = d.x - center[0], | ||
dy = d.y - center[1], | ||
dd = Math.sqrt(dx * dx + dy * dy); | ||
if (dd >= radius) return {x: d.x, y: d.y, z: 1}; | ||
var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25; | ||
return {x: center[0] + dx * k, y: center[1] + dy * k, z: Math.min(k, 10)}; | ||
d3.fisheye = { | ||
scale: function(scaleType) { | ||
return d3_fisheye_scale(scaleType(), 3, 0); | ||
}, | ||
circular: function() { | ||
var radius = 200, | ||
distortion = 2, | ||
k0, | ||
k1, | ||
focus = [0, 0]; | ||
|
||
function fisheye(d) { | ||
var dx = d.x - focus[0], | ||
dy = d.y - focus[1], | ||
dd = Math.sqrt(dx * dx + dy * dy); | ||
if (!dd || dd >= radius) return {x: d.x, y: d.y, z: 1}; | ||
var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25; | ||
return {x: focus[0] + dx * k, y: focus[1] + dy * k, z: Math.min(k, 10)}; | ||
} | ||
|
||
function rescale() { | ||
k0 = Math.exp(distortion); | ||
k0 = k0 / (k0 - 1) * radius; | ||
k1 = distortion / radius; | ||
return fisheye; | ||
} | ||
|
||
fisheye.radius = function(_) { | ||
if (!arguments.length) return radius; | ||
radius = +_; | ||
return rescale(); | ||
}; | ||
|
||
fisheye.distortion = function(_) { | ||
if (!arguments.length) return distortion; | ||
distortion = +_; | ||
return rescale(); | ||
}; | ||
|
||
fisheye.focus = function(_) { | ||
if (!arguments.length) return focus; | ||
focus = _; | ||
return fisheye; | ||
}; | ||
|
||
return rescale(); | ||
} | ||
}; | ||
|
||
function rescale() { | ||
k0 = Math.exp(power); | ||
k0 = k0 / (k0 - 1) * radius; | ||
k1 = power / radius; | ||
return fisheye; | ||
function d3_fisheye_scale(scale, d, a) { | ||
|
||
function fisheye(_) { | ||
var x = scale(_), | ||
left = x < a, | ||
v, | ||
range = d3.extent(scale.range()), | ||
min = range[0], | ||
max = range[1], | ||
m = left ? a - min : max - a; | ||
if (m == 0) m = max - min; | ||
return (left ? -1 : 1) * m * (d + 1) / (d + (m / Math.abs(x - a))) + a; | ||
} | ||
|
||
fisheye.radius = function(_) { | ||
if (!arguments.length) return radius; | ||
radius = +_; | ||
return rescale(); | ||
fisheye.distortion = function(_) { | ||
if (!arguments.length) return d; | ||
d = +_; | ||
return fisheye; | ||
}; | ||
|
||
fisheye.power = function(_) { | ||
if (!arguments.length) return power; | ||
power = +_; | ||
return rescale(); | ||
fisheye.focus = function(_) { | ||
if (!arguments.length) return a; | ||
a = +_; | ||
return fisheye; | ||
}; | ||
|
||
fisheye.center = function(_) { | ||
if (!arguments.length) return center; | ||
center = _; | ||
return fisheye; | ||
fisheye.copy = function() { | ||
return d3_fisheye_scale(scale.copy(), d, a); | ||
}; | ||
|
||
return rescale(); | ||
}; | ||
fisheye.nice = scale.nice; | ||
fisheye.ticks = scale.ticks; | ||
fisheye.tickFormat = scale.tickFormat; | ||
return d3.rebind(fisheye, scale, "domain", "range"); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,10 @@ | |
overflow: hidden; | ||
} | ||
|
||
.nvd3.background { | ||
fill: none; | ||
pointer-events: none; | ||
} | ||
|
||
|
||
/******************** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters