Skip to content

Commit 82a9bb0

Browse files
committedFeb 9, 2015
Added stacked bar chart, and bodged failing charts in example.
Note: counting article licenses doesn't work yet, data is currently duplicated from journal license.
1 parent e52dab6 commit 82a9bb0

File tree

2 files changed

+156
-16
lines changed

2 files changed

+156
-16
lines changed
 

‎jquery.reportview.js

+107-10
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ function d3_renderPie(params) {
248248
function hc_convertMultiBar(params){
249249
var hc_data_series = [];
250250
var x_labels = {"categories": []};
251-
hc_data_series.push(x_labels);
252251
for (var i = 0; i < params.data_series.length; i++) {
253252
var os = params.data_series[i];
254253
var ns = {};
@@ -260,6 +259,7 @@ function hc_convertMultiBar(params){
260259
}
261260
hc_data_series.push(ns)
262261
}
262+
hc_data_series.push(x_labels);
263263
return hc_data_series
264264
}
265265

@@ -300,7 +300,7 @@ function hc_renderMultiBar(params){
300300
text: titles.subtitle_text
301301
},
302302
xAxis: {
303-
categories: data_series[0].categories,
303+
categories: data_series.pop().categories,
304304
title: {
305305
text: titles.x_axis_label
306306
}
@@ -323,7 +323,103 @@ function hc_renderMultiBar(params){
323323
borderWidth: 0
324324
}
325325
},
326-
series: data_series.slice(1)
326+
series: data_series
327+
});
328+
}
329+
330+
function hc_convertStackedMultiBar(params){
331+
var hc_data_series = [];
332+
var x_labels = {"categories": []};
333+
for (var i=0; i < params.data_series.length; i++) {
334+
var os = params.data_series[i];
335+
x_labels.categories.push(os["key"]);
336+
for (var j = 0; j < os.values.length; j++) {
337+
if (i==0){
338+
var ns = {
339+
"name" : os.values[j].label,
340+
"data" : [os.values[j].value]
341+
};
342+
hc_data_series.push(ns)
343+
}else{
344+
hc_data_series[j]["data"].push(os.values[j].value)
345+
}
346+
}
347+
}
348+
hc_data_series.push(x_labels);
349+
return hc_data_series
350+
}
351+
352+
function hc_renderStackedMultiBar(params){
353+
var data_series = params.data_series;
354+
var selector = params.div_selector;
355+
var options = params.options;
356+
var be_3d = options.draw_3d;
357+
358+
// get chart titles, if any
359+
var titles = get_chart_titles(params);
360+
361+
var chart = new Highcharts.Chart({
362+
chart: {
363+
renderTo: selector,
364+
type: 'column',
365+
options3d: {
366+
enabled: be_3d,
367+
alpha: 15,
368+
beta: 15,
369+
depth: 50,
370+
viewDistance: 55
371+
}
372+
},
373+
credits: {
374+
enabled: false
375+
},
376+
title: {
377+
text: titles.title_text
378+
},
379+
subtitle: {
380+
text: titles.subtitle_text
381+
},
382+
xAxis: {
383+
categories: data_series.pop().categories,
384+
title: {
385+
text: titles.x_axis_label
386+
}
387+
},
388+
yAxis: {
389+
min: 0,
390+
stackLabels: {
391+
enabled: true,
392+
style: {
393+
fontWeight: 'bold',
394+
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
395+
}
396+
},
397+
title: {
398+
text: titles.y_axis_label
399+
}
400+
},
401+
tooltip: {
402+
formatter: function () {
403+
return '<b>' + this.x + '</b><br/>' +
404+
this.series.name + ': ' + this.y + '<br/>' +
405+
'Total: ' + this.point.stackTotal;
406+
}
407+
},
408+
plotOptions: {
409+
column: {
410+
pointPadding: 0.2,
411+
borderWidth: 0,
412+
stacking: 'normal',
413+
dataLabels: {
414+
enabled: true,
415+
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
416+
style: {
417+
textShadow: '0 0 3px black'
418+
}
419+
},
420+
}
421+
},
422+
series: data_series
327423
});
328424
}
329425

@@ -373,10 +469,6 @@ function d3_renderMultiBar(params) {
373469
});
374470
}
375471

