audit_rails 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 018ea54485083c4a8d874cee70668346815990df
4
- data.tar.gz: 0b16cfcce9739027baa0333d1b28ed034d59bac0
3
+ metadata.gz: 9e57ca2c04fe002da6cb8926fe248abcd4bcc665
4
+ data.tar.gz: 2a74a5654f6c7c14b5eed8eb36010ac6b47f21c1
5
5
  SHA512:
6
- metadata.gz: 047ebfb7c719dfe05e43733abaccc7854ff609704e4407cfa72834233dbf4a7dc7aa9433967a4254953e890d7822352b55302fb67b4eeeeb2c9c67aaa2d2c697
7
- data.tar.gz: 09ef9152cd6163e26bb30eb7995fbe28b9ad93992a00674e27378c7d099a6c7dda0f6a9c10735836cbefc0742beede59246dda579e3132ee23bc6749ba8ce725
6
+ metadata.gz: 962fad30c9046a061dc79cf8f481f2c74652317c536461bfbb5268c7265ac515bfd046591879ac03881e06fcbb34beb117b415a7eb67da9f268c13775e6c31d6
7
+ data.tar.gz: b9de65ce03984955cf056421bfd3b0df227be48b303b55849f46111e71269bc92a89ac3f953ecff22962a55ea82ca35c9b0a2030c1264a75400b9e9d033c7743
@@ -19,6 +19,7 @@ $(document).ready(function(){
19
19
  $('a[data-user]').on('click', function(){
20
20
  var user = $(this).attr('data-user');
21
21
  d3.select("div#pageViewsByUser>svg").remove();
22
+ d3.select('svg.legend').remove();
22
23
  d3.select("div#pageViewsShareByUser>svg").remove();
23
24
  $('a.list-group-item').removeClass('active-item');
24
25
  $(this).addClass('active-item');
@@ -1,60 +1,122 @@
1
- function pageViewsShareByUser(userName){
2
- var margin = {top: 40, right: 40, bottom: 100, left: 40},
3
- width = 650 - margin.left - margin.right,
4
- height = 360 - margin.top - margin.bottom;
5
- radius = 100, //radius
6
- color = d3.scale.category20c(); //builtin range of colors
7
-
8
- var data = JSON.parse( $('a[data-user="'+ userName +'"]').attr('data-page-visits'));;
9
- var vis = d3.select("div#pageViewsShareByUser")
10
- .append("svg:svg") //create the SVG element inside the <body>
11
- .data([data]) //associate our data with the document
12
- .attr("width", width + margin.left + margin.right)
13
- .attr("height", height + margin.top + margin.bottom)
14
- .append("svg:g") //make a group to hold our pie chart
15
- .attr("transform", "translate(" + radius*2 + "," + radius*2 + ")") //move the center of the pie chart from 0, 0 to radius, radius
16
-
17
- var arc = d3.svg.arc() //this will create <path> elements for us using arc data
18
- .outerRadius(radius);
1
+ function pageViewsShareByUser(userName) {
2
+ var margin = {
3
+ top: 40,
4
+ right: 40,
5
+ bottom: 40,
6
+ left: 40
7
+ },
8
+ width = 500 - margin.left - margin.right,
9
+ height = 500 - margin.top - margin.bottom,
10
+ inner = 90,
11
+ radius = 180, //radius
12
+ color = d3.scale.category20c(); //builtin range of colors
19
13
 
14
+ var data = JSON.parse( $('a[data-user="'+ userName +'"]').attr('data-page-visits'));
15
+ var total = d3.sum(data, function (d) {
16
+ return d3.sum(d3.values(d));
17
+ });
20
18
  var div = d3.select("body").append("div")
21
19
  .attr("class", "tooltip")
22
20
  .style("opacity", 0);
23
-
24
- var pie = d3.layout.pie() //this will create arc data for us given a list of values
25
- .value(function(d) { return d.count; }); //we must tell it out to access the value of each element in our data array
26
-
27
- var arcs = vis.selectAll("g.slice") //this selects all <g> elements with class slice (there aren't any yet)
28
- .data(pie) //associate the generated pie data (an array of arcs, each having startAngle, endAngle and value properties)
29
- .enter() //this will create <g> elements for every "extra" data element that should be associated with a selection. The result is creating a <g> for every object in the data array
30
- .append("svg:g") //create a group to hold each slice (we will have a <path> and a <text> element associated with each slice)
31
- .attr("class", "slice") //allow us to style things in the slices (like text)
21
+
22
+ var vis = d3.select("div#pageViewsShareByUser")
23
+ .append("svg:svg") //create the SVG element inside the <body>
24
+ .data([data]) //associate our data with the document
25
+ .attr("width", width + margin.left + margin.right)
26
+ .attr("height", height + margin.top + margin.bottom)
27
+ .append("svg:g") //make a group to hold our pie chart
28
+ .attr("transform", "translate(" + radius * 1.5 + "," + radius * 1.5 + ")");
29
+ var textTop = vis.append("text")
30
+ .attr("dy", ".35em")
31
+ .style("text-anchor", "middle")
32
+ .attr("class", "textTop")
33
+ .text("TOTAL")
34
+ .attr("y", -10),
35
+ textBottom = vis.append("text")
36
+ .attr("dy", ".35em")
37
+ .style("text-anchor", "middle")
38
+ .attr("class", "textBottom")
39
+ .text(total + " Views")
40
+ .attr("y", 10);
41
+
42
+ var arc = d3.svg.arc()
43
+ .innerRadius(inner)
44
+ .outerRadius(radius);
45
+ var arcOver = d3.svg.arc()
46
+ .innerRadius(inner + 5)
47
+ .outerRadius(radius + 5);
48
+
49
+ var pie = d3.layout.pie() //this will create arc data for us given a list of values
50
+ .value(function (d) {
51
+ return d.count;
52
+ }); //we must tell it out to access the value of each element in our data array
53
+
54
+ var arcs = vis.selectAll("g.slice") //this selects all <g> elements with class slice (there aren't any yet)
55
+ .data(pie) //associate the generated pie data (an array of arcs, each having startAngle, endAngle and value properties)
56
+ .enter() //this will create <g> elements for every "extra" data element that should be associated with a selection. The result is creating a <g> for every object in the data array
57
+ .append("svg:g") //create a group to hold each slice (we will have a <path> and a <text> element associated with each slice)
58
+ .attr("class", "slice") //allow us to style things in the slices (like text)
32
59
  .on('mousemove', function (d, i) {
60
+ d3.select(this).select("path").transition()
61
+ .duration(200)
62
+ .attr("d", arcOver);
63
+
64
+ textTop.text(d3.select(this).datum().data.page)
65
+ .attr("y", -10);
66
+ textBottom.text(d3.select(this).datum().data.count + " Views")
67
+ .attr("y", 10);
68
+
33
69
  div.transition()
34
70
  .duration(200)
35
71
  .style("opacity", 0.9);
36
- div.html("<strong>Page Views:</strong> <span style='color:red'>" + d.data.count + "</span>" )
72
+ div.html("<strong>Page Views:</strong> <span style='color:red'>" + d.data.count + "</span>")
37
73
  .style("left", (d3.event.pageX - 57) + "px")
38
74
  .style("top", (d3.event.pageY - 50) + "px")
39
75
  .style("z-index", 10000)
40
76
  })
41
77
  .on("mouseout", function (d) {
78
+ d3.select(this).select("path").transition()
79
+ .duration(100)
80
+ .attr("d", arc);
81
+
82
+ textTop.text("TOTAL")
83
+ .attr("y", -10);
84
+ textBottom.text(total + " Views");
85
+
42
86
  div.transition()
43
87
  .duration(500)
44
88
  .style("opacity", 0);
45
- });
46
-
47
- arcs.append("svg:path")
48
- .attr("fill", function(d, i) { return color(i); } ) //set the color for each slice to be chosen from the color function defined above
49
- .attr("d", arc); //this creates the actual SVG path using the associated data (pie) with the arc drawing function
50
-
51
- arcs.append("svg:text") //add a label to each slice
52
- .attr("transform", function(d) { //set the label's origin to the center of the arc
53
- //we have to make sure to set these before calling arc.centroid
54
- d.innerRadius = radius;
55
- // d.outerRadius = radius;
56
- return "translate(" + arc.centroid(d) + ")"; //this gives us a pair of coordinates like [50, 50]
57
- })
58
- .style("text-anchor", "end") //center the text on it's origin
59
- .text(function(d, i) { return data[i].page; }); //get the label from our original data array
60
- }
89
+ });
90
+
91
+ arcs.append("svg:path")
92
+ .attr("fill", function (d, i) {
93
+ return color(i);
94
+ }) //set the color for each slice to be chosen from the color function defined above
95
+ .attr("d", arc); //this creates the actual SVG path using the associated data (pie) with the arc drawing function
96
+
97
+ var legend = d3.select("div#pageViewsShareByUser").append("svg")
98
+ .attr("class", "legend")
99
+ .attr("width", radius)
100
+ .attr("height", radius * 2)
101
+ .selectAll("g")
102
+ .data(data)
103
+ .enter().append("g")
104
+ .attr("transform", function (d, i) {
105
+ return "translate(0," + i * 20 + ")";
106
+ });
107
+
108
+ legend.append("rect")
109
+ .attr("width", 18)
110
+ .attr("height", 18)
111
+ .style("fill", function (d, i) {
112
+ return color(i);
113
+ });
114
+
115
+ legend.append("text")
116
+ .attr("x", 24)
117
+ .attr("y", 9)
118
+ .attr("dy", ".35em")
119
+ .text(function (d) {
120
+ return d.page;
121
+ });
122
+ }
@@ -70,6 +70,9 @@
70
70
  .page-views{
71
71
  width: 245px;
72
72
  }
73
+ .left-navigation{
74
+ min-height: 650px;
75
+ }
73
76
 
74
77
  a.active-item, a.active-item:hover{
75
78
  background-color: skyblue;
@@ -1,6 +1,6 @@
1
1
  <div id='per-user-by-pages-bar' class='group'>
2
2
  <div class='clear'></div>
3
- <div class='left page-views'>
3
+ <div class='left page-views left-navigation'>
4
4
  <div class="list-group page-views">
5
5
  <% JSON.parse(@analysis_by_user_name).each do |user_hsh| %>
6
6
  <a href="#page-views-by-user" class="list-group-item" data-user='<%=user_hsh["user"]%>' data-page-visits='<%= page_visits_by_user(user_hsh['user'])%>'><%= user_hsh["user"] %> - <%= percentage_share(user_hsh["user"], user_hsh["count"], @total)%>
@@ -1,6 +1,6 @@
1
1
  <div id='per-user-by-pages-pie' class='group'>
2
2
  <div class='clear'></div>
3
- <div class='left page-views'>
3
+ <div class='left page-views left-navigation'>
4
4
  <div class="list-group page-views">
5
5
  <% JSON.parse(@analysis_by_user_name).each do |user_hsh| %>
6
6
  <a href="#page-views-by-user" class="list-group-item" data-user='<%=user_hsh["user"]%>' data-page-visits='<%= page_visits_by_user(user_hsh['user'])%>'><%= user_hsh["user"] %> - <%= percentage_share(user_hsh["user"], user_hsh["count"], @total)%>
@@ -1,3 +1,3 @@
1
1
  module AuditRails
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audit_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gourav Tiwari