-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyearframework.js
More file actions
136 lines (121 loc) · 4.46 KB
/
yearframework.js
File metadata and controls
136 lines (121 loc) · 4.46 KB
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
var basecounts = {};
var allcounts;
var d = new Date();
var thisYear = d.getFullYear();
var startYear = 1945;
//data for most recent year (or at least though February) is *super* hinky
//What was the year 30 days ago?
d.setDate(d.getDate()-30);
var endYear = d.getFullYear();
var data;
var options;
$.get( "https://med-by-year.appspot.com/showbasecounts", function( data ) {
//build out our data structure
allCounts = data.counts;
})
.fail(function() {
alert( "There was some sort of problem -- please reload the page" );
});
function yearsearch(searchkey, term) {
urlstem = "https://med-by-year.appspot.com/newsearch?q=";
url = urlstem + encodeURIComponent(term);
$.get( url, function( data ) {
if (data.hasOwnProperty('counts')) {
searches[searchkey].yearcounts = data.counts;
drawYearChart([searchkey]);
} else {
return "Nothing found for this search or too few results to chart by year. Please try again";
}
})
.fail(function() {
alert( "There was some sort of problem -- please reload the page" );
});
}
function drawYearChart(searchNumbers) {
//takes an array of searches to compare...
var searchNumbers = searchNumbers.filter(function(val) {
return !( searches[val].yearcounts == "none" );
});
if (searchNumbers.length < 1) {
$("#yearresults").empty();
$("#yearresults").append("Nothing to show");
return;
}
var yearsearches = { counts:{}, searchterms:[] };
for (var year in allCounts) {
yearsearches.counts[year] = { "total": allCounts[year] } ;
}
for (i = 0; i < searchNumbers.length; i++) {
if (searches[searchNumbers[i]].nickname) {
searchname = '"' + searches[searchNumbers[i]].nickname + '"';
} else {
searchname = searches[searchNumbers[i]].term;
}
yearsearches.searchterms.push(searchname);
myCounts = searches[searchNumbers[i]].yearcounts;
for (var year in myCounts) {
yearsearches.counts[year][searchname] = myCounts[year];
}
}
data = new google.visualization.DataTable();
//data.addColumn('string', 'Year');
data.addColumn('date', 'Year');
for (i = 0; i < yearsearches.searchterms.length; i++) {
data.addColumn('number', yearsearches.searchterms[i]);
}
for (var year in yearsearches.counts) {
if (Number(year) < startYear) { continue; }
if (Number(year) > endYear) { continue; }
//theseCounts = [year];
theseCounts = [new Date(Number(year), 11)];
for (i = 0; i < yearsearches.searchterms.length; i++) {
var term = yearsearches.searchterms[i];
var yearTotal = Number(yearsearches.counts[year]["total"]);
if (yearsearches.counts[year][term]) {
var proportion = (Number(yearsearches.counts[year][term]) / yearTotal) * 100000;
construct = {
v: proportion,
f: yearsearches.counts[year][term] + " citations"
//f: Number(yearsearches.counts[year][term]).toLocaleString() + " citations (out of " + yearTotal.toLocaleString() + " in " + year + ")"
}
theseCounts.push(construct);
//theseCounts.push(proportion);
} else {
theseCounts.push(0);
}
}
data.addRow(theseCounts);
}
options = {
/**
old options for material charts
chart: {
title: 'Proportion of citations in PubMed',
subtitle: 'proportion for each search by year'
},
//width: myyearwidth,
//height: myyearheight,
axisTitlesPosition: 'in',
vAxis: {format: 'decimal',
title: 'proportion'},
**/
vAxis: {
title: 'results per 100,000'
},
legend: { position: 'bottom',
textStyle: {fontSize: 15 } },
//chartArea:{left:10,top:10,width:'85%',height:'50%'}
};
$("#yearresults").empty();
//$( "#yrearesults" ).append( '<div class="panel panel-default">' );
//$( "#yearresults .panel" ).append( '<div id="chart_div" class="panel-body">' );
//var chart = new google.charts.Line(document.getElementById('yearresults'));
//chart.draw(data, google.charts.Line.convertOptions(options));
var date_formatter = new google.visualization.DateFormat({
pattern: "yyyy"
});
date_formatter.format(data, 0);
//trying standard
var chart = new google.visualization.LineChart(document.getElementById('yearresults'));
chart.draw(data, options);
}