376-
function hc_convertHorizontalMultibar(params){
377-
return hc_convertMultiBar(params)
378-
}
379-
380472
function hc_renderHorizontalMultibar(params){
381473
hc_renderMultiBar(params)
382474
}
@@ -468,7 +560,7 @@ function get_chart_titles(params){
468560
"debug" : false,
469561

470562
// type of graph to draw
471-
// values: pie, multibar, horizontal_multibar
563+
// values: pie, multibar, horizontal_multibar, stacked_multibar
472564
"type" : "pie",
473565

474566
// the provider of the charts. either d3 or hc (for HighCharts)
@@ -494,10 +586,15 @@ function get_chart_titles(params){
494586
"multibar_y_tick_format" : ',.0f',
495587
"multibar_transition_duration" : 500,
496588
"multibar_controls" : false,
497-
589+
590+
// convert/render functions for stacked bar chart
591+
"stacked_multibar_render" : hc_renderStackedMultiBar,
592+
"stacked_multibar_convert" : hc_convertStackedMultiBar,
593+
//"stacked_multibar_convert" : function(params) { return params.data_series },
594+
498595
// convert/render functions for horizontal bar chart
499596
"horizontal_multibar_render" : hc_renderHorizontalMultibar,
500-
"horizontal_multibar_convert" : hc_convertHorizontalMultibar,
597+
"horizontal_multibar_convert" : hc_convertMultiBar,
501598
"horizontal_multibar_show_values" : true,
502599
"horizontal_multibar_tool_tips" : true,
503600
"horizontal_multibar_controls" : false,

‎rv_example.html

+49-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@
122122
pie_donut: true,
123123
pie_show_labels: true,
124124
search_url: "http://localhost:9200/doaj/article/_search",
125+
main_title : true,
125126
facets: [
126127
{
127-
"field" : "bibjson.license.type.exact",
128+
"field" : "bibjson.journal.license.type.exact",
128129
"size" : 100,
129130
"display" : "Licence Type",
130-
"value_function" : function(value) { return value.toUpperCase() }
131+
"value_function" : function(value) { return value.toLowerCase() }
131132
}
132133
]
133134
});
@@ -141,13 +142,14 @@
141142
pie_transition_duration: 800,
142143
pie_show_labels: true,
143144
pie_label_threshold: 0.05,
145+
main_title : true,
144146
search_url: "http://localhost:9200/doaj/article/_search",
145147
facets: [
146148
{
147-
"field" : "bibjson.license.type.exact",
149+
"field" : "bibjson.journal.license.type.exact",
148150
"size" : 100,
149151
"display" : "Licence Type",
150-
"value_function" : function(value) { return value.toUpperCase() }
152+
"value_function" : function(value) { return value.toLowerCase() }
151153
}
152154
]
153155
});
@@ -165,7 +167,7 @@
165167
search_url: "http://localhost:9200/doaj/article/_search",
166168
facets: [
167169
{
168-
"field" : "bibjson.license.type.exact",
170+
"field" : "bibjson.journal.license.type.exact",
169171
"size" : 100,
170172
"display" : "Article Licence",
171173
"value_function" : function(value) { return value.toLowerCase().replace(/-/g, " ") }
@@ -191,7 +193,7 @@
191193
search_url: "http://localhost:9200/doaj/article/_search",
192194
facets: [
193195
{
194-
"field" : "bibjson.license.type.exact",
196+
"field" : "bibjson.journal.license.type.exact",
195197
"size" : 100,
196198
"display" : "Article Licence",
197199
"value_function" : function(value) { return value.toLowerCase().replace(/-/g, " ") }
@@ -208,6 +210,38 @@
208210
]
209211
});
210212
});
213+
214+
$('#report-view-stacked-facet_hc').each(function() {
215+
$(this).report({
216+
debug: true,
217+
type: "stacked_multibar",
218+
draw_3d: false,
219+
main_title : "Licenses",
220+
sub_title : "Proportion of total",
221+
x_axis_label : false,
222+
y_axis_label : false,
223+
search_url: "http://localhost:9200/doaj/article/_search",
224+
//data_series : [{"categories":["cc by","cc by nc nd","cc by nc sa","cc by","cc by nc nd","cc by nc sa"]},{"name":"Article License","data":[835,10,6]},{"name":"Journal Licence","data":[835,10,6]}],
225+
//data_series : [{"categories":["Article License","Journal Licence"]},{"name":"cc by","data":[835,835]},{"name":"cc by nc nd","data":[10,10]},{"name":"cc by nc sa","data":[6,6]}],
226+
facets: [
227+
{
228+
"field" : "bibjson.journal.license.type.exact",
229+
"size" : 100,
230+
"display" : "Article License",
231+
"value_function" : function(value) { return value.toLowerCase().replace(/-/g, " ") }
232+
},
233+
{
234+
"field" : "bibjson.journal.license.type.exact",
235+
"size" : 100,
236+
"display" : "Journal Licence",
237+
"value_function" : function(value) { return value.toLowerCase().replace(/-/g, " ") }
238+
}
239+
],
240+
fixed_filters: [
241+
{"term" : {"bibjson.journal.country.exact" : "GB"}}
242+
]
243+
});
244+
});
211245
});
212246
</script>
213247

@@ -266,6 +300,15 @@
266300
</div>
267301
</div>
268302
<hr>
303+
<div class="row-fluid">
304+
<div class="span6">
305+
<div id="report-view-stacked-facet_hc" class="bar"></div>
306+
</div>
307+
<div class="span6">
308+
<div id="empty" class="bar"></div>
309+
</div>
310+
</div>
311+
<hr>
269312
</body>
270313

271314
<footer>

0 commit comments

Comments
 (0)
Please sign in to comment.