wanwanlin0521 commited on
Commit
7e7c9ca
·
verified ·
1 Parent(s): 80022b7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +22 -4
index.html CHANGED
@@ -100,7 +100,7 @@
100
  next_button.style("display", curr_scene === 6 ? "none" : "inline");
101
  }
102
 
103
- // Load data.
104
  d3.csv("https://raw.githubusercontent.com/MainakRepositor/Datasets/master/top_200_password_2020_by_country.csv")
105
  .then(function(data) {
106
  // Populate all passwords.
@@ -108,6 +108,11 @@
108
  color_scale = d3.scaleOrdinal().domain([...tot_passwords]).range(d3.schemePaired);
109
 
110
  // Aggregate "Global" data.
 
 
 
 
 
111
  var password_counts = d3.rollup(
112
  data, v => d3.sum(v, d => parseInt(d.User_count) || 0), d => d.Password
113
  );
@@ -127,7 +132,10 @@
127
  // Parse data for countries that have top 4 population around the world.
128
  var countries = ["India", "China", "United States", "Indonesia"];
129
  var country_data = {};
130
-
 
 
 
131
  countries.forEach(country => {
132
  country_data[country] = data
133
  .filter(d => d.country === country && !isNaN(parseInt(d.User_count)))
@@ -137,6 +145,8 @@
137
  });
138
 
139
  // Parse USA data for the rest scenes.
 
 
140
  var usa_data = data
141
  .filter(d => d.country === "United States" && !isNaN(parseInt(d.User_count)) && !isNaN(parseFloat(d.Time_to_crack_in_seconds)))
142
  .map(d => ({
@@ -151,6 +161,7 @@
151
 
152
  svg.append("text").attr("x", width / 2).attr("y", -20).attr("class", "scene-title").text("Top 20 Passwords Worldwide");
153
 
 
154
  var x_scale = d3.scaleBand().domain(global_data.map(d => d.password)).range([0, width]).padding(0.05);
155
  var y_scale = d3.scaleLinear().domain([0, d3.max(global_data, d => d.count) || 1]).range([height, 0]);
156
 
@@ -194,6 +205,7 @@
194
  countries.forEach((country, i) => {
195
  var g = svg.append("g").attr("transform", `translate(${positions[i].x},${positions[i].y})`);
196
 
 
197
  var x_scale = d3.scaleBand().domain(country_data[country].map(d => d.password)).range([0, plot_width]).padding(0.05);
198
  var y_scale = d3.scaleLinear().domain([0, d3.max(country_data[country], d => d.count) || 1]).range([plot_height - 30, 0]);
199
 
@@ -236,7 +248,8 @@
236
  delete_scene();
237
 
238
  svg.append("text").attr("x", width / 2).attr("y", -20).attr("class", "scene-title").text("Top 20 Passwords in the U.S.");
239
-
 
240
  var x_scale = d3.scaleBand().domain(usa_data.slice(0, 20).map(d => d.password)).range([0, width]).padding(0.05);
241
  var y_scale = d3.scaleLinear().domain([0, d3.max(usa_data.slice(0, 20), d => d.count)]).range([height, 0]);
242
 
@@ -264,6 +277,7 @@
264
 
265
  svg.append("text").attr("x", width / 2).attr("y", -20).attr("class", "scene-title").text("Time to Crack for All U.S. Passwords");
266
 
 
267
  var x_scale = d3.scaleBand().domain(usa_data.map(d => d.password)).range([0, width]).padding(0.05);
268
  var y_scale = d3.scaleLinear().domain([0, d3.max(usa_data, d => d.time_to_crack)]).range([height, 0]);
269
 
@@ -305,6 +319,9 @@
305
 
306
  // Set up some parameters for box plot.
307
  // Method comes from: https://d3-graph-gallery.com/graph/boxplot_basic.html
 
 
 
308
  var times = usa_data.map(d => d.time_to_crack).sort(d3.ascending);
309
  var q1 = d3.quantile(times, 0.25);
310
  var median = d3.quantile(times, 0.5);
@@ -383,7 +400,8 @@
383
 
384
  svg.append("text").attr("x", width / 2).attr("y", 380).attr("text-anchor", "middle").style("font-size", "16px")
385
  .text("4. If you really want to use these popular passwords, try to put them into combinations to reduce security risk.");
386
-
 
387
  var x_scale = d3.scaleBand().domain(usa_data.slice(0, 5).map(d => d.password)).range([0, width / 2]).padding(0.05);
388
  var y_scale = d3.scaleLinear().domain([0, d3.max(usa_data.slice(0, 5), d => d.count)]).range([height - 150, 150]);
389
  var new_svg = svg.append("g").attr("transform", `translate(${(width - (width / 2)) / 2}, 0)`);
 
100
  next_button.style("display", curr_scene === 6 ? "none" : "inline");
101
  }
102
 
103
+ // Load data.
104
  d3.csv("https://raw.githubusercontent.com/MainakRepositor/Datasets/master/top_200_password_2020_by_country.csv")
105
  .then(function(data) {
106
  // Populate all passwords.
 
108
  color_scale = d3.scaleOrdinal().domain([...tot_passwords]).range(d3.schemePaired);
109
 
110
  // Aggregate "Global" data.
111
+ // Method comes from: https://observablehq.com/@d3/d3-group
112
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-array-from-method/
113
+ // Method comes from: https://d3js.org/d3-selection/selecting
114
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-node-sort-function/
115
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
116
  var password_counts = d3.rollup(
117
  data, v => d3.sum(v, d => parseInt(d.User_count) || 0), d => d.Password
118
  );
 
132
  // Parse data for countries that have top 4 population around the world.
133
  var countries = ["India", "China", "United States", "Indonesia"];
134
  var country_data = {};
135
+
136
+ // Method comes from: https://d3js.org/d3-selection/selecting
137
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
138
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-node-sort-function/
139
  countries.forEach(country => {
140
  country_data[country] = data
141
  .filter(d => d.country === country && !isNaN(parseInt(d.User_count)))
 
145
  });
146
 
147
  // Parse USA data for the rest scenes.
148
+ // Method comes from: https://d3js.org/d3-selection/selecting
149
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
150
  var usa_data = data
151
  .filter(d => d.country === "United States" && !isNaN(parseInt(d.User_count)) && !isNaN(parseFloat(d.Time_to_crack_in_seconds)))
152
  .map(d => ({
 
161
 
162
  svg.append("text").attr("x", width / 2).attr("y", -20).attr("class", "scene-title").text("Top 20 Passwords Worldwide");
163
 
164
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
165
  var x_scale = d3.scaleBand().domain(global_data.map(d => d.password)).range([0, width]).padding(0.05);
166
  var y_scale = d3.scaleLinear().domain([0, d3.max(global_data, d => d.count) || 1]).range([height, 0]);
167
 
 
205
  countries.forEach((country, i) => {
206
  var g = svg.append("g").attr("transform", `translate(${positions[i].x},${positions[i].y})`);
207
 
208
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
209
  var x_scale = d3.scaleBand().domain(country_data[country].map(d => d.password)).range([0, plot_width]).padding(0.05);
210
  var y_scale = d3.scaleLinear().domain([0, d3.max(country_data[country], d => d.count) || 1]).range([plot_height - 30, 0]);
211
 
 
248
  delete_scene();
249
 
250
  svg.append("text").attr("x", width / 2).attr("y", -20).attr("class", "scene-title").text("Top 20 Passwords in the U.S.");
251
+
252
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
253
  var x_scale = d3.scaleBand().domain(usa_data.slice(0, 20).map(d => d.password)).range([0, width]).padding(0.05);
254
  var y_scale = d3.scaleLinear().domain([0, d3.max(usa_data.slice(0, 20), d => d.count)]).range([height, 0]);
255
 
 
277
 
278
  svg.append("text").attr("x", width / 2).attr("y", -20).attr("class", "scene-title").text("Time to Crack for All U.S. Passwords");
279
 
280
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
281
  var x_scale = d3.scaleBand().domain(usa_data.map(d => d.password)).range([0, width]).padding(0.05);
282
  var y_scale = d3.scaleLinear().domain([0, d3.max(usa_data, d => d.time_to_crack)]).range([height, 0]);
283
 
 
319
 
320
  // Set up some parameters for box plot.
321
  // Method comes from: https://d3-graph-gallery.com/graph/boxplot_basic.html
322
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
323
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-node-sort-function/
324
+ // Method comes from: https://d3js.org/d3-selection/selecting
325
  var times = usa_data.map(d => d.time_to_crack).sort(d3.ascending);
326
  var q1 = d3.quantile(times, 0.25);
327
  var median = d3.quantile(times, 0.5);
 
400
 
401
  svg.append("text").attr("x", width / 2).attr("y", 380).attr("text-anchor", "middle").style("font-size", "16px")
402
  .text("4. If you really want to use these popular passwords, try to put them into combinations to reduce security risk.");
403
+
404
+ // Method comes from: https://www.geeksforgeeks.org/javascript/d3-js-d3-map-values-function/
405
  var x_scale = d3.scaleBand().domain(usa_data.slice(0, 5).map(d => d.password)).range([0, width / 2]).padding(0.05);
406
  var y_scale = d3.scaleLinear().domain([0, d3.max(usa_data.slice(0, 5), d => d.count)]).range([height - 150, 150]);
407
  var new_svg = svg.append("g").attr("transform", `translate(${(width - (width / 2)) / 2}, 0)`);