Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created January 6, 2013 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/4470504 to your computer and use it in GitHub Desktop.
Save enjalot/4470504 to your computer and use it in GitHub Desktop.
Another Inlet
{"description":"Another Inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"periodictabledump3.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.5663018052813585,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"hidepanel":false}
var svg = d3.select("svg");
var clist = new Object();
clist.Hydrogen = "#EA3445"
clist.Noble_gas = "#7BC9F0"
clist.Alkali_metals = "#FCAE70"
clist.Alkaline_earth_metals = "#0FD3BB"
clist.Semiconductors = "#B9C5B9"
clist.Other_nonmetals = "#5EA4C7"
clist.Halogens = "#CB71FD"
clist.Other_metals = "#09C4E7"
clist.Transition_metals = "#A6BCC4"
clist.Lanthanides = "#B3B390"
clist.Actinides = "#FF7F57"
clist.vague = "#9B9B9B"
var base_width = 45,
spacing = 4,
rounding = 5,
border_width = 1.44 + "px",
off_corner = -26,
info_text_size = 1.2;
// deeper element json at
// https://gist.github.com/4356217
// traced from: http://www.pnathan.com/elements.json
// minor modifications included.
/*
d3.csv("data/periodictabledump3.csv", function(csv){
data = csv;
main(data);
});
*/
var data = tributary.periodictabledump3
main(data)
/* Helper Functions */
function info_box_size(num_blocks){
return (base_width*num_blocks + spacing*(num_blocks-1))
}
function coord (input){
return off_corner + ((base_width+spacing) * parseInt(input))
}
function get_location(d){
var coordinates = [coord(d.group), coord(d.row)];
return "translate(" + coordinates + ")";
}
function get_location2(x, y){
return get_location({group: x, row: y})
}
function opacity_from_mass(m){
var v1 = Math.log(m);
return Math.log(v1/3) * 1.2
}
// reusable text setter
function set_text(x, y, classname, size, content){
var ename = d3.select(classname)
.append("text")
.attr({"x": x, "y": y})
.style({
"fill": "#232323",
"stroke-width": 0 + "px",
"font-size": size + "em",
"text-anchor": "right",
"alignment-baseline": "middle",
"font-family": "sans-serif"
})
.text(content)
return ename
}
// specific text setter for info box
function set_text2(x, y, content){
return set_text(x, y, ".group2", info_text_size, content)
}
function infoBox() {
var x = 12;
var y = 20;
var data;
var style = {
"fill": "#232323",
"stroke-width": 0 + "px",
"font-size": info_text_size + "em",
"text-anchor": "right",
"alignment-baseline": "middle",
"font-family": "sans-serif"
}
var group;
var chart = function(g) {
group = g;
console.log("hi");
var sel = group.selectAll("g")
.data([""]);
sel.enter()
.append("g")
.selectAll("text")
.data(data)
.enter()
.append("text");
sel.selectAll("text")
.data(data)
.style(style)
.attr({
x: x,
y: function(d,i) { return (i+1) * y }
})
.text(function(d) { return d })
}
chart.data = function(val) {
if(!arguments.length)
return data;
data = val;
return chart;
}
chart.style = function(val) {
if(!arguments.length)
return style;
style = val;
return chart;
}
return chart;
}
/* Worker Function */
function main(data){
var group1 = svg.append("g").classed("group1", true)
var blocks = group1.selectAll("g").data(data)
.enter()
.append("g")
.attr("transform", function(d,i){ return get_location(d)})
var rects = blocks.append("rect")
.attr({
"width": base_width,
"height": base_width,
"rx": rounding, "ry": rounding
})
.style({
"fill": function(d){
return clist[d.named_type] },
"fill-opacity": function(d){
return opacity_from_mass(d.Mass) },
"stroke": function(d){
return clist[d.named_type] },
"stroke-width": border_width
})
var text_content = blocks.append("text")
.attr({x:3, y:14})
.style({
"fill": "#232323",
"font-size": 1.2 + "em",
"text-anchor": "right",
"alignment-baseline": "middle",
"font-family": "sans-serif"
})
.text(function(d,i){return d.Symbol})
// define the info box
var info = svg.append("g").classed("group2", true)
.attr("transform", get_location2(6, 1))
.append("rect")
.attr({
"width": info_box_size(6),
"height": info_box_size(2),
"rx": rounding, "ry": rounding
})
.style({
"fill": "#C9C9C9",
"fill-opacity": 0.224,
"stroke": "#000000",
"stroke-width": border_width
})
// element data
/*
var e_name = set_text2(12, 20, "name (symbol)");
var e_mass = set_text2(12, 20*2, "mass");
var e_family = set_text2(12, 20*3, "family");
var e_charge = set_text2(12, 20*4, "protons / neutrons");
*/
blocks.on("click", function(d,i) {
console.log(d.Name)
})
var ib = infoBox();
var ibg = d3.select(".group2");
blocks.on("mouseover", function(d,i) {
ib.data([d.Name, d.Mass, d.named_type]);
ib(ibg);
})
}
At# Mass Name Symbol group type named_type row
1 1.0079400000 Hydrogen H 1 Hydrogen Hydrogen 1
2 4.0026020000 Helium He 18 nonmetals Noble_gas 1
3 6.9410000000 Lithium Li 1 metals Alkali_metals 2
4 9.0121820000 Beryllium Be 2 metals Alkaline_earth_metals 2
5 10.8110000000 Boron B 13 metaloids Semiconductors 2
6 12.0107000000 Carbon C 14 nonmetals Other_nonmetals 2
7 14.0067000000 Nitrogen N 15 nonmetals Other_nonmetals 2
8 15.9994000000 Oxygen O 16 nonmetals Other_nonmetals 2
9 18.9994000000 Fluorine F 17 nonmetals Halogens 2
10 20.1797000000 Neon Ne 18 nonmetals Noble_gas 2
11 22.9897692800 Sodium Na 1 metals Alkali_metals 3
12 24.3050000000 Magnesium Mg 2 metals Alkaline_earth_metals 3
13 26.9815386000 Aluminium Al 13 metals Other_metals 3
14 28.0855000000 Silicon Si 14 metaloids Semiconductors 3
15 30.9737620000 Phosphorus P 15 nonmetals Other_nonmetals 3
16 32.0650000000 Sulphur S 16 nonmetals Other_nonmetals 3
17 35.4530000000 Chlorine Cl 17 nonmetals Halogens 3
18 39.9480000000 Argon Ar 18 nonmetals Noble_gas 3
19 39.0983000000 Potassium K 1 metals Alkali_metals 4
20 40.0780000000 Calcium Ca 2 metals Alkaline_earth_metals 4
21 44.9559120000 Scandium Sc 3 metals Transition_metals 4
22 47.8670000000 Titanium Ti 4 metals Transition_metals 4
23 50.9415000000 Vanadium V 5 metals Transition_metals 4
24 51.9961000000 Chromium Cr 6 metals Transition_metals 4
25 54.9380450000 Manganese Mn 7 metals Transition_metals 4
26 55.8450000000 Iron Fe 8 metals Transition_metals 4
27 58.9331950000 Cobalt Co 9 metals Transition_metals 4
28 58.6934000000 Nickel Ni 10 metals Transition_metals 4
29 63.5460000000 Copper Cu 11 metals Transition_metals 4
30 65.3800000000 Zinc Zn 12 metals Transition_metals 4
31 69.7230000000 Gallium Ga 13 metals Other_metals 4
32 72.6400000000 Germanium Ge 14 metaloids Semiconductors 4
33 74.9216000000 Arsenic As 15 metaloids Semiconductors 4
34 78.9600000000 Selenium Se 16 nonmetals Other_nonmetals 4
35 79.9040000000 Bromine Br 17 nonmetals Halogens 4
36 83.7980000000 Krypton Kr 18 nonmetals Noble_gas 4
37 85.4678000000 Rubidium Rb 1 metals Alkali_metals 5
38 87.6200000000 Strontium Sr 2 metals Alkaline_earth_metals 5
39 88.9058500000 Yttrium Y 3 metals Transition_metals 5
40 91.2240000000 Zirconium Zr 4 metals Transition_metals 5
41 92.9063800000 Niobium Nb 5 metals Transition_metals 5
42 95.9600000000 Molybdenum Mo 6 metals Transition_metals 5
43 98.0000000000 Technetium Tc 7 metals Transition_metals 5
44 101.0700000000 Ruthenium Ru 8 metals Transition_metals 5
45 102.9055000000 Rhodium Rh 9 metals Transition_metals 5
46 106.4200000000 Palladium Pd 10 metals Transition_metals 5
47 107.8682000000 Silver Ag 11 metals Transition_metals 5
48 112.4110000000 Cadmium Cd 12 metals Transition_metals 5
49 114.8180000000 Indium In 13 metals Other_metals 5
50 118.7100000000 Tin Sn 14 metals Other_metals 5
51 121.7600000000 Antimony Sb 15 metaloids Semiconductors 5
52 127.6000000000 Tellurium Te 16 metaloids Semiconductors 5
53 126.9044700000 Iodine I 17 nonmetals Halogens 5
54 131.2930000000 Xenon Xe 18 nonmetals Noble_gas 5
55 132.9054519000 Cesium Cs 1 metals Alkali_metals 6
56 137.3270000000 Barium Ba 2 metals Alkaline_earth_metals 6
57 138.9054700000 Lanthanum La 4 metals Lanthanides 9
58 140.1160000000 Cerium Ce 5 metals Lanthanides 9
59 140.9076500000 Praseodymium Pr 6 metals Lanthanides 9
60 144.2420000000 Neodymium Nd 7 metals Lanthanides 9
61 145.0000000000 Promethium Pm 8 metals Lanthanides 9
62 150.3600000000 Samarium Sm 9 metals Lanthanides 9
63 151.9640000000 Europium Eu 10 metals Lanthanides 9
64 157.2500000000 Gadolinium Gd 11 metals Lanthanides 9
65 158.9253500000 Terbium Tb 12 metals Lanthanides 9
66 162.5001000000 Dysprosium Dy 13 metals Lanthanides 9
67 164.9303200000 Holmium Ho 14 metals Lanthanides 9
68 167.2590000000 Erbium Er 15 metals Lanthanides 9
69 168.9342100000 Thulium Tm 16 metals Lanthanides 9
70 173.0540000000 Ytterbium Yb 17 metals Lanthanides 9
71 174.9668000000 Lutetium Lu 18 metals Lanthanides 9
72 178.4900000000 Hafnium Hf 4 metals Transition_metals 6
73 180.9478800000 Tantalum Ta 5 metals Transition_metals 6
74 183.8400000000 Tungsten W 6 metals Transition_metals 6
75 186.2070000000 Rhenium Re 7 metals Transition_metals 6
76 190.2300000000 Osmium Os 8 metals Transition_metals 6
77 192.2170000000 Iridium Ir 9 metals Transition_metals 6
78 192.0840000000 Platinum Pt 10 metals Transition_metals 6
79 196.9665690000 Gold Au 11 metals Transition_metals 6
80 200.5900000000 Mercury Hg 12 metals Transition_metals 6
81 204.3833000000 Thallium Tl 13 metals Other_metals 6
82 207.2000000000 Lead Pb 14 metals Other_metals 6
83 208.9804010000 Bismuth Bi 15 metals Other_metals 6
84 210.0000000000 Polonium Po 16 metals Other_metals 6
85 210.0000000000 Astatine At 17 nonmetals Halogens 6
86 220.0000000000 Radon Rn 18 nonmetals Noble_gas 6
87 223.0000000000 Francium Fr 1 metals Alkali_metals 7
88 226.0000000000 Radium Ra 2 metals Alkaline_earth_metals 7
89 227.0000000000 Actinium Ac 4 metals Actinides 10
90 232.0380600000 Thorium Th 5 metals Actinides 10
91 231.0358800000 Protactinium Pa 6 metals Actinides 10
92 238.0289100000 Uranium U 7 metals Actinides 10
93 237.0000000000 Neptunium Np 8 metals Actinides 10
94 244.0000000000 Plutonium Pu 9 metals Actinides 10
95 243.0000000000 Americium Am 10 metals Actinides 10
96 247.0000000000 Curium Cm 11 metals Actinides 10
97 247.0000000000 Berkelium Bk 12 metals Actinides 10
98 251.0000000000 Californium Cf 13 metals Actinides 10
99 252.0000000000 Einsteinium Es 14 metals Actinides 10
100 257.0000000000 Fermium Fm 15 metals Actinides 10
101 258.0000000000 Mendelevium Md 16 metals Actinides 10
102 259.0000000000 Nobelium No 17 metals Actinides 10
103 262.0000000000 Lawrencium Lr 18 metals Actinides 10
104 261.0000000000 Rutherfordium Rf 4 metals Transition_metals 7
105 262.0000000000 Dubnium Db 5 metals Transition_metals 7
106 266.0000000000 Seaborgium Sg 6 metals Transition_metals 7
107 264.0000000000 Bohrium Bh 7 metals Transition_metals 7
108 277.0000000000 Hassium Hs 8 metals Transition_metals 7
109 268.0000000000 Meitnerium Mt 9 future vague 7
110 271.0000000000 Darmstadtium Ds 10 future vague 7
111 272.0000000000 Roentgenium Rg 11 future vague 7
112 285.0000000000 Copernicium Cn 12 metals Transition_metals 7
113 284.0000000000 Ununtrium Uut 13 future vague 7
114 289.0000000000 Ununquadium Uuq 14 future vague 7
115 288.0000000000 Ununpentium Uup 15 future vague 7
116 292.0000000000 Ununhexium Uuh 16 future vague 7
117 294.0000000000 Ununseptium Uus 17 future vague 7
118 294.0000000000 Ununoctium Uuo 18 future vague 7
300 138 Lanthanides 3 metals Lanthanides 6
300 227 Actinides 3 metals Actinides 7
/*
http://lesscss.org/ Pragmatic Theme by Dealga McArdle
After original "Dark Theme" ported to CodeMirror by Peter Kroon
*/
.cm-s-lesser-dark {
font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', 'Monaco', Courier, monospace !important;
line-height: 1.26em;
}
.cm-s-lesser-dark.CodeMirror { background: #1e2426; color: #EEEEEE; }
.cm-s-lesser-dark div.CodeMirror-selected {background: #064968 !important;} /* 33322B*/
.cm-s-lesser-dark .CodeMirror-cursor { border-left: 1px solid white !important; }
.cm-s-lesser-dark pre { padding: 0 8px; line-height: 1.3em; }/*editable code holder*/
div.CodeMirror span.CodeMirror-matchingbracket { color: #7EFC7E; }/*65FC65*/
.cm-s-lesser-dark .CodeMirror-gutters { background: #262626; border-right:1px solid #aaa; }
.cm-s-lesser-dark .CodeMirror-linenumber { color: #777; }
.cm-s-lesser-dark span.cm-keyword { color: DeepSkyBLue; }
.cm-s-lesser-dark span.cm-atom { color: #8CEEF7; font-weight: bold}
.cm-s-lesser-dark span.cm-number { color: Chartreuse; background: #000000;}
.cm-s-lesser-dark span.cm-def {color: #C4D8E6;}
.cm-s-lesser-dark span.cm-variable { color:#AAA; }
.cm-s-lesser-dark span.cm-variable-2 { color: #9DCFD8; }
.cm-s-lesser-dark span.cm-variable-3 { color: white; }
.cm-s-lesser-dark span.cm-property {color: #FFB78F;}
.cm-s-lesser-dark span.cm-operator {color: #92A75C;}
.cm-s-lesser-dark span.cm-comment { color: #b2b2b2; background: #000000;}
.cm-s-lesser-dark span.cm-string { color: Chartreuse; background: #424242;}
.cm-s-lesser-dark span.cm-string-2 {color: Chartreuse; background: #7E7E7E;}
.cm-s-lesser-dark span.cm-meta { color: #738C73; }
.cm-s-lesser-dark span.cm-error { color: #9d1e15; }
.cm-s-lesser-dark span.cm-qualifier {color: #000555; }
.cm-s-lesser-dark span.cm-builtin { color: #ff9e59; }
.cm-s-lesser-dark span.cm-bracket { color: #EBEFE7; }
.cm-s-lesser-dark span.cm-tag { color: #669199; }
.cm-s-lesser-dark span.cm-attribute {color: #00c;}
.cm-s-lesser-dark span.cm-header {color: #a0a;}
.cm-s-lesser-dark span.cm-quote {color: #090;}
.cm-s-lesser-dark span.cm-hr {color: #999;}
.cm-s-lesser-dark span.cm-link {color: #00c;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment