-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
83 changed files
with
55,851 additions
and
2,285 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.circlepackeR .node { | ||
cursor: pointer; | ||
} | ||
|
||
.circlepackeR .node:hover { | ||
stroke: #000; | ||
stroke-width: 1.5px; | ||
} | ||
|
||
.circlepackeR .node--leaf { | ||
fill: white; | ||
} | ||
|
||
.circlepackeR .label { | ||
font: 11px "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
text-anchor: middle; | ||
text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff, 0 -1px 0 #fff; | ||
} | ||
|
||
.circlepackeR .label, | ||
.circlepackeR .node--root, | ||
.circlepackeR .node--leaf { | ||
pointer-events: none; | ||
} |
106 changes: 106 additions & 0 deletions
106
caveat/libs/circlepackeR-binding-0.0.0.9000/circlepackeR.js
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
HTMLWidgets.widget({ | ||
|
||
name: 'circlepackeR', | ||
|
||
type: 'output', | ||
|
||
initialize: function(el, width, height) { | ||
|
||
return { | ||
|
||
} | ||
|
||
}, | ||
|
||
renderValue: function(el, x, instance) { | ||
|
||
// remove previous in case of dynamic/Shiny | ||
d3.select(el).selectAll('*').remove(); | ||
|
||
// much of this code is based on this example by Mike Bostock | ||
// https://gist.github.com/mbostock/7607535 | ||
|
||
var margin = 20, | ||
// use getBoundingClientRect since width and height | ||
// might not be in pixels | ||
diameter = Math.min(el.getBoundingClientRect().width, | ||
el.getBoundingClientRect().height); | ||
|
||
var color = d3.scale.linear() | ||
.domain([-1, 5]) | ||
.range([x.options.color_min, x.options.color_max]) | ||
.interpolate(d3.interpolateHcl); | ||
|
||
var pack = d3.layout.pack() | ||
.padding(2) | ||
.size([diameter - margin, diameter - margin]) | ||
.value(function(d) { return d[x.options.size]; }) | ||
|
||
var svg = d3.select(el).append("svg") | ||
.attr("width", diameter) | ||
.attr("height", diameter) | ||
.append("g") | ||
.attr("transform", "translate(" + diameter / 2 + "," + diameter / 2 + ")"); | ||
|
||
function createViz(root) { | ||
var focus = root, | ||
nodes = pack.nodes(root), | ||
view; | ||
|
||
var circle = svg.selectAll("circle") | ||
.data(nodes) | ||
.enter().append("circle") | ||
.attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; }) | ||
.style("fill", function(d) { return d.children ? color(d.depth) : null; }) | ||
.on("click", function(d) { if (focus !== d) zoom(d), d3.event.stopPropagation(); }); | ||
|
||
var text = svg.selectAll("text") | ||
.data(nodes) | ||
.enter().append("text") | ||
.attr("class", "label") | ||
.style("fill-opacity", function(d) { return d.parent === root ? 1 : 0; }) | ||
.style("display", function(d) { return d.parent === root ? null : "none"; }) | ||
.text(function(d) { return d.name; }); | ||
|
||
var node = svg.selectAll("circle,text"); | ||
|
||
d3.select(el) | ||
.on("click", function() { zoom(root); }); | ||
|
||
zoomTo([root.x, root.y, root.r * 2 + margin]); | ||
|
||
function zoom(d) { | ||
var focus0 = focus; focus = d; | ||
|
||
var transition = d3.transition() | ||
.duration(d3.event.altKey ? 7500 : 750) | ||
.tween("zoom", function(d) { | ||
var i = d3.interpolateZoom(view, [focus.x, focus.y, focus.r * 2 + margin]); | ||
return function(t) { zoomTo(i(t)); }; | ||
}); | ||
|
||
transition.selectAll("text") | ||
.filter(function(d) { return d.parent === focus || this.style.display === "inline"; }) | ||
.style("fill-opacity", function(d) { return d.parent === focus ? 1 : 0; }) | ||
.each("start", function(d) { if (d.parent === focus) this.style.display = "inline"; }) | ||
.each("end", function(d) { if (d.parent !== focus) this.style.display = "none"; }); | ||
} | ||
|
||
function zoomTo(v) { | ||
var k = diameter / v[2]; view = v; | ||
node.attr("transform", function(d) { return "translate(" + (d.x - v[0]) * k + "," + (d.y - v[1]) * k + ")"; }); | ||
circle.attr("r", function(d) { return d.r * k; }); | ||
} | ||
} | ||
|
||
createViz(x.data) | ||
|
||
d3.select(self.frameElement).style("height", diameter + "px"); | ||
|
||
}, | ||
|
||
resize: function(el, width, height, instance) { | ||
|
||
} | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Apache-Style Software License for ColorBrewer software and ColorBrewer Color | ||
Schemes | ||
|
||
Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State | ||
University. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
use this file except in compliance with the License. You may obtain a copy of | ||
the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations under | ||
the License. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions as source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. The end-user documentation included with the redistribution, if any, must | ||
include the following acknowledgment: "This product includes color | ||
specifications and designs developed by Cynthia Brewer | ||
(http://colorbrewer.org/)." Alternately, this acknowledgment may appear in the | ||
software itself, if and wherever such third-party acknowledgments normally | ||
appear. | ||
|
||
4. The name "ColorBrewer" must not be used to endorse or promote products | ||
derived from this software without prior written permission. For written | ||
permission, please contact Cynthia Brewer at [email protected]. | ||
|
||
5. Products derived from this software may not be called "ColorBrewer", nor | ||
may "ColorBrewer" appear in their name, without prior written permission of | ||
Cynthia Brewer. |
Oops, something went wrong.