├── .gitignore ├── LICENSE ├── README.md ├── examples ├── basic.html └── data │ ├── graph-1.json │ └── graph-2.json ├── package.json └── src └── iframe ├── images ├── favicon-16x16.png ├── favicon-dark-24x24.png ├── favicon.ico └── noise.png ├── pylinkurious.css ├── pylinkurious.html └── pylinkurious.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | build/* 3 | *.tgz 4 | *.log 5 | *.swp 6 | .idea/ 7 | -------------------------------------------------------------------------------- /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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyLinkurious 2 | [Linkurious.js](https://github.com/Linkurious/linkurious.js) integration with the [Jupyter Notebook](https://jupyter.org/). 3 | 4 | ## Install 5 | 6 | - `git clone git@github.com:Linkurious/PyLinkurious.git` 7 | - Install [Node.js](http://nodejs.org/). 8 | - Use `npm install` to install dependencies. 9 | 10 | ## Demo 11 | 12 | Run `npm start` then open the basic example on your browser at http://localhost:8000/examples/basic.html. 13 | 14 | ### Integrating the Linkurious.js iframe 15 | 16 | Add the following code in the HTML: 17 | 18 | ```html 19 | 26 | ``` 27 | 28 | ### Display your first graph 29 | 30 | ```js 31 | // Function called once the iframe is initialized: 32 | function setUpFrame() { 33 | 34 | // Get Linkurious.js instance: 35 | var LK = window.frames['pylinkurious-iframe'].LK; 36 | 37 | // Update UI components 38 | LK.updateUI(); 39 | 40 | // Load a graph sample: 41 | LK.sigma.graph.read({ 42 | nodes: [ 43 | { id: 'n0', label: 'Node 0', x: 0, y: 0, size: 1 }, 44 | { id: 'n1', label: 'Node 1', x: 50, y: -10, size: 1 } 45 | ], 46 | edges: [ 47 | { 48 | id: 'e0', 49 | label: 'Edge 0', 50 | source: 'n0', 51 | target: 'n1', 52 | size: 1 53 | } 54 | ] 55 | }); 56 | 57 | // Display the graph: 58 | LK.sigma.refresh(); 59 | LK.plugins.locate.center(); 60 | } 61 | ``` 62 | 63 | ### Browser Support 64 | 65 | All modern web browsers are supported, including: 66 | * Internet Explorer 10+ 67 | * Chrome 23+ and Chromium 68 | * Firefox 15+ 69 | * Safari 6+ 70 | 71 | ## External Dependencies 72 | 73 | - [linkurious.js](https://github.com/Linkurious/linkurious.js) 74 | - [mustache.js](https://github.com/janl/mustache.js) 75 | 76 | Some optional linkurious.js plugins require extra libraries: 77 | 78 | - [js-xlsx](https://github.com/SheetJS/js-xlsx/) 79 | - [dagre](https://github.com/cpettitt/dagre) 80 | 81 | ## Status 82 | 83 | Under development. 84 | 85 | ## License 86 | 87 | PyLinkurious is released under the GNU General Public License v.3 ("GPL"). 88 | -------------------------------------------------------------------------------- /examples/basic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Basic example - PyLinkurious 6 | 7 | 8 | 9 | 10 | 11 |

Basic example

12 | 13 | 20 | 21 | 56 | 57 | -------------------------------------------------------------------------------- /examples/data/graph-1.json: -------------------------------------------------------------------------------- 1 | {"nodes":[{"id":1047,"x":48.91,"y":-13.79,"data":{"properties":{"name":"STREAMROOT","permalink":"/organization/streamroot","first_funding_at":"13/11/2014","market":" Peer-to-Peer ","url":"http://www.crunchbase.com/organization/streamroot","country":"FRA","homepage_url":"http://www.streamroot.io","logo":"http://www.crunchbase.com/organization/streamroot/primary-image/raw","funding_rounds":1,"status":"operating","funding_total":118000,"region":"Paris","category":"|Peer-to-Peer|Video Streaming|Content Delivery|Video|","last_funding_at":"13/11/2014"},"categories":{"0":"COMPANY"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY","1":"INVESTOR"},"nodes":1,"edges":1},"1":{"edgeType":"HAS_CITY","nodeCategories":{"0":"CITY"},"nodes":1,"edges":1},"2":{"edgeType":"HAS_MARKET","nodeCategories":{"0":"MARKET"},"nodes":1,"edges":1}},"edgeCount":3,"visibleEdgeCount":3,"hiddenEdgeCount":0}},"label":"STREAMROOT","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#5FDAA2"},"color":"#5FDAA2"},{"id":0,"x":14.14,"y":-19.79,"data":{"properties":{"name":"Paris"},"categories":{"0":"CITY"},"statistics":{"digest":{"0":{"edgeType":"HAS_CITY","nodeCategories":{"0":"COMPANY","1":"INVESTOR"},"nodes":4,"edges":4},"1":{"edgeType":"HAS_CITY","nodeCategories":{"0":"COMPANY"},"nodes":428,"edges":428},"2":{"edgeType":"ACQUIRED","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":433,"visibleEdgeCount":4,"hiddenEdgeCount":429}},"label":"Paris","size":1,"glyphs":{"0":{"draw":true,"position":"top-right","content":"429"}},"colors":{"0":"#DE6FBC"},"color":"#DE6FBC"},{"id":290,"x":49.9,"y":-43.24,"data":{"properties":{"name":" Peer-to-Peer "},"categories":{"0":"MARKET"},"statistics":{"digest":{"0":{"edgeType":"HAS_MARKET","nodeCategories":{"0":"COMPANY"},"nodes":2,"edges":2}},"edgeCount":2,"visibleEdgeCount":2,"hiddenEdgeCount":0}},"label":" Peer-to-Peer ","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#D4742C"},"color":"#D4742C"},{"id":1065,"x":78.91,"y":21.42,"data":{"properties":{"name":"Techstars","permalink":"/organization/techstars","founded_at":"01/10/2006","first_funding_at":"10/02/2011","market":" Venture Capital ","founded_quarter":"2006-Q4","founded_year":2006,"url":"http://www.crunchbase.com/organization/techstars","country":"USA","homepage_url":"http://techstars.com","logo":"http://www.crunchbase.com/organization/techstars/primary-image/raw","founded_month":"2006-10","funding_rounds":3,"status":"operating","funding_total":34000000,"region":"Denver","category":"|Startups|Venture Capital|Finance|","last_funding_at":"21/09/2011","state":"CO"},"categories":{"0":"COMPANY","1":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":4,"edges":4}},"edgeCount":4,"visibleEdgeCount":4,"hiddenEdgeCount":0}},"label":"Techstars","size":7,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#5FDAA2","1":"#4EA4D4"},"color":"#4EA4D4"},{"id":1153,"x":21.74,"y":-56.6,"data":{"properties":{"name":"Weeleo","permalink":"/organization/weeleo","founded_at":"17/09/2013","first_funding_at":"11/06/2014","market":" Peer-to-Peer ","founded_quarter":"2013-Q3","founded_year":2013,"url":"http://www.crunchbase.com/organization/weeleo","country":"FRA","homepage_url":"http://www.weeleo.com","logo":"http://www.crunchbase.com/organization/weeleo/primary-image/raw","founded_month":"2013-09","funding_rounds":2,"status":"operating","funding_total":60000,"region":"Paris","category":"|Finance|Tourism|Apps|Peer-to-Peer|Travel|","last_funding_at":"01/08/2014"},"categories":{"0":"COMPANY"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"INVESTOR"},"nodes":2,"edges":2},"1":{"edgeType":"HAS_CITY","nodeCategories":{"0":"CITY"},"nodes":1,"edges":1},"2":{"edgeType":"HAS_MARKET","nodeCategories":{"0":"MARKET"},"nodes":1,"edges":1}},"edgeCount":4,"visibleEdgeCount":4,"hiddenEdgeCount":0}},"label":"Weeleo","size":4,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#5FDAA2"},"color":"#5FDAA2"},{"id":1716,"x":24.78,"y":-83.62,"data":{"properties":{"name":"Bpifrance","permalink":"/organization/bpifrance","url":"http://www.crunchbase.com/organization/bpifrance","country":"FRA","region":"Franche-Comte"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":12,"edges":12}},"edgeCount":12,"visibleEdgeCount":1,"hiddenEdgeCount":11}},"label":"Bpifrance","size":1,"glyphs":{"0":{"draw":true,"position":"top-right","content":"11"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1798,"x":-1.44,"y":-73.54,"data":{"properties":{"name":"Tumml","permalink":"/organization/tumml","market":"Startups","url":"http://www.crunchbase.com/organization/tumml","country":"USA","region":"SF Bay Area","category":"|Apps|Startups|Incubators|Nonprofits|","state":"CA","city":"San Francisco"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":1,"visibleEdgeCount":1,"hiddenEdgeCount":0}},"label":"Tumml","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":516,"x":-13.93,"y":9.14,"data":{"properties":{"name":"docTrackr","permalink":"/organization/doctrackr","founded_at":"01/01/2011","first_funding_at":"24/01/2012","market":" Enterprises ","founded_quarter":"2011-Q1","founded_year":2011,"url":"http://www.crunchbase.com/organization/doctrackr","country":"FRA","homepage_url":"http://www.docTrackr.com","logo":"http://www.crunchbase.com/organization/doctrackr/primary-image/raw","founded_month":"2011-01","funding_rounds":2,"status":"acquired","funding_total":2000000,"region":"Paris","category":"|PaaS|SaaS|Enterprises|Finance|Analytics|Document Management|Security|","last_funding_at":"02/10/2012","logofix":"http://res.cloudinary.com/crunchbase-production/image/upload/v1397188373/05cf999260da5eac38aca59a615830ad.png"},"categories":{"0":"COMPANY"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY","1":"INVESTOR"},"nodes":1,"edges":1},"1":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"INVESTOR"},"nodes":10,"edges":10},"2":{"edgeType":"HAS_CITY","nodeCategories":{"0":"CITY"},"nodes":1,"edges":1},"3":{"edgeType":"HAS_MARKET","nodeCategories":{"0":"MARKET"},"nodes":1,"edges":1}},"edgeCount":13,"visibleEdgeCount":11,"hiddenEdgeCount":2}},"label":"docTrackr","size":4,"glyphs":{"0":{"draw":true,"position":"top-right","content":"2"}},"colors":{"0":"#5FDAA2"},"color":"#5FDAA2"},{"id":937,"x":35.11,"y":54.54,"data":{"properties":{"name":"Psykosoft","permalink":"/organization/psykosoft","founded_at":"01/05/2010","first_funding_at":"24/01/2012","market":" Software ","founded_quarter":"2010-Q2","founded_year":2010,"url":"http://www.crunchbase.com/organization/psykosoft","country":"FRA","homepage_url":"http://www.psykosoft.net","logo":"http://www.crunchbase.com/organization/psykosoft/primary-image/raw","founded_month":"2010-05","funding_rounds":2,"status":"operating","funding_total":618000,"region":"FRA - Other","category":"|Finance|Video Streaming|Search|Cloud Computing|Creative|Web Development|Software|","last_funding_at":"27/06/2012","logofix":"http://res.cloudinary.com/crunchbase-production/image/upload/v1397195509/dbd34064b6331a54fa6e324b2f33f46a.png"},"categories":{"0":"COMPANY"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY","1":"INVESTOR"},"nodes":1,"edges":1},"1":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"INVESTOR"},"nodes":2,"edges":2},"2":{"edgeType":"HAS_CITY","nodeCategories":{"0":"CITY"},"nodes":1,"edges":1},"3":{"edgeType":"HAS_MARKET","nodeCategories":{"0":"MARKET"},"nodes":1,"edges":1}},"edgeCount":5,"visibleEdgeCount":2,"hiddenEdgeCount":3}},"label":"Psykosoft","size":4,"glyphs":{"0":{"draw":true,"position":"top-right","content":"3"}},"colors":{"0":"#5FDAA2"},"color":"#5FDAA2"},{"id":949,"x":19.74,"y":-0.6,"data":{"properties":{"name":"qunb","permalink":"/organization/qunb","founded_at":"10/05/2011","first_funding_at":"01/02/2012","market":" Finance ","founded_quarter":"2011-Q2","founded_year":2011,"url":"http://www.crunchbase.com/organization/qunb","country":"FRA","homepage_url":"http://www.qunb.com","logo":"http://www.crunchbase.com/organization/qunb/primary-image/raw","founded_month":"2011-05","funding_rounds":3,"status":"operating","funding_total":1140000,"region":"Paris","category":"|Finance|Big Data|Software|","last_funding_at":"25/02/2013","logofix":"http://res.cloudinary.com/crunchbase-production/image/upload/v1398231708/oligdumcljr5ukevfkqv.jpg"},"categories":{"0":"COMPANY"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY","1":"INVESTOR"},"nodes":1,"edges":1},"1":{"edgeType":"HAS_CITY","nodeCategories":{"0":"CITY"},"nodes":1,"edges":1},"2":{"edgeType":"HAS_MARKET","nodeCategories":{"0":"MARKET"},"nodes":1,"edges":1}},"edgeCount":3,"visibleEdgeCount":2,"hiddenEdgeCount":1}},"label":"qunb","size":7,"glyphs":{"0":{"draw":true,"position":"top-right","content":"1"}},"colors":{"0":"#5FDAA2"},"color":"#5FDAA2"},{"id":266,"x":-6.87,"y":-8.86,"data":{"properties":{"name":" Enterprises "},"categories":{"0":"MARKET"},"statistics":{"digest":{"0":{"edgeType":"HAS_MARKET","nodeCategories":{"0":"COMPANY"},"nodes":2,"edges":2}},"edgeCount":2,"visibleEdgeCount":1,"hiddenEdgeCount":1}},"label":" Enterprises ","size":1,"glyphs":{"0":{"draw":true,"position":"top-right","content":"1"}},"colors":{"0":"#D4742C"},"color":"#D4742C"},{"id":1217,"x":14.46,"y":56.62,"data":{"properties":{"name":"Atlas Venture","permalink":"/organization/atlas-venture","market":"Technology","url":"http://www.crunchbase.com/organization/atlas-venture","country":"USA","region":"Boston","category":"|Life Sciences|Technology|","state":"MA","city":"Cambridge"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":5,"edges":5}},"edgeCount":5,"visibleEdgeCount":2,"hiddenEdgeCount":3}},"label":"Atlas Venture","size":1,"glyphs":{"0":{"draw":true,"position":"top-right","content":"3"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1373,"x":-51.21,"y":8.66,"data":{"properties":{"name":"Lead Dog Ventures","permalink":"/organization/lead-dog-ventures","url":"http://www.crunchbase.com/organization/lead-dog-ventures","country":"USA","region":"Boston","state":"MA","city":"Wayland"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":1,"visibleEdgeCount":1,"hiddenEdgeCount":0}},"label":"Lead Dog Ventures","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1633,"x":-34.62,"y":48.05,"data":{"properties":{"name":"Joe Caruso","permalink":"/person/joe-caruso","url":"http://www.crunchbase.com/person/joe-caruso"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":1,"visibleEdgeCount":1,"hiddenEdgeCount":0}},"label":"Joe Caruso","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1651,"x":0.89,"y":-1.66,"data":{"properties":{"name":"Walt Winshall","permalink":"/person/walt-winshall","url":"http://www.crunchbase.com/person/walt-winshall"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":1,"visibleEdgeCount":1,"hiddenEdgeCount":0}},"label":"Walt Winshall","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1679,"x":-47.56,"y":-11.96,"data":{"properties":{"name":"Mike Dornbrook","permalink":"/person/mike-dornbrook","url":"http://www.crunchbase.com/person/mike-dornbrook"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":1,"visibleEdgeCount":1,"hiddenEdgeCount":0}},"label":"Mike Dornbrook","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1702,"x":-18.35,"y":36.72,"data":{"properties":{"name":"Alive Ideas","permalink":"/organization/alive-ideas","url":"http://www.crunchbase.com/organization/alive-ideas","country":"FRA","region":"Paris","city":"Paris"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":5,"edges":6}},"edgeCount":6,"visibleEdgeCount":1,"hiddenEdgeCount":5}},"label":"Alive Ideas","size":1,"glyphs":{"0":{"draw":true,"position":"top-right","content":"5"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1751,"x":-25.73,"y":-15.56,"data":{"properties":{"name":"David Opolon","permalink":"/person/david-opolon","url":"http://www.crunchbase.com/person/david-opolon"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":1,"visibleEdgeCount":1,"hiddenEdgeCount":0}},"label":"David Opolon","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"},{"id":1752,"x":-48.17,"y":28.61,"data":{"properties":{"name":"Gilles Samoun","permalink":"/person/gilles-samoun","url":"http://www.crunchbase.com/person/gilles-samoun"},"categories":{"0":"INVESTOR"},"statistics":{"digest":{"0":{"edgeType":"INVESTED_IN","nodeCategories":{"0":"COMPANY"},"nodes":1,"edges":1}},"edgeCount":1,"visibleEdgeCount":1,"hiddenEdgeCount":0}},"label":"Gilles Samoun","size":1,"glyphs":{"0":{"draw":false,"position":"top-right","content":"0"}},"colors":{"0":"#4EA4D4"},"color":"#4EA4D4"}],"edges":[{"id":668,"source":1047,"target":0,"data":{"properties":{},"type":"HAS_CITY"},"label":"HAS_CITY","size":1},{"id":1465,"source":1047,"target":290,"data":{"properties":{},"type":"HAS_MARKET"},"label":"HAS_MARKET","size":1},{"id":3546,"source":1065,"target":1047,"data":{"properties":{"funded_year":2014,"permalink":"/funding-round/1ed1ea64037208a44880bfd4ad6d7c78","funded_at":"13/11/2014","funded_quarter":"2014-Q4","raised_amount_usd":118000,"funding_round_type":"seed","funded_month":"2014-11"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":762,"source":1153,"target":0,"data":{"properties":{},"type":"HAS_CITY"},"label":"HAS_CITY","size":1},{"id":1565,"source":1153,"target":290,"data":{"properties":{},"type":"HAS_MARKET"},"label":"HAS_MARKET","size":1},{"id":3452,"source":1716,"target":1153,"data":{"properties":{"funded_year":2014,"permalink":"/funding-round/18c91d070f5a6fafe2d4cfb17a603726","funded_at":"11/06/2014","funded_quarter":"2014-Q2","raised_amount_usd":20000,"funding_round_type":"seed","funded_month":"2014-06"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3456,"source":1798,"target":1153,"data":{"properties":{"funded_year":2014,"permalink":"/funding-round/18c91d070f5a6fafe2d4cfb17a603726","funded_at":"11/06/2014","funded_quarter":"2014-Q2","raised_amount_usd":20000,"funding_round_type":"seed","funded_month":"2014-06"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":182,"source":516,"target":0,"data":{"properties":{},"type":"HAS_CITY"},"label":"HAS_CITY","size":1},{"id":578,"source":949,"target":0,"data":{"properties":{},"type":"HAS_CITY"},"label":"HAS_CITY","size":1},{"id":2919,"source":1065,"target":937,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/a1e3a04ac6f9a7de967f4e73abee08b0","funded_at":"24/01/2012","funded_quarter":"2012-Q1","raised_amount_usd":118000,"funding_round_type":"seed","funded_month":"2012-01"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":2920,"source":1065,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/d3a41a124b96c0a14903b7b3fb47de36","funded_at":"24/01/2012","funded_quarter":"2012-Q1","funding_round_type":"seed","funded_month":"2012-01"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3133,"source":1065,"target":949,"data":{"properties":{"funded_year":2013,"permalink":"/funding-round/7b33cd65beb8e6f12bed5f869b011049","funded_at":"25/02/2013","funded_quarter":"2013-Q1","funding_round_type":"seed","funded_month":"2013-02"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":988,"source":516,"target":266,"data":{"properties":{},"type":"HAS_MARKET"},"label":"HAS_MARKET","size":1},{"id":2990,"source":1217,"target":937,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/b130ae9138d8a20af67ab0c0ff586efd","funded_at":"27/06/2012","funded_quarter":"2012-Q2","raised_amount_usd":500000,"funding_round_type":"seed","funded_month":"2012-06"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3041,"source":1702,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3042,"source":1217,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3044,"source":1373,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3046,"source":1751,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3047,"source":1752,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3048,"source":1633,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3049,"source":1679,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1},{"id":3050,"source":1651,"target":516,"data":{"properties":{"funded_year":2012,"permalink":"/funding-round/30f5f0bdcb0724a162f4d25c99a90f45","funded_at":"02/10/2012","funded_quarter":"2012-Q4","raised_amount_usd":2000000,"funding_round_type":"seed","funded_month":"2012-10"},"type":"INVESTED_IN"},"label":"INVESTED_IN","size":1}]} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Linkurious SAS, Kyunghoon Kim", 3 | "name": "PyLinkurious", 4 | "version": "0.1.0", 5 | "private": false, 6 | "engine": "node 0.12.4", 7 | "homepage": "https://github.com/Linkurious/PyLinkurious", 8 | "licenses": { 9 | "type": "GPL-3.0+", 10 | "url": "https://raw.github.com/Linkurious/PyLinkurious/master/LICENSE" 11 | }, 12 | "bugs": "https://github.com/Linkurious/PyLinkurious/issues", 13 | "repository": { 14 | "type": "git", 15 | "url": "git@github.com:Linkurious/PyLinkurious.git" 16 | }, 17 | "dependencies": { 18 | "linkurious": "~1.1.0", 19 | "mustache": "~2.1.3", 20 | "xlsx": "~0.7.12", 21 | "dagre": "~0.7.4" 22 | }, 23 | "devDependencies": { 24 | "http-server": "~0.8.0" 25 | }, 26 | "scripts": { 27 | "start": "http-server -p 8000" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/iframe/images/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linkurious/PyLinkurious/b9533991deed3b9cca60cc44c9847b86087a1669/src/iframe/images/favicon-16x16.png -------------------------------------------------------------------------------- /src/iframe/images/favicon-dark-24x24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linkurious/PyLinkurious/b9533991deed3b9cca60cc44c9847b86087a1669/src/iframe/images/favicon-dark-24x24.png -------------------------------------------------------------------------------- /src/iframe/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linkurious/PyLinkurious/b9533991deed3b9cca60cc44c9847b86087a1669/src/iframe/images/favicon.ico -------------------------------------------------------------------------------- /src/iframe/images/noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linkurious/PyLinkurious/b9533991deed3b9cca60cc44c9847b86087a1669/src/iframe/images/noise.png -------------------------------------------------------------------------------- /src/iframe/pylinkurious.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PyLinkurious 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 44 | 45 | 75 | 76 | 77 |
78 | 79 | 104 | 105 | 127 | 128 |
129 | 132 | 135 | 138 | 141 | 144 |
145 | 146 | 164 | 165 | 166 | 167 | 168 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /src/iframe/pylinkurious.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Linkurious SAS 2012 - 2015 3 | * Created by Sebastien Heymann on 12/08/2015. 4 | */ 5 | 'use strict'; 6 | 7 | var LK = Object.create(null); // namespace 8 | 9 | (function(undefined) { 10 | 11 | if (typeof sigma === 'undefined') 12 | throw 'sigma is not declared'; 13 | 14 | var sigmaInstance, 15 | activeStatePlugin, 16 | designPlugin, 17 | selectPlugin, 18 | tooltipsPlugin, 19 | locatePlugin, 20 | sigmaContainer, 21 | initialized = false, 22 | NB_SEARCH_RESULTS = 5; 23 | 24 | // Available query parameters: "ui", "forceui", "graph", "cb" 25 | // - ui: features, availables values are "search","share","fullscreen","zoom","layout" 26 | // - graph: URL to the graph in JSON file format 27 | // - cb: callback function from the parent window 28 | var queryString = getQueryString(location.search.substr(1)); // substr removes "?" 29 | 30 | var settings = { 31 | /** 32 | * POWEREDBY SETTINGS: 33 | * ******************* 34 | */ 35 | poweredByHTML: ' Powered by Linkurious', 36 | poweredByURL: 'https://linkurio.us', 37 | 38 | /** 39 | * RENDERERS SETTINGS: 40 | * ******************* 41 | */ 42 | defaultEdgeType: 'tapered', 43 | // Labels: 44 | font: 'Roboto', 45 | defaultLabelColor: '#000', 46 | defaultLabelSize: 11, 47 | labelThreshold: 5, 48 | labelAlignment: 'center', 49 | defaultEdgeLabelSize: 11, 50 | edgeLabelThreshold: 4, 51 | labelHoverShadow: '', 52 | edgeLabelHoverShadow: '', 53 | // Edges: 54 | edgeColor: 'default', 55 | defaultEdgeColor: '#a9a9a9', 56 | // Nodes: 57 | defaultNodeColor: '#999999', 58 | // Hovered nodes: 59 | hoverFontStyle: 'bold', 60 | borderSize: 2, 61 | outerBorderSize: 4, 62 | nodeBorderColor: 'default', 63 | defaultNodeBorderColor: '#ffffff', 64 | defaultNodeOuterBorderColor: '#f65565', 65 | nodeHoverLevel: 1, 66 | // Hovered edges: 67 | edgeHoverExtremities: true, 68 | edgeHoverLevel: 1, 69 | // Actve nodes and edges: 70 | activeFontStyle: 'bold', 71 | nodeActiveColor: 'node', 72 | defaultNodeActiveColor: '#999999', 73 | nodeActiveLevel: 3, 74 | edgeActiveColor: 'default', 75 | defaultEdgeActiveColor: '#f65565', 76 | edgeActiveLevel: 3, 77 | 78 | // Halo: 79 | nodeHaloSize: 25, 80 | edgeHaloSize: 20, 81 | nodeHaloColor: '#ffffff', 82 | edgeHaloColor: '#ffffff', 83 | nodeHaloStroke: true, 84 | nodeHaloStrokeColor: '#a9a9a9', 85 | nodeHaloStrokeWidth: 0.5, 86 | 87 | // Node images: 88 | imgCrossOrigin: 'anonymous', 89 | 90 | /** 91 | * RESCALE SETTINGS: 92 | * ***************** 93 | */ 94 | minNodeSize: 5, 95 | maxNodeSize: 5, 96 | minEdgeSize: 2, 97 | maxEdgeSize: 2, 98 | 99 | /** 100 | * CAPTORS SETTINGS: 101 | * ***************** 102 | */ 103 | zoomingRatio: 1.382, 104 | doubleClickZoomingRatio: 1.7, 105 | zoomMin: 0.1, 106 | zoomMax: 10, 107 | doubleClickZoomDuration: 200, 108 | 109 | /** 110 | * GLOBAL SETTINGS: 111 | * **************** 112 | */ 113 | autoRescale: ['nodeSize', 'edgeSize'], 114 | doubleClickEnabled: true, 115 | enableEdgeHovering: true, 116 | edgeHoverPrecision: 10, 117 | approximateLabelWidth: true, 118 | 119 | /** 120 | * CAMERA SETTINGS: 121 | * **************** 122 | */ 123 | nodesPowRatio: 0.8, 124 | edgesPowRatio: 0.8, 125 | 126 | /** 127 | * ANIMATIONS SETTINGS: 128 | * ******************** 129 | */ 130 | animationsTime: 1000 131 | }; 132 | 133 | var tooltipsSettings = { 134 | node: { 135 | show: 'clickNode', 136 | hide: 'clickStage', 137 | cssClass: 'sigma-tooltip', 138 | position: 'top', 139 | autoadjust: true 140 | }, 141 | edge: { 142 | show: 'clickEdge', 143 | hide: 'clickStage', 144 | cssClass: 'sigma-tooltip', 145 | position: 'top', 146 | autoadjust: true 147 | } 148 | }; 149 | 150 | LK.content = {}; 151 | 152 | 153 | /** 154 | * Initialize the widget. It should be called only once. 155 | */ 156 | LK.widget = function() { 157 | if(initialized) return; 158 | 159 | initialized = true; 160 | sigmaContainer = LK.dom.$('graph-canvas'); 161 | 162 | sigmaInstance = new sigma({ 163 | renderer: { 164 | container: sigmaContainer, 165 | type: 'canvas' 166 | }, 167 | settings: settings 168 | }); 169 | 170 | // ------------------------------------------------------------------------------------------ 171 | // LOAD GRAPH 172 | // ------------------------------------------------------------------------------------------ 173 | 174 | if (typeof widgetData !== 'string' && widgetData.content) { 175 | LK.content = widgetData.content; 176 | sigmaInstance.graph.read(LK.content.graph); 177 | sigmaInstance.refresh(); 178 | } 179 | else if (queryString.graph) { 180 | sigma.parsers.json( 181 | queryString.graph, 182 | sigmaInstance, 183 | function() { 184 | sigmaInstance.refresh(); 185 | } 186 | ); 187 | } 188 | 189 | // ------------------------------------------------------------------------------------------ 190 | // SIGMA PLUGINS 191 | // ------------------------------------------------------------------------------------------ 192 | 193 | // Instantiate the Keyboards plugin: 194 | sigma.plugins.keyboard(sigmaInstance, sigmaInstance.renderers[0], { 195 | zoomingRatio: 1.3 196 | }); 197 | 198 | designPlugin = sigma.plugins.design(sigmaInstance); 199 | 200 | if (LK.content && LK.content.styles && LK.content.palette) { 201 | LK.setDesign(LK.content.styles, LK.content.palette); 202 | } 203 | 204 | activeStatePlugin = sigma.plugins.activeState(sigmaInstance); 205 | selectPlugin = sigma.plugins.select(sigmaInstance, activeStatePlugin, sigmaInstance.renderers[0]); 206 | 207 | // Instantiate the Locate plugin: 208 | locatePlugin = sigma.plugins.locate(sigmaInstance, { 209 | animation: { 210 | node: { 211 | duration: 800 212 | }, 213 | edge: { 214 | duration: 800 215 | }, 216 | center: { 217 | duration: 800 218 | } 219 | }, 220 | padding: { 221 | top: 60, 222 | right: 20, 223 | bottom: 20, 224 | left: 20 225 | }, 226 | focusOut: false, 227 | zoomDef: 0.3 228 | }); 229 | 230 | if (sigmaInstance.graph.nodes().length) { 231 | locatePlugin.center(); 232 | } 233 | 234 | var renderHalo = function() { 235 | var nodes = []; 236 | activeStatePlugin.nodes().forEach(function(node) { 237 | nodes = nodes.concat(sigmaInstance.graph.adjacentNodes(node.id)); 238 | }); 239 | nodes.concat(activeStatePlugin.nodes()); 240 | 241 | activeStatePlugin.edges().forEach(function(edge) { 242 | nodes.push(sigmaInstance.graph.nodes(edge.source)); 243 | nodes.push(sigmaInstance.graph.nodes(edge.target)); 244 | }); 245 | 246 | // TODO remove duplicates from nodes 247 | 248 | sigmaInstance.renderers[0].halo({ 249 | nodes: nodes 250 | }); 251 | }; 252 | 253 | sigmaInstance.renderers[0].bind('render', function() { 254 | renderHalo(); 255 | }); 256 | 257 | //ACTIVE EVENTS 258 | activeStatePlugin.bind('activeNodes', function () { 259 | renderHalo(); 260 | }); 261 | activeStatePlugin.bind('activeEdges', function () { 262 | renderHalo(); 263 | }); 264 | 265 | // Instantiate the PoweredBy plugin: 266 | sigmaInstance.renderers[0].poweredBy(); 267 | 268 | // Instantiate the tooltips plugin with a Mustache renderer 269 | var tooltipsNodeTmpl = LK.dom.$('tooltip-node').innerHTML; 270 | Mustache.parse(tooltipsNodeTmpl); // optional, speeds up future uses 271 | tooltipsSettings.node.template = tooltipsNodeTmpl; 272 | tooltipsSettings.node.renderer = function(node, template) { 273 | node = mustachPrepare(node, 'node'); 274 | return Mustache.render(template, node); 275 | }; 276 | 277 | var tooltipsEdgeTmpl = LK.dom.$('tooltip-edge').innerHTML; 278 | Mustache.parse(tooltipsEdgeTmpl); // optional, speeds up future uses 279 | tooltipsSettings.edge.template = tooltipsEdgeTmpl; 280 | tooltipsSettings.edge.renderer = function(edge, template) { 281 | edge = mustachPrepare(edge, 'edge'); 282 | return Mustache.render(template, edge); 283 | }; 284 | 285 | tooltipsPlugin = sigma.plugins.tooltips(sigmaInstance, sigmaInstance.renderers[0], tooltipsSettings); 286 | 287 | 288 | sigmaInstance.bind('hovers', function (event) { 289 | if(event.data.enter.nodes.length) { 290 | // Add the 'hover' class to the DOM container: 291 | if (-1 == sigmaContainer.className.indexOf('hoverNodes')) { 292 | sigmaContainer.className += ' hoverNodes'; 293 | } 294 | } 295 | else if(event.data.enter.edges.length) { 296 | // Add the 'hover' class to the DOM container: 297 | if (-1 == sigmaContainer.className.indexOf('hoverEdges')) { 298 | sigmaContainer.className += ' hoverEdges'; 299 | } 300 | } 301 | else if(event.data.leave.nodes.length || event.data.leave.edges.length) { 302 | // Remove the 'hover' class from the DOM container: 303 | sigmaContainer.className = sigmaContainer.className.replace(' hoverNodes', ''); 304 | // Remove the 'hover' class from the DOM container: 305 | sigmaContainer.className = sigmaContainer.className.replace(' hoverEdges', ''); 306 | } 307 | }); 308 | 309 | // public access for iframe parent: 310 | LK.sigma = sigmaInstance; 311 | LK.plugins = { 312 | activeState: activeStatePlugin, 313 | design: designPlugin, 314 | locate: locatePlugin, 315 | select: selectPlugin, 316 | tooltips: tooltipsPlugin 317 | }; 318 | 319 | if (queryString.cb && typeof window.parent[queryString.cb] === 'function') { 320 | window.parent[queryString.cb](); 321 | } 322 | 323 | if (widgetData.title) { 324 | document.title = widgetData.title + ' - PyLinkurious'; 325 | } 326 | if (LK.content) { 327 | if (LK.content.description) { 328 | var elt = LK.dom.all('meta[name=description]')[0]; 329 | if (elt) { 330 | elt.parentNode.removeChild(elt); 331 | } 332 | elt = document.createElement('meta'); 333 | elt.name = 'description'; 334 | elt.content = LK.content.description; 335 | LK.dom.all('head')[0].appendChild(elt); 336 | } 337 | if (widgetData.url) { 338 | LK.dom.$('url').value = widgetData.url; 339 | } 340 | if (widgetData.url) { 341 | LK.dom.$('code').value = getWidgetCode( 342 | widgetData.url, 343 | widgetData.title, 344 | LK.content.description 345 | ); 346 | } 347 | } 348 | 349 | LK.updateUI(); 350 | 351 | // In case the WebGL renderer is used, we must wait for FontAwesome to be loaded. 352 | // http://www.w3.org/TR/css-font-loading/ 353 | if (document.fonts) { 354 | // document.fonts.ready() method is going to be replaced with 355 | // document.fonts.ready attribute in the future. 356 | var fontsReady = document.fonts.ready; 357 | if (typeof(fontsReady) == "function") { 358 | fontsReady = document.fonts.ready(); 359 | } 360 | fontsReady.then(function() { 361 | LK.sigma.refresh({ skipIndexation:true }); 362 | }); 363 | } 364 | else { // wait 365 | // TODO use a polyfill such as: 366 | // https://github.com/zachleat/fontfaceonload 367 | // https://github.com/smnh/FontLoader 368 | setTimeout(function() { 369 | LK.sigma.refresh({ skipIndexation:true }); 370 | }, 2000); 371 | } 372 | 373 | return true; 374 | }; 375 | 376 | /** 377 | * Manually open a tooltip on a node. 378 | * @param node 379 | */ 380 | LK.openNodeTooltip = function(node) { 381 | var prefix = 'renderer1:'; 382 | tooltipsPlugin.open(node, tooltipsSettings.node, node[prefix + 'x'], node[prefix + 'y']); 383 | }; 384 | 385 | /** 386 | * Manually open a tooltip on an edge. 387 | * @param edge 388 | */ 389 | LK.openEdgeTooltip = function(edge) { 390 | var prefix = 'renderer1:', 391 | source = sigmaInstance.graph.nodes(edge.source), 392 | target = sigmaInstance.graph.nodes(edge.target), 393 | x = (source[prefix + 'x'] + target[prefix + 'x']) * 0.5, 394 | y = (source[prefix + 'y'] + target[prefix + 'y']) * 0.5; 395 | tooltipsPlugin.open(edge, tooltipsSettings.edge, x, y); 396 | }; 397 | 398 | /** 399 | * Close the current tooltip. 400 | */ 401 | LK.closeTooltip = function() { 402 | tooltipsPlugin.close(); 403 | }; 404 | 405 | // ------------------------------------------------------------------------------------------ 406 | // SEARCH FUNCTIONS 407 | // ------------------------------------------------------------------------------------------ 408 | 409 | LK.searchType = 'nodes'; 410 | 411 | /** 412 | * Create the footer of the search results list. 413 | * @param {DOMElement} parentElt 414 | * @param {number} tabIndex 415 | */ 416 | function createFooterElt (parentElt, tabIndex) { 417 | var elt = document.createElement('p'); 418 | elt.className = 'autocomplete_dropdown_item btn'; 419 | elt.tabIndex = tabIndex; 420 | 421 | if (LK.searchType === 'nodes') { 422 | elt.appendChild( document.createTextNode('Show edges') ); 423 | elt.onclick = function() { 424 | LK.search('edges'); 425 | }; 426 | elt.addEventListener('keydown', function(event) { 427 | switch (event.which) { 428 | case 13: // select on Enter key pressed 429 | LK.search('edges'); 430 | LK.dom.$('result-list__dropdown').firstChild.focus(); 431 | break; 432 | case 38: // up arrow 433 | if (this.previousSibling) this.previousSibling.focus(); 434 | else this.parentNode.lastChild.focus(); 435 | break; 436 | case 40: // down arrow 437 | case 9: // TAB 438 | this.parentNode.firstChild.focus(); 439 | break; 440 | default: 441 | LK.dom.$('result-list__input').focus(); 442 | } 443 | event.preventDefault(); 444 | if (event.which != 9) { 445 | event.stopPropagation(); 446 | } 447 | }); 448 | } 449 | else { 450 | elt.appendChild( document.createTextNode('Show nodes') ); 451 | elt.onclick = function() { 452 | LK.search('nodes'); 453 | }; 454 | elt.addEventListener('keydown', function(event) { 455 | switch (event.which) { 456 | case 13: // select on Enter key pressed 457 | LK.search('nodes'); 458 | LK.dom.$('result-list__dropdown').firstChild.focus(); 459 | break; 460 | case 38: // up arrow 461 | if (this.previousSibling) this.previousSibling.focus(); 462 | else this.parentNode.lastChild.focus(); 463 | break; 464 | case 40: // down arrow 465 | case 9: // TAB 466 | this.parentNode.firstChild.focus(); 467 | break; 468 | default: 469 | LK.dom.$('result-list__input').focus(); 470 | } 471 | event.preventDefault(); 472 | if (event.which != 9) { 473 | event.stopPropagation(); 474 | } 475 | }); 476 | } 477 | 478 | parentElt.appendChild(elt); 479 | } 480 | 481 | /** 482 | * Search nodes or edges. 483 | * @param type 'nodes' | 'edges' 484 | */ 485 | LK.search = function(type) { 486 | LK.searchType = type || LK.searchType; 487 | var q = LK.dom.$('result-list__input').value; 488 | 489 | if (q.length) { 490 | var nodesMatches, 491 | edgesMatches, 492 | elt, 493 | e, 494 | resultList, 495 | tabindex = 100; 496 | 497 | // Empty the list of results 498 | resultList = LK.dom.$('result-list__dropdown'); 499 | while (resultList.lastChild) { 500 | resultList.removeChild(resultList.lastChild); 501 | } 502 | 503 | // Search nodes 504 | if (LK.searchType === 'nodes') { 505 | nodesMatches = graphSearch(q, sigmaInstance.graph.nodes()) 506 | .slice(0, NB_SEARCH_RESULTS) 507 | .map(function(match) { 508 | 509 | elt = document.createElement('p'); 510 | elt.dataset.id = match.item.id; 511 | elt.className = 'autocomplete_dropdown_item'; 512 | elt.tabIndex = tabindex++; 513 | elt.onclick = nodeResultHandler; 514 | elt.addEventListener('keydown', function(event) { 515 | switch (event.which) { 516 | case 13: // select on Enter key pressed 517 | nodeResultHandler.apply(this); 518 | break; 519 | case 38: // up arrow 520 | if (this.previousSibling) this.previousSibling.focus(); 521 | else this.parentNode.lastChild.focus(); 522 | break; 523 | case 40: // down arrow 524 | if (this.nextSibling) this.nextSibling.focus(); 525 | else this.parentNode.firstChild.focus(); 526 | break; 527 | case 9: // TAB 528 | break; 529 | default: 530 | LK.dom.$('result-list__input').focus(); 531 | } 532 | if (event.which != 9) { 533 | event.preventDefault(); 534 | event.stopPropagation(); 535 | } 536 | }); 537 | elt.appendChild( document.createTextNode(match.item.label) ); 538 | return elt; 539 | }); 540 | 541 | for ( e = 0; e < nodesMatches.length; e++ ) { 542 | resultList.appendChild(nodesMatches[e]); 543 | } 544 | 545 | if (!nodesMatches.length) { 546 | elt = document.createElement('p'); 547 | elt.className = 'autocomplete_dropdown_item'; 548 | elt.tabIndex = tabindex++; 549 | elt.appendChild( document.createTextNode('0 nodes found.') ); 550 | resultList.appendChild(elt); 551 | } 552 | } 553 | 554 | // Search edges 555 | if (LK.searchType === 'edges') { 556 | edgesMatches = graphSearch(q, sigmaInstance.graph.edges()) 557 | .slice(0, NB_SEARCH_RESULTS) 558 | .map(function(match) { 559 | 560 | elt = document.createElement('p'); 561 | elt.dataset.id = match.item.id; 562 | elt.className = 'autocomplete_dropdown_item'; 563 | elt.tabIndex = tabindex++; 564 | elt.onclick = edgeResultHandler; 565 | elt.addEventListener('keydown', function(event) { 566 | switch (event.which) { 567 | case 13: // select on Enter key pressed 568 | edgeResultHandler.apply(this); 569 | break; 570 | case 38: // up arrow 571 | if (this.previousSibling) this.previousSibling.focus(); 572 | else this.parentNode.lastChild.focus(); 573 | break; 574 | case 40: // down arrow 575 | if (this.nextSibling) this.nextSibling.focus(); 576 | else this.parentNode.firstChild.focus(); 577 | break; 578 | case 9: // TAB 579 | break; 580 | default: 581 | LK.dom.$('result-list__input').focus(); 582 | } 583 | if (event.which != 9) { 584 | event.preventDefault(); 585 | event.stopPropagation(); 586 | } 587 | }); 588 | elt.appendChild( document.createTextNode(match.item.label) ); 589 | return elt; 590 | }); 591 | 592 | for ( e = 0; e < edgesMatches.length; e++ ) { 593 | resultList.appendChild( edgesMatches[e] ); 594 | } 595 | 596 | if (!edgesMatches.length) { 597 | elt = document.createElement('p'); 598 | elt.className = 'autocomplete_dropdown_item'; 599 | elt.tabIndex = tabindex++; 600 | elt.appendChild( document.createTextNode('0 edges found.') ); 601 | resultList.appendChild(elt); 602 | } 603 | } 604 | 605 | createFooterElt(resultList, tabindex++); 606 | 607 | LK.dom.show('#autocomplete__reset'); 608 | LK.dom.show('#result-list__dropdown'); 609 | } 610 | else LK.clearSearch(); 611 | }; 612 | 613 | /** 614 | * Clear search result. 615 | */ 616 | LK.clearSearch = function() { 617 | LK.dom.hide('#autocomplete__reset'); 618 | LK.dom.hide('#result-list__dropdown'); 619 | LK.dom.$('result-list__input').value = ''; 620 | LK.dom.$('result-list__input').focus(); 621 | //Clear results 622 | var resultList = LK.dom.$('result-list__dropdown'); 623 | while (resultList.lastChild) { 624 | resultList.removeChild(resultList.lastChild); 625 | } 626 | }; 627 | 628 | document.getElementById('result-list__input').addEventListener('keydown', function(event) { 629 | 630 | if (event.which == 13) { 631 | // Select the first result in the list on Enter key pressed: 632 | if (LK.dom.$('result-list__dropdown').children.length) { 633 | LK.dom.$('result-list__dropdown').firstChild.focus(); 634 | LK.dom.$('result-list__dropdown').firstChild.click(); 635 | } 636 | // Avoid submit when enter is pressed: 637 | event.preventDefault(); 638 | event.stopPropagation(); 639 | } 640 | 641 | if (!LK.dom.$('result-list__dropdown').children.length) return; 642 | 643 | // Focus on first result item: 644 | if (event.which == 9 || event.which == 40) { // TAB key or down arrow 645 | LK.dom.$('result-list__dropdown').firstChild.focus(); 646 | event.preventDefault(); // avoid double-tabbing on TAB key pressed 647 | } 648 | event.stopPropagation(); 649 | }, false); 650 | 651 | 652 | // ------------------------------------------------------------------------------------------ 653 | // LAYOUT FUNCTIONS 654 | // ------------------------------------------------------------------------------------------ 655 | 656 | /** 657 | * Start/stop the ForceLink layout. 658 | */ 659 | LK.toggleLayout = function() { 660 | var btnElt = LK.dom.$('viewController-layout').children[0]; 661 | if (sigma.layouts.isForceLinkRunning()) { 662 | sigma.layouts.stopForceLink(); 663 | btnElt.className = btnElt.className.replace('fa-pause', 'fa-play'); 664 | } 665 | else { 666 | var nodesCount = sigmaInstance.graph.nodes().length, 667 | scalingRatio = 2, 668 | gravity = (nodesCount > 250) ? (2 * nodesCount) / 100 : 2.5; 669 | 670 | // TODO replace by a more qualitative layout on graphs < 50 nodes 671 | if (nodesCount > 50) { 672 | scalingRatio = 2.5; 673 | } else if (nodesCount > 10) { 674 | scalingRatio = 5; 675 | } else if (nodesCount > 3) { 676 | scalingRatio = 10; 677 | } else if (nodesCount > 2) { 678 | scalingRatio = 30; 679 | } else { 680 | scalingRatio = 50; 681 | } 682 | 683 | if (!nodesCount) return; 684 | 685 | sigma.layouts.configForceLink(sigmaInstance, { 686 | autoStop: true, 687 | background: true, 688 | maxIterations: 1500, 689 | avgDistanceThreshold: 0.00001, 690 | linLogMode: true, 691 | barnesHutOptimize: (nodesCount > 1000), 692 | easing: 'cubicInOut', 693 | scalingRatio: scalingRatio, 694 | gravity: gravity, 695 | randomize: 'locally', 696 | randomizeFactor: 30, 697 | alignNodeSiblings: (nodesCount > 3), 698 | nodeSiblingsScale: 8, 699 | nodeSiblingsAngleMin: 0.3 700 | }) 701 | .bind('interpolate stop', function(){ 702 | btnElt.className = btnElt.className.replace('fa-pause', 'fa-play'); 703 | }); 704 | 705 | btnElt.className = btnElt.className.replace('fa-play', 'fa-pause'); 706 | sigma.layouts.startForceLink(); 707 | } 708 | }; 709 | 710 | 711 | // ------------------------------------------------------------------------------------------ 712 | // DESIGN FUNCTIONS 713 | // ------------------------------------------------------------------------------------------ 714 | 715 | /** 716 | * Clear current design, load new styles and palette, and apply. 717 | * @param styles 718 | * @param palette 719 | */ 720 | LK.setDesign = function(styles, palette) { 721 | designPlugin.clear(); 722 | designPlugin.setPalette(palette); 723 | designPlugin.setStyles(styles); 724 | 725 | if (styles.nodes && styles.nodes.icon) { 726 | sigmaInstance.settings('labelAlignment', 'right'); 727 | } 728 | else { 729 | sigmaInstance.settings('labelAlignment', ''); 730 | } 731 | 732 | designPlugin.apply(); 733 | }; 734 | 735 | 736 | // ------------------------------------------------------------------------------------------ 737 | // CAMERA FUNCTIONS 738 | // ------------------------------------------------------------------------------------------ 739 | 740 | /** 741 | * Zoom on the specified node. 742 | * @param id The node id. 743 | * @param options 744 | */ 745 | LK.locateNode = function(id, options) { 746 | locatePlugin.nodes(id, options); 747 | }; 748 | 749 | /** 750 | * Zoom on the specified edge. 751 | * @param id The edge id. 752 | * @param options 753 | */ 754 | LK.locateEdge = function(id, options) { 755 | locatePlugin.edges(id, options); 756 | }; 757 | 758 | LK.zoomOut = function() { 759 | sigma.utils.zoomTo( 760 | sigmaInstance.camera, 761 | 0, 762 | 0, 763 | 1 / sigmaInstance.settings('zoomingRatio'), 764 | { duration: 300 } 765 | ); 766 | }; 767 | 768 | LK.zoomIn = function() { 769 | sigma.utils.zoomTo( 770 | sigmaInstance.camera, 771 | 0, 772 | 0, 773 | sigmaInstance.settings('zoomingRatio'), 774 | { duration: 300 } 775 | ); 776 | }; 777 | 778 | /** 779 | * Reset the camera zoom and position. 780 | */ 781 | LK.zoomCenter = function() { 782 | sigma.utils.zoomTo( 783 | sigmaInstance.camera, 784 | 0, 785 | 0, 786 | 1, 787 | { duration: 300 } 788 | ); 789 | }; 790 | 791 | /** 792 | * Display the graph in full screen mode. 793 | */ 794 | LK.fullscreen = function() { 795 | sigmaInstance.renderers[0].fullScreen(); 796 | }; 797 | 798 | 799 | // ------------------------------------------------------------------------------------------ 800 | // SHARE FUNCTIONS 801 | // ------------------------------------------------------------------------------------------ 802 | 803 | /** 804 | * Open the Share modal 805 | */ 806 | LK.share = function() { 807 | LK.dom.show('#share-overlay'); 808 | }; 809 | 810 | /** 811 | * Close the Share modal 812 | */ 813 | LK.closeShareOverlay = function() { 814 | LK.dom.hide('#share-overlay'); 815 | }; 816 | 817 | // ------------------------------------------------------------------------------------------ 818 | // DOM UTILITY FUNCTIONS 819 | // ------------------------------------------------------------------------------------------ 820 | 821 | LK.dom = { 822 | /** 823 | * Get the DOM element by id. 824 | * @param {string} id 825 | * @returns {Element} 826 | */ 827 | $: function (id) { 828 | return document.getElementById(id); 829 | }, 830 | 831 | /** 832 | * Get a set of DOM elements by CSS selectors. 833 | * @param {string} selectors The CSS selectors. 834 | * @returns {NodeList} 835 | */ 836 | all: function (selectors) { 837 | return document.querySelectorAll(selectors); 838 | }, 839 | 840 | /** 841 | * Remove the specified CSS class from the specified DOM elements. 842 | * @param {string} selectors The CSS selectors. 843 | * @param {string} cssClass 844 | */ 845 | removeClass: function(selectors, cssClass) { 846 | var nodes = document.querySelectorAll(selectors); 847 | var l = nodes.length; 848 | for (var i = 0 ; i < l; i++ ) { 849 | var el = nodes[i]; 850 | // Bootstrap compatibility 851 | el.className = el.className.replace(cssClass, ''); 852 | } 853 | }, 854 | 855 | /** 856 | * Add the specified CSS class to the specified DOM elements. 857 | * @param {string} selectors The CSS selectors. 858 | * @param {string} cssClass 859 | */ 860 | addClass: function (selectors, cssClass) { 861 | var nodes = document.querySelectorAll(selectors); 862 | var l = nodes.length; 863 | for (var i = 0 ; i < l; i++ ) { 864 | var el = nodes[i]; 865 | // Bootstrap compatibility 866 | if (-1 == el.className.indexOf(cssClass)) { 867 | el.className += ' ' + cssClass; 868 | } 869 | } 870 | }, 871 | 872 | /** 873 | * Remove the CSS class "hidden" from the specified DOM elements. 874 | * @param {string} selectors The CSS selectors. 875 | */ 876 | show: function (selectors) { 877 | this.removeClass(selectors, 'hidden'); 878 | }, 879 | 880 | /** 881 | * Add the CSS class "hidden" to the specified DOM elements. 882 | * @param {string} selectors The CSS selectors. 883 | */ 884 | hide: function (selectors) { 885 | this.addClass(selectors, 'hidden'); 886 | }, 887 | 888 | /** 889 | * Toggle the visibility of the specified DOM elements. 890 | * @param {string} selectors The CSS selectors. 891 | * @param {string} [cssClass] the optional CSS class. Default: "hidden" 892 | */ 893 | toggle: function (selectors, cssClass) { 894 | var cssClass = cssClass || "hidden"; 895 | var nodes = document.querySelectorAll(selectors); 896 | var l = nodes.length; 897 | for (var i = 0 ; i < l; i++ ) { 898 | var el = nodes[i]; 899 | //el.style.display = (el.style.display != 'none' ? 'none' : '' ); 900 | // Bootstrap compatibility 901 | if (-1 !== el.className.indexOf(cssClass)) { 902 | el.className = el.className.replace(cssClass, ''); 903 | } else { 904 | el.className += ' ' + cssClass; 905 | } 906 | } 907 | } 908 | }; 909 | 910 | // ------------------------------------------------------------------------------------------ 911 | // WIDGET PARAMETERS 912 | // ------------------------------------------------------------------------------------------ 913 | 914 | /** 915 | * All UI features are displayed if "ui" is missing, otherwise we display the listed features only. 916 | */ 917 | LK.updateUI = function() { 918 | if ('forceui' in queryString) { 919 | LK.dom.addClass('#searchbar', 'always-opaque'); 920 | LK.dom.addClass('#viewController', 'always-opaque'); 921 | } 922 | if ('ui' in queryString) { 923 | if (queryString.ui.indexOf('search') != -1) { 924 | LK.dom.show('#searchbar'); 925 | } 926 | if (queryString.ui.indexOf('share') != -1) { 927 | LK.dom.show('#viewController-share'); 928 | } 929 | if (queryString.ui.indexOf('layout') != -1) { 930 | LK.dom.show('#viewController-layout'); 931 | } 932 | if (queryString.ui.indexOf('fullscreen') != -1) { 933 | LK.dom.show('#viewController-fullscreen'); 934 | } 935 | if (queryString.ui.indexOf('zoom') != -1) { 936 | LK.dom.show('#viewController-zoomin'); 937 | LK.dom.show('#viewController-zoomout'); 938 | } 939 | } 940 | else if ('ui' in LK.content) { 941 | if (LK.content.ui.search) { 942 | LK.dom.show('#searchbar'); 943 | } 944 | if (LK.content.ui.share) { 945 | LK.dom.show('#viewController-share'); 946 | } 947 | if (LK.content.ui.layout) { 948 | LK.dom.show('#viewController-layout'); 949 | } 950 | if (LK.content.ui.fullscreen) { 951 | LK.dom.show('#viewController-fullscreen'); 952 | } 953 | if (LK.content.ui.zoom) { 954 | LK.dom.show('#viewController-zoomin'); 955 | LK.dom.show('#viewController-zoomout'); 956 | } 957 | } 958 | else { 959 | LK.dom.show('#searchbar'); 960 | LK.dom.show('#viewController-share'); 961 | LK.dom.show('#viewController-layout'); 962 | LK.dom.show('#viewController-fullscreen'); 963 | LK.dom.show('#viewController-zoomin'); 964 | LK.dom.show('#viewController-zoomout'); 965 | } 966 | }; 967 | 968 | 969 | // ------------------------------------------------------------------------------------------ 970 | // DRAG'N'DROP FILES 971 | // ------------------------------------------------------------------------------------------ 972 | 973 | // see http://www.html5rocks.com/en/tutorials/file/dndfiles/ 974 | 975 | /** 976 | * Close the Drag modal 977 | */ 978 | LK.closeDragOverlay = function() { 979 | LK.dom.hide('#drag-overlay'); 980 | }; 981 | 982 | 983 | document.ondragover = function (e) { 984 | e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. 985 | LK.dom.show('#drag-overlay'); 986 | return false; 987 | }; 988 | 989 | document.ondrop = onDropHandler; 990 | 991 | document.getElementById('drop-zone-graph').ondragover = function (e) { 992 | LK.dom.addClass('#drop-zone-graph', 'dragover'); 993 | }; 994 | 995 | document.getElementById('drop-zone-graph').ondragleave = function (e) { 996 | LK.dom.removeClass('#drop-zone-graph', 'dragover'); 997 | }; 998 | 999 | document.getElementById('drop-zone-graph').ondrop = onDropHandler; 1000 | 1001 | document.getElementById('drop-zone-design').ondragover = function (e) { 1002 | LK.dom.addClass('#drop-zone-design', 'dragover'); 1003 | }; 1004 | 1005 | document.getElementById('drop-zone-design').ondragleave = function (e) { 1006 | LK.dom.removeClass('#drop-zone-design', 'dragover'); 1007 | }; 1008 | 1009 | document.getElementById('drop-zone-design').ondrop = onDropHandler; 1010 | 1011 | 1012 | // ------------------------------------------------------------------------------------------ 1013 | // RUN WIDGET 1014 | // ------------------------------------------------------------------------------------------ 1015 | 1016 | document.addEventListener("DOMContentLoaded", function() { 1017 | LK.widget(); 1018 | }); 1019 | 1020 | // ------------------------------------------------------------------------------------------ 1021 | // PRIVATE FUNCTIONS 1022 | // ------------------------------------------------------------------------------------------ 1023 | 1024 | /** 1025 | * Generate the widget iframe code. 1026 | * @param {string} url 1027 | * @param {string} title 1028 | * @param {string} description 1029 | * @returns {string} 1030 | */ 1031 | function getWidgetCode(url, title, description) { 1032 | var title = title || ''; 1033 | var description = description || ''; 1034 | 1035 | var iframe = '' + 1037 | '

