/
coAuthorshipSparklineContent.ftl
289 lines (228 loc) · 12.7 KB
/
coAuthorshipSparklineContent.ftl
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<#-- $This file is distributed under the terms of the license in LICENSE$ -->
<#assign visContainerID = '${sparklineVO.visContainerDivID}'>
<#if sparklineVO.shortVisMode>
<#assign sparklineContainerID = 'unique_coauthors_short_sparkline_vis'>
<#else>
<#assign sparklineContainerID = 'unique_coauthors_full_sparkline_vis'>
</#if>
<#-- This is used to prevent collision between sparkline & visualization conatiner div ids. -->
<#if visContainerID?upper_case == sparklineContainerID?upper_case>
<#assign sparklineContainerID = visContainerID + "_spark">
</#if>
<div class="staticPageBackground">
<div id="${visContainerID}">
<script type="text/javascript">
<#if sparklineVO.shortVisMode>
var visualizationOptions = {
width: 150,
height: 60,
color: '3399CC',
chartType: 'ls',
chartLabel: 'r'
};
<#else>
var visualizationOptions = {
width: 250,
height: 75,
color: '3399CC',
chartType: 'ls',
chartLabel: 'r'
};
</#if>
function drawCoauthorsSparklineVisualization(providedSparklineImgTD) {
var unknownYearPublicationCounts = ${sparklineVO.unknownYearPublications};
var onlyUnknownYearPublications = false;
var data = new google.visualization.DataTable();
data.addColumn('number', 'Year');
data.addColumn('number', 'Unique co-authors');
data.addRows(${sparklineVO.yearToEntityCountDataTable?size});
var knownYearPublicationCounts = 0;
<#list sparklineVO.yearToEntityCountDataTable as yearToUniqueCoauthorsDataElement>
data.setValue(${yearToUniqueCoauthorsDataElement.yearToEntityCounter}, 0, ${yearToUniqueCoauthorsDataElement.year});
data.setFormattedValue(${yearToUniqueCoauthorsDataElement.yearToEntityCounter}, 0, '${yearToUniqueCoauthorsDataElement.year}');
data.setValue(${yearToUniqueCoauthorsDataElement.yearToEntityCounter}, 1, ${yearToUniqueCoauthorsDataElement.currentEntitiesCount});
knownYearPublicationCounts += ${yearToUniqueCoauthorsDataElement.currentEntitiesCount};
</#list>
<#-- Create a view of the data containing only the column pertaining to coauthors count. -->
var sparklineDataView = new google.visualization.DataView(data);
<#if sparklineVO.shortVisMode>
<#-- For the short view we only want the last 10 year's view of coauthors count, hence we filter
the data we actually want to use for render. -->
sparklineDataView.setRows(data.getFilteredRows([{
column: 0,
minValue: '${sparklineVO.earliestRenderedPublicationYear?c}',
maxValue: '${sparklineVO.latestRenderedPublicationYear?c}'
}]));
<#else>
</#if>
/*
This means that all the publications have unknown years & we do not need to display
the sparkline.
*/
if (unknownYearPublicationCounts > 0 && knownYearPublicationCounts < 1) {
onlyUnknownYearPublications = true;
} else {
<#-- Create the vis object and draw it in the div pertaining to sparkline. -->
var sparkline = new google.visualization.LineChart(providedSparklineImgTD[0]);
sparkline.draw(sparklineDataView, {
width: visualizationOptions.width,
height: visualizationOptions.height,
showAxisLines: false,
showValueLabels: false,
labelPosition: 'none',
legend: { position: 'none' },
chartArea: {'width': '100%', 'height': '100%'},
colors: ['3399CC'],
hAxis: {
gridlines: {color: 'transparent'},
baselineColor: 'transparent'
},
vAxis: {
gridlines: {color: 'transparent'},
baselineColor: 'transparent'
},
backgroundColor: {
stroke: '#cfe4ed',
strokeWidth: 2
},
tooltip: {
textStyle: {fontSize: 14}
}
});
}
if (${sparklineVO.totalCollaborationshipCount?c}) {
var totalPublicationCount = ${sparklineVO.totalCollaborationshipCount?c};
} else {
var totalPublicationCount = knownYearPublicationCounts + unknownYearPublicationCounts;
}
<#if sparklineVO.shortVisMode>
<#-- We want to display how many coauthors were considered, so this is used to calculate this. -->
var shortSparkRows = sparklineDataView.getViewRows();
var renderedShortSparks = 0;
$.each(shortSparkRows, function(index, value) {
renderedShortSparks += data.getValue(value, 1);
});
/*
In case that there are only unknown publications we want the text to mention these counts,
which would not be mentioned in the other case because the renderedShortSparks only hold counts
of publications which have any date associated with it.
*/
var totalPubs = onlyUnknownYearPublications ? unknownYearPublicationCounts : renderedShortSparks;
if (totalPubs === 1) {
var pubDisplay = "${i18n().co_author?js_string}";
} else {
var pubDisplay = "${i18n().co_authors?js_string}";
}
$('#${sparklineContainerID} td.sparkline_number').text(totalPubs).css("font-weight", "bold").attr("class", "grey").append("<span style='color: #2485AE;'> " + pubDisplay + " <br/></span>");
var sparksText = ' ${i18n().within_last_10_years?js_string}';
if (totalPubs !== totalPublicationCount) {
sparksText += ' (' + totalPublicationCount + ' ${i18n().total?js_string})';
}
<#else>
/*
* Sparks that will be rendered will always be the one's which has
* any year associated with it. Hence.
* */
var renderedSparks = ${sparklineVO.renderedSparks?c};
/*
In case that there are only unknown publications we want the text to mention these counts,
which would not be mentioned in the other case because the renderedSparks only hold counts
of publications which have any date associated with it.
*/
var totalPubs = onlyUnknownYearPublications ? unknownYearPublicationCounts : renderedSparks;
if ( totalPubs == 1 ) {
var pubDisplay = "${i18n().co_author?js_string}";
} else {
var pubDisplay = "${i18n().co_authors?js_string}";
}
$('#${sparklineContainerID} td.sparkline_number').text(totalPubs).css("font-weight", "bold").attr("class", "grey").append("<span style='color: #2485AE;'> " + pubDisplay + " <br/></span>");
var sparksText = ' ${i18n().from?js_string} <span class="sparkline_range">${sparklineVO.earliestYearConsidered?c}'
+ ' - ${sparklineVO.latestRenderedPublicationYear?c}</span>';
if (totalPubs !== totalPublicationCount) {
sparksText += ' (' + totalPublicationCount + ' ${i18n().total?js_string})';
}
if (totalPublicationCount) {
sparksText += ' <br /><a href="${sparklineVO.downloadDataLink}" title="csv ${i18n().file_capitalized?js_string}">(.CSV ${i18n().file_capitalized})</a> ';
}
</#if>
if (!onlyUnknownYearPublications) {
$('#${sparklineContainerID} td.sparkline_text').html(sparksText);
}
}
/*
* This will activate the visualization. It takes care of creating
* div elements to hold the actual sparkline image and then calling the
* drawCoauthorsSparklineVisualization function.
* */
$(document).ready(function() {
var sparklineImgTD;
/*
* This is a nuclear option (creating the container in which everything goes)
* the only reason this will be ever used is the API user never submitted a
* container ID in which everything goes. The alternative was to let the
* vis not appear in the calling page at all. So now atleast vis appears but
* appended at the bottom of the body.
* */
if ($('#${visContainerID}').length === 0) {
$('<div/>', {
'id': '${visContainerID}'
}).appendTo('body');
}
if ($('#${sparklineContainerID}').length === 0) {
$('<div/>', {
'id': '${sparklineContainerID}',
'class': 'sparkline_style'
}).prependTo('#${visContainerID}');
var table = $('<table>');
table.attr('class', 'sparkline_wrapper_table');
var row = $('<tr>');
sparklineImgTD = $('<td>');
sparklineImgTD.attr('id', '${sparklineContainerID}_img');
sparklineImgTD.attr('width', visualizationOptions.width);
sparklineImgTD.attr('class', 'sparkline_style');
row.append(sparklineImgTD);
var row2 = $('<tr>');
var sparklineNumberTD = $('<td>');
sparklineNumberTD.attr('class', 'sparkline_number');
sparklineNumberTD.css('text-align', 'left');
row2.append(sparklineNumberTD);
var row3 = $('<tr>');
var sparklineTextTD = $('<td>');
sparklineTextTD.attr('class', 'sparkline_text');
sparklineTextTD.css('text-align', 'left');
row3.append(sparklineTextTD);
table.append(row);
table.append(row2);
table.append(row3);
table.prependTo('#${sparklineContainerID}');
}
google.charts.load('current', {
callback: function() {
drawCoauthorsSparklineVisualization(sparklineImgTD)
},
packages: ['bar', 'corechart', 'table', 'imagesparkline']
});
});
</script>
</div>
<!-- Sparkline Viz -->
<#if sparklineVO.shortVisMode>
<#--<span class="vis_link">-->
<p><a class="all-vivo-publications" href="${sparklineVO.fullTimelineNetworkLink}" title="${i18n().view_full_timeline_and_network}">${i18n().view_full_timeline_and_network}</a></p>
<#--</span>-->
<#else>
<!-- For Full Sparkline - Print the Table of Couauthor Counts per Year -->
<#if displayTable?? && displayTable>
<p>
<#assign tableID = "coauthors_sparkline_data_table" />
<#assign tableCaption = "${i18n().unique_coauthors_per_year} " />
<#assign tableActivityColumnName = "${i18n().count_capitalized}" />
<#assign tableContent = sparklineVO.yearToActivityCount />
<#assign fileDownloadLink = sparklineVO.downloadDataLink />
<#include "yearToActivityCountTable.ftl">
${i18n().download_data_as} <a href="${sparklineVO.downloadDataLink}" title="csv ${i18n().download}">.csv</a> ${i18n().file}.
<br />
</p>
</#if>
</#if>
</div>