├── config ├── .gitignore └── plex_vis.cfg.sample ├── .gitignore ├── __init__.py ├── requirements.txt ├── run_vis.sh ├── templates ├── login.html ├── layout.html ├── show_entries.html └── index.html ├── css ├── d3.slider.css ├── ourstyles.css └── normalize.css ├── README.md ├── plex_vis.py ├── js ├── d3.slider.js └── bubblechart.js └── LICENSE /config/.gitignore: -------------------------------------------------------------------------------- 1 | *.cfg 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | plexpy.db 2 | data/* 3 | *.pyc 4 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | from .plex_vis import app 2 | 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PlexAPI==2.0.2 2 | Flask==0.12 3 | -------------------------------------------------------------------------------- /config/plex_vis.cfg.sample: -------------------------------------------------------------------------------- 1 | SECRET_KEY="" 2 | PLEXPY_KEY="" 3 | PLEXPY_URL="" 4 | APP_URL="" 5 | ADMIN="" 6 | -------------------------------------------------------------------------------- /run_vis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export CONFIG="config/plex_vis.cfg" 3 | 4 | export FLASK_APP=plex_vis.py 5 | flask run --host=0.0.0.0 --with-threads 6 | 7 | -------------------------------------------------------------------------------- /templates/login.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block body %} 3 | {% if error %}

Error: {{ error }}{% endif %} 4 |

5 |

Login

6 |
7 | 8 | 9 | 10 |
11 |
12 | {% endblock %} 13 | -------------------------------------------------------------------------------- /templates/layout.html: -------------------------------------------------------------------------------- 1 | 2 | Plex Visualizer 3 | 4 | 5 |
6 |

Plex Visualizer

7 | {% for message in get_flashed_messages() %} 8 |
{{ message }}
9 | {% endfor %} 10 | {% block body %}{% endblock %} 11 |
12 | -------------------------------------------------------------------------------- /templates/show_entries.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% block body %} 3 | {% if session.logged_in %} 4 |
5 |
6 |
Title: 7 |
8 |
Text: 9 |
10 |
11 |
12 |
13 | {% endif %} 14 | 21 | {% endblock %} 22 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 42 | 43 |
44 |
45 |
Filter Years
46 |
47 |
48 |
49 |
Zoom
50 |
51 |
52 | 53 | 55 |
56 |
57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /css/d3.slider.css: -------------------------------------------------------------------------------- 1 | .d3-slider { 2 | position: relative; 3 | font-family: Verdana,Arial,sans-serif; 4 | font-size: 1.1em; 5 | border: 1px solid #aaaaaa; 6 | z-index: 2; 7 | } 8 | 9 | .d3-slider-horizontal { 10 | height: .8em; 11 | } 12 | 13 | .d3-slider-range { 14 | background:#2980b9; 15 | left:0px; 16 | right:0px; 17 | height: 0.8em; 18 | position: absolute; 19 | } 20 | 21 | .d3-slider-range-vertical { 22 | background:#2980b9; 23 | left:0px; 24 | right:0px; 25 | position: absolute; 26 | top:0; 27 | } 28 | 29 | .d3-slider-vertical { 30 | width: .8em; 31 | height: 100px; 32 | } 33 | 34 | .d3-slider-handle { 35 | position: absolute; 36 | width: 1.2em; 37 | height: 1.2em; 38 | border: 1px solid #d3d3d3; 39 | border-radius: 4px; 40 | background: #eee; 41 | background: linear-gradient(to bottom, #eee 0%, #ddd 100%); 42 | z-index: 3; 43 | } 44 | 45 | .d3-slider-handle:hover { 46 | border: 1px solid #999999; 47 | } 48 | 49 | .d3-slider-horizontal .d3-slider-handle { 50 | top: -.3em; 51 | margin-left: -.6em; 52 | } 53 | 54 | .d3-slider-axis { 55 | position: relative; 56 | z-index: 1; 57 | } 58 | 59 | .d3-slider-axis-bottom { 60 | top: .8em; 61 | } 62 | 63 | .d3-slider-axis-right { 64 | left: .8em; 65 | } 66 | 67 | .d3-slider-axis path { 68 | stroke-width: 0; 69 | fill: none; 70 | } 71 | 72 | .d3-slider-axis line { 73 | fill: none; 74 | stroke: #aaa; 75 | shape-rendering: crispEdges; 76 | } 77 | 78 | .d3-slider-axis text { 79 | font-size: 11px; 80 | fill: #999; 81 | } 82 | 83 | .d3-slider-vertical .d3-slider-handle { 84 | left: -.25em; 85 | margin-left: 0; 86 | margin-bottom: -.6em; 87 | } 88 | 89 | .slider_div { 90 | color: #999; 91 | } -------------------------------------------------------------------------------- /css/ourstyles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: "Open Sans"; 3 | background-color:#1f1f1f; 4 | margin:0; 5 | } 6 | 7 | h1 { 8 | color:#f9be03; 9 | } 10 | 11 | h2 { 12 | color:#f9be03; 13 | } 14 | 15 | ul { 16 | list-style: none; 17 | line-height: 50px; 18 | padding-left: 0px; 19 | border-left-width: 0px; 20 | border-right-width: 0px; 21 | border-bottom-width: 0px; 22 | border-top-color:#f9be03; 23 | border-style: solid; 24 | -webkit-margin-before: 0em; 25 | -webkit-margin-after: 0em; 26 | } 27 | 28 | li { 29 | padding-left: 15px; 30 | } 31 | .slider_div { 32 | padding: 10px 30px; 33 | } 34 | 35 | form { 36 | color: 999; 37 | } 38 | 39 | #sliders { 40 | background-color:#282828; 41 | width:260px; 42 | height: calc(100vh - 40px); 43 | float:left; 44 | margin-top: 20px; 45 | margin-left: 20px; 46 | border-radius: 4px; 47 | } 48 | 49 | .button { 50 | color: #999; 51 | font-size: 14px; 52 | border-bottom: 1px solid #232323; 53 | border-top: 1px solid #2d2d2d; 54 | } 55 | 56 | .button-active { 57 | background-color: #2f2f2f; 58 | color: #f9be03; 59 | } 60 | 61 | .button:hover { 62 | text-decoration: none; 63 | background-color: #282828; 64 | color: #eee; 65 | } 66 | 67 | .label { 68 | font-size: 14px; 69 | } 70 | 71 | 72 | #loginbox { 73 | display:flex; 74 | flex-direction:column; 75 | align-content: center; 76 | width:300px; 77 | background: #3a3a3a; 78 | border-radius: 3px; 79 | border: 1px #444 solid; 80 | padding: 20px; 81 | position: absolute; 82 | top: 50%; 83 | left: 50%; 84 | transform: translate(-50%, -50%); 85 | } 86 | 87 | #loginbox h1 { 88 | margin: 0 0 15px 0; 89 | text-align:center; 90 | } 91 | 92 | #loginbox input { 93 | box-shadow: inset 0px 0px 2px rgba(0, 0, 0, 0.2); 94 | border: 1px solid #b9b9b9; 95 | border-radius: 2px; 96 | color: #505050; 97 | height: 26px; 98 | float: left; 99 | width:290px; 100 | margin-bottom:15px; 101 | padding-left: 8px; 102 | font-size:14px; 103 | } 104 | 105 | #loginbox #submit { 106 | background: #fff; 107 | color: #505050; 108 | font-size: 14px; 109 | border: 1px solid #afafaf; 110 | height: 30px; 111 | width: 88px; 112 | font-weight: 600; 113 | border-radius: 0 2px 2px 0; 114 | box-shadow: none; 115 | float: left; 116 | margin: 0 calc(50% - 44px); 117 | padding: 0; 118 | } 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Plex Visualizer 2 | 3 | A Visulizer to help you discover new media on your [Plex Media Server](https://plex.tv). 4 | 5 | ## Features 6 | 7 | * View and general view of TV Shows and Movies 8 | * All Bubbbles are sized relative to the amount that thing has been watched 9 | * Click on any bubble to expand it to get more information or to filter it out 10 | * Login to be able to filter things you've already watched (so long as its in the plexpy.db) 11 | * Split up bubbles by Years or Genres 12 | * Filter bubbles individually, by year or by genre 13 | 14 | There are many more features that I want to implement! 15 | 16 | ![TV Show View](http://i.imgur.com/Jg8U7cB.png) 17 | 18 | ## Installation 19 | 20 | * Clone the repository 21 | * Install the requirements in a virtualenv or on your machine 22 | * `pip install -r requirements.txt` 23 | * Place a copy of your plexpy.db in data/ 24 | * Copy the plex_vis.cfg.sample to the same directory (minus the .sample) and fill in the nessicary information 25 | * SECRET_KEY: A randomly generated key to keep session info safe 26 | * PLEYPY_KEY: A plexpy API Key 27 | * PLEXPY_URL: The url to your plexpy instance. Must be accessible by the app but not necessarily by the end user 28 | * APP_URL: The public URL of the app (so that the frontend can make proxied requests) 29 | * ADMIN: The Admin user that will be able to run additional functions 30 | 31 | From here you can just execute the run_vis.sh script from the same directory to run the app! (Systemd/init.d defintions coming soon!) 32 | 33 | ## Admin Interface 34 | There are multiple endpoints that you can hit as the ADMIN account that lets you run various operations: 35 | * /regen: Regenerate the cache for anyone who is not logged in. This cache gets generated automatically the first time the server is run but never again after 36 | * /test: For somereason not all the rating_keys in my database were correct (or the latest?) as such some of the bubbles wouldn't appear properly. Running the /test endpoint will give you an output on the console of both shows and movies that have invalid rating_keys. Navigating to those rating_keys on plexpy will allow you to update the old entries and thus fix them. 37 | 38 | ## Screenshots 39 | The first view you see when you first enter the page. Lets you choose between the TV Shows and Movies on your server 40 | ![First View](http://i.imgur.com/Wl4yXJY.png) 41 | 42 | You can expand any of the bubbles to get more information about that Show/Movie 43 | ![Expanded View](http://i.imgur.com/aO7coeh.png) 44 | 45 | You can split up the chart by genre to help you narrow down what you want to watch 46 | ![Split Genre](http://i.imgur.com/IIYb1GU.png) 47 | 48 | You can also split up by year in case you are feeling an older or newer Show/Movie! 49 | ![Split Year](http://i.imgur.com/r7bhHmm.png) 50 | 51 | ## Issues 52 | 53 | There's still a lot that I want to do with this so feel free to open up an Issue and I'll try to get to it! 54 | 55 | ## Contributing 56 | 57 | I could use all the help I can get so please feel free to open up a PR if you want to contribute. 58 | 59 | There's a lot of clean up and documentation that I still need to do so I won't hold you to any standard but please try to document the functionality you add! 60 | 61 | ## License 62 | 63 | This is free software under the GPL v3 open source license. Feel free to do with it what you wish, but any modification must be open sourced. A copy of the license is included. 64 | -------------------------------------------------------------------------------- /css/normalize.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css v6.0.0 | MIT License | github.com/necolas/normalize.css */ 2 | 3 | /* Document 4 | ========================================================================== */ 5 | 6 | /** 7 | * 1. Correct the line height in all browsers. 8 | * 2. Prevent adjustments of font size after orientation changes in 9 | * IE on Windows Phone and in iOS. 10 | */ 11 | 12 | html { 13 | line-height: 1.15; /* 1 */ 14 | -ms-text-size-adjust: 100%; /* 2 */ 15 | -webkit-text-size-adjust: 100%; /* 2 */ 16 | } 17 | 18 | /* Sections 19 | ========================================================================== */ 20 | 21 | /** 22 | * Add the correct display in IE 9-. 23 | */ 24 | 25 | article, 26 | aside, 27 | footer, 28 | header, 29 | nav, 30 | section { 31 | display: block; 32 | } 33 | 34 | /** 35 | * Correct the font size and margin on `h1` elements within `section` and 36 | * `article` contexts in Chrome, Firefox, and Safari. 37 | */ 38 | 39 | h1 { 40 | font-size: 2em; 41 | margin: 0.67em 0; 42 | } 43 | 44 | /* Grouping content 45 | ========================================================================== */ 46 | 47 | /** 48 | * Add the correct display in IE 9-. 49 | * 1. Add the correct display in IE. 50 | */ 51 | 52 | figcaption, 53 | figure, 54 | main { /* 1 */ 55 | display: block; 56 | } 57 | 58 | /** 59 | * Add the correct margin in IE 8. 60 | */ 61 | 62 | figure { 63 | margin: 1em 40px; 64 | } 65 | 66 | /** 67 | * 1. Add the correct box sizing in Firefox. 68 | * 2. Show the overflow in Edge and IE. 69 | */ 70 | 71 | hr { 72 | box-sizing: content-box; /* 1 */ 73 | height: 0; /* 1 */ 74 | overflow: visible; /* 2 */ 75 | } 76 | 77 | /** 78 | * 1. Correct the inheritance and scaling of font size in all browsers. 79 | * 2. Correct the odd `em` font sizing in all browsers. 80 | */ 81 | 82 | pre { 83 | font-family: monospace, monospace; /* 1 */ 84 | font-size: 1em; /* 2 */ 85 | } 86 | 87 | /* Text-level semantics 88 | ========================================================================== */ 89 | 90 | /** 91 | * 1. Remove the gray background on active links in IE 10. 92 | * 2. Remove gaps in links underline in iOS 8+ and Safari 8+. 93 | */ 94 | 95 | a { 96 | background-color: transparent; /* 1 */ 97 | -webkit-text-decoration-skip: objects; /* 2 */ 98 | } 99 | 100 | /** 101 | * 1. Remove the bottom border in Chrome 57- and Firefox 39-. 102 | * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. 103 | */ 104 | 105 | abbr[title] { 106 | border-bottom: none; /* 1 */ 107 | text-decoration: underline; /* 2 */ 108 | text-decoration: underline dotted; /* 2 */ 109 | } 110 | 111 | /** 112 | * Prevent the duplicate application of `bolder` by the next rule in Safari 6. 113 | */ 114 | 115 | b, 116 | strong { 117 | font-weight: inherit; 118 | } 119 | 120 | /** 121 | * Add the correct font weight in Chrome, Edge, and Safari. 122 | */ 123 | 124 | b, 125 | strong { 126 | font-weight: bolder; 127 | } 128 | 129 | /** 130 | * 1. Correct the inheritance and scaling of font size in all browsers. 131 | * 2. Correct the odd `em` font sizing in all browsers. 132 | */ 133 | 134 | code, 135 | kbd, 136 | samp { 137 | font-family: monospace, monospace; /* 1 */ 138 | font-size: 1em; /* 2 */ 139 | } 140 | 141 | /** 142 | * Add the correct font style in Android 4.3-. 143 | */ 144 | 145 | dfn { 146 | font-style: italic; 147 | } 148 | 149 | /** 150 | * Add the correct background and color in IE 9-. 151 | */ 152 | 153 | mark { 154 | background-color: #ff0; 155 | color: #000; 156 | } 157 | 158 | /** 159 | * Add the correct font size in all browsers. 160 | */ 161 | 162 | small { 163 | font-size: 80%; 164 | } 165 | 166 | /** 167 | * Prevent `sub` and `sup` elements from affecting the line height in 168 | * all browsers. 169 | */ 170 | 171 | sub, 172 | sup { 173 | font-size: 75%; 174 | line-height: 0; 175 | position: relative; 176 | vertical-align: baseline; 177 | } 178 | 179 | sub { 180 | bottom: -0.25em; 181 | } 182 | 183 | sup { 184 | top: -0.5em; 185 | } 186 | 187 | /* Embedded content 188 | ========================================================================== */ 189 | 190 | /** 191 | * Add the correct display in IE 9-. 192 | */ 193 | 194 | audio, 195 | video { 196 | display: inline-block; 197 | } 198 | 199 | /** 200 | * Add the correct display in iOS 4-7. 201 | */ 202 | 203 | audio:not([controls]) { 204 | display: none; 205 | height: 0; 206 | } 207 | 208 | /** 209 | * Remove the border on images inside links in IE 10-. 210 | */ 211 | 212 | img { 213 | border-style: none; 214 | } 215 | 216 | /** 217 | * Hide the overflow in IE. 218 | */ 219 | 220 | svg:not(:root) { 221 | overflow: hidden; 222 | } 223 | 224 | /* Forms 225 | ========================================================================== */ 226 | 227 | /** 228 | * Remove the margin in Firefox and Safari. 229 | */ 230 | 231 | button, 232 | input, 233 | optgroup, 234 | select, 235 | textarea { 236 | margin: 0; 237 | } 238 | 239 | /** 240 | * Show the overflow in IE. 241 | * 1. Show the overflow in Edge. 242 | */ 243 | 244 | button, 245 | input { /* 1 */ 246 | overflow: visible; 247 | } 248 | 249 | /** 250 | * Remove the inheritance of text transform in Edge, Firefox, and IE. 251 | * 1. Remove the inheritance of text transform in Firefox. 252 | */ 253 | 254 | button, 255 | select { /* 1 */ 256 | text-transform: none; 257 | } 258 | 259 | /** 260 | * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video` 261 | * controls in Android 4. 262 | * 2. Correct the inability to style clickable types in iOS and Safari. 263 | */ 264 | 265 | button, 266 | html [type="button"], /* 1 */ 267 | [type="reset"], 268 | [type="submit"] { 269 | -webkit-appearance: button; /* 2 */ 270 | } 271 | 272 | /** 273 | * Remove the inner border and padding in Firefox. 274 | */ 275 | 276 | button::-moz-focus-inner, 277 | [type="button"]::-moz-focus-inner, 278 | [type="reset"]::-moz-focus-inner, 279 | [type="submit"]::-moz-focus-inner { 280 | border-style: none; 281 | padding: 0; 282 | } 283 | 284 | /** 285 | * Restore the focus styles unset by the previous rule. 286 | */ 287 | 288 | button:-moz-focusring, 289 | [type="button"]:-moz-focusring, 290 | [type="reset"]:-moz-focusring, 291 | [type="submit"]:-moz-focusring { 292 | outline: 1px dotted ButtonText; 293 | } 294 | 295 | /** 296 | * 1. Correct the text wrapping in Edge and IE. 297 | * 2. Correct the color inheritance from `fieldset` elements in IE. 298 | * 3. Remove the padding so developers are not caught out when they zero out 299 | * `fieldset` elements in all browsers. 300 | */ 301 | 302 | legend { 303 | box-sizing: border-box; /* 1 */ 304 | color: inherit; /* 2 */ 305 | display: table; /* 1 */ 306 | max-width: 100%; /* 1 */ 307 | padding: 0; /* 3 */ 308 | white-space: normal; /* 1 */ 309 | } 310 | 311 | /** 312 | * 1. Add the correct display in IE 9-. 313 | * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera. 314 | */ 315 | 316 | progress { 317 | display: inline-block; /* 1 */ 318 | vertical-align: baseline; /* 2 */ 319 | } 320 | 321 | /** 322 | * Remove the default vertical scrollbar in IE. 323 | */ 324 | 325 | textarea { 326 | overflow: auto; 327 | } 328 | 329 | /** 330 | * 1. Add the correct box sizing in IE 10-. 331 | * 2. Remove the padding in IE 10-. 332 | */ 333 | 334 | [type="checkbox"], 335 | [type="radio"] { 336 | box-sizing: border-box; /* 1 */ 337 | padding: 0; /* 2 */ 338 | } 339 | 340 | /** 341 | * Correct the cursor style of increment and decrement buttons in Chrome. 342 | */ 343 | 344 | [type="number"]::-webkit-inner-spin-button, 345 | [type="number"]::-webkit-outer-spin-button { 346 | height: auto; 347 | } 348 | 349 | /** 350 | * 1. Correct the odd appearance in Chrome and Safari. 351 | * 2. Correct the outline style in Safari. 352 | */ 353 | 354 | [type="search"] { 355 | -webkit-appearance: textfield; /* 1 */ 356 | outline-offset: -2px; /* 2 */ 357 | } 358 | 359 | /** 360 | * Remove the inner padding and cancel buttons in Chrome and Safari on macOS. 361 | */ 362 | 363 | [type="search"]::-webkit-search-cancel-button, 364 | [type="search"]::-webkit-search-decoration { 365 | -webkit-appearance: none; 366 | } 367 | 368 | /** 369 | * 1. Correct the inability to style clickable types in iOS and Safari. 370 | * 2. Change font properties to `inherit` in Safari. 371 | */ 372 | 373 | ::-webkit-file-upload-button { 374 | -webkit-appearance: button; /* 1 */ 375 | font: inherit; /* 2 */ 376 | } 377 | 378 | /* Interactive 379 | ========================================================================== */ 380 | 381 | /* 382 | * Add the correct display in IE 9-. 383 | * 1. Add the correct display in Edge, IE, and Firefox. 384 | */ 385 | 386 | details, /* 1 */ 387 | menu { 388 | display: block; 389 | } 390 | 391 | /* 392 | * Add the correct display in all browsers. 393 | */ 394 | 395 | summary { 396 | display: list-item; 397 | } 398 | 399 | /* Scripting 400 | ========================================================================== */ 401 | 402 | /** 403 | * Add the correct display in IE 9-. 404 | */ 405 | 406 | canvas { 407 | display: inline-block; 408 | } 409 | 410 | /** 411 | * Add the correct display in IE. 412 | */ 413 | 414 | template { 415 | display: none; 416 | } 417 | 418 | /* Hidden 419 | ========================================================================== */ 420 | 421 | /** 422 | * Add the correct display in IE 10-. 423 | */ 424 | 425 | [hidden] { 426 | display: none; 427 | } 428 | -------------------------------------------------------------------------------- /plex_vis.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import tempfile 4 | 5 | from sqlite3 import dbapi2 as sqlite3 6 | from flask import Flask, request, session, g, redirect, url_for, abort, \ 7 | render_template, flash, send_from_directory, jsonify, Response, stream_with_context 8 | 9 | import requests 10 | from plexapi.myplex import MyPlexAccount 11 | import json 12 | 13 | # create our little application :) 14 | app = Flask(__name__) 15 | app.config.from_envvar("CONFIG") 16 | plexpyapikey = app.config['PLEXPY_KEY'] 17 | plexpybaseurl = app.config['PLEXPY_URL'] 18 | app_root = app.root_path 19 | def connect_db(): 20 | """Connects to the specific database.""" 21 | rv = sqlite3.connect('data/plexpy.db') 22 | rv.row_factory = sqlite3.Row 23 | return rv 24 | 25 | def get_db(): 26 | """Opens a new database connection if there is none yet for the 27 | current application context. 28 | """ 29 | if not hasattr(g, 'sqlite_db'): 30 | g.sqlite_db = connect_db() 31 | return g.sqlite_db 32 | 33 | def get_movies(db,username): 34 | movie_query = db.execute("SELECT * FROM 'session_history_metadata' LEFT JOIN session_history ON session_history_metadata.id=session_history.id where session_history_metadata.media_type='movie'") 35 | movie_entries = movie_query.fetchall() 36 | movies={"name": "Movies", 37 | "size": 0} 38 | movies["children"] = [] 39 | # print movie_entries 40 | temp_movies = {} 41 | for entry in movie_entries: 42 | genre = entry["genres"].split(';')[0] 43 | if genre == "": 44 | genre = "None" 45 | 46 | if entry["title"] not in temp_movies.keys(): 47 | temp_movies[entry["title"]] = {} 48 | temp_movies[entry["title"]]["size"] = 0 49 | temp_movies[entry["title"]]["year"] = entry["year"] 50 | temp_movies[entry["title"]]["genre"] = genre 51 | temp_movies[entry["title"]]["watch"] = False 52 | temp_movies[entry["title"]]["key"] = entry["rating_key"] 53 | if username == entry["user"]: 54 | temp_movies[entry["title"]]["watch"] = True 55 | temp_movies[entry["title"]]["size"] += float(entry["stopped"] - entry["started"]) - float(entry["paused_counter"]) 56 | final_movies = [] 57 | 58 | for movie in temp_movies.keys(): 59 | movies["children"].append({"name": movie, 60 | "size": temp_movies[movie]["size"], 61 | "genre": temp_movies[movie]["genre"], 62 | "year": temp_movies[movie]["year"], 63 | "watch": temp_movies[movie]["watch"], 64 | "key": temp_movies[movie]["key"]}) 65 | movies["size"] += temp_movies[movie]["size"] 66 | return movies 67 | 68 | def get_tv(db,username): 69 | print "Getting TV" 70 | tv_query = db.execute("SELECT * FROM 'session_history_metadata' LEFT JOIN session_history ON session_history_metadata.id=session_history.id where session_history_metadata.media_type='episode'") 71 | tv_entries = tv_query.fetchall() 72 | tv={"name": "TV Shows", 73 | "size": 0} 74 | tv["children"] = [] 75 | temp = {} 76 | for entry in tv_entries: 77 | genre = entry["genres"].split(';')[0] 78 | if genre == "": 79 | genre = "None" 80 | if entry["grandparent_title"] not in temp.keys(): 81 | temp[entry["grandparent_title"]] = {} 82 | temp[entry["grandparent_title"]]["size"] = 0 83 | temp[entry["grandparent_title"]]["year"] = entry["year"] 84 | temp[entry["grandparent_title"]]["genre"] = genre 85 | temp[entry["grandparent_title"]]["watch"] = False 86 | temp[entry["grandparent_title"]]["key"] = entry["grandparent_rating_key"] 87 | if username == entry["user"]: 88 | temp[entry["grandparent_title"]]["watch"] = True 89 | temp[entry["grandparent_title"]]["size"] += float(entry["stopped"] - entry["started"]) - float(entry["paused_counter"]) 90 | 91 | for show in temp.keys(): 92 | tv["children"].append({"name": show, 93 | "size": temp[show]["size"], 94 | "genre": temp[show]["genre"], 95 | "year": temp[show]["year"], 96 | "watch": temp[show]["watch"], 97 | "key": temp[show]["key"]}) 98 | tv["size"] += temp[show]["size"] 99 | return tv 100 | 101 | 102 | @app.teardown_appcontext 103 | def close_db(error): 104 | """Closes the database again at the end of the request.""" 105 | if hasattr(g, 'sqlite_db'): 106 | g.sqlite_db.close() 107 | 108 | @app.route('/js/') 109 | def send_js(path): 110 | return send_from_directory('js', path) 111 | 112 | @app.route('/data/') 113 | def send_data(path): 114 | return send_from_directory('data', path) 115 | 116 | @app.route('/css/') 117 | def send_css(path): 118 | return send_from_directory('css', path) 119 | 120 | @app.route('/') 121 | def show_entries(): 122 | username = "" 123 | if session.get('logged_in'): 124 | username = session['username'] 125 | print("Logged In!") 126 | if "datafile" in session and os.path.isfile(app.root_path + session['datafile']): 127 | print "datafile exists" 128 | datafile = session['datafile'] 129 | else: 130 | db = get_db() 131 | movies = get_movies(db, username) 132 | tv = get_tv(db, username) 133 | output = { "loggedIn": True, "Movies": movies,"TV": tv} 134 | fs,datafile = tempfile.mkstemp(dir='data/', suffix=".json") 135 | with open(datafile, 'w') as outfile: 136 | json.dump(output, outfile, indent=4) 137 | datafile = datafile.replace(app.root_path,"") 138 | session['datafile'] = datafile 139 | else: 140 | datafile = "/data/notLoggedIn.json" 141 | if not os.path.isfile(app.root_path + datafile): 142 | datafile = regen(force = True) 143 | return render_template('index.html',data=datafile) 144 | 145 | 146 | @app.route('/regen') 147 | def regen(force=False): 148 | username = "" 149 | if (session.get('logged_in') and session['username'] == app.config["ADMIN"]) or force: 150 | print("Logged In!") 151 | db = get_db() 152 | movies = get_movies(db, username) 153 | tv = get_tv(db, username) 154 | output = { "loggedIn": False, "Movies": movies,"TV": tv} 155 | datafile = app.root_path + "/data/notLoggedIn.json" 156 | with open(datafile, 'w') as outfile: 157 | json.dump(output, outfile, indent=4) 158 | datafile = datafile.replace(app.root_path,"") 159 | if force: 160 | return datafile 161 | return render_template('index.html',data=datafile) 162 | else: 163 | abort(401) 164 | 165 | @app.route('/test') 166 | def testMeta(): 167 | username = "" 168 | if session.get('logged_in') and session['username'] == app.config["ADMIN"]: 169 | print("Logged In!") 170 | db = get_db() 171 | movies = get_movies(db, username) 172 | tv = get_tv(db, username) 173 | errors = [] 174 | for show in tv["children"]: 175 | print "/metadata/"+ str(show["key"]) 176 | r = requests.get(app.config['APP_URL'] + "metadata/" + str(show["key"])) 177 | if json.loads(r.json())["response"]["result"] == "error": 178 | errors.append([show["key"], show["name"], show["year"]]) 179 | print "Error with " + str(show["key"]) + ". Expecting " + show["name"] 180 | for movie in movies["children"]: 181 | print "/metadata/"+ str(movie["key"]) 182 | r = requests.get(app.config['APP_URL'] + "metadata/" + str(movie["key"])) 183 | if json.loads(r.json())["response"]["result"] == "error": 184 | errors.append([movie["key"], movie["name"], movie["year"]]) 185 | print "Error with " + str(movie["key"]) + ". Expecting " + movie["name"] 186 | for error in errors: 187 | print "Error with " + str(error[0]) + " Expecting " + error[1] + str(error[2]) 188 | datafile = "/data/notLoggedIn.json" 189 | return render_template('index.html',data=datafile) 190 | else: 191 | abort(401) 192 | 193 | 194 | @app.route('/login', methods=['GET', 'POST']) 195 | def login(): 196 | error = None 197 | if request.method == 'POST': 198 | try: 199 | account = MyPlexAccount.signin(request.form['username'], request.form['password']) 200 | session['username'] = account.username 201 | session['logged_in'] = True 202 | flash('You were logged in') 203 | return redirect(url_for('show_entries')) 204 | except: 205 | print("Login failed") 206 | return render_template('login.html', error="Login Failed") 207 | return render_template('login.html', error=error) 208 | 209 | @app.route('/logout') 210 | def logout(): 211 | try: 212 | os.remove(app.root_path + session['datafile']) 213 | except: 214 | print("File already removed?") 215 | session.pop('logged_in', None) 216 | session.pop('username', None) 217 | session.pop('datafile', None) 218 | flash('You were logged out') 219 | return redirect(url_for('show_entries')) 220 | 221 | @app.route('/metadata/') 222 | def metadata(ratingkey=None): 223 | url = plexpybaseurl + "api/v2?apikey=" + plexpyapikey + "&cmd=get_metadata" 224 | r = requests.post(url, data={"rating_key": str(ratingkey), "media_info": True}) 225 | if r.json()["response"]["result"] == "error": 226 | print "Error with " + ratingkey 227 | print r.text 228 | return jsonify(json.dumps(r.json())) 229 | 230 | @app.route('/art') 231 | def art(ratingkey=None): 232 | link = request.args.get('link') 233 | width = request.args.get('width') 234 | height = request.args.get('height') 235 | url = plexpybaseurl + "api/v2?apikey=" + plexpyapikey + "&cmd=pms_image_proxy&img=" + link + "&width=" + width + "&height=" + height 236 | print(url) 237 | r = requests.get(url,stream=True) 238 | return Response(stream_with_context(r.iter_content(4096)), content_type = r.headers['content-type']) 239 | 240 | if __name__ == "__main__": 241 | app.run(threaded=True) 242 | -------------------------------------------------------------------------------- /js/d3.slider.js: -------------------------------------------------------------------------------- 1 | /* 2 | D3.js Slider 3 | Inspired by jQuery UI Slider 4 | Copyright (c) 2013, Bjorn Sandvik - http://blog.thematicmapping.org 5 | BSD license: http://opensource.org/licenses/BSD-3-Clause 6 | */ 7 | (function (root, factory) { 8 | if (typeof define === 'function' && define.amd) { 9 | // AMD. Register as an anonymous module. 10 | define(['d3'], factory); 11 | } else if (typeof exports === 'object') { 12 | if (process.browser) { 13 | // Browserify. Import css too using cssify. 14 | require('../css/d3.slider.css'); 15 | } 16 | // Node. Does not work with strict CommonJS, but 17 | // only CommonJS-like environments that support module.exports, 18 | // like Node. 19 | module.exports = factory(require('d3')); 20 | } else { 21 | // Browser globals (root is window) 22 | root.d3.slider = factory(root.d3); 23 | } 24 | }(this, function (d3) { 25 | return function module() { 26 | "use strict"; 27 | 28 | // Public variables width default settings 29 | var min = 0, 30 | max = 100, 31 | step = 0.01, 32 | animate = true, 33 | orientation = "horizontal", 34 | axis = false, 35 | margin = 50, 36 | value, 37 | active = 1, 38 | snap = false, 39 | scale; 40 | 41 | // Private variables 42 | var axisScale, 43 | dispatch = d3.dispatch("slide", "slideend"), 44 | formatPercent = d3.format(".2%"), 45 | tickFormat = d3.format(".0"), 46 | handle1, 47 | handle2 = null, 48 | divRange, 49 | sliderLength; 50 | 51 | function slider(selection) { 52 | selection.each(function() { 53 | 54 | // Create scale if not defined by user 55 | if (!scale) { 56 | scale = d3.scale.linear().domain([min, max]); 57 | } 58 | 59 | // Start value 60 | value = value || scale.domain()[0]; 61 | 62 | // DIV container 63 | var div = d3.select(this).classed("d3-slider d3-slider-" + orientation, true); 64 | 65 | var drag = d3.behavior.drag(); 66 | drag.on('dragend', function () { 67 | dispatch.slideend(d3.event, value); 68 | }) 69 | 70 | // Slider handle 71 | //if range slider, create two 72 | // var divRange; 73 | 74 | if (toType(value) == "array" && value.length == 2) { 75 | handle1 = div.append("a") 76 | .classed("d3-slider-handle", true) 77 | .attr("xlink:href", "#") 78 | .attr('id', "handle-one") 79 | .on("click", stopPropagation) 80 | .call(drag); 81 | handle2 = div.append("a") 82 | .classed("d3-slider-handle", true) 83 | .attr('id', "handle-two") 84 | .attr("xlink:href", "#") 85 | .on("click", stopPropagation) 86 | .call(drag); 87 | } else { 88 | handle1 = div.append("a") 89 | .classed("d3-slider-handle", true) 90 | .attr("xlink:href", "#") 91 | .attr('id', "handle-one") 92 | .on("click", stopPropagation) 93 | .call(drag); 94 | } 95 | 96 | // Horizontal slider 97 | if (orientation === "horizontal") { 98 | 99 | div.on("click", onClickHorizontal); 100 | 101 | if (toType(value) == "array" && value.length == 2) { 102 | divRange = d3.select(this).append('div').classed("d3-slider-range", true); 103 | 104 | handle1.style("left", formatPercent(scale(value[ 0 ]))); 105 | divRange.style("left", formatPercent(scale(value[ 0 ]))); 106 | drag.on("drag", onDragHorizontal); 107 | 108 | var width = 100 - parseFloat(formatPercent(scale(value[ 1 ]))); 109 | handle2.style("left", formatPercent(scale(value[ 1 ]))); 110 | divRange.style("right", width+"%"); 111 | drag.on("drag", onDragHorizontal); 112 | 113 | } else { 114 | handle1.style("left", formatPercent(scale(value))); 115 | drag.on("drag", onDragHorizontal); 116 | } 117 | 118 | sliderLength = parseInt(div.style("width"), 10); 119 | 120 | } else { // Vertical 121 | 122 | div.on("click", onClickVertical); 123 | drag.on("drag", onDragVertical); 124 | if (toType(value) == "array" && value.length == 2) { 125 | divRange = d3.select(this).append('div').classed("d3-slider-range-vertical", true); 126 | 127 | handle1.style("bottom", formatPercent(scale(value[ 0 ]))); 128 | divRange.style("bottom", formatPercent(scale(value[ 0 ]))); 129 | drag.on("drag", onDragVertical); 130 | 131 | var top = 100 - parseFloat(formatPercent(scale(value[ 1 ]))); 132 | handle2.style("bottom", formatPercent(scale(value[ 1 ]))); 133 | divRange.style("top", top+"%"); 134 | drag.on("drag", onDragVertical); 135 | 136 | } else { 137 | handle1.style("bottom", formatPercent(scale(value))); 138 | drag.on("drag", onDragVertical); 139 | } 140 | 141 | sliderLength = parseInt(div.style("height"), 10); 142 | 143 | } 144 | 145 | if (axis) { 146 | createAxis(div); 147 | } 148 | 149 | 150 | function createAxis(dom) { 151 | 152 | // Create axis if not defined by user 153 | if (typeof axis === "boolean") { 154 | 155 | axis = d3.svg.axis() 156 | .ticks(Math.round(sliderLength / 100)) 157 | .tickFormat(tickFormat) 158 | .orient((orientation === "horizontal") ? "bottom" : "right"); 159 | 160 | } 161 | 162 | // Copy slider scale to move from percentages to pixels 163 | axisScale = scale.ticks ? scale.copy().range([0, sliderLength]) : scale.copy().rangePoints([0, sliderLength], 0.5); 164 | axis.scale(axisScale); 165 | 166 | // Create SVG axis container 167 | var svg = dom.append("svg") 168 | .classed("d3-slider-axis d3-slider-axis-" + axis.orient(), true) 169 | .on("click", stopPropagation); 170 | 171 | var g = svg.append("g"); 172 | 173 | // Horizontal axis 174 | if (orientation === "horizontal") { 175 | 176 | svg.style("margin-left", -margin + "px"); 177 | 178 | svg.attr({ 179 | width: sliderLength + margin * 2, 180 | height: margin 181 | }); 182 | 183 | if (axis.orient() === "top") { 184 | svg.style("top", -margin + "px"); 185 | g.attr("transform", "translate(" + margin + "," + margin + ")"); 186 | } else { // bottom 187 | g.attr("transform", "translate(" + margin + ",0)"); 188 | } 189 | 190 | } else { // Vertical 191 | 192 | svg.style("top", -margin + "px"); 193 | 194 | svg.attr({ 195 | width: margin, 196 | height: sliderLength + margin * 2 197 | }); 198 | 199 | if (axis.orient() === "left") { 200 | svg.style("left", -margin + "px"); 201 | g.attr("transform", "translate(" + margin + "," + margin + ")"); 202 | } else { // right 203 | g.attr("transform", "translate(" + 0 + "," + margin + ")"); 204 | } 205 | 206 | } 207 | 208 | g.call(axis); 209 | 210 | } 211 | 212 | function onClickHorizontal() { 213 | if (toType(value) != "array") { 214 | var pos = Math.max(0, Math.min(sliderLength, d3.event.offsetX || d3.event.layerX)); 215 | moveHandle(scale.invert ? 216 | stepValue(scale.invert(pos / sliderLength)) 217 | : nearestTick(pos / sliderLength)); 218 | } 219 | } 220 | 221 | function onClickVertical() { 222 | if (toType(value) != "array") { 223 | var pos = sliderLength - Math.max(0, Math.min(sliderLength, d3.event.offsetY || d3.event.layerY)); 224 | moveHandle(scale.invert ? 225 | stepValue(scale.invert(pos / sliderLength)) 226 | : nearestTick(pos / sliderLength)); 227 | } 228 | } 229 | 230 | function onDragHorizontal() { 231 | if ( d3.event.sourceEvent.target.id === "handle-one") { 232 | active = 1; 233 | } else if ( d3.event.sourceEvent.target.id == "handle-two" ) { 234 | active = 2; 235 | } 236 | var pos = Math.max(0, Math.min(sliderLength, d3.event.x)); 237 | moveHandle(scale.invert ? 238 | stepValue(scale.invert(pos / sliderLength)) 239 | : nearestTick(pos / sliderLength)); 240 | } 241 | 242 | function onDragVertical() { 243 | if ( d3.event.sourceEvent.target.id === "handle-one") { 244 | active = 1; 245 | } else if ( d3.event.sourceEvent.target.id == "handle-two" ) { 246 | active = 2; 247 | } 248 | var pos = sliderLength - Math.max(0, Math.min(sliderLength, d3.event.y)) 249 | moveHandle(scale.invert ? 250 | stepValue(scale.invert(pos / sliderLength)) 251 | : nearestTick(pos / sliderLength)); 252 | } 253 | 254 | function stopPropagation() { 255 | d3.event.stopPropagation(); 256 | } 257 | 258 | }); 259 | 260 | } 261 | 262 | // Move slider handle on click/drag 263 | function moveHandle(newValue) { 264 | var currentValue = toType(value) == "array" && value.length == 2 ? value[active - 1]: value, 265 | oldPos = formatPercent(scale(stepValue(currentValue))), 266 | newPos = formatPercent(scale(stepValue(newValue))), 267 | position = (orientation === "horizontal") ? "left" : "bottom"; 268 | if (oldPos !== newPos) { 269 | 270 | if (toType(value) == "array" && value.length == 2) { 271 | value[ active - 1 ] = newValue; 272 | if (d3.event) { 273 | dispatch.slide(d3.event, value ); 274 | }; 275 | } else { 276 | if (d3.event) { 277 | dispatch.slide(d3.event.sourceEvent || d3.event, value = newValue); 278 | }; 279 | } 280 | 281 | if ( value[ 0 ] >= value[ 1 ] ) return; 282 | if ( active === 1 ) { 283 | if (toType(value) == "array" && value.length == 2) { 284 | (position === "left") ? divRange.style("left", newPos) : divRange.style("bottom", newPos); 285 | } 286 | 287 | if (animate) { 288 | handle1.transition() 289 | .styleTween(position, function() { return d3.interpolate(oldPos, newPos); }) 290 | .duration((typeof animate === "number") ? animate : 250); 291 | } else { 292 | handle1.style(position, newPos); 293 | } 294 | } else { 295 | 296 | var width = 100 - parseFloat(newPos); 297 | var top = 100 - parseFloat(newPos); 298 | 299 | (position === "left") ? divRange.style("right", width + "%") : divRange.style("top", top + "%"); 300 | 301 | if (animate) { 302 | handle2.transition() 303 | .styleTween(position, function() { return d3.interpolate(oldPos, newPos); }) 304 | .duration((typeof animate === "number") ? animate : 250); 305 | } else { 306 | handle2.style(position, newPos); 307 | } 308 | } 309 | } 310 | } 311 | 312 | // Calculate nearest step value 313 | function stepValue(val) { 314 | 315 | if (val === scale.domain()[0] || val === scale.domain()[1]) { 316 | return val; 317 | } 318 | 319 | var alignValue = val; 320 | if (snap) { 321 | alignValue = nearestTick(scale(val)); 322 | } else{ 323 | var valModStep = (val - scale.domain()[0]) % step; 324 | alignValue = val - valModStep; 325 | 326 | if (Math.abs(valModStep) * 2 >= step) { 327 | alignValue += (valModStep > 0) ? step : -step; 328 | } 329 | }; 330 | 331 | return alignValue; 332 | 333 | } 334 | 335 | // Find the nearest tick 336 | function nearestTick(pos) { 337 | var ticks = scale.ticks ? scale.ticks() : scale.domain(); 338 | var dist = ticks.map(function(d) {return pos - scale(d);}); 339 | var i = -1, 340 | index = 0, 341 | r = scale.ticks ? scale.range()[1] : scale.rangeExtent()[1]; 342 | do { 343 | i++; 344 | if (Math.abs(dist[i]) < r) { 345 | r = Math.abs(dist[i]); 346 | index = i; 347 | }; 348 | } while (dist[i] > 0 && i < dist.length - 1); 349 | 350 | return ticks[index]; 351 | }; 352 | 353 | // Return the type of an object 354 | function toType(v) { 355 | return ({}).toString.call(v).match(/\s([a-zA-Z]+)/)[1].toLowerCase(); 356 | }; 357 | 358 | // Getter/setter functions 359 | slider.min = function(_) { 360 | if (!arguments.length) return min; 361 | min = _; 362 | return slider; 363 | }; 364 | 365 | slider.max = function(_) { 366 | if (!arguments.length) return max; 367 | max = _; 368 | return slider; 369 | }; 370 | 371 | slider.step = function(_) { 372 | if (!arguments.length) return step; 373 | step = _; 374 | return slider; 375 | }; 376 | 377 | slider.animate = function(_) { 378 | if (!arguments.length) return animate; 379 | animate = _; 380 | return slider; 381 | }; 382 | 383 | slider.orientation = function(_) { 384 | if (!arguments.length) return orientation; 385 | orientation = _; 386 | return slider; 387 | }; 388 | 389 | slider.axis = function(_) { 390 | if (!arguments.length) return axis; 391 | axis = _; 392 | return slider; 393 | }; 394 | 395 | slider.margin = function(_) { 396 | if (!arguments.length) return margin; 397 | margin = _; 398 | return slider; 399 | }; 400 | 401 | slider.value = function(_) { 402 | if (!arguments.length) return value; 403 | if (value) { 404 | moveHandle(stepValue(_)); 405 | }; 406 | value = _; 407 | return slider; 408 | }; 409 | 410 | slider.snap = function(_) { 411 | if (!arguments.length) return snap; 412 | snap = _; 413 | return slider; 414 | }; 415 | 416 | slider.scale = function(_) { 417 | if (!arguments.length) return scale; 418 | scale = _; 419 | return slider; 420 | }; 421 | 422 | d3.rebind(slider, dispatch, "on"); 423 | 424 | return slider; 425 | 426 | } 427 | })); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | 677 | -------------------------------------------------------------------------------- /js/bubblechart.js: -------------------------------------------------------------------------------- 1 | function hashCode(str) { // java String#hashCode 2 | var hash = 0; 3 | for (var i = 0; i < str.length; i++) { 4 | hash = str.charCodeAt(i) + ((hash << 5) - hash); 5 | } 6 | return hash; 7 | } 8 | 9 | function inArray(myArray,myValue){ 10 | var inArray = false; 11 | myArray.map(function(key){ 12 | if (key == myValue){ 13 | inArray=true; 14 | } 15 | }); 16 | return inArray; 17 | }; 18 | 19 | function plex_chart() { 20 | // Global Constants 21 | // Page size conatants 22 | var sidebar_width = 298 23 | var width = window.innerWidth-sidebar_width; 24 | var height = window.innerHeight; 25 | var center = { x: width / 2, y: height / 2 }; 26 | var max_radius = area_to_radius(.015*width*height); 27 | // if (max_radius <= 30) {max_radius = 30} 28 | 29 | 30 | // Animation Speed 31 | var damper = 0.104; 32 | 33 | // Slider params 34 | var scaleing = 1 35 | var min_year = 1917; 36 | var max_year = 2017; 37 | 38 | // Additonal vars 39 | var active = "root" 40 | var loggedIn = false 41 | 42 | // All the objects 43 | var globalGroups = []; 44 | var svg = null; 45 | var bubbles = null; 46 | var orig_nodes = null; 47 | var nodes = []; 48 | var nodes_to_display =[]; 49 | var stateHistory = []; 50 | var nav_buttons = []; 51 | var groups = []; 52 | var colorMapping = [] 53 | var years_to_show = [min_year, max_year] 54 | var filter_watched = false 55 | 56 | var toggled_groups = [] 57 | var label_filter_functions = {} 58 | var nodes_filter_functions = {} 59 | 60 | // crime: #201BAE 61 | //// Adventrue: #E3033F 62 | // Adventure: #F72C25 63 | // Movies: #F9E603 64 | // TV Shows: #F72C25 65 | // Children: #9844ff 66 | // Comedy:#32b6ef 67 | // Scifi: #78db00 68 | // Kids: f20e62 69 | //#C2F003 70 | 71 | var colors =["#f9e603", "#F72C25", "#0D5CA2", "#9844ff", 72 | "#32b6ef", "#201BAE", "#FB5003", "#FB9403", 73 | "#02A96A", "#00b916", "#badfad", "#a50520", 74 | "#FADBAD", "#f20e62", "#BEDBAD", "#BADBED", 75 | "#FEDBED", "#BEDFED", "#4b81ff", "#484848", 76 | "#848484", "#78db00", "#987654", "#456789", 77 | "#654321", "#456654", "#123321", "#F9E603", 78 | "#F72C25", "#FEDBAC", "#CADFED" 79 | ]; 80 | // var data = []; 81 | 82 | // Functions that get changed depending on whats happening 83 | var targetFunction = moveToCenter 84 | var renderFunction = render_root 85 | var onClickFunction = expandEntity 86 | var groupActionFunction = toggleGroup 87 | var groupFilter = function (d) {return d.genre}; 88 | var groupSort = function (a,b) {return d3.ascending(a,b)} 89 | var deleteFunction = function(d, toDelete) {if (groupFilter(toDelete) != groupFilter(d)) { 90 | return d 91 | }} 92 | 93 | 94 | var force = d3.layout.force() 95 | .size([width, height]) 96 | .charge(charge) 97 | // .gravity(-0.01) 98 | // .friction(0.8); 99 | 100 | var div = d3.select("body") 101 | .append("div") // declare the tooltip div 102 | .attr("class", "tooltip") 103 | .style("opacity", 0); 104 | 105 | // General Functions 106 | function charge(d) { 107 | return -Math.pow(d.radius*scaleing, 2.0) / 3.5; 108 | } 109 | 110 | function radius_to_area(radius) { 111 | let area = Math.pow(radius,2)*Math.PI() 112 | return area 113 | } 114 | 115 | function area_to_radius(area) { 116 | let radius = Math.pow(area/Math.PI, .5) 117 | return radius 118 | } 119 | 120 | function getClassColor(i){ 121 | let index = colorMapping.indexOf(i) 122 | if (index > -1) return colors[index]; 123 | return "#f9be03" 124 | } 125 | 126 | function setClassColor(data){ 127 | var all_groups = new Set() 128 | data.forEach(function (d) { d.children.forEach(function (e) {all_groups.add(e)})}) 129 | local_groups = groups_from_data(all_groups) 130 | local_groups.push({"name": "Movies", "size": "0"}) 131 | local_groups.push({"name": "TV Shows", "size": "0"}) 132 | local_groups.forEach(function (d,i) { colorMapping.push(d.name)}) 133 | } 134 | 135 | function wrap(text, width) { 136 | console.log(text) 137 | console.log(width) 138 | text.each(function() { 139 | var text = d3.select(this), 140 | words = text.text().split(/\s+/).reverse(), 141 | word, 142 | line = [], 143 | lineNumber = 0, 144 | lineHeight = 1.1 // ems 145 | y = text.attr("y"), 146 | dy = parseFloat(text.attr("dy")), 147 | tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em"); 148 | while (word = words.pop()) { 149 | word = word.replace("'''","") 150 | line.push(word); 151 | tspan.text(line.join(" ")); 152 | if (tspan.node().getComputedTextLength() > width) { 153 | line.pop(); 154 | tspan.text(line.join(" ")); 155 | line = [word]; 156 | tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word); 157 | } 158 | } 159 | }); 160 | } 161 | 162 | function calcPageSize() { 163 | width = window.innerWidth-sidebar_width; 164 | height = window.innerHeight; 165 | center = { x: width / 2, y: height / 2 }; 166 | max_radius = area_to_radius(.025*width*height); 167 | if (max_radius <= 30) {max_radius = 30} 168 | force.alpha(100000); 169 | animate() 170 | } 171 | 172 | function renderSidebar(data) { 173 | console.log("Rendering sidebar") 174 | data = JSON.parse(data) 175 | console.log(data.response.data.metadata); 176 | data = data.response.data.metadata 177 | 178 | // spans = text_to_spans(data.summary, (width*.25)-()) 179 | 180 | overlay = svg.append("g") 181 | overlay 182 | .classed("movieOverlay",true) 183 | .on("click", function(d) {svg.select("g.movieOverlay").remove()}) 184 | 185 | 186 | overlay.append("rect") 187 | .attr("height", height) 188 | .attr("width", width) 189 | .style("fill-opacity", 0.0) 190 | .on("click", function(d) {svg.select("g.movieOverlay").remove()}) 191 | 192 | sidebar = overlay.append("g") 193 | 194 | sidebar 195 | .attr("transform","translate(" + width + ", 0)").transition().attr("transform","translate(" + width*.5 + ", 0)") 196 | .style("opacity",1) 197 | 198 | defs = sidebar.append("defs") 199 | pattern = defs.append("pattern") 200 | .attr("id", "backgroundImage") 201 | .attr("height", "100%") 202 | .attr("width", "100%") 203 | .attr("patternContentUnits", "objectBoundingBox") 204 | .attr("viewBox","0 0 1 1") 205 | .attr("preserveAspectRatio", "xMidYMid slice") 206 | 207 | pattern.append("image") 208 | .attr("xlink:href", "art?link=" + data.art + "&width=1920&height=1080") 209 | .attr("height", "1") 210 | .attr("width", "1") 211 | .attr("preserveAspectRatio", "xMidYMid slice") 212 | 213 | sidebar.append("rect") 214 | .style("fill", d3.rgb("#1f1f1f")) 215 | // .attr("x", (width-width*.5)) 216 | .attr("height",height) 217 | .attr("width",width*.5) 218 | .style("opacity",1) 219 | 220 | sidebar.append("rect") 221 | .style("fill", "url(#backgroundImage)") 222 | // .attr("x", (width-width*.5)) 223 | .attr("height",height) 224 | .attr("width",width*.5) 225 | .style("opacity",.2) 226 | 227 | sidebar.append("rect") 228 | .style("fill", d3.rgb("#1f1f1f")) 229 | // .attr("x", (width-width*.5)) 230 | .attr("y", 100) 231 | .attr("height",height-100) 232 | .attr("width",width*.5) 233 | .style("opacity",.5) 234 | 235 | 236 | image = sidebar.append("image") 237 | .attr("xlink:href", "art?link=" + data.thumb + "&width=1920&height=1080") 238 | .attr("width",width*.1) 239 | .attr("height", width*.1*1.47) 240 | .attr("x", 20) 241 | .attr("y", 40) 242 | 243 | sidebar.append("text") 244 | .text(data.title) 245 | .style("fill",d3.rgb('#f9be03')) 246 | .style("font-size", 28) 247 | .style("font-family","Open Sans") 248 | .attr("x", (width*.1)+40) 249 | .attr("y", 60) 250 | 251 | console.log() 252 | summaryG = sidebar.append("g") 253 | .attr("transform", "translate(" + ((width*.1)+40) + ", 80)") 254 | 255 | summaryG.append("text") 256 | .text("'''" + data.summary + "'''") 257 | .attr("y", 0) 258 | .attr("dy", ".3em") 259 | .style("font-size", 16) 260 | .call(wrap, (width*.5)-(width*.1)-80) 261 | .style("fill",d3.rgb('white')) 262 | .style("font-family","Open Sans") 263 | // .attr("x", (width*.1)+80) 264 | 265 | sidebar.append("text") 266 | .text(function (d) { return "Studio: " + data.studio}) 267 | .classed("data-title",true) 268 | .attr("x", 20) 269 | .attr("y", ((width*.1*1.47)+60)) 270 | .attr("dy", ".3em") 271 | .style("font-size", 16) 272 | .style("fill",d3.rgb('white')) 273 | .style("font-family","Open Sans") 274 | 275 | sidebar.append("text") 276 | .text(function (d) { return "Year: " + data.year}) 277 | .classed("data-title",true) 278 | .attr("x", 20) 279 | .attr("y", ((width*.1*1.47)+80)) 280 | .attr("dy", ".3em") 281 | .style("font-size", 16) 282 | .style("fill",d3.rgb('white')) 283 | .style("font-family","Open Sans") 284 | 285 | sidebar.append("text") 286 | .text(function (d) { return "Content Rating: " + data.content_rating}) 287 | .classed("data-title",true) 288 | .attr("x", 20) 289 | .attr("y", ((width*.1*1.47)+100)) 290 | .attr("dy", ".3em") 291 | .style("font-size", 16) 292 | .style("fill",d3.rgb('white')) 293 | .style("font-family","Open Sans") 294 | .call(wrap, width*.1) 295 | 296 | console.log(data) 297 | } 298 | 299 | function expandEntity(toExpand) { 300 | console.log(toExpand.key) 301 | d3.json("/metadata/" + toExpand.key, renderSidebar) 302 | } 303 | 304 | function deleteEntity(toDelete) { 305 | console.log("deleteEntity") 306 | saveState() 307 | nodes = nodes.filter(function (d) {return deleteFunction(d, toDelete)}) 308 | animate() 309 | } 310 | 311 | function setGroupAction(payload) { 312 | saveState() 313 | groupActionFunction = payload.onClick 314 | animate() 315 | } 316 | 317 | function genreClick(group) { 318 | console.log("GenreClick") 319 | saveState() 320 | console.log(group) 321 | groupActionFunction(group) 322 | animate() 323 | } 324 | 325 | function toggleGroup(group) { 326 | saveState() 327 | var index = toggled_groups.indexOf(groupFilter(group)) 328 | if (index != -1) { 329 | toggled_groups.splice(index,1) 330 | } else { 331 | toggled_groups.push(groupFilter(group)) 332 | } 333 | } 334 | 335 | function removeGroup(group) { 336 | console.log("Attempting to remove group " + group.name) 337 | console.log(group) 338 | console.log(nodes.length) 339 | nodes = nodes.filter(function(d) {if (group.name != groupFilter(d)) { 340 | return d 341 | }}) 342 | console.log(nodes.length) 343 | } 344 | 345 | function restoreGroups(payload) { 346 | console.log(globalGroups) 347 | console.log(groups) 348 | if (toggled_groups.length > 5) { 349 | toggled_groups = []; 350 | } else { 351 | toggled_groups = globalGroups; 352 | } 353 | animate(); 354 | } 355 | 356 | function deleteSingle(payload) { 357 | saveState() 358 | onClickFunction = payload.onClick 359 | deleteFunction = payload.delete 360 | animate() 361 | } 362 | 363 | function saveState() { 364 | console.log("Saving state") 365 | console.log(toggled_groups) 366 | let state = {} 367 | state.targetFunction = targetFunction 368 | state.renderFunction = renderFunction 369 | state.groupFilter = groupFilter 370 | state.groupSort = groupSort 371 | state.groups = groups 372 | state.toggled_groups = [] 373 | toggled_groups.forEach(function (d) {state.toggled_groups.push(d)}) 374 | state.groupActionFunction = groupActionFunction 375 | state.nodes = nodes 376 | state.filter_watched = filter_watched 377 | state.nav_buttons = [] 378 | nav_buttons.forEach(function (d) {state.nav_buttons.push(d)}) 379 | stateHistory.push(state) 380 | } 381 | 382 | function restore() { 383 | state = stateHistory.pop() 384 | targetFunction = state.targetFunction 385 | renderFunction = state.renderFunction 386 | groupFilter = state.groupFilter 387 | groupSort = state.groupSort 388 | groups = state.groups 389 | groupActionFunction = state.groupActionFunction 390 | toggled_groups = [] 391 | state.toggled_groups.forEach(function(d) { toggled_groups.push(d)}) 392 | filter_watched = state.filter_watched 393 | nodes = state.nodes 394 | nav_buttons = [] 395 | state.nav_buttons.forEach(function (d) {nav_buttons.push(d)}); 396 | animate() 397 | } 398 | 399 | 400 | function restoreAll() { 401 | state = stateHistory[0] 402 | targetFunction = state.targetFunction 403 | renderFunction = state.renderFunction 404 | groupFilter = state.groupFilter 405 | groupSort = state.groupSort 406 | groups = state.groups 407 | nodes = state.nodes 408 | nav_buttons = state.nav_buttons 409 | stateHistory=[] 410 | animate() 411 | } 412 | 413 | d3.selection.prototype.moveToFront = function() { 414 | console.log("Moving to front") 415 | return this.each(function(){ 416 | this.parentNode.appendChild(this); 417 | }); 418 | }; 419 | 420 | function animate() { 421 | console.log("Animating") 422 | render_nav_bar() 423 | var max_area = 0 424 | var average_radius = 0 425 | average_radius = average_radius/nodes.length 426 | if (average_radius > 15) { 427 | console.log(average_radius) 428 | } 429 | if (filter_watched) { 430 | console.log("Filtering Watched") 431 | nodes.forEach(function(d) { d.display.push(!d.watch); }) 432 | } 433 | nodes_with_labels = nodes.filter(function (d) { var to_display = true; 434 | d.display.forEach(function (e) { 435 | to_display = to_display && e 436 | }) 437 | d.display = [] 438 | if (to_display) 439 | {return d}}) 440 | 441 | groups = groups_from_data(nodes_with_labels) 442 | globalGroups = calcGroupCenters(groups) 443 | console.log("Max radius = " + max_radius) 444 | showLabels(globalGroups) 445 | nodes_with_labels.forEach(function (d) { if ((d.year >= years_to_show[0] && d.year <= years_to_show[1]) || d.type == "root") {d.display.push(true)} 446 | else {d.display.push(false)}}) 447 | nodes_with_labels.forEach(function (d) { if (inArray(toggled_groups,groupFilter(d))) { d.display.push(false)}}) 448 | nodes_to_display = nodes_with_labels.filter(function (d) { var to_display = true; 449 | d.display.forEach(function (e) { 450 | to_display = to_display && e 451 | }) 452 | d.display = [] 453 | if (to_display) 454 | {return d}}) 455 | nodes_to_display.forEach(function(d) { if (d.value > max_area) {max_area = d.value;}}) 456 | nodes_to_display.forEach(function(d) { d.radius = max_radius*(area_to_radius(d.value)/area_to_radius(max_area)); average_radius += d.radius}) 457 | nodes_to_display = nodes_to_display.filter(function(d) { if (d.radius > 1) {return d}}) 458 | force.nodes(nodes_to_display) 459 | renderFunction() 460 | force.alpha(1) 461 | animation() 462 | } 463 | 464 | function calcGroupCenters(groups) { 465 | var local_groups = [] 466 | devs = width/(groups.length+1) 467 | curr = 0; 468 | top_y = 40; 469 | top_curr = devs; 470 | var biggest_size = 0 471 | var total_size = 0 472 | curr_y = height/2 473 | num_rows = 0 474 | // console.log(groups.length) 475 | groups.forEach(function (d) { total_size += d.size }); 476 | groups.forEach(function (d, i) { 477 | // console.log(d.size/total_size) 478 | // var curr_width = ((d.size/total_size))*width 479 | // if (curr_width < 100) {curr_width = 50}; 480 | // if (curr_width > 500) {curr_width = 500} 481 | // console.log("Current Width = " + (curr + curr_width) + " Out of " + width) 482 | // if ((curr + curr_width) >= (width-100)) { curr_y += height/2; curr = 0} 483 | local_groups.push({name: d.name, 484 | year: d.name, 485 | genre: d.name, 486 | x:top_curr, 487 | y:curr_y, 488 | top_x: top_curr, 489 | top_y: curr_y}) 490 | curr += devs; 491 | top_curr += devs; 492 | }) 493 | // local_groups.forEach(function (target) { console.log("( " + target.x + ", " + target.y + ")")}) 494 | return local_groups 495 | } 496 | 497 | function groups_from_data(data) { 498 | var groups = [] 499 | var group_sizes = {} 500 | var final_groups = [] 501 | data.forEach(function(d) { if (!inArray(groups, groupFilter(d))) { (groups.push(groupFilter(d))); group_sizes[groupFilter(d)] = 0};group_sizes[groupFilter(d)] += d.value}) 502 | groups.sort(groupSort) 503 | Object.keys(group_sizes).forEach( function (d){ 504 | final_groups.push({"name": d, "size": group_sizes[d]}) 505 | }) 506 | final_groups.sort(function (a,b) { return d3.ascending(a.name,b.name)}) 507 | return final_groups 508 | } 509 | 510 | function expandGroup(to_expand){ 511 | saveState() 512 | nav_buttons = [ 513 | { name: "Grouping", exclusive: true, children: [ 514 | { name: "Group Together", func: grouping, type: "toggle", active: true, group: "Grouping", payload: 515 | { 516 | groupFilter: function (d) {return d.genre}, 517 | groupSort: function (a,b) {return d3.ascending(a,b)}, 518 | targetFunction: moveToCenter 519 | } 520 | }, 521 | { name: "Split Genre", func: grouping, type: "toggle", active: false, group: "Grouping", payload: 522 | { 523 | groupFilter: function (d) {return d.genre}, 524 | groupSort: function (a,b) {return d3.ascending(a,b)}, 525 | targetFunction: moveToGenre 526 | } 527 | }, 528 | { name: "Split Years", func: grouping, type: "toggle", active: false, group: "Grouping", payload: 529 | { 530 | groupFilter: function (d) {return d.year}, 531 | groupSort: function (a,b) {return b-a}, 532 | targetFunction: moveToGenre 533 | } 534 | } 535 | ]}, 536 | { name: "On Click", exclusive: true, children: [ 537 | { name: "Expand " + to_expand.singular, func: deleteSingle, type: "toggle", active: true, group: "On Click", payload: 538 | { 539 | onClick: expandEntity, 540 | delete: "" 541 | } 542 | }, 543 | { name: "Remove " + to_expand.singular, func: deleteSingle, type: "toggle", active: false, group: "On Click", payload: 544 | { 545 | onClick: deleteEntity, 546 | delete: function(d, toDelete) {if (toDelete.name != d.name) { 547 | return d 548 | }} 549 | } 550 | }, 551 | { name: "Remove Genre", func: deleteSingle, type: "toggle", active: false, group: "On Click", payload: 552 | { 553 | onClick: deleteEntity, 554 | delete: function(d, toDelete) {if (groupFilter(toDelete) != groupFilter(d)) { 555 | return d 556 | }} 557 | } 558 | } 559 | ]}, 560 | { name: "Genre", exclusive: true, children: [ 561 | { name: "Remove Genre", func: setGroupAction , type: "toggle", active: false, group: "Genre", payload: 562 | { 563 | onClick: removeGroup, 564 | } 565 | }, 566 | { name: "Toggle Genre", func: setGroupAction, type: "toggle", active: true, group: "Genre", payload: 567 | { 568 | onClick: toggleGroup, 569 | } 570 | }, 571 | { name: "Toggle all Genre", func: restoreGroups, type: "push", active: false, group: "Genre", payload: 572 | { 573 | onClick: deleteEntity, 574 | delete: function(d, toDelete) {if (groupFilter(toDelete) != groupFilter(d)) { 575 | return d 576 | }} 577 | } 578 | } 579 | ]} 580 | ] 581 | result = nodes.filter(function(d) {if (to_expand.name === d.name) { 582 | return d 583 | }}) 584 | nodes = result[0].children 585 | renderFunction = render_chart 586 | animate() 587 | } 588 | 589 | var chart = function chart(selector, rawData) { 590 | ///// Button Related things: 591 | 592 | 593 | // Use the max total_amount in the data as the max in the scale's domain 594 | // note we have to ensure the total_amount is a number by converting it 595 | // with `+`. 596 | var maxAmount = d3.max(rawData, function (d) { return +d.radius; }); 597 | nodes = classes(rawData); 598 | setClassColor(nodes) 599 | 600 | orig_nodes = nodes; 601 | // Set the force's nodes to our newly created nodes array. 602 | force.nodes(nodes); 603 | 604 | // Create a SVG element inside the provided selector 605 | // with desired size. 606 | svg = d3.select('#vis') 607 | .append('svg') 608 | .attr('width', "100%") 609 | .attr('height', "100%"); 610 | 611 | 612 | // Bind nodes data to what will become DOM elements to represent them. 613 | renderFunction() 614 | force.start() 615 | // Set initial layout to single group. 616 | animate(); 617 | }; 618 | 619 | // ################################################################################################# 620 | // Functions responsible for rendering things 621 | // render_root renders the root of the chart before TV/Movies is expanded 622 | // render_chart renders the core of the data visualization 623 | // render_nav_bar renders the nav bar svg 624 | // 625 | // 626 | // ################################################################################################# 627 | // Render Functions 628 | function render_root() { 629 | svg.attr('width', width) 630 | .attr('height', height); 631 | bubbles = svg.selectAll('g.node') 632 | .data(nodes_to_display, function (d) {return d.name; }); 633 | 634 | 635 | bubbles.select("circle") 636 | .attr("r",function(d) { return d.radius*scaleing }).transition().duration(3).attr("r", function(d) { return d.radius*scaleing }) 637 | .style("fill", function(d) { return getClassColor(d.name); }) 638 | 639 | bubbles.select("text") 640 | .text(function(d) { return d.name.substring(0, d.radius / 3); }); 641 | 642 | 643 | bubbleEnter = bubbles.enter().append('g') 644 | bubbleEnter.classed("node",true) 645 | .attr("cursor","pointer"); 646 | 647 | bubbleEnter.append("circle") 648 | .style("fill", function(d) { return getClassColor(d.name); }) 649 | .attr("r",0).transition().duration(3).attr("r", function(d) { return d.radius*scaleing }) 650 | 651 | bubbleEnter.append("text") 652 | .attr("dy", ".3em") 653 | .style("text-anchor", "middle") 654 | .text(function(d) { return d.name.substring(0, d.radius / 3); }); 655 | 656 | bubbleEnter.on("mouseover", function(d) { 657 | div .transition() 658 | .duration(100) 659 | .style("visibility", "visible") 660 | .style("opacity", 0.9); 661 | div .html( 662 | "Name: " +d.name +"
"+ 663 | "Hours Watched: " + Math.round((d.value/60/60)*100)/100 664 | ) 665 | .style("left", (d3.event.pageX) + "px") 666 | .style("top", (d3.event.pageY - 28) + "px"); 667 | }) 668 | .on("mouseout", function(){return div.style("visibility", "hidden");}) 669 | .on("click", function(d){ expandGroup(d)}); 670 | 671 | 672 | bubbleExit = bubbles.exit() 673 | bubbleExit.transition().duration(5).select("circle").attr("r",0) 674 | bubbleExit.transition().duration(5).remove(); 675 | globalGroups = [] 676 | showLabels() 677 | } 678 | 679 | function render_chart() { 680 | svg.attr('width', width) 681 | .attr('height', height); 682 | 683 | bubbles = svg.selectAll('g.node') 684 | .data(nodes_to_display, function (d) { return d.name; }); 685 | 686 | 687 | bubbles.select("circle") 688 | .attr("r",function(d) { return d.radius*scaleing }).transition().duration(3).attr("r", function(d) { return d.radius*scaleing }); 689 | 690 | bubbles.select("text") 691 | .text(function(d) { return d.name.substring(0, d.radius*scaleing / 3); }); 692 | 693 | 694 | bubbleEnter = bubbles.enter().append('g') 695 | bubbleEnter.classed("node",true) 696 | .attr("cursor","pointer"); 697 | 698 | bubbleEnter.append("circle") 699 | .style("fill", function(d) { return getClassColor(d.genre); }) 700 | .attr("r",0).transition().duration(3).attr("r", function(d) { return d.radius*scaleing; }); 701 | 702 | bubbleEnter.append("text") 703 | .attr("dy", ".3em") 704 | .style("text-anchor", "middle") 705 | .text(function(d) { return d.name.substring(0, d.radius / 3); }); 706 | 707 | bubbleEnter.on("mouseover", function(d) { 708 | div .transition() 709 | .duration(100) 710 | .style("visibility", "visible") 711 | .style("opacity", 0.9); 712 | div .html( 713 | "Genre: " +d.genre +"
"+ 714 | "Name: " +d.name +"
"+ 715 | "Year: " +d.year + "
"+ 716 | "Watched: " + d.watch + "
"+ 717 | "Hours Watched: " + Math.round((d.value/60/60)*100)/100 718 | ) 719 | .style("left", (d3.event.pageX) + "px") 720 | .style("top", (d3.event.pageY - 28) + "px"); 721 | }) 722 | .on("mouseout", function(){return div.style("visibility", "hidden");}) 723 | .on("click", function(d){ onClickFunction(d)}); 724 | 725 | 726 | bubbleExit = bubbles.exit() 727 | bubbleExit.transition().duration(5).select("circle").attr("r",0) 728 | bubbleExit.transition().duration(5).remove(); 729 | } 730 | 731 | function hideSidebar() { 732 | sidebar = d3.select('#sliders') 733 | sidebar.transition().duration(10).style('width',0).style("opacity",0) 734 | sidebar_width = 48 735 | restore_sidebar = svg.append('g'); 736 | restore_sidebar.attr("id","showSidebar").classed("button", true) 737 | restore_sidebar.append('rect').attr("y",10).attr("width",100).attr("height",20).style("fill",d3.rgb("#282828")); 738 | restore_sidebar.append('text').text("Show Sidebar").attr("y",25).attr('x',20).style("fill","999") 739 | .on("click", showSidebar); 740 | calcPageSize() 741 | } 742 | 743 | function showSidebar() { 744 | sidebar = d3.select('#sliders') 745 | sidebar.transition().duration(10).style('width','260px').style("opacity",1) 746 | sidebar_width = 298 747 | svg.select('#showSidebar').remove(); 748 | calcPageSize() 749 | } 750 | 751 | function render_nav_bar() { 752 | var globalButtons = [] 753 | globalButtons.push({ name: "Reset", func: restoreAll, type: "press", active: false, group: "Global"}) 754 | globalButtons.push({ name: "Undo Last Action", func: restore, type: "press", active: false, group: "Global"}) 755 | globalButtons.push({ name: "Hide Sidebar", func: hideSidebar, type: "press", active: false, group: "Global"}) 756 | if (loggedIn) { 757 | globalButtons.push({ name: "Remove Watched", func: removeWatched, type: "toggle", active: false, group: "Global"}) 758 | globalButtons.push({ name: "Log Out", func: function() {window.location= "/logout"}, type:"press", active: false, group: "Global"}) 759 | } else { 760 | globalButtons.push({ name: "Login", func: function() {window.location= "/login"}, type:"press", active: false, group: "Global"}) 761 | } 762 | nav_buttons.push({ name: "Global", exclusive: false, children: globalButtons}) 763 | var xShift = 25 764 | var yShift = 10 765 | var yHeight = 30 766 | var nextRoot = 10 767 | nav_buttons.forEach(function(d) {d.y = nextRoot; 768 | d.children.forEach(function (e,i) { 769 | e.y = nextRoot+((i+1)*yHeight); 770 | return e; 771 | }) 772 | nextRoot = nextRoot+((d.children.length+1)*yHeight); 773 | return d}) 774 | 775 | var nav = d3.select('#navBar') 776 | var buttonGroups = nav.selectAll('ul.group') 777 | .data(nav_buttons, function (d) { return d.name}); 778 | 779 | buttonUpdate = buttonGroups.selectAll('li.button') 780 | .data(function(d) { return d.children}, function (e) { return e.name}) 781 | 782 | buttonUpdateActive = buttonGroups.selectAll('li.button-active') 783 | .data(function(d) { return d.children}, function (e) { return e.name}) 784 | 785 | buttonUpdate.classed("button-active", function(d) {return d.active}) 786 | .classed("button", function(d) {return !d.active}) 787 | 788 | buttonUpdateActive.classed("button-active", function(d) {return d.active}) 789 | .classed("button", function(d) {return !d.active}) 790 | 791 | buttonGroupEnter = buttonGroups.enter().append('ul') 792 | buttonGroupEnter.classed("group",true) 793 | 794 | buttonHeading = buttonGroupEnter.append('li') 795 | buttonHeading.classed("heading", true) 796 | 797 | buttons = buttonGroupEnter.selectAll('li.button') 798 | .data(function(d) {return d.children}, function (e) { return e.name}) 799 | 800 | buttonEnter = buttons.enter().append('li') 801 | buttonEnter.classed("button-active", function(d) {return d.active}) 802 | .classed("button", function(d) {return !d.active}) 803 | .style("cursor","pointer") 804 | .text(function(d) { return d.name }) 805 | .on("click", function(d){ toggle_button(d)}) 806 | .classed("active", function(d) {return d.active}); 807 | 808 | buttonGroups.exit().remove() 809 | 810 | } 811 | 812 | function animation() { 813 | force.on('tick', function (e) { 814 | bubbles.each(targetFunction(e.alpha)) 815 | .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) 816 | }); 817 | force.start(); 818 | } 819 | 820 | function showLabels(groups) { 821 | console.log(toggled_groups) 822 | // Another way to do this would be to create 823 | // the year texts once and then just hide them. 824 | var labels = svg.selectAll('.label') 825 | .data(globalGroups, function (d) {return d.name}); 826 | 827 | labels 828 | .style('fill', function(d) { if(inArray(toggled_groups, d.name)) { return "#999"}; 829 | return getClassColor(d.name);} ) 830 | .style('text-decoration',function(d) {if (inArray(toggled_groups, d.name)) { return "none"} 831 | return "underline"}) 832 | 833 | labels 834 | .attr('id', 'update') 835 | // .attr('x', function (d) { if (targetFunction == moveToCenter ) { return d.top_x; }; return d.x; }) 836 | // .attr('y', function (d) { if (targetFunction == moveToCenter ) { return d.top_y; };return d.y - ((height/4) - 40 ); }) 837 | .attr('x', function (d) { return d.x; }) 838 | .attr('y', function (d) { return 40; }) 839 | 840 | labels.enter().append('text') 841 | .attr('class', 'label') 842 | .style('fill', function(d) { if(inArray(toggled_groups, d.name)) { return "#999"}; 843 | return getClassColor(d.name);} ) 844 | // .attr('x', function (d) { if (targetFunction == moveToCenter ) { return d.top_x; }; return d.x}) 845 | // .attr('y', function (d) { if (targetFunction == moveToCenter ) { return d.top_y; };return d.y - ((height/4) - 40 ); }) 846 | .attr('x', function (d) { return d.x}) 847 | .attr('y', function (d) { return 40 }) 848 | .attr("cursor","pointer") 849 | .attr('text-anchor', 'middle') 850 | .style('text-decoration',function(d) {if (inArray(toggled_groups, d.name)) { return "none"} 851 | return "underline"}) 852 | 853 | .text(function (d) { return d.name; }) 854 | .on("click", function(d){ genreClick(d)}); 855 | 856 | 857 | labels.exit().remove() 858 | } 859 | ///// Target Functions 860 | // These functions are used to determine targets for Splitting 861 | function moveToCenter(alpha) { 862 | return function (d) { 863 | d.x = d.x + (center.x - d.x) * damper * alpha; 864 | d.y = d.y + (center.y - d.y) * damper * alpha; 865 | }; 866 | } 867 | 868 | function moveToGenre(alpha) { 869 | return function (d) { 870 | var target = globalGroups.filter(function(e) {if (e.name == groupFilter(d)) { 871 | return e 872 | }})[0] 873 | d.x = d.x + (target.x - d.x) * damper * alpha * 1.1; 874 | d.y = d.y + (target.y - d.y) * damper * alpha * 1.1; 875 | }; 876 | } 877 | 878 | ///// Button related things 879 | // Button function mappings: 880 | d3.select("#year_slider").call(d3.slider().axis(true).min(min_year).max(max_year).step(1).value([min_year, max_year]) 881 | .on("slide", function (evt,value) { 882 | console.log(value) 883 | years_to_show = value 884 | animate(); 885 | })) 886 | d3.select("#zoom_slider").call(d3.slider().value(50).on("slide", function(evt, value) { 887 | scaleing = value/50; 888 | console.log("Scale now equals:" + value) 889 | animate() 890 | })) 891 | 892 | // Button Functions 893 | // Set grouping and reanimate 894 | function grouping(payload) { 895 | console.log("grouping") 896 | saveState() 897 | groupFilter = payload.groupFilter; 898 | groupSort = payload.groupSort; 899 | targetFunction = payload.targetFunction; 900 | force.alpha(100000); 901 | animate() 902 | } 903 | 904 | // Togle which button is active 905 | function toggle_button(button) { 906 | nav_buttons.forEach(function (d) { 907 | if (d.name === button.group && button.type === "toggle") { 908 | if (d.exclusive) { 909 | d.children.forEach( (function (e) { 910 | if (e.name === button.name && button.type === "toggle") { e.active = true; return e}; 911 | e.active = false; return e 912 | })); 913 | } else { 914 | d.children.forEach( (function (e) { 915 | if (e.name === button.name && button.type === "toggle") { e.active = !e.active}; 916 | return e; 917 | })) 918 | } 919 | return d; 920 | }}) 921 | button.func(button.payload) 922 | } 923 | 924 | // Remove already watched entities 925 | function removeWatched() { 926 | console.log("removeWatched") 927 | saveState() 928 | filter_watched = !filter_watched; 929 | animate() 930 | } 931 | 932 | // ################################################################################################# 933 | // Functions responsible manipulating Data (from JSON) 934 | // classes seperates out the nodes appropriately 935 | // group pulls the data from indvidual groups (TV/Movies) 936 | // recurse grabs all the nodes in an individual group 937 | // 938 | // 939 | // ################################################################################################# 940 | // Data Manipulation Functions 941 | function classes(root) { 942 | var classes = [] 943 | var movies = {} 944 | var tv = {} 945 | loggedIn = root.loggedIn 946 | // TODO move singular into JSON 947 | function group(name,node,array_to_push, singular) { 948 | array_to_push.name = node.name 949 | array_to_push.value = node.size 950 | array_to_push.x = Math.random() * 900; 951 | array_to_push.y = Math.random() * 800; 952 | array_to_push.display = [true] 953 | array_to_push.type = "root" 954 | array_to_push.singular = singular 955 | children = [] 956 | recurse(null, node, children) 957 | array_to_push.children = children; 958 | } 959 | 960 | function recurse(name, node, array_to_push) { 961 | if (node.children) node.children.forEach(function(child) { recurse(node.name, child, array_to_push); }); 962 | else {array_to_push.push({genre: node.genre, 963 | name: node.name, 964 | value: node.size, 965 | year: node.year, 966 | watch: node.watch, 967 | key: node.key, 968 | // radius: Math.pow(node.size,0.5)/10, 969 | x: Math.random() * 900, 970 | y: Math.random() * 800, 971 | display: [true], 972 | type: "child", 973 | parent: node 974 | });} 975 | } 976 | 977 | group(null, root.TV, tv, "Show") 978 | group(null, root.Movies, movies, "Movie") 979 | return [movies, tv] 980 | } 981 | d3.select(window).on("resize", calcPageSize); 982 | 983 | return chart; 984 | } 985 | 986 | 987 | var myBubbleChart = plex_chart(); 988 | 989 | 990 | /* 991 | * Function called once data is loaded from CSV. 992 | * Calls bubble chart function to display inside #vis div. 993 | */ 994 | function display(error, data) { 995 | if (error) { 996 | console.log(error); 997 | } 998 | 999 | myBubbleChart('#vis', data); 1000 | } 1001 | 1002 | 1003 | d3.json(user_data, display) --------------------------------------------------------------------------------