Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved graphs on contributors/tags pages #2619

Merged
merged 5 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,46 @@ def weekly_tallies(type = 'note', span = 52)
weeks
end

def contribution_graph_making(type = 'note', span = 52, time = Time.now)
weeks = {}
week = span
count = 0;
tids = Tag.where('name IN (?)', [name])
.collect(&:tid)
nids = NodeTag.where('tid IN (?)', tids)
.collect(&:nid)
while week >= 1
#initialising month variable with the month of the starting day
#of the week
month = (time - (week*7 - 1).days).strftime('%m')
#loop for finding the maximum occurence of a month name in that week
#For eg. If this week has 3 days falling in March and 4 days falling
#in April, then we would give this week name as April and vice-versa
for i in 1..7 do
currMonth = (time - (week*7 - i).days).strftime('%m')
if month != currMonth
if i <= 4
month = currMonth
end
end
end
#Now fetching the weekly data of notes or wikis
month = month.to_i

currWeek = Tag.nodes_for_period(
type,
nids,
(time.to_i - week.weeks.to_i).to_s,
(time.to_i - (week - 1).weeks.to_i).to_s
).count(:all)

weeks[count] = [month, currWeek]
count += 1
week -= 1
end
weeks
end

def self.nodes_for_period(type, nids, start, finish)
Node.select(%i(created status type nid))
.where(
Expand Down
79 changes: 50 additions & 29 deletions app/views/tag/contributors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,58 @@
<% if @tag %>
<div id="note-graph" style="height:100px;"></div>

<script src="https://cdn.jsdelivr.net/npm/frappe-charts@0.0.8/dist/frappe-charts.min.iife.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Souravirus !
Do you think we should put this in bower.json file ? See this line :

"chart.js": "v2.7.0",

The existing chart.js library is used in this way . I think this will cause fast rendering of graphs and also will help us to easily manage newer versions .
What do you think ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okk thanks @sagarpreet-chadha I will see to it. Thanks!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagarpreet-chadha Actually I tried this with bower but the frappe-chart version on bower are not that perfect and are always giving one error or other. So, I guess this way is the best we can do. I also previously tried with frappe-charts gems but that was also not properly maintained and was giving errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay makes sense 👍 👍 👍 !

<script type="text/javascript">
(function () {

flotoptions_minimal = {
yaxis: { show: false },
xaxis: { show: true },
grid: {
borderWidth: 0,
//color: "#444",
markers: []
},
colors: [ "#08f", "#80f" ]
}

var notes = <%= @tag.weekly_tallies.to_a.sort.to_json %>

$.plot($("#note-graph"), [
{
data: notes,
hoverable: true,
// label: "Research Notes",
bars: {
show: true,
lineWidth: 0,
fillColor: "#08f",
barWidth: 0.5
}
var notes = <%= @tag.contribution_graph_making.to_a.sort.to_json %>
let months = ["J", "F", "M", "A", "M", "J", "J", "A","S", "O", "N", "D"];
let i;
let labels = new Array();
for(i = 0; i < notes.length; i++)
labels[i] = "";
let count = 0;
let prev = 0;
for(i = 0; i < notes.length; i++){
if(notes[i][1][0] != prev){
if(count == 4){
let j;
labels[i - 2] = months[prev - 1];
}
else{
labels[i - 3] = months[prev - 1];
}
prev = notes[i][1][0];
count = 0;
}
count++;
}
],flotoptions_minimal)

})()
if(count >= 3){
labels[notes.length - 3] = months[prev - 1];
}
let title = "note";
let values = new Array();
for (j = 0; j < notes.length; j++){
values[j] = notes[j][1][1];
}
let data = new Object();
data.labels = labels;
let datasets = new Array();
let obj = new Object();
obj.title = title;
obj.values = new Array();
obj.values = values;
datasets[0] = new Object();
datasets[0] = obj;
data.datasets = datasets;
let chart = new Chart({
parent: "#note-graph",
data: data,
type: "bar",
height: 115,
x_axis_mode: "tick",
y_axis_mode: "span",
is_series: 1,
colors: ['purple']
});
</script>

<br />
Expand Down