general.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /////////////////////////
  2. // GENERAL UPDATE CODE //
  3. /////////////////////////
  4. var dataStore = {
  5. picked_sn:221,
  6. selected_sn:[12, 19, 113, 190, 202, 216, 221, 300, 369, 384, 458, 512, 539,
  7. 602, 718, 773, 849, 899, 904, 944, 1047, 1053, 1129, 1155, 1179, 1189,
  8. 1213, 1224, 1236, 1254, 1277, 1279, 1310, 1330, 1399, 1597, 1724, 1768,
  9. 1789, 1804, 1935, 2006, 2016, 2028, 2034, 2059, 2137]
  10. };
  11. // general update values when new point is picked
  12. function generalPick(title, altText, imageUrl, sn) {
  13. scatterplot.form.property('value', parseInt(sn));
  14. $("#xkcdImage").attr("src", imageUrl).attr("alt", title);
  15. $("#xkcdImageTitle").text(title);
  16. $("#xkcdImageAltText").text(altText);
  17. // send picked sn_num to backend
  18. dataStore.picked_sn = parseInt(sn);
  19. requestBarchartData();
  20. }
  21. function generalSelect(sn_nums) {
  22. $("#checkbox-barchart-selected-label")
  23. .text("Selected (" + sn_nums.length + ")");
  24. dataStore.selected_sn = sn_nums;
  25. requestBarchartData()
  26. }
  27. function requestBarchartData() {
  28. d3.json("/barchart-data")
  29. .header("Content-Type", "application/json")
  30. .post(
  31. JSON.stringify(
  32. {picked_sn:dataStore.picked_sn,
  33. selected_sn:dataStore.selected_sn}
  34. ),
  35. updateBarchart);
  36. }
  37. function updateBarchart(err, data) {
  38. barchart.updateAndDraw(data);
  39. }
  40. function requestFeatureDistribution(feature_idx_list) {
  41. d3.json("/feature-data")
  42. .header("Content-Type", "application/json")
  43. .post(
  44. JSON.stringify(
  45. {feature_idx_list:feature_idx_list}
  46. ),
  47. updateFeatureDistribution);
  48. }
  49. function updateFeatureDistribution(err, data) {
  50. single_list = data[0].single.map(x=>+x);
  51. both_list = data[0].both.map(x=>+x);
  52. $("#overlapnum-featureDistribution")
  53. .text("comics containing multiple of the selected features: " + both_list.length);
  54. // deselect previous
  55. featureScatterplot.scatter.selectAll("circle")
  56. .classed("dot-single-feature", false)
  57. .classed("dot-both-feature", false);
  58. // select new
  59. featureScatterplot.scatter.selectAll("circle")
  60. .filter(function(d) { return single_list.includes(d.sn); })
  61. .classed("dot-single-feature", true);
  62. featureScatterplot.scatter.selectAll("circle")
  63. .filter(function(d) { return both_list.includes(d.sn); })
  64. .classed("dot-both-feature", true);
  65. }