quick_search-core 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -6
  3. data/app/assets/javascripts/quick_search.js.erb +9 -0
  4. data/app/assets/javascripts/quick_search/appstats.js.erb +73 -0
  5. data/app/assets/javascripts/quick_search/appstats_best_bets.js.erb +905 -0
  6. data/app/assets/javascripts/quick_search/appstats_clicks_overview.js.erb +719 -0
  7. data/app/assets/javascripts/quick_search/appstats_general_statistics.js.erb +908 -0
  8. data/app/assets/javascripts/quick_search/appstats_sessions_details.js.erb +660 -0
  9. data/app/assets/javascripts/quick_search/appstats_sessions_overview.js.erb +481 -0
  10. data/app/assets/javascripts/quick_search/appstats_spelling_suggestions.js.erb +902 -0
  11. data/app/assets/javascripts/quick_search/appstats_top_searches.js.erb +633 -0
  12. data/app/assets/javascripts/quick_search/event_tracking.js.erb +22 -33
  13. data/app/assets/javascripts/quick_search/xhr_search.js +7 -3
  14. data/app/assets/stylesheets/quick_search/appstats.scss +148 -0
  15. data/app/assets/stylesheets/quick_search/quick_search.scss +0 -16
  16. data/app/controllers/concerns/quick_search/doi_trap.rb +1 -1
  17. data/app/controllers/quick_search/appstats_controller.rb +267 -144
  18. data/app/controllers/quick_search/logging_controller.rb +165 -0
  19. data/app/controllers/quick_search/search_controller.rb +1 -23
  20. data/app/controllers/quick_search/typeahead_controller.rb +48 -0
  21. data/app/models/event.rb +6 -0
  22. data/app/models/search.rb +7 -0
  23. data/app/models/session.rb +9 -0
  24. data/app/searchers/quick_search/best_bets_searcher.rb +1 -1
  25. data/app/views/layouts/quick_search/_google_analytics.html.erb +4 -9
  26. data/app/views/layouts/quick_search/_search_form.html.erb +2 -2
  27. data/app/views/layouts/quick_search/application.html.erb +4 -0
  28. data/app/views/quick_search/appstats/_date_range.html.erb +14 -13
  29. data/app/views/quick_search/appstats/_graph_best_bets.html.erb +6 -0
  30. data/app/views/quick_search/appstats/_graph_clicks_overview.html.erb +12 -0
  31. data/app/views/quick_search/appstats/_graph_general_statistics.html.erb +19 -0
  32. data/app/views/quick_search/appstats/_graph_sessions_details.html.erb +19 -0
  33. data/app/views/quick_search/appstats/_graph_sessions_overview.html.erb +9 -0
  34. data/app/views/quick_search/appstats/_graph_spelling_suggestions.html.erb +6 -0
  35. data/app/views/quick_search/appstats/_graph_top_searches.html.erb +6 -0
  36. data/app/views/quick_search/appstats/_menu.html.erb +16 -3
  37. data/app/views/quick_search/appstats/_sessions_details_device_filters.html.erb +9 -0
  38. data/app/views/quick_search/appstats/_sessions_details_location_filters.html.erb +9 -0
  39. data/app/views/quick_search/appstats/_sessions_overview_graph_filters.html.erb +9 -0
  40. data/app/views/quick_search/appstats/clicks_overview.html.erb +3 -14
  41. data/app/views/quick_search/appstats/index.html.erb +3 -23
  42. data/app/views/quick_search/appstats/sessions_details.html.erb +9 -0
  43. data/app/views/quick_search/appstats/sessions_overview.html.erb +9 -0
  44. data/app/views/quick_search/appstats/top_searches.html.erb +3 -32
  45. data/app/views/quick_search/appstats/top_spot.html.erb +7 -7
  46. data/app/views/quick_search/search/_module_with_paging.html.erb +1 -1
  47. data/app/views/quick_search/search/_result_title.html.erb +1 -1
  48. data/config/quicksearch_config.yml.example +3 -0
  49. data/config/routes.rb +31 -3
  50. data/db/migrate/20161201141003_create_sessions.rb +12 -0
  51. data/db/migrate/20161201142811_change_event_columns.rb +11 -0
  52. data/db/migrate/20161201143901_add_session_id_to_searches.rb +5 -0
  53. data/db/migrate/20161212192454_add_date_string_columns.rb +11 -0
  54. data/db/seeds.rb +83 -7
  55. data/lib/generators/quick_search/templates/quick_search_typeahead.js +253 -0
  56. data/lib/generators/quick_search/typeahead_generator.rb +162 -0
  57. data/lib/quick_search/engine.rb +1 -0
  58. data/lib/quick_search/version.rb +1 -1
  59. data/test/dummy/db/schema.rb +25 -6
  60. data/test/dummy/log/benchmark.log +121 -241
  61. data/test/dummy/log/development.log +236 -0
  62. data/test/dummy/tmp/cache/assets/sprockets/v3.0/0b/0bXp2nnjPLNuYQRAMo1RkhNr8RSC8vqZo_7soo0XZTE.cache +1 -0
  63. data/test/dummy/tmp/cache/assets/sprockets/v3.0/3p/3pAfj3gt9c9rLmOrDkMvW2r6Swm5YhuGQ1EN3va9LDE.cache +6 -0
  64. data/test/dummy/tmp/cache/assets/sprockets/v3.0/3r/3r7qg-LCIcD5882b6GKgRTZycpAlhoSNJccVH06yRCQ.cache +3 -0
  65. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{UA/UAOIipK_ejTAUFI6XxASoweyUiC3t64VfVzV-MfsFD8.cache → 4h/4hLiHzJdffGLMZCeIkbisOdFQSyqs54YkoZpBpGotVk.cache} +0 -0
  66. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{Hr/Hr-kCuPY72nIKAdnsDTz9JqXd_z1WL6FSGMAq4HppZg.cache → 5Y/5Yh8GnSzywqhuMWMloKnL9FnuIxa9rBw6hN2Ecv0urw.cache} +0 -0
  67. data/test/dummy/tmp/cache/assets/sprockets/v3.0/8h/8hHsBZ0Il3GVKNj0HgTh-s-XpPVkHrcSY0EJ4v548sk.cache +4 -0
  68. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{fI/fInu_Gja7ik39t207tqj4CtlL0akQRbjD2T7qEtd0zE.cache → 8n/8nKAboU_CeVIX30-Q9BtSV5TXdE07WU8hO0OQ0N3KOs.cache} +0 -0
  69. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{dz/dzCaa80YgyvJINTgsyrVhKv9UQ1OC82GfAsA-IP96iQ.cache → Af/Afug8duevWkZFPkOMnZ5z_IbRT6JMZo4jw1QFmLiXXA.cache} +0 -0
  70. data/test/dummy/tmp/cache/assets/sprockets/v3.0/C2/C24SLDoUbdiHRmPZx5lIZ3XPXmn9FDq7j7gZmbpDtcE.cache +1 -0
  71. data/test/dummy/tmp/cache/assets/sprockets/v3.0/CH/CHuDjj47dHGqRD3uN1JNwnlFyjjEKB09KR6WVsLj2Do.cache +3 -0
  72. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ci/Cif3NOwhu5i6Qm3iRv2gNJLi_cu8yDVz0Nrq8TZu1tc.cache +3 -0
  73. data/test/dummy/tmp/cache/assets/sprockets/v3.0/FQ/FQWd8V-Pek1LBAfW9vzcG-FpWySsPRhMVzH9DlPxLWU.cache +1 -0
  74. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Fa/FaYEz8CfLTkxVZvnbgKGvJMhhBwNvEgsZgUwaHNRlaQ.cache +0 -0
  75. data/test/dummy/tmp/cache/assets/sprockets/v3.0/IA/IALQq6ICbs3VBSRsaUmGuN73Qv5wDfWTP86VmMh_sVs.cache +0 -0
  76. data/test/dummy/tmp/cache/assets/sprockets/v3.0/K1/K1jnTrW-_s64kqCA6fnoQ-ID-rDaGX34J-TNPyzDbLs.cache +1 -0
  77. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Mz/MzXE1Go_GKyu6AvJPhw394BtPM_jVTf0hMwobBi15tk.cache +1 -0
  78. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Os/OsIhoBDw5N2AWGQ-EMK79tgwPS1AC6Dy_gMSJdOv2Ss.cache +0 -0
  79. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{B5/B5ptGSZGmgHvoK2UDCAtpMhWxJEKxKFhyL9ACeBfzQk.cache → PC/PCth9nzoRrp5GI3Ut8FxlGpXjH63V7k2p4PRwfyu2sQ.cache} +0 -0
  80. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Pw/Pw3Jv2p7MsQz6pttCZig6VMVQ30sRyIDRS-2nM32yqY.cache +3 -0
  81. data/test/dummy/tmp/cache/assets/sprockets/v3.0/RI/RIOgtcuvLAJZl62RvAzqine3jCO3i2qyhswiW2G1bw8.cache +3 -0
  82. data/test/dummy/tmp/cache/assets/sprockets/v3.0/R_/R_6WhfFaPUAOAFfFd4bgUonI5aB4Fa6iOMY2J6G3U98.cache +4 -0
  83. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{pj/pjJDYrBipDo6Tr9_-W4UDzfZZ4UPTy9YpXrBQFRXnlo.cache → S3/S3gPdA-Zqya5r6wNhnlwqGV3B3-GDaA8i1fL_jo66AI.cache} +0 -0
  84. data/test/dummy/tmp/cache/assets/sprockets/v3.0/SS/SS3eYrFE6ghi5G_3POW760Y4BWo5OAaK5QjDrRGXOcs.cache +1 -0
  85. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{jj/jjdQCKZsewws2eRP7b2AVxRMvseOp8djjlDkB8UOtac.cache → Sq/SqjdxmYsdurpx9xk1ks32WEtf3D9_2BysE7RMxnOlmU.cache} +1 -1
  86. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{os/os0qWv3yDfep0e7vVSGTgfn_n3xc4C4QZgmMzLQn0Ks.cache → Ta/TaJnQ_l0sfSsDOyVoi-S-KZQ6vIwzBhmS6hmNA_n8ug.cache} +0 -0
  87. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{o6/o6ZQbq1aBFuVrE2xLbSbyZH2736sWM3Yj4ky9chT1bI.cache → X_/X_CxFXEdZo2C_in7FopAuAbplHn6W_V0SXyVQAMnTzI.cache} +0 -0
  88. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{sR/sRU-UT8qK_38kkiFDXKBPogO1oOZuSvJFH-pgqPL_Ms.cache → Yh/YhRWll6bzgYE6Dmc5fVKbHyv5om4y3-27UrWeUbQcGk.cache} +0 -0
  89. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{OD/ODHapE0li3WI1laVJoksoI5nmQd-8dDJXq_VxS4XefE.cache → _u/_uiA10I5HyJR94Tbc4a06CzdrQCAXX7Iz86WS5PKDQo.cache} +0 -0
  90. data/test/dummy/tmp/cache/assets/sprockets/v3.0/ai/ainCVF4dxXf85KoOLUSHvMMGg0qBNc7Vg-s-9v2ENJI.cache +4 -0
  91. data/test/dummy/tmp/cache/assets/sprockets/v3.0/cQ/cQqt0ri9GFvVnIs1pJUugIJs5tDuGQMMntW5CwpK6YY.cache +1 -0
  92. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{1n/1nStVaWIQEwAlksUpB1fInwq6v3TikPvuRaSwwCnCLQ.cache → e0/e0Y2Gz8ftaW2O0RjoN2iWguitI-JQZckScAZqlQYkng.cache} +0 -0
  93. data/test/dummy/tmp/cache/assets/sprockets/v3.0/iH/iHnlNNY3rfdbVqt8LZBfcDQYONR8dA8LmxA9fv5paro.cache +2 -0
  94. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{F0/F0oWBwLHpGFYNNtnGav-dJFH8rMDpNA5L8_aWm5Wq34.cache → ir/irxgIDPIY6Wz6fHWYp1dIrqAT1_8oa6-oiwqbFE_e-w.cache} +0 -0
  95. data/test/dummy/tmp/cache/assets/sprockets/v3.0/kn/knUtyVrg7nMIPldZa4MHhe7cC9eMchLZS4mc5HDWgDY.cache +1 -0
  96. data/test/dummy/tmp/cache/assets/sprockets/v3.0/ks/ks4DoIuUV6oUzoiXoPh7sW1k5ExNoUkR7ICjwuRnAT0.cache +1 -0
  97. data/test/dummy/tmp/cache/assets/sprockets/v3.0/m3/m375QQakjXd_2Trpvdot-i90nmeCCh0HWtzS66ZvxUU.cache +1 -0
  98. data/test/dummy/tmp/cache/assets/sprockets/v3.0/rQ/rQ_FgYkT2hdw9A6XmJKGgVb2dMtCrWWHwtS0X1_kdl0.cache +1 -0
  99. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{pw/pwiIhcWPwTuy5Miz5zqOQGYFx-K3TbaCVQ6ls7EBkk0.cache → rU/rUqFWwHqrT5jeIFCEezOPsMMZiAU7ri6RKBGS2ezAfg.cache} +0 -0
  100. data/test/dummy/tmp/cache/assets/sprockets/v3.0/{pO/pO8hHVwybv1ZJBdPa2YC6bjqmk020OYFl85TYxtmrWQ.cache → rq/rqf5-J6k_zLc9ZlUgMj28nviKtRsko3-iEp_m_uNeY0.cache} +0 -0
  101. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  102. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  103. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  104. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  105. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  106. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  107. metadata +143 -119
  108. data/app/assets/javascripts/quick_search/appstats.js +0 -8
  109. data/app/views/quick_search/appstats/_click_count_table.html.erb +0 -23
  110. data/app/views/quick_search/appstats/_top_spot_report_table.html.erb +0 -33
  111. data/app/views/quick_search/appstats/module_click_detail.html.erb +0 -32
  112. data/app/views/quick_search/appstats/top_spot_detail.html.erb +0 -35
  113. data/test/dummy/tmp/cache/assets/sprockets/v3.0/0_/0_w_ydOOEFQOoETxJa-IxKppQocaiDwM5V08djCPYso.cache +0 -3
  114. data/test/dummy/tmp/cache/assets/sprockets/v3.0/3m/3mWfBeEpm_bJvaPQZYvnnAVtE_2helOWh_Tv-cEflrk.cache +0 -5
  115. data/test/dummy/tmp/cache/assets/sprockets/v3.0/4s/4sg52OgD5l4qx4GnojCVxg2itqwqb-KRanEdmdMus3Y.cache +0 -0
  116. data/test/dummy/tmp/cache/assets/sprockets/v3.0/5U/5UPnsccuZFLk9OqbmFMvB55mbvGptApx9Z55HWjEN90.cache +0 -3
  117. data/test/dummy/tmp/cache/assets/sprockets/v3.0/9a/9acKNgyVD8_WK401tMy6Ce98g-LS4VpwFvGQdzCV9mI.cache +0 -0
  118. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ba/BaymviI8cwAJQMOIzWCf6Lt-PM2sNFTvY9hQKsfDNNw.cache +0 -3
  119. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Dd/DdFHg3C_voetfvKGKX7t8PGzZlkO45-huHNtaou5rxg.cache +0 -1
  120. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Fp/FprCQeeZguht46WNSpA3Y3JHKehovFXrj63nDrvvwFE.cache +0 -1
  121. data/test/dummy/tmp/cache/assets/sprockets/v3.0/GJ/GJrfWiarIi0Dt6sdKVMfUF1cdZ6NbqZxXHhzNbFtpBw.cache +0 -1
  122. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Gp/GpoziOxxB-hisco0rl7Nnsnw0UWud7R9Yge2Q3o1eN4.cache +0 -2
  123. data/test/dummy/tmp/cache/assets/sprockets/v3.0/It/It5VkJv-53-LICLKZWWyp2WcbD86DGotAL0MY3hhfpg.cache +0 -6
  124. data/test/dummy/tmp/cache/assets/sprockets/v3.0/O6/O6dw148Xya7NYlsRFMEzJyvRcySM6iOL1jRUpdQo9B8.cache +0 -1
  125. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Oj/OjMkKTW7OkthjJAQHDID8GV30IZC9F0dJ1zGiFame9U.cache +0 -4
  126. data/test/dummy/tmp/cache/assets/sprockets/v3.0/SU/SUtZ_ltPqy9A9A-_zqNPhNPvjxCOnrdqXHSZv5S9mOk.cache +0 -1
  127. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Tv/TvZgmm69VEMHUJQIBoij61oXMkgzp6whVo7l8mJ9qpw.cache +0 -3
  128. data/test/dummy/tmp/cache/assets/sprockets/v3.0/YJ/YJZdK01T1KTS84Mb6p_2TasmJNZeGZc4FMtBPCKGr_M.cache +0 -3
  129. data/test/dummy/tmp/cache/assets/sprockets/v3.0/ah/ahhhd3ysbQmVDNzq2L_rb4t6rqqdnqeY6ujztBoZDA8.cache +0 -1
  130. data/test/dummy/tmp/cache/assets/sprockets/v3.0/gv/gvZKkbgiExbcQrT4eo0HB-j4JoDRAxdmDjKRxeEdK0Y.cache +0 -1
  131. data/test/dummy/tmp/cache/assets/sprockets/v3.0/hj/hj_r-O1QjHJIPcZVnlB_FGPdIRAi9NkxpT2oXDRIsGE.cache +0 -1
  132. data/test/dummy/tmp/cache/assets/sprockets/v3.0/o2/o2V1ahk8vFR6sXWNh5BB7w6MBj04zCyX-o1xFZONydE.cache +0 -1
  133. data/test/dummy/tmp/cache/assets/sprockets/v3.0/tE/tEO71oPPFXN_2c4p39nU0OiF9ARg13fjdQlnPqAx1KY.cache +0 -4
  134. data/test/dummy/tmp/cache/assets/sprockets/v3.0/tW/tWFRsAv4WWu2ch-x3AJZd3KOvBXG3MwH6Q6Xn-tFBtw.cache +0 -1
  135. data/test/dummy/tmp/cache/assets/sprockets/v3.0/x6/x6W754ylumshr3wBUHHmcgyWs8UR3Od7FaI6tqvjKmk.cache +0 -1
  136. data/test/dummy/tmp/cache/assets/sprockets/v3.0/yy/yyJ1P7RQciOiW8TgQiu1RMDdbWd4rqxd2BGU9HkY3L8.cache +0 -0
