index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Xkcd Data Visualization</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <!-- favicon (by default flask only serves from static) -->
  8. <link rel="shortcut icon" href="static/favicons/favicon.ico">
  9. <link rel="apple-touch-icon" sizes="180x180" href="static/favicons/apple-touch-icon.png">
  10. <link rel="icon" type="image/png" sizes="32x32" href="static/favicons/favicon-32x32.png">
  11. <link rel="icon" type="image/png" sizes="16x16" href="static/favicons/favicon-16x16.png">
  12. <link rel="manifest" href="static/favicons/site.webmanifest">
  13. <meta name="msapplication-TileColor" content="#00aba9">
  14. <meta name="theme-color" content="#ffffff">
  15. <!-- Patrick Hand font -->
  16. <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Patrick+Hand" />
  17. <!-- Latest compiled and minified CSS -->
  18. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  19. <!-- jQuery library -->
  20. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  21. <!-- popper.min.js for Popovers -->
  22. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  23. <!-- Latest compiled JavaScript -->
  24. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  25. <!-- custom stylesheet -->
  26. <link rel="stylesheet" href="static/styles.css">
  27. </head>
  28. <body>
  29. <header class="box">
  30. <h1>Xkcd Data Visualization</h1>
  31. <h4>Similar comics are clustered together!</h4>
  32. </header>
  33. <main>
  34. <div class="container">
  35. <div class="row row-no-gutters">
  36. <div class="col-sm-6">
  37. <section class="box" id="featureDistributionMenu" style="padding-left: 20px;">
  38. <h3>
  39. Feature Distribution Menu
  40. <button type="button" class="btn btn-outline-secondary" data-container="body" data-toggle="popover" data-placement="bottom"
  41. title="Feature Distribution Menu"
  42. data-content='
  43. <strong>select a feature to see the distribution of all the comics with that feature</strong>
  44. <ul style="text-align:center;">
  45. <li>
  46. <h4>selection list</h4>
  47. <p>select feature by clicking</p>
  48. <p>on pc, search by typing first letter or using find tool on menu</p>
  49. </li>
  50. <li>
  51. <h4>select multiple</h4>
  52. <p>windows: ctrl+click</p>
  53. <p>mac: cmd+click</p>
  54. </li>
  55. <li>
  56. <h4>select consecutive</h4>
  57. <p>on pc: shift+click</p>
  58. </li>
  59. </ul>
  60. '
  61. data-html="true">
  62. <img src="static/glyphicons/info.svg" class="info-icon">
  63. </button>
  64. </h3>
  65. <div style="display: flex;">
  66. <div style="flex: auto;">
  67. <h3>{{num_features}} Features</h3>
  68. <select id="select-featureDistribution" size="20" multiple></select>
  69. </div>
  70. <div style="flex: auto;">
  71. <div style="padding-left: 20px;">
  72. <h3>Selected Features:</h3>
  73. <div style="text-align: left;" id="selected-featureDistribution" class="box"></div>
  74. <h3 id="overlapnum-featureDistribution">comics containing multiple of the selected features: </h3>
  75. <br>
  76. <button id="button-clear-featureDistribution" type="button">Clear Selection</button>
  77. </div>
  78. </div>
  79. </div>
  80. </section>
  81. </div>
  82. <div class="col-sm-6">
  83. <section class="box" id="featureDistribution">
  84. <h3>Feature Distribution
  85. <button type="button" class="btn btn-outline-secondary" data-container="body" data-toggle="popover" data-placement="bottom"
  86. title="Feature Distribution"
  87. data-content='
  88. <strong>tsne-embedding of comic relations where similar comics are closer together</strong>
  89. <ul style="text-align:center;">
  90. <li>
  91. <div class="tooltip-key">hover on point</div>
  92. <p>populate tooltip with comic title</p>
  93. </li>
  94. <li>
  95. <h4>color: orange</h4>
  96. <p>comic has one of the selected features</p>
  97. </li>
  98. <li>
  99. <h4>color: black</h4>
  100. <p>comic has multiple of the selected features</p>
  101. </li>
  102. <li>
  103. <h4>color: blue</h4>
  104. <p>comic has none of the selected features</p>
  105. </li>
  106. <li>
  107. <h4>color: red</h4>
  108. <p>comic picked on click, show details in picked comic panel</p>
  109. </li>
  110. <li>
  111. <h4>brush points</h4>
  112. <p>click and drag on scatterplot to zoom in</p>
  113. </li>
  114. <li>
  115. <h4>double / triple click on graph</h4>
  116. <p>zoom out</p>
  117. </li>
  118. </ul>
  119. '
  120. data-html="true">
  121. <img src="static/glyphicons/info.svg" class="info-icon">
  122. </button>
  123. </h3>
  124. <div id="chart-featureDistribution"></div>
  125. </section>
  126. </div>
  127. </div>
  128. </div>
  129. <div class="container">
  130. <div class="row row-no-gutters">
  131. <div class="col-sm-6">
  132. <section class="box" id="barchart">
  133. <h3>TFIDF of Top Words in Selected Comics
  134. <button type="button" class="btn btn-outline-secondary" data-container="body" data-toggle="popover" data-placement="bottom"
  135. title="TFIDF of Top Words in Selected Comics"
  136. data-content='
  137. <strong>compare selected comic&#39s most important words & summed TFIDF (importance) scores</strong>
  138. <ul style="text-align:center;">
  139. <li>
  140. <h4>color: red</h4>
  141. <p>picked comic&#39s TFIDF value</p>
  142. </li>
  143. <li>
  144. <h4>color: orange</h4>
  145. <p>selected comic group&#39s summed TFIDF value</p>
  146. </li>
  147. <li>
  148. <h4>color: blue</h4>
  149. <p>word&#39s total TFIDF score</p>
  150. </li>
  151. <li>
  152. <h4>checkbox</h4>
  153. <p>hide/show group&#39s TFIDF bar, adjust axis</p>
  154. </li>
  155. </ul>
  156. '
  157. data-html="true">
  158. <img src="static/glyphicons/info.svg" class="info-icon">
  159. </button>
  160. </h3>
  161. <div>
  162. <input type="checkbox" class="checkbox-barchart" id="checkbox-barchart-picked" value="picked" checked>
  163. <label for="checkbox-barchart-picked">Picked (1)</label>
  164. <input type="checkbox" class="checkbox-barchart" id="checkbox-barchart-selected" value="selected" checked>
  165. <label for="checkbox-barchart-selected" id="checkbox-barchart-selected-label">Selected ()</label>
  166. <input type="checkbox" class="checkbox-barchart" id="checkbox-barchart-all" value="all" checked>
  167. <label for="checkbox-barchart-all">All ({{num_comics}})</label>
  168. </div>
  169. <div id="chart-barchart"></div>
  170. </section>
  171. </div>
  172. <div class="col-sm-6">
  173. <section class="box" id="scatterplot">
  174. <h3>TFIDF to LSA to TSNE Comic Relations
  175. <button type="button" class="btn btn-outline-secondary" data-container="body" data-toggle="popover" data-placement="bottom"
  176. title="TFIDF to LSA to TSNE Comic Relations"
  177. data-content='
  178. <strong>tsne-embedding of comic relations where similar comics are closer together</strong>
  179. <ul style="text-align:center;">
  180. <li>
  181. <div class="tooltip-key">hover on point</div>
  182. <p>populate tooltip with comic serial number and title</p>
  183. </li>
  184. <li>
  185. <h4>color: red</h4>
  186. <p>comic picked on click, show details in picked comic panel</p>
  187. </li>
  188. <li>
  189. <h4>color: orange</h4>
  190. <p>comic selected on brush, brush empty area to clear</p>
  191. </li>
  192. <li>
  193. <h4>color: blue</h4>
  194. <p>unselected comic</p>
  195. </li>
  196. <li>
  197. <h4>input area</h4>
  198. <p>pick specific comic by serial number</p>
  199. </li>
  200. <li>
  201. <h4>brush points</h4>
  202. <p>click and drag on scatterplot to select and zoom in</p>
  203. </li>
  204. <li>
  205. <h4>double / triple click on graph</h4>
  206. <p>zoom out</p>
  207. </li>
  208. </ul>
  209. '
  210. data-html="true">
  211. <img src="static/glyphicons/info.svg" class="info-icon">
  212. </button>
  213. </h3>
  214. <div class="input-group">
  215. <span class="input-group-addon">Pick Comic 1-{{num_comics}}</span>
  216. <input class="form-control" type="number" id="form-scatterplot-picked" min="1" max={{num_comics}} step="1">
  217. </div>
  218. <div id="chart-scatterplot"></div>
  219. </section>
  220. </div>
  221. </div>
  222. </div>
  223. <div class="container">
  224. <div class="row row-no-gutters">
  225. <div class="col-sm-6">
  226. <section id="pictureDiv" class="box">
  227. <h3>Picked Comic Info
  228. <button type="button" class="btn btn-outline-secondary" data-container="body" data-toggle="popover" data-placement="bottom"
  229. title="Picked Comic Info"
  230. data-content='<strong>see picked comic&#39s title, image, and alt-text</strong>'
  231. data-html="true">
  232. <img src="static/glyphicons/info.svg" class="info-icon">
  233. </button>
  234. </h3>
  235. <p id="xkcdImageTitle"> 221: Random Number </p>
  236. <img id="xkcdImage" alt="221: Random Number"
  237. src="https://www.explainxkcd.com/wiki/images/f/fe/random_number.png"
  238. style='height: 100%; width: 100%; object-fit: contain'>
  239. <p id="xkcdImageAltText"> Alt Text </p>
  240. </section>
  241. </div>
  242. <div class="col-sm-6">
  243. <section class="box" style="text-align:left;">
  244. <h3>Process</h3>
  245. <ol style="text-align:left;">
  246. <li>scrape comics transcript, title, and alt-text from explainxkcd.com</li>
  247. <li>clean data by removing domain-specific stop-words (e.g. character names), lemminize and stem words (e.g. “chocolates”, “chocolatey”, “choco” all count as the root word, “chocolate”)</li>
  248. <li>represent each of the {{num_comics}} comic as a {{num_features}}-dim text vector of term-frequency x inverse document frequency (tf-idf) scores</li>
  249. <li>reduce the effects of synonymy and polysemy, and reduce the feature space from 7000 unique words to 50 feature by perform latent semantic analysis with truncated svd</li>
  250. <li>create 2d embedding of document relations with t-sne that shows similar comics located closer together</li>
  251. <li>build interactive, reactive data analysis web application with d3.js, bootstrap, and flask</li>
  252. </ol>
  253. <h3>Background Information on Xkcd Comics</h3>
  254. <p>
  255. xkcd comics are "A webcomic of romance, sarcasm, math, and language"
  256. (xkcd slogan). These comics are licensed under a Creative Commons
  257. Attribution-NonCommercial 2.5 License, and their transcripts are available
  258. on www.explainxkcd.com (xkcd comic's wiki). This web application uses
  259. the first {{num_comics}} comics as data source.
  260. </p>
  261. </section>
  262. </div>
  263. </div>
  264. </div>
  265. </main>
  266. <footer class="box">
  267. <p>
  268. Gati Aher, April 2020 |
  269. <a href="https://github.com/GatiAher/Xkcd_Data_Visualization">
  270. <img src="static/glyphicons/mark-github.svg" class="github-icon">
  271. </a>
  272. </p>
  273. </footer>
  274. <script src="https://d3js.org/d3.v4.min.js"></script>
  275. <script src="static/chart.js"></script>
  276. <script src="static/scatterplot.js"></script>
  277. <script src="static/barchart.js"></script>
  278. <script src="static/general.js"></script>
  279. <script>
  280. var comic_data = {{ return_comic_data.comic_data | safe }};
  281. var feature_names = {{ return_feature_names.feature_names | safe }};
  282. // add features to feature distribution menu
  283. for (const idx in feature_names) {
  284. $('#select-featureDistribution').append($('<option>', {value:idx, text:feature_names[idx]}));
  285. }
  286. var featureScatterplot = new Scatterplot("featureDistribution",
  287. selectOnBrushFlag=false, pickOnClickFlag=true,
  288. pickOnFormFlag=false, selectOnSelectMenuFlag=true);
  289. featureScatterplot.updateAndDraw(comic_data);
  290. var scatterplot = new Scatterplot("scatterplot");
  291. scatterplot.updateAndDraw(comic_data);
  292. var barchart = new Barchart("barchart");
  293. // initial state of feature selection menu
  294. $("#select-featureDistribution").val(["3301", "3849"]);
  295. $('#selected-featureDistribution').text("number (200), random (71)");
  296. requestFeatureDistribution(["3301", "3849"]);
  297. // initial coloring of selected dots
  298. scatterplot.scatter.selectAll("circle")
  299. .filter(function(d) { return dataStore.selected_sn.includes(d.sn); })
  300. .classed("dot-selected", true);
  301. // initial coloring of picked dot
  302. scatterplot.scatter.selectAll("circle")
  303. .filter(function(d) { return d.sn == dataStore.picked_sn })
  304. .classed("dot-picked", true);
  305. // initial state of pick elements
  306. generalPick("221: Random Number",
  307. "RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.",
  308. "https://www.explainxkcd.com/wiki/images/f/fe/random_number.png", 221);
  309. // initial state of select elements
  310. generalSelect(dataStore.selected_sn);
  311. // BUG: call again to fix incomplete draw barchart
  312. requestBarchartData();
  313. // add clear feature to clear selection button
  314. $("#button-clear-featureDistribution").click(function(){
  315. $("#select-featureDistribution option:selected").prop("selected", false);
  316. $('#selected-featureDistribution').text("");
  317. requestFeatureDistribution([]);
  318. });
  319. // initialize all popovers
  320. $(function () {
  321. $('[data-toggle="popover"]').popover()
  322. });
  323. </script>
  324. </body>
  325. </html>