' + title + ' on ' + 1038 | 'Linkurious.

'; 1039 | 1040 | if (description.length) { 1041 | iframe += '

' + description + '

'; 1042 | } 1043 | return iframe; 1044 | } 1045 | 1046 | /** 1047 | * Format the node or edge data for Mustache. 1048 | * @param item 1049 | * @param type 'node' or 'edge' 1050 | * @return The modified item. 1051 | */ 1052 | function mustachPrepare(item, type) { 1053 | // see http://stackoverflow.com/a/9058774/ 1054 | item.mustacheProperties = []; 1055 | item.mustacheCategories = []; 1056 | 1057 | if(item.data) { 1058 | for (var prop in item.data.properties){ 1059 | if (item.data.properties.hasOwnProperty(prop)){ 1060 | item.mustacheProperties.push({ 1061 | 'key' : prop, 1062 | 'value' : item.data.properties[prop] 1063 | }); 1064 | } 1065 | } 1066 | if (type === 'node') { 1067 | for (var prop in item.data.categories){ 1068 | if (item.data.categories.hasOwnProperty(prop)){ 1069 | item.mustacheCategories.push(item.data.categories[prop]); 1070 | } 1071 | } 1072 | } 1073 | else { 1074 | item.mustacheCategories = [item.data.type]; 1075 | } 1076 | } 1077 | 1078 | return item; 1079 | } 1080 | 1081 | /** 1082 | * Search on sigma nodes or sigma edges. 1083 | * @param {string} q The query string. 1084 | * @param {array} items Nodes or edges. 1085 | * @returns {array} 1086 | */ 1087 | function graphSearch(q, items) { 1088 | q = q.trim().toLowerCase(); 1089 | 1090 | return items.map(function(item) { 1091 | return { 1092 | item: item, 1093 | score: fuzzysearch(q, (item.label || '').trim().toLowerCase(), 3) 1094 | }; 1095 | }).filter(function(res) { 1096 | return res.score != Number.POSITIVE_INFINITY; 1097 | }).sort(function(a, b) { 1098 | return a.score - b.score; 1099 | }); 1100 | } 1101 | 1102 | 1103 | /** 1104 | * Fuzzy searching allows for flexibly matching a string with partial input, 1105 | * useful for filtering data very quickly based on lightweight user input. 1106 | * Returns score lower than Infinity if needle matches haystack using a fuzzy-searching algorithm. 1107 | * Note that this program doesn't implement levenshtein distance, but rather 1108 | * a simplified version where there's no approximation. The method will return a score lower 1109 | * than Infinity only if each character in the needle can be found in the haystack and 1110 | * occurs after the preceding matches. To sum up: 1111 | * - score = +Inf: not a match. 1112 | * - score > 0: number of characters read before finding the last character of needle 1113 | * (doesn't count the characters of needle). 1114 | * - score = 0: the needle is a substring of haystack. 1115 | * - score < 0: perfect match. 1116 | * 1117 | * @see https://github.com/bevacqua/fuzzysearch (modified) 1118 | * @param {string} needle 1119 | * @param {string} haystack 1120 | * @param {number} cutoff The maximum score before Infinity. 1121 | * @returns {number} score 1122 | */ 1123 | function fuzzysearch (needle, haystack, cutoff) { 1124 | var 1125 | hlen = haystack.length, 1126 | nlen = needle.length, 1127 | hops = - needle.length + 1, 1128 | hops_limit = cutoff || 10, 1129 | incr = 0, 1130 | nch, i, j; 1131 | 1132 | if (nlen > hlen) { 1133 | return Number.POSITIVE_INFINITY; 1134 | } 1135 | if (nlen === hlen) { 1136 | return (needle === haystack) ? -1 : Number.POSITIVE_INFINITY; 1137 | } 1138 | if (nlen == 1) { 1139 | hops = haystack.indexOf(needle); 1140 | return (hops < 0) ? Number.POSITIVE_INFINITY : hops; 1141 | } 1142 | outer: for (i = 0, j = 0; i < nlen; i++) { 1143 | nch = needle.charCodeAt(i); 1144 | while (j < hlen) { 1145 | hops += incr; 1146 | if (incr && hops > hops_limit) { 1147 | return Number.POSITIVE_INFINITY; 1148 | } 1149 | if (haystack.charCodeAt(j++) === nch) { 1150 | incr = 1; 1151 | continue outer; 1152 | } 1153 | } 1154 | return Number.POSITIVE_INFINITY; 1155 | } 1156 | 1157 | return hops; 1158 | } 1159 | 1160 | /** 1161 | * Select a node from the list of search results. It should be called by an event on the item. 1162 | * @returns {boolean} 1163 | */ 1164 | function nodeResultHandler() { 1165 | var id = this.dataset.id; 1166 | activeStatePlugin.dropNodes(); 1167 | activeStatePlugin.dropEdges(); 1168 | activeStatePlugin.addNodes(id); 1169 | LK.closeTooltip(); 1170 | LK.clearSearch(); 1171 | LK.locateNode(id, { onComplete: function() { 1172 | LK.openNodeTooltip(sigmaInstance.graph.nodes(id)); 1173 | }}); 1174 | return false; 1175 | } 1176 | 1177 | /** 1178 | * Select an edge from the list of search results. It should be called by an event on the item. 1179 | * @returns {boolean} 1180 | */ 1181 | function edgeResultHandler() { 1182 | var id = this.dataset.id; 1183 | activeStatePlugin.dropNodes(); 1184 | activeStatePlugin.dropEdges(); 1185 | activeStatePlugin.addEdges(id); 1186 | LK.closeTooltip(); 1187 | LK.clearSearch(); 1188 | LK.locateEdge(id, { onComplete: function() { 1189 | LK.openEdgeTooltip(sigmaInstance.graph.edges(id)); 1190 | }}); 1191 | return false; 1192 | } 1193 | 1194 | /** 1195 | * Parse the query string and returns an object of parameter<>value. 1196 | * @see http://jsperf.com/querystring-with-javascript 1197 | * @param q 1198 | * @returns {{}} 1199 | */ 1200 | function getQueryString (q) { 1201 | return (function(a) { 1202 | if (a == "") return {}; 1203 | var b = {}; 1204 | for (var i = 0; i < a.length; ++i) { 1205 | var p = a[i].split('='); 1206 | if (p.length != 2) continue; 1207 | b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); 1208 | } 1209 | return b; 1210 | })(q.split("&")); 1211 | } 1212 | 1213 | /** 1214 | * Handle the onDrop event to either load a graph of a design. 1215 | * @param e 1216 | */ 1217 | function onDropHandler(e) { 1218 | e.preventDefault(); 1219 | e.stopPropagation(); // stop browser from redirecting 1220 | 1221 | for (var i = 0; i < e.dataTransfer.files.length; i++) { 1222 | var file = e.dataTransfer.files[i]; 1223 | var reader = new FileReader(file); 1224 | 1225 | if (file.name.slice(-4) === 'gexf') { 1226 | reader.onload = function(e) { 1227 | designPlugin.reset(); 1228 | var parser = new DOMParser(); 1229 | var domElement = parser.parseFromString(e.target.result, "text/xml"); 1230 | sigma.parsers.gexf( 1231 | domElement, 1232 | sigmaInstance, 1233 | function() { 1234 | // Fix data: 1235 | sigmaInstance.graph.nodes().forEach(function(node) { 1236 | node.size = node.size || 1; 1237 | node.color = node.color || '#ddd'; 1238 | }); 1239 | sigmaInstance.refresh(); 1240 | locatePlugin.center(); 1241 | } 1242 | ); 1243 | LK.dom.hide('#drag-overlay'); 1244 | }; 1245 | reader.readAsText(file); 1246 | } 1247 | else if (file.name.slice(-4) === 'json') { 1248 | reader.onload = function(e) { 1249 | var data = JSON.parse(e.target.result); 1250 | if (data.nodes) { 1251 | // Load graph 1252 | sigmaInstance.graph.clear(); 1253 | designPlugin.reset(); 1254 | sigmaInstance.graph.read(data); 1255 | sigmaInstance.refresh(); 1256 | locatePlugin.center(); 1257 | } 1258 | else { 1259 | LK.setDesign(data.styles, data.palette); 1260 | } 1261 | LK.dom.hide('#drag-overlay'); 1262 | }; 1263 | reader.readAsText(file); 1264 | } 1265 | else { 1266 | console.error('Wrong file type.'); 1267 | } 1268 | } 1269 | } 1270 | 1271 | }).call(this); 1272 | --------------------------------------------------------------------------------