forked from biovisualize/d3visualization
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
233 lines (190 loc) · 9.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!doctype html>
<html>
<head>
<title></title>
<meta charset=utf-8>
<script type="text/javascript" src="./d3.v3.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Monda:400,700' rel='stylesheet' type='text/css'>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-38721366-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="info">rCharts Gallery | <a class="about-link" href="">About</a></div>
<div class="about-box" style='text-align:justify;'>
<span class="about-close" style="cursor: pointer;">x</span>
<h1>Gallery</h1>
<p>This is a gallery of examples, tutorials and applications that make use of <a href="http://github.com/ramnathv/rCharts">rCharts</a>, an R package that helps create interactive charts using multiple javascript libraries. You can filter the gallery to search by author, library, visualization type and so on. You can also share the url to a filtered result gallery. For example, if you want to share all visualizations done by me, you can just share this url : <a href="http://rcharts.github.io/gallery/#author=Ramnath Vaidyanathan">http://rcharts.github.io/gallery/#author=Ramnath Vaidyanathan</a>.</p>
<p>This gallery is using a <a href="https://docs.google.com/spreadsheet/ccc?key=0AovoNzJt5GetdEhQVDgyYXpJMnZ2M2J2YmtvX0I5Snc#gid=0">Google Spreadsheet</a> for storing data. It makes it easier to keep the gallery updated with the latest examples and have everything in one place.</p>
<h1>How to Contribute</h1>
<p>You can share your work with me and I can add it to the official gallery. I will be putting together a Google Form that you can use to submit your entries directly. Every entry will need a title, a url, link to a screenshot and a minimum set of tags. </p>
<p>If you want to see new functionalities feel free to <a href="https://github.com/rcharts/gallery/pulls">contribute</a> or to send a <a href="https://github.com/rcharts/gallery/issues">feature request</a> </p>
<h1>Credits</h1>
<p>This gallery uses the same codebase as the <a href="http://biovisualize.github.com/d3visualization">d3js gallery</a>, developed by Christophe Viau <a href="https://twitter.com/d3visualization">@d3visualization</a>, with the help of the community and support from <a href="http://www.datameer.com">Datameer</a>. and <a href="https://twitter.com/mrejfox">@mrejfox</a>. I would like to thank Christophe Viau for kindly letting me use it.</p>
<p>Every entry in this gallery is copyrighted by its author. If you want your work to be removed, a special copyright mention to be added or credit information changed, just <a href="https://github.com/rcharts/gallery/issues">file a request</a> and we will answer your request promptly, as we strongly feel open-source is about respect for the creators.</p>
</div>
<div id="nav">
<div class="menu1-container"></div>
<div class="menu2-container">
<input type="text" class="menu2-search" />
</div>
</div>
<div id="list">
<div class="menu3-container"></div>
</div>
<script type="text/javascript">
d3.select('.about-link').on('click', function(d, i){
d3.event.preventDefault();
d3.select('.about-box').style({display: 'block'});
})
d3.select('.about-close').on('click', function(d, i){ d3.select('.about-box').style({display: 'none'}); });
var vizTypeScale = d3.scale.category20c();
var splitChar = '; ';
var json;
var data1 = {
href: function(d, i){return '#'+ d.dimension+'=all';},
html: function(d, i){ return d.displayName;}
};
var data2 = {
href: function(d, i){ return '#'+ d.dimension+'='+d.key; },
html: function(d, i){ return d.key+' <span class="value">'+ d.value+'</span>';}
};
var data3 = {
href: function(d, i){return d.url;},
html: function(d, i){
var content = d.title;
if(d.author) content += ' '+'<span class="author">'+d.author+'</span>';
if(d.thumbnail) content += "<br /> <img src='"+d.thumbnail+"' class='thumbnail'/><br />";
return content;}
};
function getDocHeight() {
var doc = document;
return Math.max(
doc.body.scrollHeight, doc.documentElement.scrollHeight,
doc.body.offsetHeight, doc.documentElement.offsetHeight,
doc.body.clientHeight, doc.documentElement.clientHeight
);
}
var thumbSize = 250;
var menu3Width = parseInt(d3.select('#list').style('width'));
var numInOneScreen = Math.ceil(menu3Width / thumbSize) * Math.ceil(getDocHeight() / thumbSize);
var numInView = numInOneScreen;
var gUrl = 'https://docs.google.com/spreadsheet/pub?key=0AovoNzJt5GetdEhQVDgyYXpJMnZ2M2J2YmtvX0I5Snc&output=csv'
d3.csv('gallery_2015_07_14.csv', function(error, _json){
// d3.csv('d3gallery_feb282013.csv', function(error, _json){
json = _json.reverse();
buildList(dataTransformMenu1(), '.menu1-container', data1);
buildList(dataTransformMenu2('visualizationType'), '.menu2-container', data2);
// buildList(dataView(dataTransformMenu3('title', 'all'), numInView), '.menu3-container', data3);
processLocationHash();
});
function dataTransformMenu1(){
//TODO: change in spreadsheet
var dimensionsMap = {author: 'Author', visualizationType: 'Chart type', title: 'Title'};
return d3.keys(dimensionsMap).map(function(d, i){return {dimension: d, displayName: dimensionsMap[d]};});
}
function dataTransformMenu2(dimension, filter){
var splitted = d3.merge(json.map(function(d, i){
return splitter(d[dimension]);
}));
var filtered = (filter) ? splitted.filter(function(d, i){ return d.toLowerCase().indexOf(filter.toLowerCase()) != -1; }) : splitted;
var unemptied = filtered.map(function(d, i){return (d == '') ? 'untagged' : d;});
var grouped = groupCount(unemptied);
var prepared = d3.entries(grouped).map(function(d, i){
d.dimension = dimension;
return d;
});
var sorted = prepared.sort(function(a, b){return b.value - a.value});
return sorted;
}
function splitter(data){
return (data.indexOf(splitChar) !== -1) ? data.split(splitChar) : data;
}
function groupCount(arr) {
var uniques = {}, val;
var dups = {};
for (var i = 0, len = arr.length; i < len; i++) {
val = arr[i];
if (val in uniques) {
uniques[val]++;
dups[val] = uniques[val];
} else uniques[val] = 1;
}
// return(dups);
return(uniques);
}
var cachedData;
function dataTransformMenu3(dimension, value){
var filtered = json.filter(function(d, i){
var splitted = splitter(d[dimension]);
if (value == 'all') return true;
else if(value == 'untagged') return (splitted == '');
//TODO: use the grouped data instead
else if(splitted.indexOf(value) >= 0) return true;
else return false;
});
var sorted = filtered.sort(function(a, b){
return (a.thumbnail == '') - (b.thumbnail == '');
});
cachedData = sorted;
return sorted;
}
function dataView(data, num){
return data.slice(0, num);
}
function buildList(data, containerSelector, content){
d3.select(containerSelector).selectAll("li.entry").remove();
updateList(data, containerSelector, content);
}
function updateList(data, containerSelector, content){
var entries = d3.select(containerSelector)
.selectAll("li.entry")
.data(data)
.enter().append("li")
.attr('class', 'entry')
.append('a')
.attr('href', content.href)
.html(content.html);
}
d3.select('.menu2-search')
.on('change', function(d, i){ filterList(this.value); })
.on('keyup', function(d, i){ filterList(this.value); });
d3.select('body').on('mouseover', function(){
if (d3.event.target.nodeName == 'A') d3.select('.menu2-search').node().blur();
});
function filterList(value){
var dimension = window.location.hash.substring(1).split('=')[0] || 'visualizationType';
buildList(dataTransformMenu2(dimension, value), '.menu2-container', data2);
}
function processLocationHash(){
d3.select('#list').node().scrollTop = 0;
numInView = numInOneScreen;
if(window.location.hash) {
var hash = window.location.hash.substring(1);
var hashSplit = hash.split('=');
if(hashSplit[1] == 'all') buildList(dataTransformMenu2(hashSplit[0]), '.menu2-container', data2);
buildList(dataView(dataTransformMenu3(hashSplit[0], hashSplit[1]), numInView), '.menu3-container', data3);
}else{
buildList(dataView(dataTransformMenu3('title', 'all'), numInView), '.menu3-container', data3);
}
}
d3.select(window).on('hashchange', function () {
processLocationHash();
});
d3.select('#list').on('scroll', function(d, i){
if(this.scrollHeight - this.scrollTop <= getDocHeight()){
numInView += numInOneScreen;
updateList(dataView(cachedData, numInView), '.menu3-container', data3);
}
});
</script>
</body>
</html>