@@ -0,0 +1,902 @@
1
+ <% url_helper = QuickSearch::Engine.routes.url_helpers %>
2
+
3
+ (function() {
4
+ var Globals = {};
5
+
6
+ $(document).on("turbolinks:load", function() {
7
+ if ($("#graph_spelling_suggestions").length) {
8
+ d3.select("#spIconContainer").append("i")
9
+ .attr("class", "fa fa-spinner fa-spin fa-5x fa-fw big-icon")
10
+ .attr("id", "spIcon");
11
+ // Redraw graph if the date range is changed
12
+ document.getElementById("dateButton").addEventListener("click", function() {
13
+ var from = $("#from").datepicker("getDate");
14
+ var to = new Date($("#to").datepicker("getDate").getTime() + 1000*60*60*24);
15
+ document.getElementById("numDays").innerHTML = "" + parseInt((to-from)/(1000*60*60*24));
16
+ if (document.getElementById("num").value>200) { document.getElementById("num").value = "20"; }
17
+ $.ajax({
18
+ type: "GET",
19
+ contentType: "application/json; charset=utf-8",
20
+ url: '<%= url_helper.data_spelling_suggestions_path %>',
21
+ dataType: "json",
22
+ data: {
23
+ "start_date": from,
24
+ "end_date": to,
25
+ "num_results": (document.getElementById("num").value>200) ? Globals.Data.length : document.getElementById("num").value
26
+ },
27
+ success: function(suggestionDataSet) {
28
+ var suggestionData = _.cloneDeep(suggestionDataSet);
29
+ Globals.OriginalData = suggestionData;
30
+ Globals.Data = suggestionData;
31
+ sort_search_data(Globals.Sort);
32
+ },
33
+ error: function(result) {
34
+ error();
35
+ }
36
+ });
37
+ });
38
+ $.ajax({
39
+ type: "GET",
40
+ contentType: "application/json; charset=utf-8",
41
+ url: '<%= url_helper.data_spelling_suggestions_path %>',
42
+ dataType: "json",
43
+ success: function(suggestionDataSet) {
44
+ d3.select("#spIcon").transition().duration(250)
45
+ .style("opacity", .000001)
46
+ .remove();
47
+ var suggestionData = _.cloneDeep(suggestionDataSet);
48
+ Globals.OriginalData = suggestionData;
49
+ Globals.Data = suggestionData;
50
+ Globals.Sort = 0;
51
+ Globals.Height = 450;
52
+ draw_graph_spelling_suggestions(false);
53
+ },
54
+ error: function(result) {
55
+ error();
56
+ }
57
+ });
58
+ }
59
+ });
60
+
61
+ function error() {
62
+ console.log("Error retrieving data");
63
+ }
64
+
65
+ function draw_graph_spelling_suggestions(resetExpanded) {
66
+ if ($("#graph_spelling_suggestions").length) {
67
+ // General Variables
68
+ var svg; // SVG to contain graph
69
+ var dataInt; // Internal reference to graph dataset
70
+ var sortStates; // Array indicating the currently selected sort state
71
+ var key; // Key function to maintain object constancy
72
+ var triangle; // Triangle object for sort buttons
73
+ // Dimension Variables
74
+ var margin; // Blank space around edge of SVG left as margin
75
+ var rowHeight; // Height of each row of data
76
+ var width; // Drawable width of SVG (not including margins)
77
+ var height; // Drawable height of SVG (not including margins)
78
+ var oldHeight; // Previous height of SVG
79
+ var textPadding; // Padding around text elements
80
+ var barHeight; // Height of data bars
81
+ var rankWidth; // Width of rank column
82
+ var categoryWidth; // Width of category column
83
+ var serveWidth; // Width of serves column
84
+ var clickWidth; // Width of click column
85
+ var ratioWidth; // Width of ratio column
86
+ var childOffset; // Horizontal offset for child elements drawn on element expansion
87
+ var serveBarStart; // Beginning x for serves data bar
88
+ var clickBarStart; // Beginning x for click data bar
89
+ var ratioBarStart; // Beginning x for ratio data bar
90
+ var triangleSpacing;// Space around triangular sort buttons
91
+ // Scale Variables
92
+ var serveScale; // Scale for serve count data bar
93
+ var clickScale; // Scale for click count data bar
94
+ var ratioScale; // Scale for ratio data bar
95
+ // Selection Variables
96
+ var groupEnter; // Entry selection for gAll
97
+ var gAll; // Group containing all elements
98
+ var headGroupEnter; // Entry selection for headRow
99
+ var headRow; // Group containing all head elements
100
+ var headEnter; // Entry selection for all head elements
101
+ var triangles; // Sort triangles
102
+ var dataGroupEnter; // Entry selection for dataRows
103
+ var dataRows; // Group containing all data elements
104
+ var dataRects; // Background rectangles
105
+ var dataRanks; // Rank text
106
+ var dataLabels; // Label text
107
+ var dataServes; // Serve text
108
+ var dataClicks; // Click text
109
+ var dataRatios; // Ratio text
110
+ var serveBar; // Serve count data bar
111
+ var clickBar; // Click count data bar
112
+ var ratioBar; // Ratio data bar
113
+ var lightBorder; // Light border (surrounds all elements)
114
+ var darkBorder; // Dark border (surrounds data elements)
115
+
116
+ // Initialize General Variables ///////////////////////////////////////////////////////////
117
+ svg = d3.select("#graph_spelling_suggestions");
118
+
119
+ dataInt = Globals.Data;
120
+
121
+ sortStates = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
122
+ sortStates[Globals.Sort] = 1;
123
+
124
+ key = function(d) {
125
+ return d.key;
126
+ };
127
+
128
+ triangle = d3.symbol().type(d3.symbolTriangle).size(20);
129
+
130
+ // Initialize Dimension Variables /////////////////////////////////////////////////////////
131
+ margin = {
132
+ top: 20,
133
+ right: 20,
134
+ bottom: 20,
135
+ left: 20
136
+ };
137
+ rowHeight = 35;
138
+ width = +svg.attr("width") - margin.left - margin.right;
139
+ height = (dataInt.length + 1) * rowHeight;
140
+ oldHeight = Globals.Height;
141
+ textPadding = 5;
142
+ barHeight = 25;
143
+ rankWidth = 2 * width / 20;
144
+ categoryWidth = 5 * width / 20;
145
+ serveWidth = 4 * width / 20;
146
+ clickWidth = 4 * width / 20;
147
+ ratioWidth = 5 * width / 20;
148
+ childOffset = 20;
149
+ serveBarStart = rankWidth + categoryWidth + 4 * textPadding + 13 * d3.max(dataInt, function(d) {
150
+ return d.serves.toString().length;
151
+ });
152
+ clickBarStart = rankWidth + categoryWidth + serveWidth + 4 * textPadding + 13 * d3.max(dataInt, function(d) {
153
+ return d.clicks.toString().length;
154
+ });
155
+ ratioBarStart = rankWidth + categoryWidth + serveWidth + clickWidth + 4 * textPadding + 13 * d3.max(dataInt, function(d) {
156
+ return d.ratio.toString().length;
157
+ });
158
+ triangleSpacing = 15;
159
+
160
+ // Initialize Scale Variables /////////////////////////////////////////////////////////////
161
+ serveScale = d3.scaleLinear().rangeRound([0, rankWidth + categoryWidth + serveWidth - serveBarStart - triangleSpacing]);
162
+ serveScale.domain([0, d3.max(dataInt, function(d) {
163
+ return d.serves;
164
+ })]);
165
+
166
+ clickScale = d3.scaleLinear().rangeRound([0, rankWidth + categoryWidth + serveWidth + clickWidth - clickBarStart - triangleSpacing]);
167
+ clickScale.domain([0, d3.max(dataInt, function(d) {
168
+ return d.clicks;
169
+ })]);
170
+
171
+ ratioScale = d3.scaleLinear().rangeRound([0, rankWidth + categoryWidth + serveWidth + clickWidth + ratioWidth - ratioBarStart - triangleSpacing]);
172
+ ratioScale.domain([0, d3.max(dataInt, function(d) {
173
+ return d.ratio;
174
+ })]);
175
+
176
+ // Misc ///////////////////////////////////////////////////////////////////////////////////
177
+ // Transition the svg height depending on previous height
178
+ svg.transition().delay(function(d) {
179
+ if (oldHeight > height) {
180
+ return 500;
181
+ } else {
182
+ return 0;
183
+ }
184
+ })
185
+ .duration(750)
186
+ .attr("height", height + margin.top + margin.bottom)
187
+ .on("end", function(d) {
188
+ Globals.Height = height;
189
+ });
190
+
191
+ // Reset expanded categories when after a resort
192
+ if (resetExpanded) {
193
+ dataInt.forEach(function(d) {
194
+ d.expanded = 0;
195
+ });
196
+ }
197
+
198
+ // Make overarching group /////////////////////////////////////////////////////////////////
199
+ groupEnter = svg.selectAll("g").data([dataInt]).enter();
200
+
201
+ groupEnter.append("g")
202
+ .attr("class", "gAll");
203
+
204
+ gAll = svg.select(".gAll")
205
+ .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
206
+
207
+ // Make header row ////////////////////////////////////////////////////////////////////////
208
+ headGroupEnter = gAll.selectAll(".headRow").data([dataInt]).enter();
209
+
210
+ headGroupEnter.append("g")
211
+ .attr("class", "headRow");
212
+
213
+ headRow = gAll.select(".headRow")
214
+ .attr("transform", "translate(0,0)");
215
+
216
+ headEnter = headRow.selectAll("rect").data([dataInt]).enter();
217
+
218
+ // Make background rect
219
+ headEnter.append("rect")
220
+ .attr("class", "darkBar")
221
+ .attr("x", 0)
222
+ .attr("y", 0)
223
+ .attr("width", width)
224
+ .attr("height", rowHeight);
225
+
226
+ // Make rank text & sort rect
227
+ headEnter.append("text")
228
+ .text("Rank")
229
+ .attr("class", "headText")
230
+ .attr("transform", "translate(" + textPadding + "," + (rowHeight / 2 + textPadding) + ")");
231
+
232
+ headEnter.append("rect")
233
+ .attr("class", "sortRect")
234
+ .attr("x", (rankWidth - 2 * triangleSpacing))
235
+ .attr("y", 0)
236
+ .attr("width", 2 * triangleSpacing)
237
+ .attr("height", rowHeight)
238
+ .on("click", function(d) {
239
+ if (Globals.Sort == 0) {
240
+ sort_search_data(1);
241
+ } else {
242
+ sort_search_data(0);
243
+ }
244
+ });
245
+
246
+ // Make category text & sort rect
247
+ headEnter.append("text")
248
+ .text("Suggestion")
249
+ .attr("class", "headText")
250
+ .attr("transform", "translate(" + (rankWidth + textPadding) + "," + (rowHeight / 2 + textPadding) + ")");
251
+
252
+ headEnter.append("rect")
253
+ .attr("class", "sortRect")
254
+ .attr("x", (rankWidth + categoryWidth - 2 * triangleSpacing))
255
+ .attr("y", 0)
256
+ .attr("width", 2 * triangleSpacing)
257
+ .attr("height", rowHeight)
258
+ .on("click", function(d) {
259
+ if (Globals.Sort == 2) {
260
+ sort_search_data(3);
261
+ } else {
262
+ sort_search_data(2);
263
+ }
264
+ });
265
+
266
+ // Make serve text & sort rect
267
+ headEnter.append("text")
268
+ .text("Serve Count")
269
+ .attr("class", "headText")
270
+ .attr("transform", "translate(" + (rankWidth + categoryWidth + textPadding) + "," + (rowHeight / 2 + textPadding) + ")");
271
+
272
+ headEnter.append("rect")
273
+ .attr("class", "sortRect")
274
+ .attr("x", (rankWidth + categoryWidth + serveWidth - 2 * triangleSpacing))
275
+ .attr("y", 0)
276
+ .attr("width", 2 * triangleSpacing)
277
+ .attr("height", rowHeight)
278
+ .on("click", function(d) {
279
+ if (Globals.Sort == 4) {
280
+ sort_search_data(5);
281
+ } else {
282
+ sort_search_data(4);
283
+ }
284
+ });
285
+
286
+ // Make click text & sort rect
287
+ headEnter.append("text")
288
+ .text("Click Count")
289
+ .attr("class", "headText")
290
+ .attr("transform", "translate(" + (rankWidth + categoryWidth + serveWidth + textPadding) + "," + (rowHeight / 2 + textPadding) + ")");
291
+
292
+ headEnter.append("rect")
293
+ .attr("class", "sortRect")
294
+ .attr("x", (rankWidth + categoryWidth + serveWidth + clickWidth - 2 * triangleSpacing))
295
+ .attr("y", 0)
296
+ .attr("width", 2 * triangleSpacing)
297
+ .attr("height", rowHeight)
298
+ .on("click", function(d) {
299
+ if (Globals.Sort == 6) {
300
+ sort_search_data(7);
301
+ } else {
302
+ sort_search_data(6);
303
+ }
304
+ });
305
+
306
+ // Make ratio text & sort rect
307
+ headEnter.append("text")
308
+ .text("Click/Serve")
309
+ .attr("class", "headText")
310
+ .attr("transform", "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth + textPadding) + "," + (rowHeight / 2 + textPadding) + ")");
311
+
312
+ headEnter.append("rect")
313
+ .attr("class", "sortRect")
314
+ .attr("x", (rankWidth + categoryWidth + serveWidth + clickWidth + ratioWidth - 2 * triangleSpacing))
315
+ .attr("y", 0)
316
+ .attr("width", 2 * triangleSpacing)
317
+ .attr("height", rowHeight)
318
+ .on("click", function(d) {
319
+ if (Globals.Sort == 8) {
320
+ sort_search_data(9);
321
+ } else {
322
+ sort_search_data(8);
323
+ }
324
+ });
325
+
326
+ // Make sort triangles
327
+ triangles = headRow.selectAll("path").data(sortStates);
328
+
329
+ triangles.enter().append("path")
330
+ .attr("d", triangle)
331
+ .attr("pointer-events", "none")
332
+ .attr("transform", function(d, i) {
333
+ if (i == 0) {
334
+ return "translate(" + (rankWidth - triangleSpacing) + "," + (rowHeight / 2 - textPadding) + ")";
335
+ } else if (i == 1) {
336
+ return "translate(" + (rankWidth - triangleSpacing) + "," + (rowHeight / 2 + textPadding) + ") rotate(180)";
337
+ } else if (i == 2) {
338
+ return "translate(" + (rankWidth + categoryWidth - triangleSpacing) + "," + (rowHeight / 2 - textPadding) + ")";
339
+ } else if (i == 3) {
340
+ return "translate(" + (rankWidth + categoryWidth - triangleSpacing) + "," + (rowHeight / 2 + textPadding) + ") rotate(180)";
341
+ } else if (i == 4) {
342
+ return "translate(" + (rankWidth + categoryWidth + serveWidth - triangleSpacing) + "," + (rowHeight / 2 - textPadding) + ")";
343
+ } else if (i == 5) {
344
+ return "translate(" + (rankWidth + categoryWidth + serveWidth - triangleSpacing) + "," + (rowHeight / 2 + textPadding) + ") rotate(180)";
345
+ } else if (i == 6) {
346
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth - triangleSpacing) + "," + (rowHeight / 2 - textPadding) + ")";
347
+ } else if (i == 7) {
348
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth - triangleSpacing) + "," + (rowHeight / 2 + textPadding) + ") rotate(180)";
349
+ } else if (i == 8) {
350
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth + ratioWidth - triangleSpacing) + "," + (rowHeight / 2 - textPadding) + ")";
351
+ } else if (i == 9) {
352
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth + ratioWidth - triangleSpacing) + "," + (rowHeight / 2 + textPadding) + ") rotate(180)";
353
+ }
354
+ })
355
+ .merge(triangles)
356
+ .transition().duration(500)
357
+ .attr("fill", function(d, i) {
358
+ if (d) {
359
+ return "steelblue";
360
+ } else {
361
+ return "lightsteelblue";
362
+ }
363
+ });
364
+
365
+ // Make data rows /////////////////////////////////////////////////////////////////////////
366
+ dataGroupEnter = gAll.selectAll(".dataRow").data([dataInt]).enter();
367
+
368
+ dataGroupEnter.append("g")
369
+ .attr("class", "dataRows");
370
+
371
+ dataRows = gAll.select(".dataRows")
372
+ .attr("transform", "translate(0,0)");
373
+
374
+ // Make background rects
375
+ dataRects = dataRows.selectAll(".darkBar, .lightBar").data(dataInt, key);
376
+
377
+ dataRects.transition().delay(function(d) {
378
+ if (oldHeight > height) {
379
+ return 500;
380
+ } else {
381
+ return 0;
382
+ }
383
+ })
384
+ .duration(750)
385
+ .attr("y", function(d, i) {
386
+ return (i + 1) * rowHeight;
387
+ });
388
+ dataRects.exit().remove();
389
+ dataRects.enter().append("rect")
390
+ .style("opacity", .000001)
391
+ .attr("class", function(d, i) { return "darkBar"; })
392
+ .attr("x", 0)
393
+ .attr("y", function(d, i) {
394
+ return (i + 1) * rowHeight;
395
+ })
396
+ .attr("width", width)
397
+ .attr("height", rowHeight)
398
+ .transition().delay(750).duration(500)
399
+ .style("opacity", 1);
400
+
401
+ // Make rank text
402
+ dataRanks = dataRows.selectAll(".dataRank").data(dataInt, key);
403
+
404
+ dataRanks.transition().delay(function(d) {
405
+ if (oldHeight > height) {
406
+ return 500;
407
+ } else {
408
+ return 0;
409
+ }
410
+ })
411
+ .duration(750)
412
+ .attr("transform", function(d, i) {
413
+ if (!d.parent) {
414
+ return "translate(" + textPadding + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
415
+ } else {
416
+ return "translate(" + (textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
417
+ }
418
+ });
419
+ dataRanks.exit().transition().duration(500)
420
+ .style("opacity", .000001)
421
+ .remove();
422
+ dataRanks.enter().append("text")
423
+ .style("opacity", .000001)
424
+ .text(function(d) {
425
+ return d.rank;
426
+ })
427
+ .attr("class", "dataRank")
428
+ .attr("transform", function(d, i) {
429
+ if (!d.parent) {
430
+ return "translate(" + textPadding + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
431
+ } else {
432
+ return "translate(" + (textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
433
+ }
434
+ })
435
+ .transition().delay(750).duration(500)
436
+ .style("opacity", 1);
437
+
438
+ // Make label text
439
+ dataLabels = dataRows.selectAll(".dataLabel").data(dataInt, key);
440
+
441
+ dataLabels.transition().delay(function(d) {
442
+ if (oldHeight > height) {
443
+ return 500;
444
+ } else {
445
+ return 0;
446
+ }
447
+ })
448
+ .duration(750)
449
+ .attr("transform", function(d, i) {
450
+ if (!d.parent) {
451
+ return "translate(" + (rankWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
452
+ } else {
453
+ return "translate(" + (rankWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
454
+ }
455
+ })
456
+ .text(function(d) {
457
+ if (d.label.length > 25) {
458
+ return d.label.slice(0, 20) + "...";
459
+ } else {
460
+ return d.label;
461
+ }
462
+ });
463
+ dataLabels.exit().transition().duration(500)
464
+ .style("opacity", .000001)
465
+ .remove();
466
+ dataLabels.enter().append("text")
467
+ .style("opacity", .000001)
468
+ .text(function(d) {
469
+ if (d.label.length > 25) {
470
+ return d.label.slice(0, 20) + "...";
471
+ } else {
472
+ return d.label;
473
+ }
474
+ })
475
+ .attr("class", "dataLabel")
476
+ .attr("transform", function(d, i) {
477
+ if (!d.parent) {
478
+ return "translate(" + (rankWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
479
+ } else {
480
+ return "translate(" + (rankWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
481
+ }
482
+ })
483
+ .transition().delay(750).duration(500)
484
+ .style("opacity", 1);
485
+
486
+ // Make serve text
487
+ dataServes = dataRows.selectAll(".dataServe").data(dataInt, key);
488
+
489
+ dataServes.transition().delay(function(d) {
490
+ if (oldHeight > height) {
491
+ return 500;
492
+ } else {
493
+ return 0;
494
+ }
495
+ })
496
+ .duration(750)
497
+ .attr("transform", function(d, i) {
498
+ if (!d.parent) {
499
+ return "translate(" + (rankWidth + categoryWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
500
+ } else {
501
+ return "translate(" + (rankWidth + categoryWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
502
+ }
503
+ })
504
+ .text(function(d) {
505
+ return d.serves;
506
+ });
507
+ dataServes.exit().transition().duration(500)
508
+ .style("opacity", .000001)
509
+ .remove();
510
+ dataServes.enter().append("text")
511
+ .style("opacity", .000001)
512
+ .text(function(d) {
513
+ return d.serves;
514
+ })
515
+ .attr("class", "dataServe")
516
+ .attr("transform", function(d, i) {
517
+ if (!d.parent) {
518
+ return "translate(" + (rankWidth + categoryWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
519
+ } else {
520
+ return "translate(" + (rankWidth + categoryWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
521
+ }
522
+ })
523
+ .transition().delay(750).duration(500)
524
+ .style("opacity", 1);
525
+
526
+ // Make click text
527
+ dataClicks = dataRows.selectAll(".dataClick").data(dataInt, key);
528
+
529
+ dataClicks.transition().delay(function(d) {
530
+ if (oldHeight > height) {
531
+ return 500;
532
+ } else {
533
+ return 0;
534
+ }
535
+ })
536
+ .duration(750)
537
+ .attr("transform", function(d, i) {
538
+ if (!d.parent) {
539
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
540
+ } else {
541
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
542
+ }
543
+ })
544
+ .text(function(d) {
545
+ return d.clicks;
546
+ });
547
+ dataClicks.exit().transition().duration(500)
548
+ .style("opacity", .000001)
549
+ .remove();
550
+ dataClicks.enter().append("text")
551
+ .style("opacity", .000001)
552
+ .text(function(d) {
553
+ return d.clicks;
554
+ })
555
+ .attr("class", "dataClick")
556
+ .attr("transform", function(d, i) {
557
+ if (!d.parent) {
558
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
559
+ } else {
560
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
561
+ }
562
+ })
563
+ .transition().delay(750).duration(500)
564
+ .style("opacity", 1);
565
+
566
+ // Make ratio text
567
+ dataRatios = dataRows.selectAll(".dataRatio").data(dataInt, key);
568
+
569
+ dataRatios.transition().delay(function(d) {
570
+ if (oldHeight > height) {
571
+ return 500;
572
+ } else {
573
+ return 0;
574
+ }
575
+ })
576
+ .duration(750)
577
+ .attr("transform", function(d, i) {
578
+ if (!d.parent) {
579
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
580
+ } else {
581
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
582
+ }
583
+ })
584
+ .text(function(d) {
585
+ return d.ratio + "%";
586
+ });
587
+ dataRatios.exit().transition().duration(500)
588
+ .style("opacity", .000001)
589
+ .remove();
590
+ dataRatios.enter().append("text")
591
+ .style("opacity", .000001)
592
+ .text(function(d) {
593
+ return d.ratio + "%";
594
+ })
595
+ .attr("class", "dataRatio")
596
+ .attr("transform", function(d, i) {
597
+ if (!d.parent) {
598
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth + textPadding) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
599
+ } else {
600
+ return "translate(" + (rankWidth + categoryWidth + serveWidth + clickWidth + textPadding + childOffset) + "," + Math.floor((i + 1) * rowHeight + rowHeight / 2 + textPadding) + ")";
601
+ }
602
+ })
603
+ .transition().delay(750).duration(500)
604
+ .style("opacity", 1);
605
+
606
+ // Make serve bars
607
+ serveBar = dataRows.selectAll(".serveBar, .lightServeBar").data(dataInt, key);
608
+
609
+ serveBar.transition().delay(function(d) {
610
+ if (oldHeight > height) {
611
+ return 500;
612
+ } else {
613
+ return 0;
614
+ }
615
+ })
616
+ .duration(750)
617
+ .attr("y", function(d, i) {
618
+ return (i + 1) * rowHeight + (rowHeight - barHeight) / 2;
619
+ })
620
+ .attr("width", function(d) {
621
+ return serveScale(d.serves);
622
+ })
623
+ .attr("x", function(d) {
624
+ return serveBarStart;
625
+ });
626
+ serveBar.exit().transition().duration(500)
627
+ .attr("width", 0)
628
+ .remove();
629
+ serveBar.enter().append("rect")
630
+ .attr("class", function(d) {
631
+ if (!d.parent) {
632
+ return "serveBar";
633
+ } else {
634
+ return "lightServeBar";
635
+ }
636
+ })
637
+ .style("cursor", function(d) {
638
+ if (!d.parent) {
639
+ return "pointer";
640
+ } else {
641
+ return "auto";
642
+ }
643
+ })
644
+ .attr("x", function(d) {
645
+ return serveBarStart;
646
+ })
647
+ .attr("y", function(d, i) {
648
+ return (i + 1) * rowHeight + (rowHeight - barHeight) / 2;
649
+ })
650
+ .attr("width", function(d) {
651
+ return 0;
652
+ })
653
+ .attr("height", barHeight)
654
+ .on("click", function(d) { expand(d) })
655
+ .transition().delay(750).duration(500)
656
+ .attr("width", function(d) {
657
+ return serveScale(d.serves);
658
+ });
659
+
660
+ // Make click bars
661
+ clickBar = dataRows.selectAll(".clickBar, .lightClickBar").data(dataInt, key);
662
+
663
+ clickBar.transition().delay(function(d) {
664
+ if (oldHeight > height) {
665
+ return 500;
666
+ } else {
667
+ return 0;
668
+ }
669
+ })
670
+ .duration(750)
671
+ .attr("y", function(d, i) {
672
+ return (i + 1) * rowHeight + (rowHeight - barHeight) / 2;
673
+ })
674
+ .attr("width", function(d) {
675
+ return clickScale(d.clicks);
676
+ })
677
+ .attr("x", function(d) {
678
+ return clickBarStart;
679
+ });
680
+ clickBar.exit().transition().duration(500)
681
+ .attr("width", 0)
682
+ .remove();
683
+ clickBar.enter().append("rect")
684
+ .attr("class", function(d) {
685
+ if (!d.parent) {
686
+ return "clickBar";
687
+ } else {
688
+ return "lightClickBar";
689
+ }
690
+ })
691
+ .style("cursor", function(d) {
692
+ if (!d.parent) {
693
+ return "pointer";
694
+ } else {
695
+ return "auto";
696
+ }
697
+ })
698
+ .attr("x", function(d) {
699
+ return clickBarStart;
700
+ })
701
+ .attr("y", function(d, i) {
702
+ return (i + 1) * rowHeight + (rowHeight - barHeight) / 2;
703
+ })
704
+ .attr("width", function(d) {
705
+ return 0;
706
+ })
707
+ .attr("height", barHeight)
708
+ .on("click", function(d) { expand(d) })
709
+ .transition().delay(750).duration(500)
710
+ .attr("width", function(d) {
711
+ return clickScale(d.clicks);
712
+ });
713
+
714
+ // Make ratio bars
715
+ ratioBar = dataRows.selectAll(".ratioBar , .lightRatioBar").data(dataInt, key);
716
+
717
+ ratioBar.transition().delay(function(d) {
718
+ if (oldHeight > height) {
719
+ return 500;
720
+ } else {
721
+ return 0;
722
+ }
723
+ })
724
+ .duration(750)
725
+ .attr("y", function(d, i) {
726
+ return (i + 1) * rowHeight + (rowHeight - barHeight) / 2;
727
+ })
728
+ .attr("width", function(d) {
729
+ return ratioScale(d.ratio);
730
+ })
731
+ .attr("x", function(d) {
732
+ return ratioBarStart;
733
+ });
734
+ ratioBar.exit().transition().duration(500)
735
+ .attr("width", 0)
736
+ .remove();
737
+ ratioBar.enter().append("rect")
738
+ .attr("class", function(d) {
739
+ if (!d.parent) {
740
+ return "ratioBar";
741
+ } else {
742
+ return "lightRatioBar";
743
+ }
744
+ })
745
+ .style("cursor", function(d) {
746
+ if (!d.parent) {
747
+ return "pointer";
748
+ } else {
749
+ return "auto";
750
+ }
751
+ })
752
+ .attr("x", function(d) {
753
+ return ratioBarStart;
754
+ })
755
+ .attr("y", function(d, i) {
756
+ return (i + 1) * rowHeight + (rowHeight - barHeight) / 2;
757
+ })
758
+ .attr("width", function(d) {
759
+ return 0;
760
+ })
761
+ .attr("height", barHeight)
762
+ .on("click", function(d) { expand(d) })
763
+ .transition().delay(750).duration(500)
764
+ .attr("width", function(d) {
765
+ return ratioScale(d.ratio);
766
+ });
767
+
768
+ // Add borders ////////////////////////////////////////////////////////////////////////////
769
+ lightBorder = gAll.selectAll(".lightBorder").data([dataInt]);
770
+
771
+ lightBorder.transition().delay(function(d) {
772
+ if (oldHeight > height) {
773
+ return 500;
774
+ } else {
775
+ return 0;
776
+ }
777
+ })
778
+ .duration(750)
779
+ .attr("height", height);
780
+ lightBorder.exit().remove();
781
+ lightBorder.enter().append("rect")
782
+ .attr("class", "lightBorder")
783
+ .attr("x", 0)
784
+ .attr("y", 0)
785
+ .attr("width", width)
786
+ .attr("height", height);;
787
+
788
+ darkBorder = gAll.selectAll(".darkBorder").data([dataInt]);
789
+
790
+ darkBorder.transition().delay(function(d) {
791
+ if (oldHeight > height) {
792
+ return 500;
793
+ } else {
794
+ return 0;
795
+ }
796
+ })
797
+ .duration(750)
798
+ .attr("height", height - rowHeight);
799
+ darkBorder.exit().remove();
800
+ darkBorder.enter().append("rect")
801
+ .attr("class", "darkBorder")
802
+ .attr("x", 0)
803
+ .attr("y", rowHeight)
804
+ .attr("width", width)
805
+ .attr("height", height - rowHeight);
806
+ }
807
+ }
808
+
809
+ function expand(d) {
810
+ if (!d.expanded && !d.parent) {
811
+ d.expanded = 1;
812
+ load_details(d.label);
813
+ } else if (d.expanded && !d.parent) {
814
+ d.expanded = 0;
815
+ remove_details(d.label);
816
+ }
817
+ }
818
+
819
+ function sort_search_data(sort) {
820
+ if (Globals.Data.length != Globals.OriginalData.length) { // If details are present, those must be removed before resort
821
+ // Go back to original data set (no details)
822
+ Globals.Data = Globals.OriginalData.sort(function(a,b) { return determine_sort(Globals.Sort, a, b) });
823
+
824
+ // Resort data after delay
825
+ setTimeout(function() {
826
+ Globals.Data = Globals.OriginalData.sort(function(a,b) { return determine_sort(sort, a, b) });
827
+ draw_graph_spelling_suggestions(true);
828
+ }, 750);
829
+ } else { // Otherwise, you can just resort the data
830
+ Globals.Data = Globals.OriginalData.sort(function(a,b) { return determine_sort(sort, a, b) });
831
+ }
832
+
833
+ // Update global sort
834
+ Globals.Sort = sort;
835
+ draw_graph_spelling_suggestions(true);
836
+ }
837
+
838
+ function determine_sort(sort, a, b) {
839
+ switch(sort) {
840
+ case 0: return d3.ascending(a.rank,b.rank);
841
+ case 1: return d3.ascending(b.rank,a.rank);
842
+
843
+ case 2: return d3.ascending(a.label,b.label);
844
+ case 3: return d3.ascending(b.label,a.label);
845
+
846
+ case 4: return d3.ascending(a.serves,b.serves);
847
+ case 5: return d3.ascending(b.serves,a.serves);
848
+
849
+ case 6: return d3.ascending(a.clicks,b.clicks);
850
+ case 7: return d3.ascending(b.clicks,a.clicks);
851
+
852
+ case 8: return d3.ascending(a.ratio,b.ratio);
853
+ case 9: return d3.ascending(b.ratio,a.ratio);
854
+ }
855
+ }
856
+
857
+ function load_details(item) {
858
+ var updateData = _.cloneDeep(Globals.Data);
859
+ var from = $("#from").datepicker("getDate");
860
+ var to = new Date($("#to").datepicker("getDate").getTime() + 1000*60*60*24);
861
+ $.ajax({
862
+ type: "GET",
863
+ contentType: "application/json; charset=utf-8",
864
+ url: '<%= url_helper.data_spelling_details_path %>',
865
+ dataType: "json",
866
+ data: {
867
+ "item": item,
868
+ "start_date": from,
869
+ "end_date": to
870
+ },
871
+ success: function(detailSet) {
872
+ var detailData = _.cloneDeep(detailSet);
873
+ var index = _.findIndex(updateData, {
874
+ "label": item
875
+ });
876
+ updateData = _.concat(_.slice(updateData, 0, index + 1), detailData, _.slice(updateData, index + 1, updateData.length));
877
+
878
+ Globals.Data = updateData;
879
+ draw_graph_spelling_suggestions(false);
880
+ },
881
+ error: function(result) {
882
+ error();
883
+ }
884
+ });
885
+ }
886
+
887
+ function remove_details(item) {
888
+ var updateData = _.cloneDeep(Globals.Data);
889
+ var startIndex = _.findIndex(updateData, {
890
+ "label": item
891
+ });
892
+ var endIndex = startIndex + 1;
893
+ while (endIndex < updateData.length && updateData[endIndex].parent) {
894
+ endIndex++;
895
+ }
896
+ updateData = _.concat(_.slice(updateData, 0, startIndex + 1), _.slice(updateData, endIndex, updateData.length));
897
+
898
+ Globals.Data = updateData;
899
+ draw_graph_spelling_suggestions(false);
900
+ }
901
+
902
+ })();