Compare commits

..

747 Commits

Author SHA1 Message Date
Peter Thorson 4231edec53 package as alpha4 2013-10-11 06:39:55 -05:00
Peter Thorson 4761938600 bugfix 2013-10-10 14:05:09 -05:00
Peter Thorson bf5f2852f9 updates license information for UTF8 validation logic references #294 2013-10-10 14:00:10 -05:00
Peter Thorson e16972b153 HTTP requests ending normally are no longer logged as errors. references #294 2013-10-10 13:47:01 -05:00
Peter Thorson 3d0d28affc Eliminate spurious expired timers in certain error conditions references #295 2013-10-10 13:45:49 -05:00
Peter Thorson 63cdaec0ba removes unused variable set per static analysis 2013-10-10 13:14:06 -05:00
Peter Thorson 43a258efaa updates changelog 2013-10-10 08:42:13 -05:00
Peter Thorson 3d57d412f7 Updates COPYING file to include all bundled licenses references #294 2013-10-10 08:20:03 -05:00
Peter Thorson 97e5e5fc7b replaces sha1 library with a more clearly licensed project references #294 2013-10-10 08:19:43 -05:00
Peter Thorson ed39a6ab1a Re-introduces strands to asio transport 2013-10-06 14:58:29 -05:00
Peter Thorson 67804061ea update changelog 2013-10-06 11:02:29 -05:00
Peter Thorson b934e71ace adjust transport async_accept and async_connect to use connection_ptr instead of connection_hdl
prevents a newly created connection_ptr from being destroyed
immediately after accepting or connecting.
2013-10-06 10:51:41 -05:00
Peter Thorson 96f7d0f3f2 catch test error condition better 2013-10-06 10:48:23 -05:00
Peter Thorson 013c2da7e8 removes internal connection tracking mechanism from endpoint 2013-10-06 10:47:59 -05:00
Peter Thorson aebdb26dc6 additional debug log detail 2013-10-06 10:34:15 -05:00
Peter Thorson 550365df6a updates iostream tests for new safer/less leaky API 2013-09-28 07:57:38 -05:00
Peter Thorson e91d6f6a45 refactor iostream read completion to remove memory leak 2013-09-28 07:56:41 -05:00
Peter Thorson de6d15c9fc adds documentation notes about when fatal_error and eof methods showed up 2013-09-28 07:56:03 -05:00
Peter Thorson 3035c8dc0a Deprecates iostream transport readsome in favor of read_some
which is more consistent with the naming of the rest of the library.
2013-09-28 07:55:41 -05:00
Peter Thorson c175ec4f42 Adds preliminary signaling to iostream transport of eof and fatal transport errors 2013-09-27 21:24:33 -05:00
Peter Thorson e6319f51a4 Updates transport code to use shared rather than raw pointers. references #293 2013-09-26 07:43:10 -05:00
Peter Thorson d17569fa87 fixes issue where custom headers couldn't be set for client connections 2013-09-25 08:18:46 -05:00
Peter Thorson f22c542a0d update credits for previous fix 2013-08-30 16:34:54 -05:00
Peter Thorson e9cb0b840f fixes a compile error on visual studio when using interrupts 2013-08-30 15:52:26 -05:00
Peter Thorson bd9c9767e1 Updates message buffer documentation and style 2013-08-17 12:16:21 -05:00
Peter Thorson 80133d6d55 fix unit tests 2013-08-15 08:37:29 -05:00
Peter Thorson ac41f467ed Merge branch 'master' of https://github.com/zaphoyd/websocketpp
Conflicts:
	changelog.md
2013-08-15 07:46:48 -05:00
Peter Thorson cab72215aa adds new close codes per IANA registry 2013-08-15 07:46:07 -05:00
Peter Thorson 12d240ff09 fix typo 2013-08-12 11:25:12 -05:00
Peter Thorson 107d3c9bb6 add set_remote_endpoint method to iostream transport 2013-08-12 11:22:45 -05:00
Peter Thorson 49c07296dd iostream transport documentation 2013-08-12 11:22:26 -05:00
Peter Thorson 8475f5f200 add iostream transport set_secure functionality 2013-08-12 11:21:41 -05:00
Peter Thorson 8ef8372af1 transport policy documentation 2013-08-12 11:16:59 -05:00
Peter Thorson 4a10d8ddfd iostream transport docs and code style 2013-08-12 11:16:45 -05:00
Peter Thorson f02c6f1c75 code style 2013-08-05 08:32:43 -05:00
Peter Thorson eb9ab6f70f add constexpr to static logging tests 2013-08-05 08:32:28 -05:00
Peter Thorson a2d92c9a21 style and documentation 2013-08-05 08:28:22 -05:00
Peter Thorson 6e23a6ec3c fix documentation bugs 2013-08-05 08:26:51 -05:00
Peter Thorson c30d000359 fix documentation typos, add client clarification 2013-07-31 22:42:55 -05:00
Peter Thorson ffe59ab078 documentation and code style 2013-07-30 22:13:56 -05:00
Peter Thorson e457467e9b Fix typo in .gitattributes, fixes #280 2013-07-27 11:29:34 -05:00
Peter Thorson 485304b438 Add missing locale include, fixes #281 2013-07-27 11:27:26 -05:00
Peter Thorson 3bab403c1b Refactor asio_transport and add full docs and exception free varient methods 2013-07-27 11:24:24 -05:00
Peter Thorson c017331959 remove trailing whitespace 2013-07-21 07:49:15 -05:00
Peter Thorson df828914c7 remove unneeded code and trailing whitespace 2013-07-21 07:38:27 -05:00
Peter Thorson 2c879ee797 Wrap ioservice run_one method. Fixes #278 2013-07-21 07:00:28 -05:00
Peter Thorson 241cf697f6 Suppress error when shutting down a closed connection 2013-07-17 07:28:26 -05:00
Peter Thorson c6f579a52a remove regex libs from CMAKE files 2013-07-17 07:26:53 -05:00
Peter Thorson 3f08de3d9d alpha3 release 2013-07-16 18:19:35 -05:00
Peter Thorson a9f3821d99 rename echo_client to testee client to better reflect its role 2013-07-14 11:02:59 -05:00
Peter Thorson 2964acd6d7 disable frame payload logging by default 2013-07-14 10:57:05 -05:00
Peter Thorson d564189d4c Merge pull request #274 from hobu/master
Implement conditional cmake configuration for echo_server_tls and add cmake config for print_server and telemetry_client
2013-07-14 08:56:17 -07:00
Peter Thorson ddca46f5d6 update changelog 2013-07-14 10:52:00 -05:00
Peter Thorson 7f062297de complete and clean up sha1 refactoring
move the remainder of documentation and licenses into sha1.hpp. Remove
unused files.
2013-07-14 10:49:40 -05:00
Peter Thorson 1c199aca6e minor refactoring of sha1 code
Update code style to better match project. Add more documentation. Add
some C++ specific features to improve compatibility and reduce warnings
with C++ applications. Add original project unit tests to WebSocket++
test suite.
2013-07-14 10:34:47 -05:00
Peter Thorson b8af39fd82 formatting 2013-07-13 13:29:10 -05:00
Peter Thorson c94621bd29 case insensitive header comparisons fixes #220 and #275 2013-07-13 13:28:56 -05:00
Howard Butler b83b054c7e add CMake config for print_server and telemetry_client 2013-07-11 10:54:43 -05:00
Howard Butler f6bcb86a6c Implement conditional cmake configuration for echo_server_tls 2013-07-10 16:09:38 -05:00
Peter Thorson 28ac69c800 temporary workaround for a g++ compile issue 2013-07-09 21:59:28 -05:00
Peter Thorson b866e4e0ca Refactors URI to be exception and regex free 2013-07-09 16:50:47 -05:00
Peter Thorson cdaf57cf7d update copyright date 2013-07-09 16:45:10 -05:00
Peter Thorson 2d49035a6d remove deprecated constants 2013-07-09 16:44:29 -05:00
Peter Thorson 686b835f3d update changelog 2013-07-08 19:02:14 -05:00
Peter Thorson 8f2c4264e1 Server header/User agent adjustments & tests
Updates behavior to drop the headers if user_agent is set to the empty
string and to allow overriding the Server header from the validate
function. Updates docs and adds a number of tests
2013-07-08 18:07:33 -05:00
Peter Thorson 5c608910d5 fix interface mismatch 2013-07-05 11:44:20 -05:00
Peter Thorson 229698dbb0 add experimental connection get message buffer method 2013-07-05 11:41:47 -05:00
Peter Thorson 6bd1bfd4f2 add basic compression/decompression implimentation 2013-07-03 06:19:08 -05:00
Peter Thorson dbd0fc5372 remove debug printing 2013-07-03 06:16:42 -05:00
Peter Thorson 7454bf68f6 re-enable permessage_deflate test 2013-06-30 19:46:29 -05:00
Peter Thorson 5b7f4a8c14 remove unneeded methods 2013-06-30 19:39:03 -05:00
Peter Thorson 9dd53d2e28 code style 2013-06-30 19:38:50 -05:00
Peter Thorson 915f5c77a8 support c2s_max_window_size 2013-06-30 18:34:21 -05:00
Peter Thorson 36cae596db update documentation 2013-06-30 18:32:37 -05:00
Peter Thorson 407b931395 Add s2c_max_window_bits negotiation 2013-06-29 17:53:53 -05:00
Peter Thorson 25b530b8a8 fix bug that prevented multiple attributes from working 2013-06-27 19:49:13 -05:00
Peter Thorson 038a9aee58 setting and negotiation of c2s_no_context_takeover 2013-06-27 19:48:48 -05:00
Peter Thorson 9749c0a3d5 enable server initiated s2c_no_context_takeover 2013-06-27 19:02:28 -05:00
Peter Thorson c7b1ddd9fa permessage-deflate negotiation of s2c_no_context_takeover 2013-06-27 18:35:32 -05:00
Peter Thorson 7a0d9c0238 cleanup permessage deflate extension 2013-06-25 21:07:46 -05:00
Peter Thorson cb08f07cb0 add combination error code / string type 2013-06-25 20:59:29 -05:00
Peter Thorson 743cd7a713 HTTP cleanup and documentation 2013-06-25 20:57:30 -05:00
Peter Thorson 88fe1bfb1c Fix issue where pong timeout handler always fired 2013-06-24 14:59:19 -05:00
Peter Thorson 5fd65a934b fix typo 2013-06-24 13:35:25 -05:00
Peter Thorson bb1420fe06 endpoint code style 2013-06-24 13:33:06 -05:00
Peter Thorson 0264b63fc3 Add ping and pong endpoint wrapper methods 2013-06-24 13:32:56 -05:00
Peter Thorson 256f8325e8 spelling, documentation, and style 2013-06-23 21:06:33 -05:00
Peter Thorson ce410a9428 transport documentation and style 2013-06-23 19:41:48 -05:00
Peter Thorson 573dedcb9d transport code style 2013-06-23 16:26:37 -05:00
Peter Thorson 4f8b2bdc98 transport documentation & style 2013-06-23 16:18:03 -05:00
Peter Thorson 330d564ded Flags 64 bit literals in frame unit tests references #264 2013-06-22 20:10:49 -05:00
Peter Thorson 161a5b169a Merge pull request #262 from breyed/streamed-timestamp
Write timestamp directly to output stream
2013-06-22 17:59:03 -07:00
Peter Thorson 7d36965149 Add accessor for raw http requests references #266 2013-06-22 10:59:26 -05:00
Peter Thorson de5684aef3 add test fail handler 2013-06-22 10:50:28 -05:00
Peter Thorson fd93ad89cb update documentation and code style 2013-06-16 21:08:53 -05:00
Peter Thorson 6d620aa1e8 add documentation & update code style 2013-06-15 12:46:39 -05:00
Peter Thorson 816fe6410d update documentation & code style 2013-06-15 12:39:57 -05:00
Peter Thorson f3c65ab609 documentation 2013-06-15 12:34:11 -05:00
Peter Thorson c938d9fd15 use strict masking for incoming messages references #264 2013-06-14 21:55:14 -05:00
Peter Thorson 0b764bdc62 add byte_mask_circ 2013-06-14 21:49:24 -05:00
Peter Thorson 86e2f364de fix readme 2013-06-14 21:48:46 -05:00
Peter Thorson 54dd4c8084 look up version rather than hardcode 2013-06-14 21:48:29 -05:00
Peter Thorson cae30acf91 update byte mask to use separate input & output types references #264
In particular this allows const iterators to be use for the input types.
2013-06-12 20:52:48 -05:00
Peter Thorson 24c1804e40 update documentation 2013-06-12 19:23:05 -05:00
breyed 8c6a360600 Write timestamp directly to output stream
This uses put_time (if supported) to avoid having to first write the timestamp to a temporary buffer and then copy it to the stream.
2013-06-09 18:28:19 -05:00
Peter Thorson 5c35535ffd update changelog 2013-06-09 18:26:41 -05:00
Peter Thorson 3256c72d98 Merge pull request #261 from breyed/master
added guards to avoid macro definition when used with boost_config.hpp
2013-06-09 16:24:09 -07:00
breyed 07ab02407f added guards to avoid macro definition when used with boost_config.hpp 2013-06-09 18:03:49 -05:00
Peter Thorson edc0057a03 update unit test 2013-06-09 17:39:49 -05:00
Peter Thorson 9161119b4d bump version to alpha2 2013-06-09 17:24:24 -05:00
Peter Thorson 7db60e3429 fix poor server handling of double close frames fixes #259 2013-06-09 17:03:14 -05:00
Peter Thorson 3c0b8a81b0 Fix handling of spurious frames after close. Fixes #258 2013-06-09 16:41:04 -05:00
Peter Thorson b812fd001b Change default HTTP response error code to 426
Changes default HTTP response error code when no http_handler is
defined from 500/Internal Server Error to 426/Upgrade Required
2013-06-09 16:20:53 -05:00
Peter Thorson 3a43986d9e add documentation & normalize code style 2013-06-09 14:58:32 -05:00
Peter Thorson 64b1b52297 adds documentation on locations of version info 2013-06-09 11:07:19 -05:00
Peter Thorson dc048ed021 test use of doxygen todo command 2013-06-09 11:05:48 -05:00
Peter Thorson 60b167bcb7 updates changelog 2013-06-09 09:27:08 -05:00
Peter Thorson e680ca1ef4 add comment + TODO regarding VSPP warning 2013-06-09 09:25:30 -05:00
Peter Thorson 21d79e28c6 maybe fix markdown # escape? 2013-06-09 09:20:31 -05:00
Peter Thorson d25a254e81 remove logger dynamic allocation 2013-06-09 09:20:04 -05:00
Peter Thorson 3e144cfd75 Merge pull request #257 from zaphoyd/experimental
merge last bit of changes from experimental to master
2013-06-09 07:15:12 -07:00
Peter Thorson a5bb90807b Merge pull request #252 from breyed/visual-studio
Fixed Visual Studio 2012 warnings and formatting
2013-06-09 07:05:53 -07:00
Peter Thorson 096a7dbaa8 escape # in readme 2013-06-09 08:58:15 -05:00
Peter Thorson 577591aaa1 readme updates 2013-06-09 08:55:53 -05:00
Peter Thorson a401a4448d update version information to 0.3.0-alpha1 2013-06-09 08:46:54 -05:00
Peter Thorson ace76f54f9 update docs for 0.3.x in master branch fixes #197 2013-06-09 08:31:05 -05:00
Peter Thorson 1eaa1b790f update travis for 0.3.x in master 2013-06-09 08:30:03 -05:00
Peter Thorson c2a5f0bfa1 Merge pull request #255 from zaphoyd/0.3.x-cmake
merge final bits of 0.3.x-cmake into experimental
2013-06-09 06:13:59 -07:00
Peter Thorson b71b224860 Merge branch 'experimental' into 0.3.x-cmake 2013-06-09 08:13:02 -05:00
Peter Thorson be1d9fd64e Merge pull request #248 from resiprocate/0.3.x-cmake
Fix typo, add sip_client example (SIP over WebSockets)
2013-06-09 05:59:37 -07:00
Peter Thorson bcac77306f Merge pull request #254 from breyed/boost-config
Automatically configure platform via Boost.Config
2013-06-09 05:56:52 -07:00
Peter Thorson dd563c6647 corrects TCP close behavior references #227 fixes #25
Per RFC6455 clients prefer to wait for servers to initiate TCP close.
timers ensure that clients don't wait forever. Servers close TCP
immediately.
2013-06-09 07:36:55 -05:00
Peter Thorson 0ab1333a2f add transport integration helper handlers delay and close 2013-06-09 07:34:10 -05:00
Peter Thorson b9c66e9a7f transport integration test formatting cleanup 2013-06-09 07:33:48 -05:00
Peter Thorson 56e81cb6eb impliment close handshake timeouts references #226 2013-06-09 07:33:30 -05:00
Peter Thorson c228f70a9f complete handshake timeout references #226 2013-06-08 18:32:23 -05:00
Peter Thorson f35918ce6e split log_fail_result from log_close_result 2013-06-08 18:32:23 -05:00
Peter Thorson 33a0d89633 add transport integration dummy TCP client
client connects and never sends anything. the client ends on EOF
2013-06-08 18:32:23 -05:00
Peter Thorson bf582aa2c1 add unit test for server open handshake timeout 2013-06-08 18:32:23 -05:00
Peter Thorson 88c553f1fc silence unit tests 2013-06-08 18:32:23 -05:00
Peter Thorson 96270a9f3d add test for client opening handshake 2013-06-08 18:32:23 -05:00
Peter Thorson c6381a2311 start client handshake timer 2013-06-08 18:32:22 -05:00
Peter Thorson cff8604148 cancel handshake timers when handshake is complete 2013-06-08 18:32:22 -05:00
Peter Thorson dfcd8a2967 set detailed error code on terminate 2013-06-08 18:32:22 -05:00
Peter Thorson 593c26f087 fix devel debug comment 2013-06-08 18:32:22 -05:00
Peter Thorson 408639a0b5 whitespace 2013-06-08 18:32:22 -05:00
Peter Thorson b591e9fa7e add handshake timeout handlers 2013-06-08 18:32:22 -05:00
Peter Thorson f2486d4aef add handshake timer & associated handlers 2013-06-08 18:32:22 -05:00
Peter Thorson 1892e0f13b remove unused code 2013-06-08 18:32:22 -05:00
Peter Thorson 8ee6a4a64b set state to closing after we send our close frame 2013-06-08 18:32:22 -05:00
Peter Thorson c86601f123 add methods to retrieve WebSocket close codes & reasons 2013-06-08 18:32:22 -05:00
Peter Thorson 0f02119d48 adds new error codes for handshake timeouts 2013-06-08 18:32:22 -05:00
Peter Thorson 196523ba42 adds a machine readable internal error code
To be used for storing detailed error codes for why connections failed
or were closed
2013-06-08 18:32:22 -05:00
Peter Thorson 4a94a7c518 Merge pull request #253 from breyed/spelling
fixed spelling, including "experimental" in API
2013-06-08 09:19:41 -07:00
breyed e68d492ed2 Fixed Visual Studio 2012 warnings
Fixed daylight savings time formatting problem on Windows
2013-06-08 11:07:02 -05:00
breyed 808a8ce0a9 fixed spelling, including "experimental" in API 2013-06-08 11:03:11 -05:00
breyed cd8e1a25bb fixed comment at end of include guard 2013-06-08 10:34:09 -05:00
breyed 2352f09c68 Automatically configure platform via Boost.Config 2013-06-08 10:26:55 -05:00
Peter Thorson 55fa61feb1 Merge remote-tracking branch 'origin/0.3.x-cmake' into experimental 2013-06-08 09:29:53 -05:00
Peter Thorson 17083a4d4e Merge pull request #251 from jefferai/0.3.x-cmake
Add missing condition_variable include
2013-06-06 06:21:09 -07:00
Jeff Mitchell 2b6b4862ce Add missing condition_variable include 2013-06-05 14:12:13 -04:00
Daniel Pocock de4ad9e7f3 Add README for sip_client 2013-05-31 16:59:06 +02:00
Daniel Pocock 45e305b5c2 Fixes for sip_client new 0.3 API 2013-05-31 16:56:27 +02:00
Daniel Pocock 3dd3fd28d4 Correct the Via header for WS transport 2013-05-31 16:45:17 +02:00
Daniel Pocock 1dfa629ae4 Sending a SIP OPTIONS message 2013-05-31 15:45:34 +02:00
Daniel Pocock a549f2b99e Renaming contents of sip_client from echo_client 2013-05-31 14:47:41 +02:00
Daniel Pocock ca108ac693 Add examples/sip_client based on examples/echo_client 2013-05-31 14:45:54 +02:00
Daniel Pocock 7d513e1e11 Fix typo 2013-05-31 14:40:52 +02:00
Peter Thorson 2e2a8e4346 documentation and reorganization 2013-05-30 23:30:04 -05:00
Peter Thorson 808179551f remove dead code 2013-05-30 23:29:48 -05:00
Peter Thorson 38a565888f adds documentation 2013-05-30 18:05:34 -05:00
Peter Thorson dcb13d58be updates hybi00 to use new md5 header 2013-05-30 17:56:57 -05:00
Peter Thorson e8aa1e0e12 consolodates md5 code 2013-05-30 17:50:10 -05:00
Peter Thorson fcac7071eb adds documentation 2013-05-30 13:32:45 -05:00
Peter Thorson ea36bf1cf7 removes unused files 2013-05-30 13:32:33 -05:00
Peter Thorson 245978fd86 remove unneeded dependencies 2013-05-29 09:22:27 -05:00
Peter Thorson 6e0411020c fix broken package name 2013-05-29 09:17:17 -05:00
Peter Thorson ad2ff8ca0a fix travis script? 2013-05-29 09:15:37 -05:00
Peter Thorson 7e6d4212a5 only load boost libraries that we need to improve test times 2013-05-29 09:09:03 -05:00
Peter Thorson 7ca4f37c2c stop the server after the last connection ends and let the server thread clean up 2013-05-29 09:07:48 -05:00
Peter Thorson 370bd93182 remove exception suppression, test framework will catch these 2013-05-29 09:07:19 -05:00
Peter Thorson d9e3f626e2 use custom config so we can play with timer duration values 2013-05-29 09:06:46 -05:00
Peter Thorson b43717cd43 Merge branch 'experimental' of github.com:zaphoyd/websocketpp into experimental 2013-05-29 08:48:31 -05:00
Peter Thorson e4c4cf2018 updates readme and roadmap 2013-05-29 08:48:22 -05:00
Peter Thorson f0f346dabe experimental dual core travis build 2013-05-29 08:48:08 -05:00
Peter Thorson a29132e6f4 Merge pull request #245 from jefferai/0.3.x-cmake
Overload get_connection to allow passing in an already-constructed uri_p...
2013-05-28 10:39:59 -07:00
Jeff Mitchell 0a7aaa2632 Overload get_connection to allow passing in an already-constructed uri_ptr. This avoid the need for using the regex, which GCC does not implement yet. 2013-05-28 13:15:01 -04:00
Peter Thorson 10a8af1ac3 adds pong timer support and new full stack automated integration testing for it 2013-05-26 22:04:28 -05:00
Peter Thorson 5677b5f400 adds dummy timer support + tests to iostream transport 2013-05-26 20:02:08 -05:00
Peter Thorson f10e2d9b21 Merge pull request #240 from jefferai/0.3.x-cmake
Needs to be uppercase Version for case-sensitive systems
2013-05-26 12:36:27 -07:00
Peter Thorson ec8b73cad4 clarifies the purpose of utility client and removes contradictory comments references #242 2013-05-24 22:14:06 -07:00
Jeff Mitchell ca6aa12fbc Add websocketpp_found variable 2013-05-20 16:50:34 -04:00
Jeff Mitchell 2aea85a773 Needs to be uppercase Version for case-sensitive systems 2013-05-20 10:24:29 -04:00
Peter Thorson 2c09846722 Merge pull request #239 from zaphoyd/experimental
updates cmake branch with latest changes
2013-05-18 05:05:00 -07:00
Peter Thorson 8f8bbb99e9 adds more unit tests for http requests 2013-05-18 06:56:49 -05:00
Peter Thorson d7e5235036 extract URI for HTTP connections also 2013-05-18 06:54:56 -05:00
Peter Thorson dd534ace64 switches processor to use new free get_uri function 2013-05-18 06:54:32 -05:00
Peter Thorson 065dd26779 adds free processor extract uri from request utility method 2013-05-18 06:53:46 -05:00
Peter Thorson 8c6b049e99 adds better support for custom URI schemes 2013-05-18 06:53:17 -05:00
Peter Thorson f988315ea8 updates broadcast_server to use common/thread rather than hardcoding boost thread 2013-05-16 10:31:02 -05:00
Peter Thorson 4474868372 adds unique_lock and condition_variable to common thread tools 2013-05-16 10:30:38 -05:00
Peter Thorson 5c4719080c Merge pull request #236 from jefferai/0.3.x-cmake
CMake fixes/enhancements
2013-05-15 06:40:02 -07:00
Jeff Mitchell 980fa8db67 Create -config and -configversion files so find_package in other
CMake-using applications works to include websocketpp. Also, a lot of
cleanup.
2013-05-15 08:23:37 -04:00
Peter Thorson f3faf404dd merge from experimental 2013-05-14 15:22:22 -05:00
Peter Thorson a2a02ba063 adds a debug log statement 2013-05-14 15:14:57 -05:00
Peter Thorson 3c015ca356 Merge pull request #232 from jefferai/0.3.x-cmake
Actually recursively install header files.
2013-05-13 07:06:33 -07:00
Peter Thorson 19edfe3c60 adds tests for TLS timers 2013-05-13 09:05:31 -05:00
Peter Thorson a8f649892f renames mock logger to stub logger 2013-05-13 09:03:12 -05:00
Peter Thorson 27d5ec3394 adds Doxygen file 2013-05-13 07:53:41 -05:00
Peter Thorson d8310780ac adds documentation 2013-05-13 07:50:43 -05:00
Peter Thorson a77d92e99a switches the order of error and access log paramters to be consistent with the rest of the library 2013-05-13 07:50:29 -05:00
Jeff Mitchell e88b30e94d Don't use Doxygen in the standard cmake build dir 2013-05-12 10:26:31 -04:00
Jeff Mitchell c6f3ce4d39 Actually recursively install header files. 2013-05-11 18:51:44 -04:00
Peter Thorson 4a4c763d18 Merge pull request #231 from zaphoyd/experimental
bring cmake branch in line with experimental
2013-05-11 13:57:46 -07:00
Peter Thorson ae207afb10 Merge pull request #230 from jefferai/0.3.x-cmake
Add basic Doxyfile
2013-05-11 13:51:06 -07:00
Peter Thorson 0d7677b1b1 use travis for all 0.3.x branches 2013-05-11 15:50:47 -05:00
Peter Thorson c3d484f1ea preliminary work on unit tests for timers 2013-05-11 15:49:48 -05:00
Peter Thorson 0a4995bce5 adds missing include files 2013-05-11 15:48:32 -05:00
Peter Thorson 8f7843094d edits for consistency 2013-05-11 15:48:21 -05:00
Peter Thorson 738822813f Adds an empty mock logger 2013-05-11 15:47:56 -05:00
Jeff Mitchell c3fb69833c Add basic Doxyfile 2013-05-11 16:09:23 -04:00
Peter Thorson 5bd0332d19 return error code by value rather than reference 2013-05-11 09:43:09 -05:00
Peter Thorson cb5955ccc5 defines timers before using them 2013-05-11 09:40:19 -05:00
Peter Thorson 2f050cf412 updates socket policy error handling 2013-05-11 09:36:42 -05:00
Peter Thorson 67edd83a7c adds post_init (tls) and shutdown timers references #226 2013-05-11 07:11:00 -05:00
Peter Thorson c8f603ed1c simplify tls async shutdown 2013-05-11 07:09:59 -05:00
Peter Thorson d37dd26f43 rename config constants for consistency 2013-05-11 07:09:42 -05:00
Peter Thorson 3ac8a99cec fixes some typos 2013-05-10 17:18:33 -05:00
Peter Thorson 58fd1b80c2 refactors dns resolve timer to be more robust and adds connect timer 2013-05-10 17:17:13 -05:00
Peter Thorson 43ba642b53 removes timeouts from socket policy (moving them a level up) 2013-05-10 17:13:46 -05:00
Peter Thorson 4e06c837ff adds post/pre init and connect timeout values to default configs 2013-05-10 17:07:52 -05:00
Peter Thorson b23c7fd93a define NOMINMAX to fix VCPP warnings references #203
reported by KHeresy
2013-05-10 16:08:46 -05:00
Peter Thorson 8966c88d2f add platform specific preprocessor settings section 2013-05-10 16:04:43 -05:00
Peter Thorson e2462ec30b use endpoint set_timer rather than connection 2013-05-10 16:02:33 -05:00
Peter Thorson 4adfc452d0 adds more robust proxy timeout behavior 2013-05-10 08:43:37 -05:00
Peter Thorson 80990aaec9 adds travis build status to readme 2013-05-10 07:08:59 -05:00
Peter Thorson 34327a69c6 disable travis ci clang build on ubuntu until scons can be fixed 2013-05-09 20:03:25 -05:00
Peter Thorson 92ff87c144 install boost libraries, not just headers 2013-05-09 19:55:39 -05:00
Peter Thorson 0ec7c187b8 libs not plural 2013-05-09 19:49:51 -05:00
Peter Thorson 6780d15bee invalid yml! 2013-05-09 19:47:15 -05:00
Peter Thorson e4467487e0 travis ci update 2013-05-09 19:46:06 -05:00
Peter Thorson 257149e9db experimental travis-ci support references #171 2013-05-09 19:43:35 -05:00
Peter Thorson d83c2913b2 add user manual to readme 2013-05-09 19:43:35 -05:00
Peter Thorson 16999a14c7 fixes some silly mistakes references #229 2013-05-09 16:35:39 -05:00
Peter Thorson 4d0a1c98a9 optimization level 2/3 fails to pass unit tests. need to investigate 2013-05-09 16:34:47 -05:00
Peter Thorson 49a866dc8e test line breaks 2013-05-09 07:18:30 -05:00
Peter Thorson 837b9f82ae update readme 2013-05-09 07:16:15 -05:00
Peter Thorson e9553268fd update email 2013-05-09 07:14:02 -05:00
Peter Thorson 11a4fc4132 fix spacing 2013-05-09 07:13:23 -05:00
Peter Thorson 80ea946938 fix italic formatting 2013-05-09 07:12:45 -05:00
Peter Thorson 273c8e82b0 updates non-code supporting documentation 2013-05-09 07:11:59 -05:00
Peter Thorson 98c8c2ae5c Merge pull request #228 from zaphoyd/experimental
Merge experimental into 0.3.x-cmake
2013-05-09 04:35:11 -07:00
Peter Thorson 7a0a987f57 Merge pull request #225 from jefferai/0.3.x-cmake
More CMake updates
2013-05-09 04:32:59 -07:00
Peter Thorson d85ea32851 adds timer support to asio endpoints, impliments dns resolve timer references #226 2013-05-08 08:52:52 -05:00
Peter Thorson b408ab876e adds method to set proxy timeout duration at runtime 2013-05-07 20:45:28 -05:00
Peter Thorson 747bc55bcf adds documentation and error handling to proxy methods 2013-05-07 20:45:04 -05:00
Peter Thorson fd46083c4a updates frame unit tests to use more specific checks 2013-05-07 20:34:17 -05:00
Peter Thorson 5d0d1379b6 adds timer support for asio transport and adds proxy connect timeout references #226 2013-05-07 17:49:02 -05:00
Peter Thorson 175cab8d22 updates configs to add default timer wait times references #226 2013-05-07 17:46:41 -05:00
Peter Thorson bda4cf3a46 updates derived configs to also derive transport_config from base 2013-05-07 17:46:17 -05:00
Peter Thorson 96158ee8b5 print get connection errors 2013-05-07 13:07:36 -05:00
Peter Thorson 215c9bcdab adds better debugging options for the scons build system 2013-05-07 13:07:35 -05:00
Jeff Mitchell 92651f1f14 Affect the install location for headers only; honor the normal/given install prefix otherwise. 2013-05-07 12:47:33 -04:00
Jeff Mitchell 693fa27fed Make finding boost conditional upon examples being built; remove building when possible by only using header versions of files 2013-05-07 12:38:41 -04:00
Peter Thorson 8e40c53f97 adds new async terminate interface which significantly improves error handling 2013-05-07 09:38:26 -05:00
Peter Thorson 6bd62edb43 removes unused code & updates naming conventions 2013-05-07 09:37:37 -05:00
Peter Thorson 75af01cda4 updates asio transport base unit tests for new interface 2013-05-07 09:35:48 -05:00
Peter Thorson 42ca501f76 adds async_shutdown interface to transport connections 2013-05-07 09:35:13 -05:00
Peter Thorson 7d8f1ea163 revert ignore of TLS short read references #224 2013-05-07 07:02:17 -05:00
Peter Thorson b0cf22c66b Merge pull request #222 from jefferai/0.3.x-cmake
Fix a number of CMake-related issues
2013-05-06 12:09:56 -07:00
Jeff Mitchell 0aba4f3695 Fix a number of CMake problems: clang detection, shared library support, etc. 2013-05-06 13:12:02 -04:00
Jeff Mitchell 5c9de71415 Merge remote-tracking branch 'upstream/experimental' into 0.3.x-cmake 2013-05-06 13:09:40 -04:00
Peter Thorson 4807d54155 corrects visual studio 2008 temporary overflow debug warning references #221 2013-05-06 08:23:40 -05:00
Peter Thorson 3304647c3f removes stray space from proxy auth header references #132 2013-05-06 08:22:03 -05:00
Peter Thorson b2fbb7b8ba registers missing handlers 2013-05-05 19:09:03 -05:00
Peter Thorson f6f4befe46 adds new tls_short_read transport error 2013-05-05 19:06:55 -05:00
Peter Thorson dc7872d647 test ignoring TLS short reads 2013-05-05 18:57:17 -05:00
Peter Thorson 844334efbb fixes perftest constructor call 2013-05-05 18:47:30 -05:00
Peter Thorson 2dcc87a7d3 fixes incorrect duration type 2013-05-05 18:46:30 -05:00
Peter Thorson 0ff8bbfbb7 adds proper close status 2013-05-05 18:43:33 -05:00
Peter Thorson 971482e0b8 typos 2013-05-05 18:42:00 -05:00
Peter Thorson b4edb1be06 some stuff for performance testing 2013-05-05 18:38:10 -05:00
Peter Thorson 3da5bb6b2c don't block on SSL shutdown 2013-05-05 18:09:16 -05:00
Peter Thorson b1f9e9b069 send absolute authority to proxy init 2013-05-05 17:28:25 -05:00
Peter Thorson 3fcc3b6b75 adds the ability to get the absolute authority of a uri 2013-05-05 17:28:03 -05:00
Peter Thorson 03e6f6dd11 ugh tabs 2013-05-05 17:16:13 -05:00
Peter Thorson b29a2f3456 removes old code 2013-05-05 17:12:13 -05:00
Peter Thorson adb0eedc24 splits transport init into pre-and post proxy steps 2013-05-05 16:14:38 -05:00
Peter Thorson cb40f81978 adjusts how remote endpoint logging is printed 2013-05-05 15:15:53 -05:00
Peter Thorson 24f6943336 fixes more typos 2013-05-05 15:13:45 -05:00
Peter Thorson ced601f8d7 fixes some typos 2013-05-05 15:12:34 -05:00
Peter Thorson c1e0545d58 adds debug logging for the connect and dns resolve seps 2013-05-05 12:18:23 -05:00
Peter Thorson d908c1afd2 update copyright dates and fix whitespace that doesn't match projec style 2013-05-05 11:23:31 -05:00
Peter Thorson 3c9f3206c5 tls support for utility client 2013-05-04 14:25:21 -05:00
Peter Thorson 2fa6e6f4d4 security policy socket_init handler now uses tls socket stream type rather than raw socket 2013-05-04 14:25:11 -05:00
Peter Thorson 8dad7aba45 propogate handle setting through to the security policy 2013-05-04 14:24:24 -05:00
Peter Thorson c559e0a623 connection initialization errors are properly logged and propogated 2013-05-04 11:52:52 -05:00
Peter Thorson 6561a9be20 adds security policy interface documentation 2013-05-04 11:52:13 -05:00
Peter Thorson 54fdf1af72 adds transport policy interface documentation 2013-05-04 11:51:55 -05:00
Peter Thorson 5440ecfcb7 adjusts variable names to match coding style 2013-05-04 11:50:52 -05:00
Peter Thorson d44131397e Merge pull request #219 from jonnenauha/cmake_prebuild_system
Cmake prebuild system against 0.3.x-cmake
2013-05-03 19:06:53 -07:00
unknown 1e6c1f9807 Merge remote-tracking branch 'upstream/0.3.x-cmake' into cmake_prebuild_system
Conflicts:
	websocketpp/endpoint.hpp
2013-05-04 02:07:17 +03:00
Peter Thorson b6a741ed23 fixes utility client tls settings 2013-05-03 17:12:51 -05:00
Peter Thorson 8906f19caa fixes asio tls client config name 2013-05-03 17:12:43 -05:00
Peter Thorson 28eecb80e0 adds utility client example 2013-05-03 17:08:05 -05:00
Peter Thorson 64f7e24b4d read proxy info from the right socket 2013-05-03 14:32:35 -05:00
Peter Thorson 380116b3df un-breaks VCPP and doesn't seem to affect anything else 2013-05-03 11:20:42 -05:00
Jonne Nauha db0a2eb7f5 Fix stdint.hpp for <=VC9. 2013-05-03 11:20:08 -05:00
Peter Thorson cde8a9e204 wites proxy connect to next layer 2013-05-03 08:41:50 -05:00
Peter Thorson 84283db1e5 adds wrapper for getting the next layer of the socket stack to tls and basic templates 2013-05-03 08:41:38 -05:00
Peter Thorson 14e80a4ff1 detab 2013-05-03 08:33:43 -05:00
Peter Thorson 0cba06bd67 fixes error namespacing 2013-05-03 08:33:12 -05:00
Peter Thorson 05fb9aadb1 detab 2013-05-03 08:32:59 -05:00
Peter Thorson 87da82698f re-orders methods properly 2013-05-03 08:32:52 -05:00
Peter Thorson 2cebf3a30b adds proxy basic auth support references #132 2013-05-03 08:00:41 -05:00
Peter Thorson 8f35121445 write proxy connect to the raw socket references #132 2013-05-03 07:59:47 -05:00
Peter Thorson 1e2762e648 adds error handling to proxy initiation 2013-05-03 07:57:08 -05:00
Peter Thorson d9d3804e5f adds convenience method to base64 encode strings 2013-05-03 07:56:09 -05:00
Peter Thorson 5be8ecca87 impliments hybi00 close frames references #195 2013-05-02 19:28:29 -05:00
Peter Thorson b06ba38fce removes debug printing 2013-05-02 19:26:13 -05:00
Peter Thorson 24774fc124 adds a bunch of explicit casts where signedness or truncation occurs references #218 2013-05-01 08:24:02 -05:00
Peter Thorson 0905b7d4e9 switches static to reinterpret_cast references #218 2013-05-01 07:00:37 -05:00
Peter Thorson 754651c9eb readme status update 2013-05-01 06:42:05 -05:00
Peter Thorson 04bbb4aa43 cleans up acceptor on destruction of endpoint transport component references #217 2013-05-01 06:23:11 -05:00
Peter Thorson b0b7f5e586 explicitly casts assignments with differing signedness references #218 2013-05-01 06:18:21 -05:00
Peter Thorson 371aa07180 fixes SConscript name comment 2013-05-01 06:10:16 -05:00
Peter Thorson c13ec1beb7 adds set(none) as alias for clear all references #207 2013-04-30 17:53:07 -05:00
Peter Thorson 00c29e42ac disable circshift test for a bit 2013-04-30 17:43:48 -05:00
Peter Thorson 40c10ff6e7 potential endianness fix 2013-04-30 17:42:36 -05:00
Peter Thorson df8d7f3f0d unit test fix 2013-04-30 17:21:16 -05:00
Peter Thorson f110b0bc65 potential solution for PPC masking bug 2013-04-30 17:14:34 -05:00
Peter Thorson 568743e587 fixes bug in unit test 2013-04-30 17:14:22 -05:00
Peter Thorson 54a9ed6e24 Fixes isystem flag 2013-04-30 17:14:11 -05:00
Peter Thorson 5ee8000b12 updates readme progress report 2013-04-29 16:58:53 -05:00
Peter Thorson be07587659 removes expensive development logging from non-debug builds 2013-04-29 13:06:17 -05:00
Peter Thorson 865da6dba2 allow end user dynamic tests 2013-04-29 13:03:25 -05:00
Peter Thorson 4b99ad7ed4 Merge pull request #216 from oberstet/experimental
add testee server
2013-04-28 11:11:12 -07:00
Tobias Oberstein d4f2b6083d logging: total silence 2013-04-28 20:06:28 +02:00
Tobias Oberstein eeb6d778ff add testee server 2013-04-28 19:54:25 +02:00
Peter Thorson 2c3892bb56 Merge pull request #215 from oberstet/experimental
some Windows build fixes
2013-04-28 08:15:32 -07:00
Tobias Oberstein 53a7a67d80 some Windows build fixes 2013-04-28 17:09:09 +02:00
Peter Thorson a500ec144f allow proxies to work with secure websockets 2013-04-27 22:15:21 -05:00
Peter Thorson 5d71935441 completes basic client proxy support references #132 2013-04-27 13:58:33 -05:00
Peter Thorson 2a71b89bbc better debug messages 2013-04-27 13:57:44 -05:00
Peter Thorson ea7ac38ed7 bugfixes and tests for new http istream consume 2013-04-27 13:55:25 -05:00
Peter Thorson aaaa2b4a65 updates uri unit tests to allow http schemes 2013-04-27 13:54:57 -05:00
Peter Thorson bb702c6589 update URI to be able to store and manipulate HTTP URIs 2013-04-27 13:15:41 -05:00
Peter Thorson de1ceff418 initial work on client proxy support references #132 2013-04-26 08:56:18 -05:00
Peter Thorson ca8716ae53 remove unused code 2013-04-26 08:55:56 -05:00
Peter Thorson 64eb09db06 initial work on istream input for http parsers 2013-04-26 08:55:36 -05:00
Peter Thorson 1bbb0cba7f readme update 2013-04-26 08:55:04 -05:00
Peter Thorson 1f194ea327 hybi00 unit test bugfix 2013-04-26 08:54:58 -05:00
Peter Thorson e6c0a7b506 refactor configs to remove duplicate code and add http processor types to transport config 2013-04-26 08:54:40 -05:00
Peter Thorson f46b305df8 fixes typo, references #213 2013-04-26 06:15:42 -05:00
Peter Thorson fe28f29ab4 updates readme 2013-04-25 19:48:47 -05:00
Peter Thorson d9d6338cc2 adds some additional debugging output 2013-04-25 18:55:21 -05:00
Peter Thorson 5e50387596 adjusts some hybi00 handshake settings 2013-04-25 18:54:48 -05:00
Peter Thorson b4c2bfd13a adds hybi00 frame read code + tests 2013-04-25 08:52:21 -05:00
Peter Thorson 66a3db1740 note that hybi13 processor needs incoming message buffer validation 2013-04-25 08:51:57 -05:00
Peter Thorson 34a9d47b9c adds error type for no incoming message buffers 2013-04-25 08:51:25 -05:00
Peter Thorson d4be2a9b4d more frame writing unit tests 2013-04-25 06:36:09 -05:00
Peter Thorson 6095b90cc1 adds hybi00 support for writing messages 2013-04-25 06:27:36 -05:00
Peter Thorson 285069b178 final cleanup 2013-04-24 07:47:58 -05:00
Peter Thorson 6359f3bb0a clean up 2013-04-24 07:25:42 -05:00
Peter Thorson 94919f125c character by character experiment 2013-04-24 07:21:58 -05:00
Peter Thorson e304deacad typo 2013-04-24 07:03:36 -05:00
Peter Thorson 0bc908674a flush logger output 2013-04-24 07:02:39 -05:00
Peter Thorson d1e05df4fa some logging 2013-04-24 07:00:39 -05:00
Peter Thorson 1081fcb6ef tests with iostream_server 2013-04-24 06:56:59 -05:00
Peter Thorson 948d9a487f fixes missing return value 2013-04-23 21:15:17 -05:00
Peter Thorson d40321333a additional documentation and cleanup 2013-04-23 13:37:51 -05:00
Peter Thorson 04244da3f9 small logic cleanup 2013-04-23 13:28:54 -05:00
Peter Thorson fbdc122774 adds an fail handler to telemetry client 2013-04-23 13:23:53 -05:00
Peter Thorson 04f4aab1a9 default connection close status is the abnormal close rather than 0 2013-04-23 13:23:15 -05:00
Peter Thorson 5c9be64230 pass through endpoint errors are now filed under info rather than devel 2013-04-23 13:23:02 -05:00
Peter Thorson 648c387048 adds some explanatory comments 2013-04-23 12:41:35 -05:00
Peter Thorson 72b3def6d6 tabs to spaces 2013-04-23 12:35:05 -05:00
Peter Thorson f51960e8ff adds telemetry client example 2013-04-23 12:33:25 -05:00
Peter Thorson c68e2207c2 adds print server example 2013-04-23 12:33:18 -05:00
Peter Thorson b9ec2d5ae9 removes raw debugging output 2013-04-23 12:33:05 -05:00
Peter Thorson c2fe98c9a4 cleans up session::state values 2013-04-23 12:32:45 -05:00
Peter Thorson a10a5a7bcd adds lib::thread 2013-04-23 12:32:13 -05:00
Peter Thorson 5f87341e9e adds file based logging to iostream server 2013-04-23 10:03:56 -05:00
Peter Thorson 6fe8d8a4f9 ignore log files 2013-04-23 10:03:31 -05:00
Peter Thorson 1421403603 adds ability to set arbitrary stream for logging 2013-04-23 10:03:24 -05:00
Peter Thorson 30d3c8a895 removes cout statement 2013-04-23 10:03:04 -05:00
Peter Thorson 07a4394ba6 new iostream example 2013-04-23 09:26:57 -05:00
Peter Thorson e7483e82ac adds manual input options for iostream transport 2013-04-23 09:26:50 -05:00
Peter Thorson cd8b467225 expected EOF after clean close no longer triggers fatal error references #209 2013-04-20 09:30:02 -05:00
Peter Thorson d987f7b0d5 user agent strings in connect logging are now properly quoted 2013-04-20 08:56:45 -05:00
Peter Thorson 91250fcd54 adds a string_replace_all utility function 2013-04-20 08:56:19 -05:00
Peter Thorson 466c9bd626 removes redundant code from echo_server 2013-04-20 08:34:58 -05:00
Peter Thorson 72b5fada72 adds close result logging 2013-04-20 08:34:28 -05:00
Peter Thorson ea3426868c adds asio transport eof error detection 2013-04-20 08:33:53 -05:00
Peter Thorson f877098f7c fixes debug config 2013-04-20 08:33:27 -05:00
Peter Thorson 4c1abab02b removes unneeded dependencies and makes base64 validation more strict references #209 2013-04-20 07:44:06 -05:00
Peter Thorson 98171d525e adds C++ namespaces to <cstring> methods references #209 2013-04-20 07:30:52 -05:00
Peter Thorson 4ada7f9b0b updates asio transport endpoint with a few more io_service convenience pass through methods references #211 2013-04-20 07:25:34 -05:00
Peter Thorson 4bc4518df0 Fixes send buffer going out of scope, references #209 2013-04-16 11:26:13 -05:00
Peter Thorson 16f28ea671 adds debug/devel configs 2013-04-12 08:13:28 -05:00
Peter Thorson 894124c042 improves error reporting and adds remote endpoint address to connection open logging 2013-04-12 08:13:18 -05:00
Peter Thorson b12bff7d5d impliments get_remote_endpoint for asio transport 2013-04-12 08:12:45 -05:00
Peter Thorson b38e41e459 some test work on removing uri regex dependency 2013-04-12 08:12:21 -05:00
Peter Thorson 6a37bf3a43 update copyright date 2013-04-12 08:11:48 -05:00
Peter Thorson 5e595d7fe6 adds error logging config settings to clients 2013-04-12 08:11:36 -05:00
Peter Thorson c8fada14f7 adds configurable static logging channels 2013-04-08 09:44:32 -05:00
Peter Thorson 1e97e3dcf5 adds connection client methods for adding subprotocols to the handshake request 2013-04-07 12:18:03 -05:00
Peter Thorson a9b30b6b07 updates processors to support writing handshake requests with subprotocols 2013-04-07 12:17:10 -05:00
Peter Thorson bfbb4a94db adds an example to demonstrate subprotocol negotiation 2013-04-06 15:30:58 -05:00
Peter Thorson 51caf0517e adds support for retrieving headers from the request and response objects 2013-04-06 15:30:35 -05:00
Peter Thorson d47327d2a6 updates readme progress list 2013-04-06 12:12:35 -05:00
Peter Thorson 0c9c121160 moves subprotocol extraction into the processor 2013-04-06 12:10:39 -05:00
Peter Thorson ddd1a95460 refactors hybi00 unit tests to remove duplicate code and use more specific BOOST checks 2013-04-06 12:10:16 -05:00
Peter Thorson 17fcb3f8be adds subprotocol selection to connection 2013-04-06 11:09:41 -05:00
Peter Thorson 8f812aafd5 adds subprotocol processing to handshake processors 2013-04-06 11:09:11 -05:00
Peter Thorson 6d1b956aff adds preliminary server side subprotocol negotiation 2013-04-05 21:10:19 -05:00
Peter Thorson 10db03d710 more work on subprotocol tests 2013-04-05 09:30:15 -05:00
Peter Thorson 9f0649cb91 adds integration tests for the server role 2013-04-05 08:29:17 -05:00
Peter Thorson 8c7c31362d Adds storage and getter for negotiated subprotocol 2013-04-05 08:28:54 -05:00
Peter Thorson 1f450fd034 refactors connection testing to extract more common functionality 2013-04-05 08:28:13 -05:00
Peter Thorson 9ebd169675 fixes a crash when strftime overflowed buffer #205 2013-04-05 07:29:20 -05:00
Peter Thorson c937f71b49 changes extension permessage-compress to permessage-deflate per latest draft spec 2013-04-04 08:18:39 -05:00
Peter Thorson dff7a57e3d updates HTTP parser to use an ordered list of parameters rather than unordered
order matters as far as websocket extension negotation goes
2013-04-04 08:18:05 -05:00
Jonne Nauha df4d7167fd CMake continued: Try to detect g++, clang, windows and osx and setup appropriate defines and build flags. Improve so that each setup can define platform, boost and ssl libs. I tried to copy everything that I could from the scons scripts, probably some of this can be removed (might be automated from cmake already), left todo:s for that. Added building simple examples, more to follow. NOTE: This has only been tested on windows. 2013-04-03 01:56:10 +03:00
Jonne Nauha 75b2497f2b Fix intrusive_ptr template init on windows. The second template argument should probably be removed if its not neccesary for other platforms. I did not find boost documentation for what the second argument actually does, but in the meanwhile ifdeffed so that builds on windows (yes its ugly). Fixes #198 (with a semi hack). 2013-04-03 01:52:22 +03:00
Jonne Nauha 834e3e4fae Fix stdint.hpp for <=VC9. 2013-04-03 01:48:35 +03:00
Jonne Nauha e039a57ee0 CMake prebuild system: Initial commit that has most of the basics down. Only tested on windows atm. TODO: Properly support examples, tests and cpp11 defines to build websocketpp in different setups. 2013-04-01 17:48:47 +03:00
Peter Thorson 73e877f1b8 removes unused headers to avoid confusion references #202 2013-04-01 08:43:43 -05:00
Peter Thorson 7739d4fe72 updates readme 2013-03-31 21:43:22 -05:00
Peter Thorson a8e3ae47dd more readme updates 2013-03-31 21:35:11 -05:00
Peter Thorson dcdeb96c62 readme updates 2013-03-31 21:21:39 -05:00
Peter Thorson f38acd5784 impliments the autobahn echo client spec to allow autobahn test suite to test the client 2013-03-31 21:20:14 -05:00
Peter Thorson 800028d1a9 Changes HTTP response parser behavior to only read response bodies when a content length header is present 2013-03-31 21:16:33 -05:00
Peter Thorson 8587647657 Adds echo_client example 2013-03-31 15:12:57 -05:00
Peter Thorson babe00bc60 adds default client configs 2013-03-31 15:12:09 -05:00
Peter Thorson 35dbc8c8aa adds asio async connect and resolve functionality 2013-03-31 15:11:58 -05:00
Peter Thorson 7a1e9a2f59 fixes connection client bug where it would wait for the HTTP body to be read when there wasn't one 2013-03-31 15:11:39 -05:00
Peter Thorson e7e0c05e9a async_connect requires uri as a parameter now 2013-03-31 15:11:05 -05:00
Peter Thorson 4d78ba6daf fixes typo 2013-03-31 15:10:09 -05:00
Peter Thorson 859689bdf7 removes extraneous debug code 2013-03-31 15:09:59 -05:00
Peter Thorson 439efa0895 adds getter for connection uri part 2 2013-03-31 15:09:42 -05:00
Peter Thorson 2d35726edb adds getter for connection URI 2013-03-31 15:09:17 -05:00
Peter Thorson 7efcf1b047 processors now generate correct random masking keys 2013-03-31 15:08:43 -05:00
Peter Thorson 8a083528a2 finishes client handshake processing 2013-03-31 12:38:47 -05:00
Peter Thorson 13ec782a4f lots of tests 2013-03-31 12:37:59 -05:00
Peter Thorson aec59a1eb9 adds client handshake request generation and server response validation 2013-03-31 12:37:43 -05:00
Peter Thorson 6659846b2e extracts a method for processing handshake keys 2013-03-31 12:37:20 -05:00
Peter Thorson 45198eb4c6 major overhaul to processor unit tests to reduce duplicated code 2013-03-31 10:49:31 -05:00
Peter Thorson c5842802e2 turns on error reporting by default 2013-03-31 09:24:53 -05:00
Peter Thorson f423d051ee adds a new processor error code 2013-03-31 09:24:31 -05:00
Peter Thorson 1475e30930 updates http constants to match the code style of the rest of the library 2013-03-31 09:24:15 -05:00
Peter Thorson 46fb7e6645 adds more logic for reading client handshake responses 2013-03-30 22:41:57 -05:00
Peter Thorson ddddef5444 updates to unit tests to support new connection and processor api that includes RNG 2013-03-30 20:12:37 -05:00
Peter Thorson 67c740e264 adds HTTP request sending to connections 2013-03-30 19:55:40 -05:00
Peter Thorson cb6c396a6b adds handshake request processing to hybi13 and 00 processors 2013-03-30 19:55:04 -05:00
Peter Thorson f494c72006 adds RNG support for endpoints, connections, and processors 2013-03-30 19:54:26 -05:00
Peter Thorson 39c278a871 Adds the ability to detect and use constexpr to the C++11 common header 2013-03-30 17:49:56 -05:00
Peter Thorson b5b2fb9e0a adds default client version to core config 2013-03-30 17:49:35 -05:00
Peter Thorson 837d9eef9f Fixes a member variable that was not initialized before use 2013-03-30 17:48:35 -05:00
Peter Thorson 26d601e7c4 impliments async connect for iostream transport 2013-03-30 07:57:10 -05:00
Peter Thorson 3eef03d31e disables termination of connections that return bad handles 2013-03-30 07:56:50 -05:00
Peter Thorson 924bb1a050 adds client endpoint connection methods 2013-03-30 07:55:05 -05:00
Peter Thorson f2d939ab37 moves transport endpoing base types into the right file 2013-03-30 07:54:36 -05:00
Peter Thorson 8ced80b2ed adds method to retrieve connection handle from iostream connections 2013-03-30 07:53:45 -05:00
Peter Thorson 1ddd43ccb0 client get_connection now sets URI 2013-03-30 07:05:31 -05:00
Peter Thorson 7afcd866a0 adds the ability to set a connection URI outside of the server handshake 2013-03-30 07:05:08 -05:00
Peter Thorson afd5646ca5 adds more client functionality and associated tests 2013-03-28 22:58:54 -05:00
Peter Thorson 0b0106a97f adds is_secure method to transport endpoint 2013-03-28 22:58:39 -05:00
Peter Thorson 4f00240a3b adds preliminary foundations for client support 2013-03-28 22:43:55 -05:00
Peter Thorson e2489001cf adds connection dependencies 2013-03-28 22:43:23 -05:00
Peter Thorson 842c5749fc adds more error codes 2013-03-28 22:43:07 -05:00
Peter Thorson ef857ea831 splits basic logger from log constants 2013-03-28 22:42:51 -05:00
Peter Thorson e54c890b4b adds role unit test modules 2013-03-28 22:41:51 -05:00
Peter Thorson dfd61f8504 updates copyright dates 2013-03-28 22:41:23 -05:00
Peter Thorson 91c1e59ec4 fixes a legacy/hybi00 handshake processing bug on 32 bit x86 2013-03-28 08:23:59 -05:00
Peter Thorson ff04d307e5 Updates readme 2013-03-19 11:29:41 -05:00
Peter Thorson 45092c9633 adds get_io_service to asio transport 2013-03-17 22:57:27 -05:00
Peter Thorson ceea7f7be9 adds additional C++11 library blacklist defines 2013-03-17 22:10:08 -05:00
Peter Thorson 59d7efd1ba updates iostream unit tests 2013-03-17 21:48:43 -05:00
Peter Thorson 16c7d42bed adds boost_system for mutex dependency 2013-03-17 21:46:12 -05:00
Peter Thorson 3822384105 testing new scons g++ config 2013-03-17 21:43:12 -05:00
Peter Thorson f3810fa45e testing with regex common header 2013-03-17 21:41:09 -05:00
Peter Thorson a547ee5a7a adds logging of connection opening results 2013-03-17 20:13:51 -05:00
Peter Thorson 0236f0c722 adds lots of iostream transport unit tests 2013-03-17 18:28:46 -05:00
Peter Thorson d5d5a3330d adds logger test case with real concurrency primitives 2013-03-17 18:28:29 -05:00
Peter Thorson caa828defe adds lots of documentation to iostream transport 2013-03-17 18:27:54 -05:00
Peter Thorson 51633781e3 fixes missing dependency on the logger 2013-03-17 18:27:42 -05:00
Peter Thorson c73df1f3b5 fixes uninitialized m_output_stream variable 2013-03-17 18:27:21 -05:00
Peter Thorson 8e6bdfe42f impliments get_remote_endpoint for iostream transport 2013-03-17 18:26:46 -05:00
Peter Thorson 8e2b424887 fixes handling for zero length reads and reads to zero length buffers 2013-03-17 18:26:16 -05:00
Peter Thorson 940108b2a8 fixes a bug in scatter gather writes with lengths other than 1 2013-03-17 18:25:35 -05:00
Peter Thorson 2584aed3d9 Fixes a bug in back to back iostream reads 2013-03-17 18:24:36 -05:00
Peter Thorson 727328cc9a updates output_stream member variable name to be consistent with WebSocket++ style 2013-03-17 18:24:07 -05:00
Peter Thorson f7c36c46e9 adds new unit testing utility error code 2013-03-17 18:22:27 -05:00
Peter Thorson 7db9817d20 adds more transport documentation 2013-03-17 18:22:02 -05:00
Peter Thorson 56f5472c88 terminate test 2013-03-16 20:59:03 -05:00
Peter Thorson f51a650027 Enables C++11 STL random usage on g++ 2013-03-16 09:02:39 -05:00
Peter Thorson 8e23bbf5b2 adds missing iostream include to random test 2013-03-15 07:56:55 -05:00
Peter Thorson 54ef4db3a1 adds example code for enriched and associative storage 2013-03-10 13:22:53 -05:00
Peter Thorson b3a07d0978 adds overridable connection base class 2013-03-10 08:47:58 -05:00
Peter Thorson 117a76f1f9 updates gitignore 2013-03-08 08:47:45 -06:00
Peter Thorson e5758d7b58 adds code from some of the manual examples 2013-03-08 08:47:28 -06:00
Peter Thorson 213451370d adds an overload of get_con_from_hdl that throws 2013-03-08 08:45:40 -06:00
Peter Thorson 6f34b0f062 adds functional support for std::ref 2013-03-08 08:44:55 -06:00
Peter Thorson ee847e37fb adds more tests for endpoint base classes 2013-03-06 09:10:05 -06:00
Peter Thorson c7e0647626 fixes typo 2013-03-06 08:33:20 -06:00
Peter Thorson 37b1c65904 impliments a user overridable endpoint base class and associated tests 2013-03-06 08:33:11 -06:00
Peter Thorson 40abb49483 adds tests related to request bodies 2013-03-03 17:34:53 -06:00
Peter Thorson a6ce671c56 moves body to parser rather than response since requests can have bodies too. 2013-03-03 17:34:41 -06:00
Peter Thorson aaff9a5f49 makes none the default RNG to avoid requiring random_device in server configs 2013-03-03 17:34:03 -06:00
Peter Thorson 14b2012328 Adds RNG unit tests 2013-03-02 20:47:30 -06:00
Peter Thorson 8b7fe18a85 updates config to add RNG policy 2013-03-02 20:47:23 -06:00
Peter Thorson fbe991d9c2 updates boost random headers 2013-03-02 20:47:11 -06:00
Peter Thorson b373a388e7 completes int_generator policies 2013-03-02 20:47:01 -06:00
Peter Thorson ea4e66e14b additional iostream thread safety 2013-03-02 20:46:36 -06:00
Peter Thorson 8ec273e363 makes a cast explicit 2013-03-02 12:21:27 -06:00
Peter Thorson 45b3ed51ff moves some typedefs to public from protected 2013-03-01 17:28:12 -06:00
Peter Thorson 447c398479 fixes issue where close handler would be called twice 2013-02-24 16:29:53 -06:00
Peter Thorson ce95137ef5 Removes more implicit casts 2013-02-17 07:44:41 -06:00
Peter Thorson 78b52be803 removes force casting from int to bool 2013-02-17 07:13:09 -06:00
Peter Thorson e4f6aafb04 fixes some more visual studio warnings 2013-02-16 12:48:07 -06:00
Peter Thorson 9e19765bdf Fixes MSVC++ C4800 error (converting char to bool) 2013-02-16 12:41:07 -06:00
Peter Thorson 5c01b272fe changes generic to general because generic is a reserved word in visual studio 2013-02-16 12:31:32 -06:00
Peter Thorson e0abafbd71 moves stdint header to common includes 2013-02-08 08:48:39 -06:00
Peter Thorson f529ff2fbc updates connection test build dependency 2013-02-08 08:43:55 -06:00
Peter Thorson ddfc0566f5 adds timer support 2013-02-02 13:10:06 -06:00
Peter Thorson faaa8eb03e initial work on timer support 2013-02-02 10:54:30 -06:00
Peter Thorson 7d76532165 adds some documentation examples 2013-02-02 10:54:30 -06:00
Peter Thorson 6861398648 adds lowercase synonyms for some constants 2013-02-02 10:54:30 -06:00
Peter Thorson 3a92ff981a Merge pull request #183 from eandre/experimental
Added missing 'inline' directives
2013-02-01 15:43:45 -08:00
Peter Thorson 780847bf43 cleans up handle_accept error paths 2013-02-01 09:11:43 -06:00
Peter Thorson 99bc0abffc updates write_flag code to be robust and exception/thread safe 2013-02-01 08:59:57 -06:00
Peter Thorson 8d050767e1 fixes warning 2013-02-01 08:59:35 -06:00
Peter Thorson 45813db04d simplifies sending close frames 2013-02-01 07:55:42 -06:00
Peter Thorson 5ea7ee328e adds state check to connection::close 2013-02-01 07:50:13 -06:00
Peter Thorson 662b4333aa updates close adaptor to proper connection interface 2013-02-01 07:50:03 -06:00
Peter Thorson d0cbb07d5c adds documentation and adaptors for connection::close 2013-02-01 07:41:04 -06:00
Peter Thorson b999051959 adds raw array based send adaptors to endpoint 2013-02-01 07:26:20 -06:00
Peter Thorson 7ffbe8bfd8 moves bad_connection error handling into get_con_from_hdl 2013-02-01 07:25:44 -06:00
Peter Thorson 30134f8545 moves adaptor functions into endpoint_impl 2013-02-01 07:19:11 -06:00
Peter Thorson 30412282ee Updates constructor field order 2013-02-01 07:18:06 -06:00
Peter Thorson aa9644f2a8 fixes typo 2013-02-01 07:13:09 -06:00
Peter Thorson 1bfe86d795 Adds raw array send method to connection 2013-02-01 07:09:02 -06:00
Peter Thorson 5b9afc0309 updates message buffer's set and append payload methods to allow both std::string and raw array input 2013-02-01 07:02:38 -06:00
Peter Thorson 4063440895 temporary logging test changes 2013-01-31 20:30:02 -06:00
Peter Thorson c88cdaf2f4 updates buffer size to a more efficient default 2013-01-31 20:29:08 -06:00
Peter Thorson 6925a68f95 temporary fix for outgoing frame corruption issue #references 179 2013-01-31 08:41:37 -06:00
Peter Thorson 4928f84feb removes un-thread-safe access to cout 2013-01-31 08:40:46 -06:00
Peter Thorson b4903dad0b adds an application level logging level 2013-01-31 08:40:16 -06:00
Peter Thorson 7fe9eb592f refines endpoint logging interface 2013-01-31 08:39:57 -06:00
Peter Thorson 080fd42a0b updates readme 2013-01-27 10:39:55 -06:00
Peter Thorson 1979502a05 adds default logging settings to echo_server and catches more setup exceptions 2013-01-27 10:37:47 -06:00
Peter Thorson fa85811c07 adds some logger tests 2013-01-27 10:37:14 -06:00
Peter Thorson c83f8f485a adds pass through logging adaptor to endpoint 2013-01-27 10:36:19 -06:00
Peter Thorson 0bb60df7fc adds a typedef for logging levels 2013-01-27 10:35:57 -06:00
Peter Thorson 375108aabf Switches cout based logging to logging policy 2013-01-27 08:20:08 -06:00
Peter Thorson 37b6b5fb3c updates tests for logger 2013-01-27 08:19:32 -06:00
Peter Thorson 389e5925d7 splits asio/asio_no_tls up a bit better, adds logging information to configs 2013-01-27 08:19:19 -06:00
Peter Thorson a5d3555f96 whitespace 2013-01-27 08:18:10 -06:00
Andre Eriksson d6edaac02b Added missing 'inline' directives 2013-01-26 09:12:38 +01:00
Peter Thorson 6ab39622e5 adds basic logger class, with tests, and updates configs to include it 2013-01-20 20:24:26 -06:00
Peter Thorson 278909aad6 adds common chrono header 2013-01-20 20:23:47 -06:00
Peter Thorson 295c51c2c5 updates copyright year 2013-01-20 20:23:37 -06:00
Peter Thorson 9b142e3edc adds common/thread header and updates concurrency policies to use it 2013-01-20 20:23:22 -06:00
Peter Thorson 18fef37837 additional work on the broadcast server example 2013-01-20 14:31:54 -06:00
Peter Thorson 44e47267e9 initial work on broadcast_server example 2013-01-20 11:05:30 -06:00
Peter Thorson 290b719048 inlines appropriate functions to work when included in multiple translation units. fixes #178 2013-01-20 09:02:17 -06:00
Peter Thorson 7b2ed75e46 moves network related utility functions into network header 2013-01-20 08:57:51 -06:00
Peter Thorson c76771b323 splits connection test into two translation units 2013-01-20 08:56:38 -06:00
Peter Thorson 9a7631b2da updates endpoint concurrency features 2013-01-20 08:56:11 -06:00
Peter Thorson eb1603177f updates close to include network header 2013-01-10 08:47:16 -06:00
Peter Thorson 931bd92782 adds a common header to organize platform specific network related includes 2013-01-10 08:45:51 -06:00
Peter Thorson 8dbcb79eb5 Update BOOSTROOT build env variable to have consistant naming 2013-01-10 07:08:03 -06:00
Peter Thorson eb706ab7bd disable dev test application by default since it has some extra unwanted dependencies 2013-01-10 07:07:38 -06:00
Peter Thorson e1a333e4f3 include missing header 2013-01-10 07:07:08 -06:00
Peter Thorson cbaee8b4d5 notes about initialization 2013-01-09 09:15:26 -06:00
Peter Thorson f0006864dc updates readme 2013-01-09 09:14:53 -06:00
Peter Thorson 5d7e32fa10 rearranges some stuff 2013-01-09 08:05:43 -06:00
Peter Thorson 43ad5ee342 adds endpoint initialization tests 2013-01-09 07:20:35 -06:00
Peter Thorson 58dd020753 simplifies init_asio signature 2013-01-09 07:20:21 -06:00
Peter Thorson 4edc446b01 fixes a bug cleaning up external io_services 2013-01-09 07:20:05 -06:00
Peter Thorson 107b60dd01 adds endpoint unit test suite 2013-01-09 07:07:01 -06:00
Peter Thorson 7ab2d2c937 removed unnecessary typenames 2013-01-09 07:06:50 -06:00
Peter Thorson 1b83d5e855 better debug printing 2013-01-09 07:06:38 -06:00
Peter Thorson 0e6e41d1c4 adds some more status info to the readme 2013-01-09 06:15:04 -06:00
Peter Thorson a81a266c53 updates TLS code to new handler system 2013-01-09 06:14:39 -06:00
Peter Thorson a3e2e31e91 removes more dead code 2013-01-08 07:49:34 -06:00
Peter Thorson 4f914f8477 updates tests and echo server to new handler interface 2013-01-08 07:48:32 -06:00
Peter Thorson b315f9f684 adds send adaptor functions to endpoints 2013-01-08 07:47:59 -06:00
Peter Thorson a3acc4a1cf removes all old style handler code 2013-01-08 06:43:47 -06:00
Peter Thorson 31cc4af4f4 cleanup 2013-01-08 06:33:06 -06:00
Peter Thorson ef8898afef adds support for message_handler 2013-01-08 06:33:02 -06:00
Peter Thorson 8df37fffbc Updates on_http and validate handlers to use new handler interface 2013-01-07 17:14:29 -06:00
Peter Thorson e7b87e5d54 Updates on_ping, on_pong, and on_pong_timeout handlers to new interface 2013-01-07 16:53:14 -06:00
Peter Thorson 235b567b59 Updates on_close and on_fail to use new handler style 2013-01-07 12:45:09 -06:00
Peter Thorson ebfb8b8e2f Removes handler_interface from all transport code 2013-01-07 12:30:41 -06:00
Peter Thorson 6a4173578e Removes handler_interface types from socket components 2013-01-07 12:27:17 -06:00
Peter Thorson fe582e90e0 updates connection and endpoint to use new component styles 2013-01-07 12:23:21 -06:00
Peter Thorson 8b890d755b Updates asio transport components to new styles 2013-01-07 12:22:46 -06:00
Peter Thorson 052abf06ad Updates asio socket components to new styles 2013-01-07 12:22:16 -06:00
Peter Thorson e339e0f5c6 Updates server role with new component style 2013-01-07 12:21:28 -06:00
Peter Thorson 7aa7f3af80 Updates iostream transport to new component style 2013-01-07 12:20:41 -06:00
Peter Thorson f9c62ee778 Updates configs for new socket API 2013-01-07 12:18:37 -06:00
Peter Thorson f5d4cbe143 updates asio on_tcp_init callback to new api 2013-01-06 10:10:35 -06:00
Peter Thorson ce7b09767a adds documentation 2013-01-06 10:10:18 -06:00
Peter Thorson 2ad049055c updates echo_server to use new interrupt API 2013-01-06 09:59:55 -06:00
Peter Thorson 05f9faebf5 updates interrupt functionality to latest API spec 2013-01-06 09:59:38 -06:00
Peter Thorson 5949c58d2e updates transport accept loop to use connection_hdl and not be a template function 2013-01-06 09:19:08 -06:00
Peter Thorson a48c788ecc asio transport connection now recieves connection hdl 2013-01-06 09:17:09 -06:00
Peter Thorson 9ca476ae22 iostream connection now receives connection hdl 2013-01-06 09:16:49 -06:00
Peter Thorson 7bbfaa78bc connection forwards handle to transport 2013-01-06 09:16:11 -06:00
Peter Thorson db6b32b90b const correctness 2013-01-06 09:15:55 -06:00
Peter Thorson 77422dec25 better qualifies subclass typedefs 2013-01-06 09:15:20 -06:00
Peter Thorson d705a805eb adds ability to retrieve connection_hdl and some docs 2013-01-06 08:53:58 -06:00
Peter Thorson 9253e4fca2 adds a pointer type 2013-01-06 08:50:25 -06:00
Peter Thorson b5a5fd6fe3 adds a pointer type 2013-01-06 08:50:15 -06:00
Peter Thorson 266ceafa26 connects interrupt's error handling 2013-01-06 08:49:55 -06:00
Peter Thorson 21eb1bbd35 adds a convenience function to retrieve connection pointers from handles 2013-01-06 08:49:36 -06:00
Peter Thorson 853c46a0f5 clarifies source of request_type redefinition 2013-01-06 06:45:35 -06:00
Peter Thorson a6002daddd fixes security category make_error_code 2013-01-06 06:43:20 -06:00
Peter Thorson 448588ac5c fixes missing return value 2013-01-06 06:42:55 -06:00
Peter Thorson 2af6ccb7a7 Adds initial readme 2013-01-06 06:12:59 -06:00
Peter Thorson f10f8a4ce0 Initial commit from private 0.3 repository 2013-01-06 06:09:15 -06:00
Peter Thorson 5809440f1a Updates multithreaded non-forked listen methods to not prematurely close the endpoint. references #168 2013-01-04 07:06:54 -06:00
Peter Thorson 4799525445 removes endpoint state change that breaks multi-threaded servers references #168 2013-01-04 06:28:44 -06:00
Peter Thorson 0c4d239aeb fixes formatting 2012-12-19 06:45:46 -06:00
Peter Thorson 43970572f5 version bump 2012-12-19 06:36:28 -06:00
Peter Thorson 6a1dccc8cb corrects an infinite loop when the acceptor is closed in thread pool mode references #168 2012-12-19 06:26:28 -06:00
Peter Thorson 6aa11a7fac Updates user agent/version string 2012-12-11 07:45:20 -06:00
Peter Thorson 0318700c00 m_requested_subprotocols wasn't getting populated. fixes #155
Thank you to robagar for finding this bug and jeffjcrowe for supplying
a patch
2012-12-11 07:07:25 -06:00
Peter Thorson 27a6d6f4d3 Close acceptor on stop_listen. fixes #161 2012-12-11 06:53:43 -06:00
Peter Thorson ce1c1d3a76 removes unnecessary check fixes #163 2012-12-11 06:42:50 -06:00
Peter Thorson 1c8ba9954e Adjusts ordering guarantees on message sending references #149 2012-10-12 07:56:05 -05:00
Peter Thorson 52ce31bea4 updates the order of endpoint and handler construction #references 147 2012-10-12 06:36:23 -05:00
Peter Thorson 47a3c060ee Revert "Fix Compiler Warning on using std::copy: no point using STL routines inside low-level C-style code"
This reverts commit 5dfe48b043.
2012-10-12 06:31:18 -05:00
Peter Thorson d80d9afd88 preliminary work on a fix to the ARM aliasing issues 2012-10-12 06:29:42 -05:00
Peter Thorson 25322aac0d adds missing virtual destructor 2012-10-12 06:29:42 -05:00
Peter Thorson 10ac9c41ec removes unused varaible from wsperf 2012-10-12 06:29:42 -05:00
Peter Thorson 492ada4788 updates SConstruct compile flags for posix and darwin 2012-10-12 06:29:41 -05:00
Peter Thorson b73f1526b6 Merge pull request #148 from NNemec/master
Various small changes of general interest
2012-10-12 04:29:12 -07:00
Norbert Nemec 34a10b0916 split server::listen interface into start_listen and stop_listen, allowing the controlling thread to continue running asynchronously. (Legacy interface provided) 2012-10-09 15:08:25 +02:00
Norbert Nemec db0a43a228 Disable warning C4355 for plain.hpp similar to server.hpp (beware: this hides a real design problem) 2012-10-09 14:06:20 +02:00
Norbert Nemec dbdb150021 clarify interface by correct argument names 2012-10-09 14:00:07 +02:00
Norbert Nemec 5dfe48b043 Fix Compiler Warning on using std::copy: no point using STL routines inside low-level C-style code 2012-10-09 13:59:52 +02:00
Norbert Nemec 3e3b5a0bb8 fix compiler issue 2012-10-09 12:15:17 +02:00
Norbert Nemec 54b1931963 Fix compiler issue: boost/cstdint.hpp contains the types inside boost:: namespace. <stdint.h> should be available by default. vcpp2008 has its own workaround. 2012-10-09 12:15:03 +02:00
Norbert Nemec c2f83814dc Update vcpp2008 project files and use common.vsprops for configuring external dependencies (i.e. boost) 2012-10-09 12:11:01 +02:00
Peter Thorson dd9899c34b Adds virtual destructors to handler interfaces fixes #136 2012-09-24 07:47:14 -05:00
Peter Thorson a17a27dd5c updates set_handler to by synchronous fixes #139 2012-09-24 07:41:25 -05:00
Peter Thorson 546846af19 Merge pull request #141 from 422053362/patch-1
Workaround for windows min and max macros with std::min and std::max
2012-09-24 05:12:01 -07:00
422053362 12245fd745 Update src/roles/client.hpp
sometimes it cause error。
 I have check the function "uniform_int_distribution" ,
 the right way to construct is
 boost::random::uniform_int_distribution<>(
                (std::numeric_limits<int32_t>::min)(),
                (std::numeric_limits<int32_t>::max)()
             )
not 
 boost::random::uniform_int_distribution<>(
                std::numeric_limits<int32_t>::min(),
                std::numeric_limits<int32_t>::max()
             )
maybe sometimes the second way would not cause error,but sometimes it dose.so I modified.
2012-09-23 05:33:57 +08:00
Peter Thorson 16aaa00a1c Fixes an issue where http handler callback is called before building the URI #references #118
Thank you ShuminHuang for filing this bug
2012-08-04 09:59:41 -05:00
Peter Thorson 4b3ca1911b Merge pull request #131 from jrosser/fixes
Small fixes for compiling on Ubuntu 12.04
2012-08-04 07:44:12 -07:00
Peter Thorson 925b4cdd68 Merge pull request #124 from oberstet/master
minor thing
2012-08-04 07:36:10 -07:00
Jonathan Rosser 6f0722b04e fix build of fuzzing_client
this seems fairly fundamental - does nothing else use this and fail?
2012-07-31 13:01:04 +01:00
Jonathan Rosser 3ecec05364 fix stress_client warning and compile error 2012-07-31 13:00:53 +01:00
Jonathan Rosser a0040da1d7 add another missing linkage against pthreads 2012-07-31 09:44:27 +01:00
Jonathan Rosser 159b9d3a88 fix missing boost_thread from some examples 2012-07-29 08:47:16 +01:00
Jonathan Rosser b7009335fe fix usage of C99 macros in C++ 2012-07-26 11:29:10 +01:00
Tobias Oberstein 44bacdb323 does away with VC++ warning: C4309 - truncation of constant value 2012-07-18 14:09:39 +02:00
Peter Thorson 3208b1b493 fixes telemetry server bug references #121 2012-07-11 08:47:45 -05:00
Peter Thorson 1f8113bbd6 adds telemetry server example 2012-07-11 08:20:37 -05:00
Peter Thorson 87d76a3995 Fixes a frame read issue with hybi00 references #101 2012-07-10 07:25:27 -05:00
Peter Thorson 84e021e679 updates makefile for wsperf stress test 2012-06-28 06:52:11 -05:00
Peter Thorson 8d9f55ad23 Merge pull request #117 from dasty/master
Just fixing compilation issue for people who use makefile
2012-06-28 04:39:15 -07:00
Peter Thorson 9716a2269c Merge pull request #113 from pmarques/master
Compiler error due to ambiguous methods resolution
2012-06-28 04:36:40 -07:00
Radek Dostal 125142a7d1 $(CXX) linker should not be run for build of object files
Signed-off-by: Radek Dostal <rd@radekdostal.com>
2012-06-18 18:57:51 +02:00
Peter Thorson f78b9df4ad disable file descriptor limits by default to not confuse windows 2012-06-07 13:46:18 -05:00
Peter Thorson 241a28cbd7 javascript reference clients for message_test and stress_test 2012-06-07 13:44:56 -05:00
Peter Thorson 61be3c182c stress_test now supports message sending & stats 2012-06-07 13:44:56 -05:00
Peter Thorson a3b7546d65 Merge pull request #116 from oberstet/master
make win build and warn free
2012-06-07 05:57:20 -07:00
Peter Thorson 0cd1c58505 stress_test parameter parsing 2012-06-07 06:09:24 -05:00
Peter Thorson 674042f576 preliminary support for thousands of connections on darwin and linux 2012-06-07 06:09:02 -05:00
Peter Thorson 0b10e9c0a3 adds extract string support for wscmd 2012-06-07 06:07:42 -05:00
Tobias Oberstein 9838895d39 slight adjust 2012-06-07 12:55:07 +02:00
Tobias Oberstein 19173e9584 some minor things (make win build warn free) 2012-06-07 12:49:55 +02:00
Peter Thorson b58cf53353 some windows fixes 2012-06-05 08:39:08 -05:00
Peter Thorson 2d12256c7c adds handshake delay and test doneness check 2012-06-05 08:26:06 -05:00
Peter Thorson 1d3942622a this can cause crazy runaway reconnects, need to rethink 2012-06-05 08:25:52 -05:00
Peter Thorson 002e75891e adds preliminary stress_test mode to wsperf 2012-06-04 08:47:37 -05:00
Peter Thorson 2f6565565b adds client on_handshake_init callback 2012-06-04 08:47:37 -05:00
Peter Thorson 232fd1ebf6 Merge pull request #115 from beeftaco/master
Updated project and solution files for better Windows compatibility
2012-05-29 04:06:41 -07:00
beeftaco 469c97c7d9 Updated compatibility for VS2010 2012-05-28 11:47:34 -07:00
Patrick F. Marques 8e091853cc Correction of compiler error due to ambiguous "call conversionS" 2012-05-03 10:40:57 +01:00
Peter Thorson 899b7e3bea defines CPP11 friend fix for Visual Studio 2012-04-22 15:22:40 -05:00
Peter Thorson 9ba194a7f9 fixes #103 2012-04-13 08:47:48 -05:00
Peter Thorson e928f4a566 adds preliminary machine readable connection failure information 2012-04-13 08:34:22 -05:00
Peter Thorson 31a9f9a9bc potential fixes for hixie76 handshakes, references #101 2012-04-13 07:38:15 -05:00
Peter Thorson 7875f03f76 adds WS handshake timeout 2012-04-13 07:36:00 -05:00
Peter Thorson 419178dead adds hook for on_handshake_init 2012-04-13 07:35:29 -05:00
Peter Thorson a4bca13636 generic timeout support 2012-04-13 07:34:50 -05:00
Peter Thorson 8d846000bf adds on_tcp_init hook and TLS handshake timeout 2012-04-13 07:34:22 -05:00
Peter Thorson dc3be3d658 adds on_tcp_init hook 2012-04-13 07:34:11 -05:00
Peter Thorson 75ef3defe9 adds header needed on unix 2012-04-13 07:33:52 -05:00
Peter Thorson 0eedb6e8b6 moves JS libraries into "vendor" folder to escape Linguist 2012-04-13 07:33:30 -05:00
Peter Thorson 04f8413f7d Merge pull request #104 from jdale88/master
Compiler fixes for VS2010
2012-04-12 19:25:01 -07:00
Jamie Dale 42afb69ede Compiler fixes for VS2010.
This fixes some errors caused by Windows defining things like min and max, as well as a number of warnings about type conversion, unused parameters, inability to generate assignment operators, and constant conditions.

All type conversions were assumed to be intentional, and static_casts have been added to remove the compiler warnings.

The server code should now build cleanly with level 4 warnings enabled (as used in my project), and the client code should build cleanly with level 3 warnings enabled (as used by the WebSocket++ projects).
2012-04-12 19:31:12 +01:00
Peter Thorson af23ead5fc removes more duplicate javascript libraries 2012-04-10 09:09:07 -05:00
Peter Thorson dc1e432cdf removes second bundled copy of slot 2012-04-10 09:03:11 -05:00
Peter Thorson 7c4c359ef9 disable experimental support for client thread pool by default 2012-04-10 08:54:51 -05:00
Peter Thorson 1512598e3f logging robustness changes 2012-04-10 08:26:23 -05:00
Peter Thorson 9bc3220b5e message processor performance improvements 2012-04-10 08:25:46 -05:00
Peter Thorson 8129787625 to_hex for char* 2012-04-10 08:24:54 -05:00
Peter Thorson 14802c7afc wsperf logging and preliminary stress_test work 2012-04-10 08:24:39 -05:00
Peter Thorson 64156eff9f updates build system files 2012-04-10 08:22:30 -05:00
Peter Thorson 4e7b899dc7 new wsperf module files 2012-04-10 08:21:57 -05:00
Peter Thorson ea19f1e501 masking utility functions and unit tests 2012-04-10 08:21:35 -05:00
Peter Thorson f3fc8a2466 cleans up and documents some hixie 76 issues references #101 2012-04-07 10:15:28 -05:00
Peter Thorson 6c9d814392 fixes #78 2012-04-07 10:06:36 -05:00
Peter Thorson eb79122da9 update Xcode project 2012-04-07 10:03:32 -05:00
Peter Thorson bb2154613c removes some debug code 2012-04-07 10:02:53 -05:00
Peter Thorson 5f3fbc9593 Merge branch 'master' of github.com:zaphoyd/websocketpp 2012-03-28 09:51:05 -05:00
Peter Thorson b2f57039ae fixes user agent header typo, fixes #100 2012-03-28 09:50:26 -05:00
Peter Thorson 0c90670176 fixes wsperf build on g++ 4.6 2012-03-27 08:15:41 -05:00
Peter Thorson b8ddddfe01 masking optimizations off by default 2012-03-25 14:33:00 -05:00
Peter Thorson 0f95459ac4 preliminary masking code performance improvements 2012-03-25 08:40:29 -05:00
Peter Thorson 368a0f3726 fixes mutex support in const methods 2012-03-25 08:39:39 -05:00
Peter Thorson 3017830e77 clean up legacy code 2012-03-23 13:44:24 -05:00
Peter Thorson edf244daf7 better detached connection error handling 2012-03-23 13:44:03 -05:00
Peter Thorson 2109723b34 adds thread pool support to concurrent_server example 2012-03-21 22:46:38 -06:00
Peter Thorson 9348aa4c21 adds thread pool support to server 2012-03-21 22:37:04 -06:00
Peter Thorson 6ca0b49ae0 more concurrency cleanup, misc features 2012-03-21 21:57:58 -06:00
Peter Thorson 517852cd95 adds silent close option 2012-03-21 21:57:20 -06:00
Peter Thorson d20a2f6fef hybi processor silent close frame 2012-03-21 21:56:51 -06:00
Peter Thorson 461fe64242 async handle_read_frame in server 2012-03-21 21:56:23 -06:00
Peter Thorson 892fdd2456 updates defaults 2012-03-21 21:56:01 -06:00
Peter Thorson 3cef677c31 docs and concurrency clean up 2012-03-19 16:20:27 -06:00
Peter Thorson 2f6a014a2e docs and cleanup 2012-03-19 16:19:44 -06:00
Peter Thorson 59efe59466 wrap async calls with strand 2012-03-19 15:53:49 -06:00
Peter Thorson 9d221c6a84 updates some todos 2012-03-19 15:53:17 -06:00
Peter Thorson 60c2f8efb2 lots of new constants 2012-03-19 15:50:11 -06:00
Peter Thorson b5cd8488ce update chat client for new API 2012-03-19 15:49:51 -06:00
Peter Thorson 8e73e436d0 WS++ very fast fail on utf8 fixes 2012-03-18 16:41:54 -05:00
Peter Thorson 14562aa8bc enable angle by default 2012-03-18 16:41:30 -05:00
Peter Thorson ae12a9ee52 C++ style copy and set 2012-03-18 14:33:13 -05:00
Peter Thorson 41cd2ac01e Merge pull request #95 from blindmatrix/76296fe2dd49c55d85f818005ea9bb6901807c79
Fixed compile-time warnings
2012-03-18 11:42:21 -07:00
Sven Almgren 76296fe2dd Fixed broken conversion 2012-03-15 16:15:41 +01:00
Sven Almgren 9cdc8e7009 Merge branch 'master' of https://github.com/zaphoyd/websocketpp 2012-03-15 15:15:50 +01:00
Sven Almgren 6fabf34630 Removed some nonstrict-alias code 2012-03-15 15:15:19 +01:00
Peter Thorson f6fd0f4fb2 Merge pull request #93 from oberstet/master
Build fixes
2012-03-15 06:33:06 -07:00
Tobias Oberstein 09c541185d disable TLS build on Win .. needs OpenSSL dev .. 2012-03-15 14:27:25 +01:00
Tobias Oberstein c6bb4912b2 fix scons build 2012-03-15 14:11:21 +01:00
Peter Thorson 3994731df8 Merge branch 'master' of github.com:zaphoyd/websocketpp 2012-03-15 07:37:31 -05:00
Peter Thorson 6b32481a87 make static library default 2012-03-15 07:36:29 -05:00
Peter Thorson 2fa84a07f0 Merge pull request #92 from blindmatrix/master
Removed extra comma in header (and more stuff)
2012-03-15 05:36:08 -07:00
Sven Almgren 1a0796d315 Removed duplicate variable in assignment (m_state = m_state = X) 2012-03-15 12:57:34 +01:00
Sven Almgren 002b8a2c35 Removed extra comma, as -pedantic complains 2012-03-15 11:56:34 +01:00
464 changed files with 31415 additions and 63469 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
# Lineendings
*.sln eol=crlf
*.vcproj eol=crlf
*.vcxproj* eol=crfl
*.vcxproj* eol=crlf
# Whitespace rules
# strict (no trailing, no tabs)
@@ -15,4 +15,4 @@
*.txt whitespace=trailing-space,space-before-tab,cr-at-eol
# special files which must ignore whitespace
*.patch whitespace=-trailing-space
*.patch whitespace=-trailing-space
+27
View File
@@ -14,6 +14,28 @@
*.so.?.?.?
*.a
*.dylib
lib/*
# CMake
*.cmake
*.dir
CMakeFiles
INSTALL.*
ZERO_CHECK.*
CMakeCache.txt
install_manifest.txt
# Windows/Visual Studio
*.vcproj*
*.sln
*.suo
*.ncb
*/Debug/*
*/*/Debug/*
*/Release/*
*/*/Release/*
*/RelWithDebInfo/*
*/*/RelWithDebInfo/*
objs_shared/
objs_static/
@@ -50,4 +72,9 @@ examples/wsperf/wsperf
.sconsign.dblite
build/
doxygen/
examples/wsperf/wsperf_client
*.out
*.log
+22
View File
@@ -0,0 +1,22 @@
language: cpp
compiler:
- gcc
before_install:
- sudo apt-get install libboost-regex1.48-dev libboost-system1.48-dev libboost-thread1.48-dev libboost-test1.48-dev libboost-random1.48-dev -y
env:
global:
- BOOST_INCLUDES=/usr/include
- BOOST_LIBS=/usr/lib
script: scons -j 2 && scons test
branches:
only:
- master
- permessage-deflate
- experimental
- 0.3.x-cmake
notifications:
recipients:
- travis@zaphoyd.com
email:
on_success: change
on_failure: always
+237
View File
@@ -0,0 +1,237 @@
############ Setup project and cmake
# Project name
project (websocketpp)
# Minimum cmake requirement. We should require a quite recent
# cmake for the dependency find macros etc. to be up to date.
cmake_minimum_required (VERSION 2.6)
set (WEBSOCKETPP_MAJOR_VERSION 0)
set (WEBSOCKETPP_MINOR_VERSION 3)
set (WEBSOCKETPP_PATCH_VERSION 0)
set (WEBSOCKETPP_VERSION ${WEBSOCKETPP_MAJOR_VERSION}.${WEBSOCKETPP_MINOR_VERSION}.${WEBSOCKETPP_PATCH_VERSION})
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
if (WIN32 AND NOT CYGWIN)
set (DEF_INSTALL_CMAKE_DIR cmake)
else ()
set (DEF_INSTALL_CMAKE_DIR lib/cmake/websocketpp)
endif ()
set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
# Make relative paths absolute (needed later on)
foreach (p INCLUDE CMAKE)
set (var INSTALL_${p}_DIR)
if (NOT IS_ABSOLUTE "${${var}}")
set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif ()
endforeach ()
# Set CMake library search policy
if (COMMAND cmake_policy)
cmake_policy (SET CMP0003 NEW)
cmake_policy (SET CMP0005 NEW)
endif ()
# Disable unnecessary build types
set (CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "Configurations" FORCE)
# Include our cmake macros
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include (CMakeHelpers)
############ Paths
set (WEBSOCKETPP_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set (WEBSOCKETPP_INCLUDE ${WEBSOCKETPP_ROOT}/websocketpp)
set (WEBSOCKETPP_BUILD_ROOT ${CMAKE_CURRENT_BINARY_DIR})
set (WEBSOCKETPP_BIN ${WEBSOCKETPP_BUILD_ROOT}/bin)
set (WEBSOCKETPP_LIB ${WEBSOCKETPP_BUILD_ROOT}/lib)
# CMake install step prefix. I assume linux users want the prefix to
# be the default /usr or /usr/local so this is only adjusted on Windows.
# - Windows: Build the INSTALL project in your solution file.
# - Linux/OSX: make install.
if (MSVC)
set (CMAKE_INSTALL_PREFIX "${WEBSOCKETPP_ROOT}/install")
endif ()
############ Build customization
# Override from command line "CMake -D<OPTION>=TRUE/FALSE/0/1/ON/OFF"
option (ENABLE_CPP11 "Build websocketpp with CPP11 features enabled." TRUE)
option (BUILD_EXAMPLES "Build websocketpp examples." FALSE)
option (BUILD_TESTS "Build websocketpp tests." FALSE)
if (BUILD_TESTS OR BUILD_EXAMPLES)
############ Compiler specific setup
set (WEBSOCKETPP_PLATFORM_LIBS "")
set (WEBSOCKETPP_PLATFORM_TSL_LIBS "")
set (WEBSOCKETPP_BOOST_LIBS "")
# VC9 and C++11 reasoning
if (ENABLE_CPP11 AND MSVC AND MSVC90)
message("* Detected Visual Studio 9 2008, disabling C++11 support.")
set (ENABLE_CPP11 FALSE)
endif ()
# Detect clang. Not officially reported by cmake.
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-v" ERROR_VARIABLE CXX_VER_STDERR)
if ("${CXX_VER_STDERR}" MATCHES ".*clang.*")
set (CMAKE_COMPILER_IS_CLANGXX 1)
endif ()
# C++11 defines
if (ENABLE_CPP11)
add_definitions (-D_WEBSOCKETPP_CPP11_STL_)
endif ()
# Visual studio
if (MSVC)
set (WEBSOCKETPP_BOOST_LIBS system thread)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Gy /GF /Ox /Ob2 /Ot /Oi /MP /arch:SSE2 /fp:fast")
set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
add_definitions (/W3 /wd4996 /wd4995 /wd4355)
add_definitions (-DUNICODE -D_UNICODE)
add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
add_definitions (-DNOMINMAX)
endif ()
# g++
if (CMAKE_COMPILER_IS_GNUCXX)
set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
set (WEBSOCKETPP_PLATFORM_TSL_LIBS ssl crypto)
set (WEBSOCKETPP_BOOST_LIBS system thread)
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x")
if (NOT APPLE)
add_definitions (-DNDEBUG -Wall -Wcast-align) # todo: should we use CMAKE_C_FLAGS for these?
endif ()
# Try to detect version. Note: Not tested!
execute_process (COMMAND ${CMAKE_CXX_COMPILER} "-dumpversion" OUTPUT_VARIABLE GCC_VERSION)
if ("${GCC_VERSION}" STRGREATER "4.4.0")
message("* C++11 support partially enabled due to GCC version ${GCC_VERSION}")
set (WEBSOCKETPP_BOOST_LIBS system thread)
endif ()
endif ()
# clang
if (CMAKE_COMPILER_IS_CLANGXX)
if (NOT APPLE)
set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
else()
set (WEBSOCKETPP_PLATFORM_LIBS pthread)
endif()
set (WEBSOCKETPP_PLATFORM_TSL_LIBS ssl crypto)
set (WEBSOCKETPP_BOOST_LIBS system thread)
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x -stdlib=libc++") # todo: is libc++ really needed here?
if (NOT APPLE)
add_definitions (-DNDEBUG -Wall -Wno-padded) # todo: should we use CMAKE_C_FLAGS for these?
endif ()
endif ()
# OSX, can override above.
if (APPLE)
add_definitions (-DNDEBUG -Wall)
endif ()
if (BUILD_EXAMPLES)
list (APPEND WEBSOCKETPP_BOOST_LIBS random)
endif()
############ Dependencies
# Set BOOST_ROOT env variable or pass with cmake -DBOOST_ROOT=path.
# BOOST_ROOT can also be defined by a previous run from cmake cache.
if (NOT "$ENV{BOOST_ROOT_CPP11}" STREQUAL "")
# Scons documentation for BOOST_ROOT_CPP11:
# "look for optional second boostroot compiled with clang's libc++ STL library
# this prevents warnings/errors when linking code built with two different
# incompatible STL libraries."
file (TO_CMAKE_PATH "$ENV{BOOST_ROOT_CPP11}" BOOST_ROOT)
set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
endif ()
if ("${BOOST_ROOT}" STREQUAL "")
file (TO_CMAKE_PATH "$ENV{BOOST_ROOT}" BOOST_ROOT)
# Cache BOOST_ROOT for runs that do not define $ENV{BOOST_ROOT}.
set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
endif ()
message ("* Configuring Boost")
message (STATUS "-- Using BOOST_ROOT")
message (STATUS " " ${BOOST_ROOT})
if (MSVC)
set (Boost_USE_MULTITHREADED TRUE)
set (Boost_USE_STATIC_LIBS TRUE)
else ()
set (Boost_USE_MULTITHREADED FALSE)
set (Boost_USE_STATIC_LIBS FALSE)
endif ()
set (Boost_FIND_REQUIRED TRUE)
set (Boost_FIND_QUIETLY TRUE)
set (Boost_DEBUG FALSE)
set (Boost_USE_MULTITHREADED TRUE)
set (Boost_ADDITIONAL_VERSIONS "1.39.0" "1.40.0" "1.41.0" "1.42.0" "1.43.0" "1.44.0" "1.46.1") # todo: someone who knows better spesify these!
find_package (Boost 1.39.0 COMPONENTS "${WEBSOCKETPP_BOOST_LIBS}")
if (Boost_FOUND)
# Boost is a project wide global dependency.
include_directories (${Boost_INCLUDE_DIRS})
link_directories (${Boost_LIBRARY_DIRS})
# Pretty print status
message (STATUS "-- Include Directories")
foreach (include_dir ${Boost_INCLUDE_DIRS})
message (STATUS " " ${include_dir})
endforeach ()
message (STATUS "-- Library Directories")
foreach (library_dir ${Boost_LIBRARY_DIRS})
message (STATUS " " ${library_dir})
endforeach ()
message (STATUS "-- Libraries")
foreach (boost_lib ${Boost_LIBRARIES})
message (STATUS " " ${boost_lib})
endforeach ()
message ("")
else ()
message (FATAL_ERROR "Failed to find required dependency: boost")
endif ()
find_package(OpenSSL)
endif()
############ Add projects
# Add main library
add_subdirectory (websocketpp)
# Add examples
if (BUILD_EXAMPLES)
add_subdirectory (examples)
endif ()
# Add tests
if (BUILD_TESTS)
add_subdirectory (test)
endif ()
print_used_build_config()
export (PACKAGE websocketpp)
configure_file (websocketpp-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake" @ONLY)
configure_file (websocketpp-configVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake" @ONLY)
# Install the websocketpp-config.cmake and websocketpp-configVersion.cmake
install (FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake"
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
+145
View File
@@ -0,0 +1,145 @@
Main Library:
Copyright (c) 2013, Peter Thorson. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the WebSocket++ Project nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Bundled Libraries:
****** Base 64 Library (base64/base64.hpp) ******
base64.hpp is a repackaging of the base64.cpp and base64.h files into a
single header suitable for use as a header only library. This conversion was
done by Peter Thorson (webmaster@zaphoyd.com) in 2012. All modifications to
the code are redistributed under the same license as the original, which is
listed below.
base64.cpp and base64.h
Copyright (C) 2004-2008 René Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
****** SHA1 Library (sha1/sha1.hpp) ******
sha1.hpp is a repackaging of the sha1.cpp and sha1.h files from the shallsha1
library (http://code.google.com/p/smallsha1/) into a single header suitable for
use as a header only library. This conversion was done by Peter Thorson
(webmaster@zaphoyd.com) in 2013. All modifications to the code are redistributed
under the same license as the original, which is listed below.
Copyright (c) 2011, Micael Hildenborg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Micael Hildenborg nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Micael Hildenborg ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Micael Hildenborg BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****** MD5 Library (common/md5.hpp) ******
md5.hpp is a reformulation of the md5.h and md5.c code from
http://www.opensource.apple.com/source/cups/cups-59/cups/md5.c to allow it to
function as a component of a header only library. This conversion was done by
Peter Thorson (webmaster@zaphoyd.com) in 2012 for the WebSocket++ project. The
changes are released under the same license as the original (listed below)
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
L. Peter Deutsch
ghost@aladdin.com
****** UTF8 Validation logic (utf8_validation.hpp) ******
utf8_validation.hpp is adapted from code originally written by Bjoern Hoehrmann
<bjoern@hoehrmann.de>. See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for
details.
The original license:
Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1874
View File
File diff suppressed because it is too large Load Diff
-246
View File
@@ -1,246 +0,0 @@
################################################################################
#
# Copyright (c) 2011, Peter Thorson. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the WebSocket++ Project nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# This Makefile was derived from a similar one included in the libjson project
# It's authors were Jonathan Wallace and Bernhard Fluehmann.
objects = network_utilities.o sha1.o base64.o md5.o uri.o hybi_header.o data.o
BOOST_PREFIX ?= /usr/local
BOOST_LIB_PATH ?= $(BOOST_PREFIX)/lib
BOOST_INCLUDE_PATH ?= $(BOOST_PREFIX)/include
libs = -L$(BOOST_LIB_PATH) -lboost_system -lboost_date_time -lboost_regex -lboost_random -lboost_program_options -lboost_thread
//libs_static = $(BOOST_PATH)/boost_system.a $(BOOST_PATH)/boost_regex.a
OS=$(shell uname)
# CPP11 build
ifeq ($(CPP11), 1)
CPP11_ = -std=c++0x -stdlib=libc++
else
CPP11_ ?=
endif
# Defaults
ifeq ($(OS), Darwin)
cxxflags_default = -c $(CPP11_) -Wall -O2 -DNDEBUG -I$(BOOST_INCLUDE_PATH)
else
cxxflags_default = -c -Wall -O2 -DNDEBUG -I$(BOOST_INCLUDE_PATH)
endif
cxxflags_small = -c
cxxflags_debug = -c -g -O0
cxxflags_shared = -f$(PIC)
libname = libwebsocketpp
libname_hdr = websocketpp
libname_debug = $(libname)
suffix_shared = so
suffix_shared_darwin = dylib
suffix_static = a
major_version = 0
minor_version = 2.0
objdir = objs
# Variables
prefix ?= /usr/local
exec_prefix ?= $(prefix)
libdir ?= lib
includedir ?= include
srcdir ?= src
CXX ?= c++
AR ?= ar
PIC ?= PIC
BUILD_TYPE ?= default
SHARED ?= 1
# Internal Variables
inst_path = $(exec_prefix)/$(libdir)
include_path = $(prefix)/$(includedir)
# BUILD_TYPE specific settings
ifeq ($(BUILD_TYPE), debug)
CXXFLAGS = $(cxxflags_debug)
libname := $(libname_debug)
else
CXXFLAGS ?= $(cxxflags_default)
endif
# SHARED specific settings
ifeq ($(SHARED), 1)
ifeq ($(OS), Darwin)
libname_shared = $(libname).$(suffix_shared_darwin)
else
libname_shared = $(libname).$(suffix_shared)
endif
libname_shared_major_version = $(libname_shared).$(major_version)
lib_target = $(libname_shared_major_version).$(minor_version)
objdir := $(objdir)_shared
CXXFLAGS := $(CXXFLAGS) $(cxxflags_shared)
else
lib_target = $(libname).$(suffix_static)
objdir := $(objdir)_static
endif
# Phony targets
.PHONY: all banner installdirs install install_headers clean uninstall \
uninstall_headers
# Targets
all: $(lib_target)
@echo "============================================================"
@echo "Done"
@echo "============================================================"
banner:
@echo "============================================================"
@echo "libwebsocketpp version: "$(major_version).$(minor_version) "target: "$(target) "OS: "$(OS)
@echo "============================================================"
installdirs: banner
mkdir -p $(objdir)
# Libraries
ifeq ($(SHARED),1)
$(lib_target): banner installdirs $(addprefix $(objdir)/, $(objects))
@echo "Link "
cd $(objdir) ; \
if test "$(OS)" = "Darwin" ; then \
$(CXX) -dynamiclib $(libs) -Wl,-dylib_install_name -Wl,$(libname_shared_major_version) -o $@ $(objects) ; \
else \
$(CXX) -shared $(libs) -Wl,-soname,$(libname_shared_major_version) -o $@ $(objects) ; \
fi ; \
mv -f $@ ../
@echo "Link: Done"
else
$(lib_target): banner installdirs $(addprefix $(objdir)/, $(objects))
@echo "Archive"
cd $(objdir) ; \
$(AR) -cvq $@ $(objects) ; \
mv -f $@ ../
@echo "Archive: Done"
endif
# Compile object files
$(objdir)/sha1.o: $(srcdir)/sha1/sha1.cpp
$(CXX) $< -o $@ $(CXXFLAGS)
$(objdir)/base64.o: $(srcdir)/base64/base64.cpp
$(CXX) $< -o $@ $(CXXFLAGS)
$(objdir)/hybi_header.o: $(srcdir)/processors/hybi_header.cpp
$(CXX) $< -o $@ $(CXXFLAGS)
$(objdir)/data.o: $(srcdir)/messages/data.cpp
$(CXX) $< -o $@ $(CXXFLAGS)
$(objdir)/md5.o: $(srcdir)/md5/md5.c
$(CXX) $< -o $@ $(CXXFLAGS)
$(objdir)/%.o: $(srcdir)/%.cpp
$(CXX) $< -o $@ $(CXXFLAGS)
ifeq ($(SHARED),1)
install: banner install_headers $(lib_target)
@echo "Install shared library"
mkdir -p $(inst_path)
cp -f ./$(lib_target) $(inst_path)
cd $(inst_path) ; \
ln -sf $(lib_target) $(libname_shared_major_version) ; \
ln -sf $(libname_shared_major_version) $(libname_shared)
if test "$(OS)" != "Darwin" ; then \
ldconfig ; \
fi
@echo "Install shared library: Done."
else
install: banner install_headers $(lib_target)
@echo "Install static library"
mkdir -p $(inst_path)
cp -f ./$(lib_target) $(inst_path)
@echo "Install static library: Done."
endif
install_headers: banner
@echo "Install header files"
mkdir -p $(include_path)/$(libname_hdr)
# cp -f ./*.hpp $(include_path)/$(libname_hdr)
cp -f ./$(srcdir)/*.hpp $(include_path)/$(libname_hdr)
mkdir -p $(include_path)/$(libname_hdr)/base64
cp -f ./$(srcdir)/base64/base64.h $(include_path)/$(libname_hdr)/base64
mkdir -p $(include_path)/$(libname_hdr)/sha1
cp -f ./$(srcdir)/sha1/sha1.h $(include_path)/$(libname_hdr)/sha1
mkdir -p $(include_path)/$(libname_hdr)/http
cp -f ./$(srcdir)/http/*.hpp $(include_path)/$(libname_hdr)/http
mkdir -p $(include_path)/$(libname_hdr)/logger
cp -f ./$(srcdir)/logger/*.hpp $(include_path)/$(libname_hdr)/logger
mkdir -p $(include_path)/$(libname_hdr)/md5
cp -f ./$(srcdir)/md5/md5.h $(include_path)/$(libname_hdr)/md5
cp -f ./$(srcdir)/md5/md5.hpp $(include_path)/$(libname_hdr)/md5
mkdir -p $(include_path)/$(libname_hdr)/messages
cp -f ./$(srcdir)/messages/*.hpp $(include_path)/$(libname_hdr)/messages
mkdir -p $(include_path)/$(libname_hdr)/processors
cp -f ./$(srcdir)/processors/*.hpp $(include_path)/$(libname_hdr)/processors
mkdir -p $(include_path)/$(libname_hdr)/rng
cp -f ./$(srcdir)/rng/*.hpp $(include_path)/$(libname_hdr)/rng
mkdir -p $(include_path)/$(libname_hdr)/roles
cp -f ./$(srcdir)/roles/*.hpp $(include_path)/$(libname_hdr)/roles
mkdir -p $(include_path)/$(libname_hdr)/sockets
cp -f ./$(srcdir)/sockets/*.hpp $(include_path)/$(libname_hdr)/sockets
mkdir -p $(include_path)/$(libname_hdr)/utf8_validator
cp -f ./$(srcdir)/utf8_validator/*.hpp $(include_path)/$(libname_hdr)/utf8_validator
chmod -R a+r $(include_path)/$(libname_hdr)
find $(include_path)/$(libname_hdr) -type d -exec chmod a+x {} \;
@echo "Install header files: Done."
clean: banner
@echo "Clean library and object folder"
rm -rf $(objdir)
rm -f $(lib_target)
@echo "Clean library and object folder: Done"
ifeq ($(SHARED),1)
uninstall: banner uninstall_headers
@echo "Uninstall shared library"
rm -f $(inst_path)/$(libname_shared)
rm -f $(inst_path)/$(libname_shared_major_version)
rm -f $(inst_path)/$(lib_target)
ldconfig
@echo "Uninstall shared library: Done"
else
uninstall: banner uninstall_headers
@echo "Uninstall static library"
rm -f $(inst_path)/$(lib_target)
@echo "Uninstall static library: Done"
endif
uninstall_headers: banner
@echo "Uninstall header files"
rm -rf $(include_path)/$(libname)
@echo "Uninstall header files: Done"
+157 -54
View File
@@ -1,15 +1,21 @@
#AddOption('--prefix',
# dest='prefix',
# nargs=1, type='string',
# action='store',
# metavar='DIR',
# help='installation prefix')
#env = Environment(PREFIX = GetOption('prefix'))
import os, sys
import os, sys, commands
env = Environment(ENV = os.environ)
# figure out a better way to configure this
if os.environ.has_key('CXX'):
env['CXX'] = os.environ['CXX']
if os.environ.has_key('DEBUG'):
env['DEBUG'] = os.environ['DEBUG']
if os.environ.has_key('CXXFLAGS'):
#env['CXXFLAGS'] = os.environ['CXXFLAGS']
env.Append(CXXFLAGS = os.environ['CXXFLAGS'])
if os.environ.has_key('LINKFLAGS'):
#env['LDFLAGS'] = os.environ['LDFLAGS']
env.Append(LINKFLAGS = os.environ['LINKFLAGS'])
## Boost
##
## Note: You need to either set BOOSTROOT to the root of a stock Boost distribution
@@ -17,30 +23,35 @@ env = Environment(ENV = os.environ)
## needs BOOST_INCLUDES=/usr/include/boost and BOOST_LIBS=/usr/lib like Ubuntu.
##
if os.environ.has_key('BOOSTROOT'):
env['BOOST_INCLUDES'] = os.environ['BOOSTROOT']
env['BOOST_LIBS'] = os.path.join(os.environ['BOOSTROOT'], 'stage', 'lib')
os.environ['BOOST_ROOT'] = os.environ['BOOSTROOT']
if os.environ.has_key('BOOST_ROOT'):
env['BOOST_INCLUDES'] = os.environ['BOOST_ROOT']
env['BOOST_LIBS'] = os.path.join(os.environ['BOOST_ROOT'], 'stage', 'lib')
elif os.environ.has_key('BOOST_INCLUDES') and os.environ.has_key('BOOST_LIBS'):
env['BOOST_INCLUDES'] = os.environ['BOOST_INCLUDES']
env['BOOST_LIBS'] = os.environ['BOOST_LIBS']
else:
raise SCons.Errors.UserError, "Neither BOOSTROOT, nor BOOST_INCLUDES + BOOST_LIBS was set!"
raise SCons.Errors.UserError, "Neither BOOST_ROOT, nor BOOST_INCLUDES + BOOST_LIBS was set!"
env.Append(CPPPATH = [env['BOOST_INCLUDES']])
env.Append(LIBPATH = [env['BOOST_LIBS']])
if os.environ.has_key('WSPP_ENABLE_CPP11'):
env['WSPP_ENABLE_CPP11'] = True
else:
env['WSPP_ENABLE_CPP11'] = False
boost_linkshared = False
def boostlibs(libnames):
if env['PLATFORM'].startswith('win'):
def boostlibs(libnames,localenv):
if localenv['PLATFORM'].startswith('win'):
# Win/VC++ supports autolinking. nothing to do.
# http://www.boost.org/doc/libs/1_49_0/more/getting_started/windows.html#auto-linking
return []
else:
libs = []
prefix = env['SHLIBPREFIX'] if boost_linkshared else env['LIBPREFIX']
suffix = env['SHLIBSUFFIX'] if boost_linkshared else env['LIBSUFFIX']
prefix = localenv['SHLIBPREFIX'] if boost_linkshared else localenv['LIBPREFIX']
suffix = localenv['SHLIBSUFFIX'] if boost_linkshared else localenv['LIBSUFFIX']
for name in libnames:
lib = File(os.path.join(env['BOOST_LIBS'], '%sboost_%s%s' % (prefix, name, suffix)))
lib = File(os.path.join(localenv['BOOST_LIBS'], '%sboost_%s%s' % (prefix, name, suffix)))
libs.append(lib)
return libs
@@ -50,84 +61,176 @@ if env['PLATFORM'].startswith('win'):
'WIN32_LEAN_AND_MEAN',
'_WIN32_WINNT=0x0600',
'_CONSOLE',
'_WEBSOCKETPP_CPP11_FRIEND_'])
'BOOST_TEST_DYN_LINK',
'NOMINMAX',
'_WEBSOCKETPP_CPP11_MEMORY_',
'_WEBSOCKETPP_CPP11_FUNCTIONAL_'])
arch_flags = '/arch:SSE2'
opt_flags = '/Ox /Oi /fp:fast'
warn_flags = '/W3 /wd4996 /wd4995 /wd4355'
env['CCFLAGS'] = '%s /EHsc /GR /GS- /MD /nologo %s %s' % (warn_flags, arch_flags, opt_flags)
env['LINKFLAGS'] = '/INCREMENTAL:NO /MANIFEST /NOLOGO /OPT:REF /OPT:ICF /MACHINE:X86'
elif env['PLATFORM'] == 'posix':
env.Append(CPPDEFINES = ['NDEBUG'])
env.Append(CCFLAGS = ['-Wall', '-fno-strict-aliasing'])
env.Append(CCFLAGS = ['-O3', '-fomit-frame-pointer', '-march=core2'])
if env.has_key('DEBUG'):
env.Append(CCFLAGS = ['-g', '-O0'])
else:
env.Append(CPPDEFINES = ['NDEBUG'])
env.Append(CCFLAGS = ['-O1', '-fomit-frame-pointer'])
env.Append(CCFLAGS = ['-Wall'])
#env['LINKFLAGS'] = ''
elif env['PLATFORM'] == 'darwin':
if env.has_key('DEBUG'):
env.Append(CCFLAGS = ['-g', '-O0'])
else:
env.Append(CPPDEFINES = ['NDEBUG'])
env.Append(CCFLAGS = ['-O1', '-fomit-frame-pointer'])
env.Append(CCFLAGS = ['-Wall'])
#env['LINKFLAGS'] = ''
if env['PLATFORM'].startswith('win'):
env['LIBPATH'] = env['BOOST_LIBS']
#env['LIBPATH'] = env['BOOST_LIBS']
pass
else:
env['LIBPATH'] = ['/usr/lib',
'/usr/local/lib',
env['BOOST_LIBS']]
'/usr/local/lib'] #, env['BOOST_LIBS']
# Compiler specific warning flags
if env['CXX'].startswith('g++'):
#env.Append(CCFLAGS = ['-Wconversion'])
env.Append(CCFLAGS = ['-Wcast-align'])
elif env['CXX'].startswith('clang++'):
#env.Append(CCFLAGS = ['-Wcast-align'])
#env.Append(CCFLAGS = ['-Wglobal-constructors'])
#env.Append(CCFLAGS = ['-Wconversion'])
env.Append(CCFLAGS = ['-Wno-padded'])
# Wpadded
# Wsign-conversion
platform_libs = []
tls_libs = []
tls_build = False
if env['PLATFORM'] == 'posix':
platform_libs = ['pthread', 'rt']
tls_libs = ['ssl', 'crypto']
tls_build = True
elif env['PLATFORM'] == 'darwin':
tls_libs = ['ssl', 'crypto']
tls_build = True
elif env['PLATFORM'].startswith('win'):
# Win/VC++ supports autolinking. nothing to do.
pass
## Append WebSocket++ path
env.Append(CPPPATH = ['#'])
##### Set up C++11 environment
polyfill_libs = [] # boost libraries used as drop in replacements for incomplete
# C++11 STL implementations
env_cpp11 = env.Clone ()
if env_cpp11['CXX'].startswith('g++'):
# TODO: check g++ version
GCC_VERSION = commands.getoutput(env_cpp11['CXX'] + ' -dumpversion')
if GCC_VERSION > "4.4.0":
print "C++11 build environment partially enabled"
env_cpp11.Append(WSPP_CPP11_ENABLED = "true",CXXFLAGS = ['-std=c++0x'],TOOLSET = ['g++'],CPPDEFINES = ['_WEBSOCKETPP_CPP11_STL_'])
else:
print "C++11 build environment is not supported on this version of G++"
elif env_cpp11['CXX'].startswith('clang++'):
print "C++11 build environment enabled"
env_cpp11.Append(WSPP_CPP11_ENABLED = "true",CXXFLAGS = ['-std=c++0x','-stdlib=libc++'],LINKFLAGS = ['-stdlib=libc++'],TOOLSET = ['clang++'],CPPDEFINES = ['_WEBSOCKETPP_CPP11_STL_'])
# look for optional second boostroot compiled with clang's libc++ STL library
# this prevents warnings/errors when linking code built with two different
# incompatible STL libraries.
if os.environ.has_key('BOOST_ROOT_CPP11'):
env_cpp11['BOOST_INCLUDES'] = os.environ['BOOST_ROOT_CPP11']
env_cpp11['BOOST_LIBS'] = os.path.join(os.environ['BOOST_ROOT_CPP11'], 'stage', 'lib')
elif os.environ.has_key('BOOST_INCLUDES_CPP11') and os.environ.has_key('BOOST_LIBS_CPP11'):
env_cpp11['BOOST_INCLUDES'] = os.environ['BOOST_INCLUDES_CPP11']
env_cpp11['BOOST_LIBS'] = os.environ['BOOST_LIBS_CPP11']
else:
print "C++11 build environment disabled"
# if the build system is known to allow the isystem modifier for library include
# values then use it for the boost libraries. Otherwise just add them to the
# regular CPPPATH values.
if env['CXX'].startswith('g++') or env['CXX'].startswith('clang'):
env.Append(CPPFLAGS = '-isystem ' + env['BOOST_INCLUDES'])
else:
env.Append(CPPPATH = [env['BOOST_INCLUDES']])
env.Append(LIBPATH = [env['BOOST_LIBS']])
# if the build system is known to allow the isystem modifier for library include
# values then use it for the boost libraries. Otherwise just add them to the
# regular CPPPATH values.
if env_cpp11['CXX'].startswith('g++') or env_cpp11['CXX'].startswith('clang'):
env_cpp11.Append(CPPFLAGS = '-isystem ' + env_cpp11['BOOST_INCLUDES'])
else:
env_cpp11.Append(CPPPATH = [env_cpp11['BOOST_INCLUDES']])
env_cpp11.Append(LIBPATH = [env_cpp11['BOOST_LIBS']])
releasedir = 'build/release/'
debugdir = 'build/debug/'
testdir = 'build/test/'
builddir = releasedir
Export('env')
Export('env_cpp11')
Export('platform_libs')
Export('boostlibs')
Export('tls_libs')
Export('polyfill_libs')
## END OF CONFIG !!
## TARGETS:
static_lib, shared_lib = SConscript('src/SConscript',
variant_dir = builddir + 'websocketpp',
duplicate = 0)
if not env['PLATFORM'].startswith('win'):
# Unit tests, add test folders with SConscript files to to_test list.
to_test = ['utility','http','logger','random','processors','message_buffer','extension','transport/iostream','transport/asio','roles','endpoint','connection','transport'] #,'http','processors','connection'
wslib = static_lib
Export('wslib')
for t in to_test:
new_tests = SConscript('#/test/'+t+'/SConscript',variant_dir = testdir + t, duplicate = 0)
for a in new_tests:
new_alias = Alias('test', [a], a.abspath)
AlwaysBuild(new_alias)
wsperf = SConscript('#/examples/wsperf/SConscript',
variant_dir = builddir + 'wsperf',
duplicate = 0)
# Main test application
#main = SConscript('#/examples/dev/SConscript',variant_dir = builddir + 'dev',duplicate = 0)
echo_server = SConscript('#/examples/echo_server/SConscript',
variant_dir = builddir + 'echo_server',
duplicate = 0)
# echo_server
echo_server = SConscript('#/examples/echo_server/SConscript',variant_dir = builddir + 'echo_server',duplicate = 0)
echo_server_tls = SConscript('#/examples/echo_server_tls/SConscript',
variant_dir = builddir + 'echo_server_tls',
duplicate = 0)
# echo_server_tls
if tls_build:
echo_server_tls = SConscript('#/examples/echo_server_tls/SConscript',variant_dir = builddir + 'echo_server_tls',duplicate = 0)
echo_client = SConscript('#/examples/echo_client/SConscript',
variant_dir = builddir + 'echo_client',
duplicate = 0)
# broadcast_server
broadcast_server = SConscript('#/examples/broadcast_server/SConscript',variant_dir = builddir + 'broadcast_server',duplicate = 0)
chat_client = SConscript('#/examples/chat_client/SConscript',
variant_dir = builddir + 'chat_client',
duplicate = 0)
# testee_server
testee_server = SConscript('#/examples/testee_server/SConscript',variant_dir = builddir + 'testee_server',duplicate = 0)
chat_server = SConscript('#/examples/chat_server/SConscript',
variant_dir = builddir + 'chat_server',
duplicate = 0)
# testee_client
testee_client = SConscript('#/examples/testee_client/SConscript',variant_dir = builddir + 'testee_client',duplicate = 0)
concurrent_server = SConscript('#/examples/concurrent_server/SConscript',
variant_dir = builddir + 'concurrent_server',
duplicate = 0)
# utility_client
utility_client = SConscript('#/examples/utility_client/SConscript',variant_dir = builddir + 'utility_client',duplicate = 0)
# subprotocol_server
subprotocol_server = SConscript('#/examples/subprotocol_server/SConscript',variant_dir = builddir + 'subprotocol_server',duplicate = 0)
if not env['PLATFORM'].startswith('win'):
# iostream_server
iostream_server = SConscript('#/examples/iostream_server/SConscript',variant_dir = builddir + 'iostream_server',duplicate = 0)
# telemetry_client
telemetry_client = SConscript('#/examples/telemetry_client/SConscript',variant_dir = builddir + 'telemetry_client',duplicate = 0)
# print_server
print_server = SConscript('#/examples/print_server/SConscript',variant_dir = builddir + 'print_server',duplicate = 0)
+75
View File
@@ -0,0 +1,75 @@
HEAD
0.3.0-alpha4 - 2013-10-11
- HTTP requests ending normally are no longer logged as errors. Thank you Banaan
for reporting. #294
- Eliminates spurious expired timers in certain error conditions. Thank you
Banaan for reporting. #295
- Consolidates all bundled library licenses into the COPYING file. #294
- Updates bundled sha1 library to one with a cleaner interface and more
straight-forward license. Thank you lotodore for reporting and Evgeni Golov
for reviewing. #294
- Re-introduces strands to asio transport, allowing `io_service` thread pools to
be used (with some limitations).
- Removes endpoint code that kept track of a connection list that was never used
anywhere. Removes a lock and reduces connection creation/deletion complexity
from O(log n) to O(1) in the number of connections.
- A number of internal changes to transport APIs
- Deprecates iostream transport `readsome` in favor of `read_some` which is more
consistent with the naming of the rest of the library.
- Adds preliminary signaling to iostream transport of eof and fatal transport
errors
- Updates transport code to use shared pointers rather than raw pointers to
prevent asio from retaining pointers to connection methods after the
connection goes out of scope. #293 Thank you otaras for reporting.
- Fixes an issue where custom headers couldn't be set for client connections
Thank you Jerry Win and Wolfram Schroers for reporting.
- Fixes a compile error on visual studio when using interrupts. Thank you Javier
Rey Neira for reporting this.
- Adds new 1012 and 1013 close codes per IANA registry
- Add `set_remote_endpoint` method to iostream transport.
- Add `set_secure` method to iostream transport.
- Fix typo in .gitattributes file. Thank you jstarasov for reporting this. #280
- Add missing locale include. Thank you Toninoso for reporting this. #281
- Refactors `asio_transport` endpoint and adds full documentation and exception
free varients of all methods.
- Removes `asio_transport` endpoint method cancel(). Use `stop_listen()` instead
- Wrap internal `io_service` `run_one()` method
- Suppress error when trying to shut down a connection that was already closed
0.3.0-alpha3 - 2013-07-16
- Minor refactor to bundled sha1 library
- HTTP header comparisons are now case insensitive. #220, #275
- Refactors URI to be exception free and not use regular expressions. This
eliminates the dependency on boost or C++11 regex libraries allowing native
C++11 usage on GCC 4.4 and higher and significantly reduces staticly built
binary sizes.
- Updates handling of Server and User-Agent headers to better handle custom
settings and allow suppression of these headers for security purposes.
- Fix issue where pong timeout handler always fired. Thank you Steven Klassen
for reporting this bug.
- Add ping and pong endpoint wrapper methods
- Add `get_request()` pass through method to connection to allow calling methods
specific to the HTTP policy in use.
- Fix issue compile error with `WEBSOCKETPP_STRICT_MASKING` enabled and another
issue where `WEBSOCKETPP_STRICT_MASKING` was not applied to incoming messages.
Thank you Petter Norby for reporting and testing these bugs. #264
- Add additional macro guards for use with boost_config. Thank you breyed
for testing and code. #261
0.3.0-alpha2 - 2013-06-09
- Fix a regression that caused servers being sent two close frames in a row
to end a connection uncleanly. #259
- Fix a regression that caused spurious frames following a legitimate close
frames to erroneously trigger handlers. #258
- Change default HTTP response error code when no http_handler is defined from
500/Internal Server Error to 426/Upgrade Required
- Remove timezone from logger timestamp to work around issues with the Windows
implimentation of strftime. Thank you breyed for testing and code. #257
- Switch integer literals to char literals to improve VCPP compatibility.
Thank you breyed for testing and code. #257
- Add MSVCPP warning suppression for the bundled SHA1 library. Thank you breyed
for testing and code. #257
0.3.0-alpha1 - 2013-06-09
- Initial Release
+78
View File
@@ -0,0 +1,78 @@
# Print build configuration
macro (print_used_build_config)
message ("\n=========== Used Build Configuration =============\n")
message (STATUS "ENABLE_CPP11 = " ${ENABLE_CPP11})
message (STATUS "BUILD_EXAMPLES = " ${BUILD_EXAMPLES})
message (STATUS "BUILD_TESTS = " ${BUILD_TESTS})
message ("")
message (STATUS "WEBSOCKETPP_ROOT = " ${WEBSOCKETPP_ROOT})
message (STATUS "WEBSOCKETPP_BIN = " ${WEBSOCKETPP_BIN})
message (STATUS "WEBSOCKETPP_LIB = " ${WEBSOCKETPP_LIB})
message (STATUS "Install prefix = " ${CMAKE_INSTALL_PREFIX})
message ("")
message (STATUS "WEBSOCKETPP_BOOST_LIBS = ${WEBSOCKETPP_BOOST_LIBS}")
message (STATUS "WEBSOCKETPP_PLATFORM_LIBS = ${WEBSOCKETPP_PLATFORM_LIBS}")
message (STATUS "WEBSOCKETPP_PLATFORM_TSL_LIBS = ${WEBSOCKETPP_PLATFORM_TSL_LIBS}")
message ("")
endmacro ()
# Adds the given folder_name into the source files of the current project.
# Use this macro when your module contains .cpp and .h files in several subdirectories.
# Your sources variable needs to be WSPP_SOURCE_FILES and headers variable WSPP_HEADER_FILES.
macro(add_source_folder folder_name)
file(GLOB H_FILES_IN_FOLDER_${folder_name} ${folder_name}/*.hpp ${folder_name}/*.h)
file(GLOB CPP_FILES_IN_FOLDER_${folder_name} ${folder_name}/*.cpp ${folder_name}/*.c)
source_group("Header Files\\${folder_name}" FILES ${H_FILES_IN_FOLDER_${folder_name}})
source_group("Source Files\\${folder_name}" FILES ${CPP_FILES_IN_FOLDER_${folder_name}})
set(WSPP_HEADER_FILES ${WSPP_HEADER_FILES} ${H_FILES_IN_FOLDER_${folder_name}})
set(WSPP_SOURCE_FILES ${WSPP_SOURCE_FILES} ${CPP_FILES_IN_FOLDER_${folder_name}})
endmacro()
# Initialize target.
macro (init_target NAME)
set (TARGET_NAME ${NAME})
message ("** " ${TARGET_NAME})
# Include our own module path. This makes #include "x.h"
# work in project subfolders to include the main directory headers.
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
endmacro ()
# Build executable for executables
macro (build_executable TARGET_NAME)
set (TARGET_LIB_TYPE "EXECUTABLE")
message (STATUS "-- Build Type:")
message (STATUS " " ${TARGET_LIB_TYPE})
add_executable (${TARGET_NAME} ${ARGN})
include_directories (${WEBSOCKETPP_ROOT} ${WEBSOCKETPP_INCLUDE})
set_target_properties (${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${WEBSOCKETPP_BIN})
set_target_properties (${TARGET_NAME} PROPERTIES DEBUG_POSTFIX d)
endmacro ()
# Finalize target for all types
macro (final_target)
if ("${TARGET_LIB_TYPE}" STREQUAL "EXECUTABLE")
install (TARGETS ${TARGET_NAME}
RUNTIME DESTINATION "bin"
CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
endif ()
# install headers, directly from current source dir and look for subfolders with headers
file (GLOB_RECURSE TARGET_INSTALL_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.hpp)
foreach (hppfile ${TARGET_INSTALL_HEADERS})
get_filename_component (currdir ${hppfile} PATH)
install (FILES ${hppfile} DESTINATION "include/${TARGET_NAME}/${currdir}")
endforeach()
endmacro ()
macro (link_boost)
target_link_libraries (${TARGET_NAME} ${Boost_LIBRARIES})
endmacro ()
macro (link_openssl)
target_link_libraries (${TARGET_NAME} ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
endmacro ()
-17
View File
@@ -1,17 +0,0 @@
Using this file to track boost dependency testing.
Mac OS X 10.7.2, XCode 4.2.1, boost built using default darwin 4.2.1 toolset, example compiled with g++ 4.2.x
SSL echo server
boost 1.48.0 - OK
boost 1.47.0 - OK
boost 1.46.1 - significant SSL context constructor change. SSL support might require 1.47
plain echo server
boost 1.48.0 - OK
boost 1.47.0 - OK
boost 1.46.1 - OK
boost 1.45.0 - ?
boost 1.44.0 - OK
boost 1.43.0 - OK
boost 1.42.0 - Does not build on Mac OS X 10.7
View File
+52
View File
@@ -0,0 +1,52 @@
#include <set>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
typedef websocketpp::server<websocketpp::config::asio> server;
using websocketpp::connection_hdl;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
class broadcast_server {
public:
broadcast_server() {
m_server.init_asio();
m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1));
m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1));
m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2));
}
void on_open(connection_hdl hdl) {
m_connections.insert(hdl);
}
void on_close(connection_hdl hdl) {
m_connections.erase(hdl);
}
void on_message(connection_hdl hdl, server::message_ptr msg) {
for (auto it : m_connections) {
m_server.send(it,msg);
}
}
void run(uint16_t port) {
m_server.listen(port);
m_server.start_accept();
m_server.run();
}
private:
typedef std::set<connection_hdl,std::owner_less<connection_hdl>> con_list;
server m_server;
con_list m_connections;
};
int main() {
broadcast_server server;
server.run(9002);
}
+65
View File
@@ -0,0 +1,65 @@
#include <functional>
#include <mutex>
#include <set>
#include <thread>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
typedef websocketpp::server<websocketpp::config::asio> server;
using websocketpp::connection_hdl;
class count_server {
public:
count_server() : m_count(0) {
m_server.init_asio();
m_server.set_open_handler(bind(&count_server::on_open,this,_1));
m_server.set_close_handler(bind(&count_server::on_close,this,_1));
}
void on_open(connection_hdl hdl) {
std::lock_guard<std::mutex> lock(m_mutex);
m_connections.insert(hdl);
}
void on_close(connection_hdl hdl) {
std::lock_guard<std::mutex> lock(m_mutex);
m_connections.erase(hdl);
}
void count() {
while (1) {
sleep(1);
m_count++;
std::stringstream ss;
ss << m_count;
std::lock_guard<std::mutex> lock(m_mutex);
for (auto it : m_connections) {
m_server.send(it,ss.str(),websocketpp::frame::opcode::text);
}
}
}
void run(uint16_t port) {
m_server.listen(port);
m_server.start_accept();
m_server.run();
}
private:
typedef std::set<connection_hdl,std::owner_less<connection_hdl>> con_list;
int m_count;
server m_server;
con_list m_connections;
std::mutex m_mutex;
};
int main() {
count_server server;
std::thread t(std::bind(&count_server::count,&server));
server.run(9002);
}
+6
View File
@@ -0,0 +1,6 @@
file (GLOB SDIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach (SUBDIR ${SDIRS})
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/CMakeLists.txt")
add_subdirectory (${SUBDIR})
endif ()
endforeach ()
-18
View File
@@ -1,18 +0,0 @@
DIRS=broadcast_server_tls chat_client chat_server concurrent_server echo_client echo_server echo_server_tls fuzzing_client fuzzing_server_tls stress_client wsperf
.PHONY:
all: build
.PHONY:
build: $(DIRS:%=%.build)
.PHONY:
clean: $(DIRS:%=%.clean)
.PHONY:
%.build:
$(MAKE) -C $(@:%.build=%)
.PHONY:
%.clean:
$(MAKE) -C $(@:%.clean=%) clean
@@ -0,0 +1,88 @@
#include <iostream>
#include <map>
#include <exception>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
typedef websocketpp::server<websocketpp::config::asio> server;
using websocketpp::connection_hdl;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
struct connection_data {
int sessionid;
std::string name;
};
class print_server {
public:
print_server() : m_next_sessionid(1) {
m_server.init_asio();
m_server.set_open_handler(bind(&print_server::on_open,this,::_1));
m_server.set_close_handler(bind(&print_server::on_close,this,::_1));
m_server.set_message_handler(bind(&print_server::on_message,this,::_1,::_2));
}
void on_open(connection_hdl hdl) {
connection_data data;
data.sessionid = m_next_sessionid++;
data.name = "";
m_connections[hdl] = data;
}
void on_close(connection_hdl hdl) {
connection_data& data = get_data_from_hdl(hdl);
std::cout << "Closing connection " << data.name
<< " with sessionid " << data.sessionid << std::endl;
m_connections.erase(hdl);
}
void on_message(connection_hdl hdl, server::message_ptr msg) {
connection_data& data = get_data_from_hdl(hdl);
if (data.name == "") {
data.name = msg->get_payload();
std::cout << "Setting name of connection with sessionid "
<< data.sessionid << " to " << data.name << std::endl;
} else {
std::cout << "Got a message from connection " << data.name
<< " with sessionid " << data.sessionid << std::endl;
}
}
connection_data& get_data_from_hdl(connection_hdl hdl) {
auto it = m_connections.find(hdl);
if (it == m_connections.end()) {
// this connection is not in the list. This really shouldn't happen
// and probably means something else is wrong.
throw std::invalid_argument("No data available for session");
}
return it->second;
}
void run(uint16_t port) {
m_server.listen(port);
m_server.start_accept();
m_server.run();
}
private:
typedef std::map<connection_hdl,connection_data,std::owner_less<connection_hdl>> con_list;
int m_next_sessionid;
server m_server;
con_list m_connections;
};
int main() {
print_server server;
server.run(9002);
}
+23
View File
@@ -0,0 +1,23 @@
## Broadcast Server example
##
Import('env')
Import('env_cpp11')
Import('boostlibs')
Import('platform_libs')
Import('polyfill_libs')
env = env.Clone ()
env_cpp11 = env_cpp11.Clone ()
prgs = []
# if a C++11 environment is available build using that, otherwise use boost
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
ALL_LIBS = boostlibs(['system'],env_cpp11) + [platform_libs] + [polyfill_libs]
prgs += env_cpp11.Program('broadcast_server', ["broadcast_server.cpp"], LIBS = ALL_LIBS)
else:
ALL_LIBS = boostlibs(['system','thread'],env) + [platform_libs] + [polyfill_libs]
prgs += env.Program('broadcast_server', ["broadcast_server.cpp"], LIBS = ALL_LIBS)
Return('prgs')
@@ -0,0 +1,158 @@
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include <iostream>
/*#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>*/
#include <websocketpp/common/thread.hpp>
typedef websocketpp::server<websocketpp::config::asio> server;
using websocketpp::connection_hdl;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
using websocketpp::lib::thread;
using websocketpp::lib::mutex;
using websocketpp::lib::unique_lock;
using websocketpp::lib::condition_variable;
/* on_open insert connection_hdl into channel
* on_close remove connection_hdl from channel
* on_message queue send to all channels
*/
enum action_type {
SUBSCRIBE,
UNSUBSCRIBE,
MESSAGE
};
struct action {
action(action_type t, connection_hdl h) : type(t), hdl(h) {}
action(action_type t, server::message_ptr m) : type(t), msg(m) {}
action_type type;
websocketpp::connection_hdl hdl;
server::message_ptr msg;
};
class broadcast_server {
public:
broadcast_server() {
// Initialize Asio Transport
m_server.init_asio();
// Register handler callbacks
m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1));
m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1));
m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2));
}
void run(uint16_t port) {
// listen on specified port
m_server.listen(port);
// Start the server accept loop
m_server.start_accept();
// Start the ASIO io_service run loop
try {
m_server.run();
} catch (const std::exception & e) {
std::cout << e.what() << std::endl;
} catch (websocketpp::lib::error_code e) {
std::cout << e.message() << std::endl;
} catch (...) {
std::cout << "other exception" << std::endl;
}
}
void on_open(connection_hdl hdl) {
unique_lock<mutex> lock(m_action_lock);
//std::cout << "on_open" << std::endl;
m_actions.push(action(SUBSCRIBE,hdl));
lock.unlock();
m_action_cond.notify_one();
}
void on_close(connection_hdl hdl) {
unique_lock<mutex> lock(m_action_lock);
//std::cout << "on_close" << std::endl;
m_actions.push(action(UNSUBSCRIBE,hdl));
lock.unlock();
m_action_cond.notify_one();
}
void on_message(connection_hdl hdl, server::message_ptr msg) {
// queue message up for sending by processing thread
unique_lock<mutex> lock(m_action_lock);
//std::cout << "on_message" << std::endl;
m_actions.push(action(MESSAGE,msg));
lock.unlock();
m_action_cond.notify_one();
}
void process_messages() {
while(1) {
unique_lock<mutex> lock(m_action_lock);
while(m_actions.empty()) {
m_action_cond.wait(lock);
}
action a = m_actions.front();
m_actions.pop();
lock.unlock();
if (a.type == SUBSCRIBE) {
unique_lock<mutex> lock(m_connection_lock);
m_connections.insert(a.hdl);
} else if (a.type == UNSUBSCRIBE) {
unique_lock<mutex> lock(m_connection_lock);
m_connections.erase(a.hdl);
} else if (a.type == MESSAGE) {
unique_lock<mutex> lock(m_connection_lock);
con_list::iterator it;
for (it = m_connections.begin(); it != m_connections.end(); ++it) {
m_server.send(*it,a.msg);
}
} else {
// undefined.
}
}
}
private:
typedef std::set<connection_hdl,std::owner_less<connection_hdl>> con_list;
server m_server;
con_list m_connections;
std::queue<action> m_actions;
mutex m_action_lock;
mutex m_connection_lock;
condition_variable m_action_cond;
};
int main() {
try {
broadcast_server server;
// Start a thread to run the processing loop
thread t(bind(&broadcast_server::process_messages,&server));
// Run the asio loop with the main thread
server.run(9002);
t.join();
} catch (std::exception & e) {
std::cout << e.what() << std::endl;
}
}
-17
View File
@@ -1,17 +0,0 @@
BOOST_LIBS=boost_system boost_date_time boost_regex
include ../common.mk
LDFLAGS := $(LDFLAGS) -lcrypto -lssl -lpthread
broadcast_server: broadcast_server_tls.o
$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS)
%.o: %.cpp
$(CXX) -c $(CFLAGS) -o $@ $^
# cleanup by removing generated files
#
.PHONY: clean
clean:
rm -f *.o broadcast_server
@@ -1,348 +0,0 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WebSocket++ Broadcast Admin</title>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="flot/jquery.js"></script>
<script language="javascript" type="text/javascript" src="flot/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="md5.js"></script>
</head>
<body>
<script type="text/javascript">
var options = {"console_enabled": true};
var ws_client;
var ws_admin;
var url;
var data2 = [], total_points = 240;
var stale_data = null;
var message_history = [];
var ack_history = [];
var client_history = [];
var msgs = {};
function connect() {
url = document.getElementById("server_url").value;
if ("WebSocket" in window) {
ws_client = new WebSocket(url);
ws_admin = new WebSocket(url+"/admin");
} else if ("MozWebSocket" in window) {
ws_client = new MozWebSocket(url);
ws_admin = new MozWebSocket(url+"/admin");
} else {
$("#messages").innerHTML += "This Browser does not support WebSockets<br />";
return;
}
ws_client.onopen = function(e) {
$("#messages").append("Client: A client connection to "+url+" has been opened.<br />");
$("#server_url").disabled = true;
$("#toggle_connect").html("Disconnect");
};
ws_admin.onopen = function(e) {
$("#messages").append("Client: An admin connection to "+url+"/admin has been opened.<br />");
$("#server_url").disabled = true;
$("#toggle_connect").html("Disconnect");
};
ws_client.onerror = function(e) {
$("#messages").append("Client: An error occured on the client channel, see console log for more details.<br />");
console.log(e);
};
ws_admin.onerror = function(e) {
$("#messages").append("Client: An error occured on the admin channel, see console log for more details.<br />");
console.log(e);
};
ws_client.onclose = function(e) {
$("#messages").append("Client: The client connection to "+url+" was closed.<br />");
clear_hud();
};
ws_admin.onclose = function(e) {
$("#messages").append("Client: The admin connection to "+url+"/admin was closed.<br />");
clear_hud();
};
ws_client.onmessage = function(e) {
if (options.console_enabled) {
if (e.data.length <= 126) {
$("#messages").append("Broadcasted Message: "+e.data+"<br />");
} else {
$("#messages").append("Broadcasted Message: [message of size: "+e.data.length+"]<br />");
}
}
ws_client.send("ack:"+hex_md5(e.data)+"=1;");
}
ws_admin.onmessage = function(e) {
foo = JSON.parse(e.data);
if (foo.type == "message") {
if (options.console_enabled) {
document.getElementById("messages").innerHTML += "Broadcasted Message: "+foo.value+"<br />";
}
} else if (foo.type == "error") {
if (options.console_enabled) {
document.getElementById("messages").innerHTML += "Command Error: "+foo.value+"<br />";
}
} else if (foo.type == "con") {
document.getElementById("connected_clients").innerHTML = foo.value;
} else if (foo.type == "stats") {
var msg_delta = 0;
var data_delta = 0;
for (var i in foo.messages) {
var hash = foo.messages[i].hash;
if (hash in msgs) {
msg_delta += foo.messages[i].acked-msgs[hash]["acked"];
data_delta += msg_delta*foo.messages[i].size;
msgs[hash]["sent"] = foo.messages[i].sent;
msgs[hash]["acked"] = foo.messages[i].acked;
msgs[hash]["time"] = foo.messages[i].time;
} else {
msgs[hash] = {"id":foo.messages[i].id,
"sent":foo.messages[i].sent,
"acked":foo.messages[i].acked,
"size":foo.messages[i].size,
"time":foo.messages[i].time}
msg_delta += foo.messages[i].acked;
data_delta += msg_delta*foo.messages[i].size;
}
}
var o = "";
for (i in msgs) {
o += "<tr><td>"+msgs[i].id+"</td><td>"+msgs[i].sent+"</td><td>"+msgs[i].acked+"</td><td>"+format_data(msgs[i].size)+"</td><td>"+msgs[i].time+"</td><td>"+(msgs[i].time != 0 ? (msgs[i].acked/(msgs[i].time/1000.0)).toFixed(0)+"/s" : "")+"</td><td>"+(msgs[i].time != 0 ? format_data(msgs[i].acked*msgs[i].size/(msgs[i].time/1000.0))+"/s" : "")+"</td></tr>";
}
$("#sent_messages").html(o);
/*document.getElementById("messages_per_sec").innerHTML = foo.messages+"/s";
document.getElementById("bytes_per_sec").innerHTML = format_data(foo.bytes)+"/s";
document.getElementById("messages_sent").innerHTML = foo.messages_sent;
document.getElementById("messages_acked").innerHTML = foo.messages_acked;
document.getElementById("bytes_sent").innerHTML = format_data(foo.bytes_sent);*/
document.getElementById("admin_connections").innerHTML = foo.admin_connections;
document.getElementById("connected_clients").innerHTML = foo.connections;
client_history.push([foo.timestamp,foo.connections]);
if (client_history.length > total_points) {
client_history = client_history.slice(client_history.length-total_points);
}
data2.push([foo.timestamp,data_delta]);
if (data2.length > total_points) {
data2 = data2.slice(data2.length-total_points);
}
message_history.push([foo.timestamp,msg_delta]);
if (message_history.length > total_points) {
message_history = message_history.slice(message_history.length-total_points);
}
} else {
document.getElementById("messages").innerHTML += "Unrecognized Server Command.<br />";
}
}
}
function clear_hud() {
document.getElementById("server_url").disabled = false;
document.getElementById("toggle_connect").innerHTML = "Connect";
document.getElementById("connected_clients").innerHTML = "N/A";
document.getElementById("admin_connections").innerHTML = "N/A";
document.getElementById("messages_per_sec").innerHTML = "N/A";
document.getElementById("bytes_per_sec").innerHTML = "N/A";
document.getElementById("messages_sent").innerHTML = "N/A";
document.getElementById("bytes_sent").innerHTML = "N/A";
document.getElementById("messages_acked").innerHTML = "N/A";
}
function disconnect() {
ws_client.close();
ws_admin.close();
}
function toggle_connect() {
if (document.getElementById("server_url").disabled === false) {
connect();
} else {
disconnect();
}
}
function broadcast() {
if (ws_client === undefined || ws_client.readyState != 1) {
$("#messages").append("Client: Client websocket is not avaliable for writing<br />");
return;
}
ws_client.send(document.getElementById("msg").value);
document.getElementById("msg").value = "";
}
function send_command(command,args) {
var cmd = command+":";
ws_admin.send(cmd);
}
function send_test_message(size,type) {
ws_client.send((new Array(size+1)).join("*"));
}
function format_data(val) {
if (val > 1000000)
return (val / 1000000).toFixed(2) + " MB";
else if (val > 1000)
return (val / 1000).toFixed(2) + " kB";
else
return val.toFixed(0) + " B";
}
$(function () {
// setup control widget
var updateInterval = 500;
$("#updateInterval").val(updateInterval).change(function () {
var v = $(this).val();
if (v && !isNaN(+v)) {
updateInterval = +v;
if (updateInterval < 1)
updateInterval = 1;
if (updateInterval > 2000)
updateInterval = 2000;
$(this).val("" + updateInterval);
}
});
function suffixFormatter(val, axis) {
if (val > 1000000)
return (val / 1000000).toFixed(axis.tickDecimals) + " MB";
else if (val > 1000)
return (val / 1000).toFixed(axis.tickDecimals) + " kB";
else
return val.toFixed(axis.tickDecimals) + " B";
}
// setup plot
var options = {
series: { shadowSize: 0 }, // drawing is faster without shadows
xaxis: { mode: "time" }
};
var options_data = {
series: { shadowSize: 0 }, // drawing is faster without shadows
yaxis: { tickFormatter: suffixFormatter},
xaxis: { mode: "time" }
};
var plot_clients = $.plot($("#client_history"), [ client_history ], options);
var plot_messages = $.plot($("#message_history"), [ message_history ], options);
var plot_bytes = $.plot($("#bytes_history"), [ data2 ], options_data);
function update() {
plot_clients.setData([ client_history ]);
plot_clients.setupGrid();
plot_clients.draw();
plot_messages.setData([ message_history ]);
plot_messages.setupGrid();
plot_messages.draw();
plot_bytes.setData([ data2 ]);
plot_bytes.setupGrid();
plot_bytes.draw();
setTimeout(update, updateInterval);
}
update();
});
</script>
<style>
body,html {
margin: 0px;
padding: 0px;
height:100%;
font-family: sans-serif;
font-size: 12px;
}
#controls {
float:right;
background-color: #333;
color: #fff;
padding: 5px;
}
#controls h2 {
font-family: sans-serif;
font-size: 16px;
margin-bottom: 4px;
}
#controls h3 {
font-family: sans-serif;
font-size: 14px;
margin-bottom: 4px;
}
#messages {
height: 100%;
overflow: scroll;
}
</style>
<div id="controls">
<div id="server">
<input type="text" name="server_url" id="server_url" value="ws://localhost:9002" />
<button id="toggle_connect" onclick="toggle_connect();">Connect</button>
</div>
<div id="message_input"><input type="text" name="msg" id="msg" value="Hello World!" />
<button onclick="broadcast();">Broadcast</button></div>
<h2>Stats</h2>
<h3>Server</h3>
<div>Connected Clients: <span id="connected_clients">N/A</span><br /></div>
<div>Admin Clients: <span id="admin_connections">N/A</span><br /></div>
<div id="client_history" style="width:320px;height:200px;"></div>
<h3>Messages</h3>
<div>Messages Sent: <span id="messages_sent">N/A</span><br /></div>
<div>Messages Acked: <span id="messages_acked">N/A</span><br /></div>
<div>Messages Rate: <span id="messages_per_sec">N/A</span><br /></div>
<div id="message_history" style="width:320px;height:200px;"></div>
<div>
<table>
<thead>
<tr><th>id</th><th>sent</th><th>acked</th><th>size</th><th>time</th><th>message rate</th><th>data rate</th></tr>
</thead>
<tbody id="sent_messages">
</tbody>
</table>
</div>
<h3>Data</h3>
<div>Bytes Sent: <span id="bytes_sent">N/A</span><br /></div>
<div>Data Rate: <span id="bytes_per_sec">N/A</span><br /></div>
<div id="bytes_history" style="width:320px;height:200px;"></div>
</div>
<div id="messages"></div>
</body>
</html>
@@ -1,200 +0,0 @@
/*
* Copyright (c) 2011, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WEBSOCKETPP_BROADCAST_ADMIN_HANDLER_HPP
#define WEBSOCKETPP_BROADCAST_ADMIN_HANDLER_HPP
#include "../../src/sockets/tls.hpp"
#include "../../src/websocketpp.hpp"
#include "broadcast_handler.hpp"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <map>
#include <set>
#include <sstream>
namespace websocketpp {
namespace broadcast {
template <typename endpoint_type>
class admin_handler : public endpoint_type::handler {
public:
typedef admin_handler<endpoint_type> type;
typedef boost::shared_ptr<type> ptr;
typedef typename endpoint_type::handler_ptr handler_ptr;
typedef typename handler<endpoint_type>::ptr broadcast_handler_ptr;
typedef typename endpoint_type::connection_ptr connection_ptr;
admin_handler()
: m_epoch(boost::posix_time::time_from_string("1970-01-01 00:00:00.000"))
{}
void on_open(connection_ptr connection) {
if (!m_timer) {
m_timer.reset(new boost::asio::deadline_timer(connection->get_io_service(),boost::posix_time::seconds(0)));
m_timer->expires_from_now(boost::posix_time::milliseconds(250));
m_timer->async_wait(boost::bind(&type::on_timer,this,boost::asio::placeholders::error));
}
m_connections.insert(connection);
}
// this dummy tls init function will cause all TLS connections to fail.
// TLS handling for broadcast::handler is usually done by a lobby handler.
// If you want to use the broadcast handler alone with TLS then return the
// appropriately filled in context here.
boost::shared_ptr<boost::asio::ssl::context> on_tls_init() {
return boost::shared_ptr<boost::asio::ssl::context>();
}
void on_load(connection_ptr connection, handler_ptr old_handler) {
this->on_open(connection);
m_lobby = old_handler;
}
void track(broadcast_handler_ptr target) {
m_broadcast_handler = target;
}
void on_close(connection_ptr connection) {
m_connections.erase(connection);
}
void on_message(connection_ptr connection,websocketpp::message::data_ptr msg) {
typename std::set<connection_ptr>::iterator it;
wscmd::cmd command = wscmd::parse(msg->get_payload());
if (command.command == "close") {
handle_close(connection,command);
} else {
command_error(connection,"Invalid Command");
}
}
void command_error(connection_ptr connection,const std::string msg) {
std::string str = "{\"type\":\"error\",\"value\":\""+msg+"\"}";
connection->send(str);
}
// close: - close this connection
// close:all; close all connections
void handle_close(connection_ptr connection,const wscmd::cmd& command) {
if (!m_broadcast_handler) {
// Unable to connect to local broadcast handler
return;
}
m_broadcast_handler->close_connection(connection_ptr());
}
long get_ms(boost::posix_time::ptime s) const {
boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_period period(s,now);
return period.length().total_milliseconds();
}
void on_timer(const boost::system::error_code& error) {
if (!m_broadcast_handler) {
// Unable to connect to local broadcast handler
return;
}
if (m_connections.size() > 0) {
long milli_seconds = get_ms(m_epoch);
std::stringstream update;
update << "{\"type\":\"stats\""
<< ",\"timestamp\":" << milli_seconds
<< ",\"connections\":" << m_broadcast_handler->get_connection_count()
<< ",\"admin_connections\":" << m_connections.size()
<< ",\"messages\":[";
const msg_map& m = m_broadcast_handler->get_message_stats();
msg_map::const_iterator msg_it;
msg_map::const_iterator last = m.end();
if (m.size() > 0) {
last--;
}
for (msg_it = m.begin(); msg_it != m.end(); msg_it++) {
update << "{\"id\":" << (*msg_it).second.id
<< ",\"hash\":\"" << (*msg_it).second.hash << "\""
<< ",\"sent\":" << (*msg_it).second.sent
<< ",\"acked\":" << (*msg_it).second.acked
<< ",\"size\":" << (*msg_it).second.size
<< ",\"time\":" << (*msg_it).second.time
<< "}" << (msg_it == last ? "" : ",");
}
update << "]}";
m_broadcast_handler->clear_message_stats();
typename std::set<connection_ptr>::iterator it;
websocketpp::message::data_ptr msg = (*m_connections.begin())->get_data_message();
if (msg) {
msg->reset(frame::opcode::TEXT);
msg->set_payload(update.str());
for (it = m_connections.begin(); it != m_connections.end(); it++) {
(*it)->send(msg);
}
} else {
// error no avaliable message buffers
}
}
m_timer->expires_from_now(boost::posix_time::milliseconds(250));
m_timer->async_wait(
boost::bind(
&type::on_timer,
this,
boost::asio::placeholders::error
)
);
}
private:
handler_ptr m_lobby;
broadcast_handler_ptr m_broadcast_handler;
std::set<connection_ptr> m_connections;
boost::posix_time::ptime m_epoch;
boost::shared_ptr<boost::asio::deadline_timer> m_timer;
};
} // namespace broadcast
} // namespace websocketpp
#endif // WEBSOCKETPP_BROADCAST_ADMIN_HANDLER_HPP
@@ -1,202 +0,0 @@
/*
* Copyright (c) 2011, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WEBSOCKETPP_BROADCAST_HANDLER_HPP
#define WEBSOCKETPP_BROADCAST_HANDLER_HPP
#include "wscmd.hpp"
#include "../../src/sockets/tls.hpp"
#include "../../src/websocketpp.hpp"
#include "../../src/md5/md5.hpp"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <map>
#include <set>
namespace websocketpp {
namespace broadcast {
/// this structure is used to keep track of message statistics
struct msg {
int id;
size_t sent;
size_t acked;
size_t size;
uint64_t time;
std::string hash;
boost::posix_time::ptime time_sent;
};
typedef std::map<std::string,struct msg> msg_map;
template <typename endpoint_type>
class handler : public endpoint_type::handler {
public:
typedef handler<endpoint_type> type;
typedef boost::shared_ptr<type> ptr;
typedef typename endpoint_type::handler_ptr handler_ptr;
typedef typename endpoint_type::connection_ptr connection_ptr;
handler() : m_nextid(0) {}
void on_open(connection_ptr connection) {
m_connections.insert(connection);
}
// this dummy tls init function will cause all TLS connections to fail.
// TLS handling for broadcast::handler is usually done by a lobby handler.
// If you want to use the broadcast handler alone with TLS then return the
// appropriately filled in context here.
boost::shared_ptr<boost::asio::ssl::context> on_tls_init() {
return boost::shared_ptr<boost::asio::ssl::context>();
}
void on_load(connection_ptr connection, handler_ptr old_handler) {
this->on_open(connection);
m_lobby = old_handler;
}
void on_close(connection_ptr connection) {
m_connections.erase(connection);
}
void on_message(connection_ptr connection,message::data_ptr msg) {
wscmd::cmd command = wscmd::parse(msg->get_payload());
std::cout << "msg: " << msg->get_payload() << std::endl;
if (command.command == "ack") {
handle_ack(connection,command);
} else {
broadcast_message(msg);
}
}
void command_error(connection_ptr connection,const std::string msg) {
connection->send("{\"type\":\"error\",\"value\":\""+msg+"\"}");
}
// ack:e3458d0aceff8b70a3e5c0afec632881=38;e3458d0aceff8b70a3e5c0afec632881=42;
void handle_ack(connection_ptr connection,const wscmd::cmd& command) {
wscmd::arg_list::const_iterator arg_it;
size_t count;
for (arg_it = command.args.begin(); arg_it != command.args.end(); arg_it++) {
if (m_msgs.find(arg_it->first) == m_msgs.end()) {
std::cout << "ack for message we didn't send" << std::endl;
continue;
}
count = atol(arg_it->second.c_str());
if (count == 0) {
continue;
}
struct msg& m(m_msgs[arg_it->first]);
m.acked += count;
if (m.acked == m.sent) {
m.time = get_ms(m.time_sent);
}
}
}
// close: - close this connection
// close:all; close all connections
void close_connection(connection_ptr connection) {
if (connection){
connection->close(close::status::NORMAL);
} else {
typename std::set<connection_ptr>::iterator it;
for (it = m_connections.begin(); it != m_connections.end(); it++) {
(*it)->close(close::status::NORMAL);
}
}
}
void broadcast_message(message::data_ptr msg) {
std::string hash = md5_hash_hex(msg->get_payload());
struct msg& new_msg(m_msgs[hash]);
new_msg.id = m_nextid++;
new_msg.hash = hash;
new_msg.size = msg->get_payload().size();
new_msg.time_sent = boost::posix_time::microsec_clock::local_time();
new_msg.time = 0;
typename std::set<connection_ptr>::iterator it;
// broadcast to clients
for (it = m_connections.begin(); it != m_connections.end(); it++) {
//(*it)->send(msg->get_payload(),(msg->get_opcode() == frame::opcode::BINARY));
for (int i = 0; i < 10; i++) {
(*it)->send(msg);
}
}
new_msg.sent = m_connections.size()*10;
new_msg.acked = 0;
}
long get_ms(boost::posix_time::ptime s) const {
boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_period period(s,now);
return period.length().total_milliseconds();
}
// hooks for admin console
size_t get_connection_count() const {
return m_connections.size();
}
const msg_map& get_message_stats() const {
return m_msgs;
}
void clear_message_stats() {
m_msgs.empty();
}
private:
handler_ptr m_lobby;
int m_nextid;
msg_map m_msgs;
std::set<connection_ptr> m_connections;
};
} // namespace broadcast
} // namespace websocketpp
#endif // WEBSOCKETPP_BROADCAST_HANDLER_HPP
@@ -1,141 +0,0 @@
/*
* Copyright (c) 2011, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WEBSOCKETPP_BROADCAST_SERVER_HANDLER_HPP
#define WEBSOCKETPP_BROADCAST_SERVER_HANDLER_HPP
#include "../../src/sockets/tls.hpp"
#include "../../src/websocketpp.hpp"
#include "broadcast_handler.hpp"
#include "broadcast_admin_handler.hpp"
#include <boost/date_time/posix_time/posix_time.hpp>
namespace websocketpp {
namespace broadcast {
template <typename endpoint_type>
class server_handler : public endpoint_type::handler {
public:
typedef server_handler<endpoint_type> type;
typedef boost::shared_ptr<type> ptr;
typedef typename endpoint_type::handler_ptr handler_ptr;
typedef typename admin_handler<endpoint_type>::ptr admin_handler_ptr;
typedef typename handler<endpoint_type>::ptr broadcast_handler_ptr;
typedef typename endpoint_type::connection_ptr connection_ptr;
server_handler();
std::string get_password() const {
return "test";
}
boost::shared_ptr<boost::asio::ssl::context> on_tls_init() {
// create a tls context, init, and return.
boost::shared_ptr<boost::asio::ssl::context> context(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
try {
context->set_options(boost::asio::ssl::context::default_workarounds |
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::single_dh_use);
context->set_password_callback(boost::bind(&type::get_password, this));
context->use_certificate_chain_file("../../src/ssl/server.pem");
context->use_private_key_file("../../src/ssl/server.pem", boost::asio::ssl::context::pem);
context->use_tmp_dh_file("../../src/ssl/dh512.pem");
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
return context;
}
void validate(connection_ptr connection) {}
void on_open(connection_ptr connection) {
if (connection->get_resource() == "/admin") {
connection->set_handler(m_admin_handler);
} else {
connection->set_handler(m_broadcast_handler);
}
}
void on_unload(connection_ptr connection, handler_ptr new_handler) {
}
void on_close(connection_ptr connection) {}
void on_message(connection_ptr connection,websocketpp::message::data_ptr msg) {}
void http(connection_ptr connection);
void on_fail(connection_ptr connection) {
std::cout << "connection failed" << std::endl;
}
// utility
handler_ptr get_broadcast_handler() {
return m_broadcast_handler;
}
private:
admin_handler_ptr m_admin_handler;
broadcast_handler_ptr m_broadcast_handler;
};
} // namespace broadcast
} // namespace websocketpp
namespace websocketpp {
namespace broadcast {
template <class endpoint>
server_handler<endpoint>::server_handler()
: m_admin_handler(new admin_handler<endpoint>()),
m_broadcast_handler(new handler<endpoint>())
{
m_admin_handler->track(m_broadcast_handler);
}
template <class endpoint>
void server_handler<endpoint>::http(connection_ptr connection) {
std::stringstream foo;
foo << "<html><body><p>"
<< m_broadcast_handler->get_connection_count()
<< " current connections.</p></body></html>";
connection->set_body(foo.str());
}
} // namespace broadcast
} // namespace websocketpp
#endif // WEBSOCKETPP_BROADCAST_SERVER_HANDLER_HPP
@@ -1,128 +0,0 @@
/*
* Copyright (c) 2011, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "../../src/sockets/tls.hpp"
#include "../../src/websocketpp.hpp"
#include "broadcast_server_handler.hpp"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <cstring>
#include <set>
#include <sys/resource.h>
//typedef websocketpp::endpoint<websocketpp::role::server,websocketpp::socket::plain> plain_endpoint_type;
//typedef plain_endpoint_type::handler_ptr plain_handler_ptr;
//typedef websocketpp::endpoint<websocketpp::role::server,websocketpp::socket::ssl> tls_endpoint_type;
//typedef tls_endpoint_type::handler_ptr tls_handler_ptr;
using websocketpp::server;
using websocketpp::server_tls;
int main(int argc, char* argv[]) {
unsigned short port = 9002;
bool tls = false;
// 12288 is max OS X limit without changing kernal settings
const rlim_t ideal_size = 10000;
rlim_t old_size;
rlim_t old_max;
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_NOFILE, &rl);
if (result == 0) {
//std::cout << "System FD limits: " << rl.rlim_cur << " max: " << rl.rlim_max << std::endl;
old_size = rl.rlim_cur;
old_max = rl.rlim_max;
if (rl.rlim_cur < ideal_size) {
std::cout << "Attempting to raise system file descriptor limit from " << rl.rlim_cur << " to " << ideal_size << std::endl;
rl.rlim_cur = ideal_size;
if (rl.rlim_max < ideal_size) {
rl.rlim_max = ideal_size;
}
result = setrlimit(RLIMIT_NOFILE, &rl);
if (result == 0) {
std::cout << "Success" << std::endl;
} else if (result == EPERM) {
std::cout << "Failed. This server will be limited to " << old_size << " concurrent connections. Error code: Insufficient permissions. Try running process as root. system max: " << old_max << std::endl;
} else {
std::cout << "Failed. This server will be limited to " << old_size << " concurrent connections. Error code: " << errno << " system max: " << old_max << std::endl;
}
}
}
if (argc == 2) {
// TODO: input validation?
port = atoi(argv[1]);
}
if (argc == 3) {
// TODO: input validation?
port = atoi(argv[1]);
tls = !strcmp(argv[2],"-tls");
}
try {
if (tls) {
server_tls::handler_ptr handler(new websocketpp::broadcast::server_handler<server_tls>());
server_tls endpoint(handler);
endpoint.alog().unset_level(websocketpp::log::alevel::ALL);
endpoint.elog().set_level(websocketpp::log::elevel::ALL);
std::cout << "Starting Secure WebSocket broadcast server on port " << port << std::endl;
endpoint.listen(port);
} else {
server::handler_ptr handler(new websocketpp::broadcast::server_handler<server>());
server endpoint(handler);
endpoint.alog().unset_level(websocketpp::log::alevel::ALL);
endpoint.elog().set_level(websocketpp::log::elevel::ALL);
//endpoint.alog().set_level(websocketpp::log::alevel::DEVEL);
std::cout << "Starting WebSocket broadcast server on port " << port << std::endl;
endpoint.listen(port);
}
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
}
return 0;
}
File diff suppressed because it is too large Load Diff
@@ -1,76 +0,0 @@
Frequently asked questions
--------------------------
Q: How much data can Flot cope with?
A: Flot will happily draw everything you send to it so the answer
depends on the browser. The excanvas emulation used for IE (built with
VML) makes IE by far the slowest browser so be sure to test with that
if IE users are in your target group.
1000 points is not a problem, but as soon as you start having more
points than the pixel width, you should probably start thinking about
downsampling/aggregation as this is near the resolution limit of the
chart anyway. If you downsample server-side, you also save bandwidth.
Q: Flot isn't working when I'm using JSON data as source!
A: Actually, Flot loves JSON data, you just got the format wrong.
Double check that you're not inputting strings instead of numbers,
like [["0", "-2.13"], ["5", "4.3"]]. This is most common mistake, and
the error might not show up immediately because Javascript can do some
conversion automatically.
Q: Can I export the graph?
A: This is a limitation of the canvas technology. There's a hook in
the canvas object for getting an image out, but you won't get the tick
labels. And it's not likely to be supported by IE. At this point, your
best bet is probably taking a screenshot, e.g. with PrtScn.
Q: The bars are all tiny in time mode?
A: It's not really possible to determine the bar width automatically.
So you have to set the width with the barWidth option which is NOT in
pixels, but in the units of the x axis (or the y axis for horizontal
bars). For time mode that's milliseconds so the default value of 1
makes the bars 1 millisecond wide.
Q: Can I use Flot with libraries like Mootools or Prototype?
A: Yes, Flot supports it out of the box and it's easy! Just use jQuery
instead of $, e.g. call jQuery.plot instead of $.plot and use
jQuery(something) instead of $(something). As a convenience, you can
put in a DOM element for the graph placeholder where the examples and
the API documentation are using jQuery objects.
Depending on how you include jQuery, you may have to add one line of
code to prevent jQuery from overwriting functions from the other
libraries, see the documentation in jQuery ("Using jQuery with other
libraries") for details.
Q: Flot doesn't work with [insert name of Javascript UI framework]!
A: The only non-standard thing used by Flot is the canvas tag;
otherwise it is simply a series of absolute positioned divs within the
placeholder tag you put in. If this is not working, it's probably
because the framework you're using is doing something weird with the
DOM, or you're using it the wrong way.
A common problem is that there's display:none on a container until the
user does something. Many tab widgets work this way, and there's
nothing wrong with it - you just can't call Flot inside a display:none
container as explained in the README so you need to hold off the Flot
call until the container is actually displayed (or use
visibility:hidden instead of display:none or move the container
off-screen).
If you find there's a specific thing we can do to Flot to help, feel
free to submit a bug report. Otherwise, you're welcome to ask for help
on the forum/mailing list, but please don't submit a bug report to
Flot.
@@ -1,22 +0,0 @@
Copyright (c) 2007-2009 IOLA and Ole Laursen
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
@@ -1,9 +0,0 @@
# Makefile for generating minified files
.PHONY: all
# we cheat and process all .js files instead of an exhaustive list
all: $(patsubst %.js,%.min.js,$(filter-out %.min.js,$(wildcard *.js)))
%.min.js: %.js
yui-compressor $< -o $@
-508
View File
@@ -1,508 +0,0 @@
Flot 0.7
--------
API changes:
Multiple axes support. Code using dual axes should be changed from
using x2axis/y2axis in the options to using an array (although
backwards-compatibility hooks are in place). For instance,
{
xaxis: { ... }, x2axis: { ... },
yaxis: { ... }, y2axis: { ... }
}
becomes
{
xaxes: [ { ... }, { ... } ],
yaxes: [ { ... }, { ... } ]
}
Note that if you're just using one axis, continue to use the
xaxis/yaxis directly (it now sets the default settings for the
arrays). Plugins touching the axes must be ported to take the extra
axes into account, check the source to see some examples.
A related change is that the visibility of axes is now auto-detected.
So if you were relying on an axis to show up even without any data in
the chart, you now need to set the axis "show" option explicitly.
"tickColor" on the grid options is now deprecated in favour of a
corresponding option on the axes, so { grid: { tickColor: "#000" }}
becomes { xaxis: { tickColor: "#000"}, yaxis: { tickColor: "#000"} },
but if you just configure a base color Flot will now autogenerate a
tick color by adding transparency. Backwards-compatibility hooks are
in place.
Final note: now that IE 9 is coming out with canvas support, you may
want to adapt the excanvas include to skip loading it in IE 9 (the
examples have been adapted thanks to Ryley Breiddal). An alternative
to excanvas using Flash has also surfaced, if your graphs are slow in
IE, you may want to give it a spin:
http://code.google.com/p/flashcanvas/
Changes:
- Support for specifying a bottom for each point for line charts when
filling them, this means that an arbitrary bottom can be used
instead of just the x axis (based on patches patiently provided by
Roman V. Prikhodchenko).
- New fillbetween plugin that can compute a bottom for a series from
another series, useful for filling areas between lines (see new
example percentiles.html for a use case).
- More predictable handling of gaps for the stacking plugin, now all
undefined ranges are skipped.
- Stacking plugin can stack horizontal bar charts.
- Navigate plugin now redraws the plot while panning instead of only
after the fact (can be disabled by setting the pan.frameRate option
to null), raised by lastthemy (issue 235).
- Date formatter now accepts %0m and %0d to get a zero-padded month or
day (issue raised by Maximillian Dornseif).
- Revamped internals to support an unlimited number of axes, not just
dual (sponsored by Flight Data Services,
www.flightdataservices.com).
- New setting on axes, "tickLength", to control the size of ticks or
turn them off without turning off the labels.
- Axis labels are now put in container divs with classes, for instance
labels in the x axes can be reached via ".xAxis .tickLabel".
- Support for setting the color of an axis (sponsored by Flight Data
Services, www.flightdataservices.com).
- Tick color is now auto-generated as the base color with some
transparency (unless you override it).
- Support for aligning ticks in the axes with "alignTicksWithAxis" to
ensure that they appear next to each other rather than in between,
at the expense of possibly awkward tick steps (sponsored by Flight
Data Services, www.flightdataservices.com).
- Support for customizing the point type through a callback when
plotting points and new symbol plugin with some predefined point
types (sponsored by Utility Data Corporation).
- Resize plugin for automatically redrawing when the placeholder
changes size, e.g. on window resizes (sponsored by Novus Partners).
A resize() method has been added to plot object facilitate this.
- Support Infinity/-Infinity for plotting asymptotes by hacking it
into +/-Number.MAX_VALUE (reported by rabaea.mircea).
- Support for restricting navigate plugin to not pan/zoom an axis (based
on patch by kkaefer).
- Support for providing the drag cursor for the navigate plugin as an
option (based on patch by Kelly T. Moore).
- Options for controlling whether an axis is shown or not (suggestion
by Timo Tuominen) and whether to reserve space for it even if it
isn't shown.
- New attribute $.plot.version with the Flot version as a string.
- The version comment is now included in the minified jquery.flot.min.js.
- New options.grid.minBorderMargin for adjusting the minimum margin
provided around the border (based on patch by corani, issue 188).
- Refactor replot behaviour so Flot tries to reuse the existing
canvas, adding shutdown() methods to the plot (based on patch by
Ryley Breiddal, issue 269). This prevents a memory leak in Chrome
and hopefully makes replotting faster for those who are using $.plot
instead of .setData()/.draw(). Also update jQuery to 1.5.1 to
prevent IE leaks fixed in jQuery.
- New real-time line chart example.
- New hooks: drawSeries, shutdown
Bug fixes:
- Fixed problem with findNearbyItem and bars on top of each other
(reported by ragingchikn, issue 242).
- Fixed problem with ticks and the border (based on patch from
ultimatehustler69, issue 236).
- Fixed problem with plugins adding options to the series objects.
- Fixed a problem introduced in 0.6 with specifying a gradient with {
brightness: x, opacity: y }.
- Don't use $.browser.msie, check for getContext on the created canvas
element instead and try to use excanvas if it's not found (fixes IE
9 compatibility).
- highlight(s, index) was looking up the point in the original s.data
instead of in the computed datapoints array, which breaks with
plugins that modify the datapoints (such as the stacking plugin).
Issue 316 reported by curlypaul924.
- More robust handling of axis from data passed in from getData()
(problem reported by Morgan).
- Fixed problem with turning off bar outline (issue 253, fix by Jordi
Castells).
- Check the selection passed into setSelection in the selection
plugin, to guard against errors when synchronizing plots (fix by Lau
Bech Lauritzen).
- Fix bug in crosshair code with mouseout resetting the crosshair even
if it is locked (fix by Lau Bech Lauritzen and Banko Adam).
- Fix bug with points plotting using line width from lines rather than
points.
- Fix bug with passing non-array 0 data (for plugins that don't expect
arrays, patch by vpapp1).
- Fix errors in JSON in examples so they work with jQuery 1.4.2
(fix reported by honestbleeps, issue 357).
- Fix bug with tooltip in interacting.html, this makes the tooltip
much smoother (fix by bdkahn). Fix related bug inside highlighting
handler in Flot.
- Use closure trick to make inline colorhelpers plugin respect
jQuery.noConflict(true), renaming the global jQuery object (reported
by Nick Stielau).
- Listen for mouseleave events and fire a plothover event with empty
item when it occurs to drop highlights when the mouse leaves the
plot (reported by by outspirit).
- Fix bug with using aboveData with a background (reported by
amitayd).
- Fix possible excanvas leak (report and suggested fix by tom9729).
- Fix bug with backwards compatibility for shadowSize = 0 (report and
suggested fix by aspinak).
- Adapt examples to skip loading excanvas (fix by Ryley Breiddal).
- Fix bug that prevent a simple f(x) = -x transform from working
correctly (fix by Mike, issue 263).
- Fix bug in restoring cursor in navigate plugin (reported by Matteo
Gattanini, issue 395).
- Fix bug in picking items when transform/inverseTransform is in use
(reported by Ofri Raviv, and patches and analysis by Jan and Tom
Paton, issue 334 and 467).
- Fix problem with unaligned ticks and hover/click events caused by
padding on the placeholder by hardcoding the placeholder padding to
0 (reported by adityadineshsaxena, Matt Sommer, Daniel Atos and some
other people, issue 301).
- Update colorhelpers plugin to avoid dying when trying to parse an
invalid string (reported by cadavor, issue 483).
Flot 0.6
--------
API changes:
1. Selection support has been moved to a plugin. Thus if you're
passing selection: { mode: something }, you MUST include the file
jquery.flot.selection.js after jquery.flot.js. This reduces the size
of base Flot and makes it easier to customize the selection as well as
improving code clarity. The change is based on a patch from andershol.
2. In the global options specified in the $.plot command,
"lines", "points", "bars" and "shadowSize" have been moved to a
sub-object called "series", i.e.
$.plot(placeholder, data, { lines: { show: true }})
should be changed to
$.plot(placeholder, data, { series: { lines: { show: true }}})
All future series-specific options will go into this sub-object to
simplify plugin writing. Backward-compatibility code is in place, so
old code should not break.
3. "plothover" no longer provides the original data point, but instead
a normalized one, since there may be no corresponding original point.
4. Due to a bug in previous versions of jQuery, you now need at least
jQuery 1.2.6. But if you can, try jQuery 1.3.2 as it got some
improvements in event handling speed.
Changes:
- Added support for disabling interactivity for specific data series
(request from Ronald Schouten and Steve Upton).
- Flot now calls $() on the placeholder and optional legend container
passed in so you can specify DOM elements or CSS expressions to make
it easier to use Flot with libraries like Prototype or Mootools or
through raw JSON from Ajax responses.
- A new "plotselecting" event is now emitted while the user is making
a selection.
- The "plothover" event is now emitted immediately instead of at most
10 times per second, you'll have to put in a setTimeout yourself if
you're doing something really expensive on this event.
- The built-in date formatter can now be accessed as
$.plot.formatDate(...) (suggestion by Matt Manela) and even
replaced.
- Added "borderColor" option to the grid (patch from Amaury Chamayou
and patch from Mike R. Williamson).
- Added support for gradient backgrounds for the grid, take a look at
the "setting options" example (based on patch from Amaury Chamayou,
issue 90).
- Gradient bars (suggestion by stefpet).
- Added a "plotunselected" event which is triggered when the selection
is removed, see "selection" example (suggestion by Meda Ugo);
- The option legend.margin can now specify horizontal and vertical
margins independently (suggestion by someone who's annoyed).
- Data passed into Flot is now copied to a new canonical format to
enable further processing before it hits the drawing routines. As a
side-effect, this should make Flot more robust in the face of bad
data (and fixes issue 112).
- Step-wise charting: line charts have a new option "steps" that when
set to true connects the points with horizontal/vertical steps
instead of diagonal lines.
- The legend labelFormatter now passes the series in addition to just
the label (suggestion by Vincent Lemeltier).
- Horizontal bars (based on patch by Jason LeBrun).
- Support for partial bars by specifying a third coordinate, i.e. they
don't have to start from the axis. This can be used to make stacked
bars.
- New option to disable the (grid.show).
- Added pointOffset method for converting a point in data space to an
offset within the placeholder.
- Plugin system: register an init method in the $.flot.plugins array
to get started, see PLUGINS.txt for details on how to write plugins
(it's easy). There are also some extra methods to enable access to
internal state.
- Hooks: you can register functions that are called while Flot is
crunching the data and doing the plot. This can be used to modify
Flot without changing the source, useful for writing plugins. Some
hooks are defined, more are likely to come.
- Threshold plugin: you can set a threshold and a color, and the data
points below that threshold will then get the color. Useful for
marking data below 0, for instance.
- Stack plugin: you can specify a stack key for each series to have
them summed. This is useful for drawing additive/cumulative graphs
with bars and (currently unfilled) lines.
- Crosshairs plugin: trace the mouse position on the axes, enable with
crosshair: { mode: "x"} (see the new tracking example for a use).
- Image plugin: plot prerendered images.
- Navigation plugin for panning and zooming a plot.
- More configurable grid.
- Axis transformation support, useful for non-linear plots, e.g. log
axes and compressed time axes (like omitting weekends).
- Support for twelve-hour date formatting (patch by Forrest Aldridge).
- The color parsing code in Flot has been cleaned up and split out so
it's now available as a separate jQuery plugin. It's included inline
in the Flot source to make dependency managing easier. This also
makes it really easy to use the color helpers in Flot plugins.
Bug fixes:
- Fixed two corner-case bugs when drawing filled curves (report and
analysis by Joshua Varner).
- Fix auto-adjustment code when setting min to 0 for an axis where the
dataset is completely flat on that axis (report by chovy).
- Fixed a bug with passing in data from getData to setData when the
secondary axes are used (issue 65, reported by nperelman).
- Fixed so that it is possible to turn lines off when no other chart
type is shown (based on problem reported by Glenn Vanderburg), and
fixed so that setting lineWidth to 0 also hides the shadow (based on
problem reported by Sergio Nunes).
- Updated mousemove position expression to the latest from jQuery (bug
reported by meyuchas).
- Use CSS borders instead of background in legend (fix printing issue 25
and 45).
- Explicitly convert axis min/max to numbers.
- Fixed a bug with drawing marking lines with different colors
(reported by Khurram).
- Fixed a bug with returning y2 values in the selection event (fix
by exists, issue 75).
- Only set position relative on placeholder if it hasn't already a
position different from static (reported by kyberneticist, issue 95).
- Don't round markings to prevent sub-pixel problems (reported by Dan
Lipsitt).
- Make the grid border act similarly to a regular CSS border, i.e.
prevent it from overlapping the plot itself. This also fixes a
problem with anti-aliasing when the width is 1 pixel (reported by
Anthony Ettinger).
- Imported version 3 of excanvas and fixed two issues with the newer
version. Hopefully, this will make Flot work with IE8 (nudge by
Fabien Menager, further analysis by Booink, issue 133).
- Changed the shadow code for lines to hopefully look a bit better
with vertical lines.
- Round tick positions to avoid possible problems with fractions
(suggestion by Fred, issue 130).
- Made the heuristic for determining how many ticks to aim for a bit
smarter.
- Fix for uneven axis margins (report and patch by Paul Kienzle) and
snapping to ticks (concurrent report and patch by lifthrasiir).
- Fixed bug with slicing in findNearbyItems (patch by zollman).
- Make heuristic for x axis label widths more dynamic (patch by
rickinhethuis).
- Make sure points on top take precedence when finding nearby points
when hovering (reported by didroe, issue 224).
Flot 0.5
--------
Backwards API change summary: Timestamps are now in UTC. Also
"selected" event -> becomes "plotselected" with new data, the
parameters for setSelection are now different (but backwards
compatibility hooks are in place), coloredAreas becomes markings with
a new interface (but backwards compatibility hooks are in place).
Interactivity: added a new "plothover" event and this and the
"plotclick" event now returns the closest data item (based on patch by
/david, patch by Mark Byers for bar support). See the revamped
"interacting with the data" example for some hints on what you can do.
Highlighting: you can now highlight points and datapoints are
autohighlighted when you hover over them (if hovering is turned on).
Support for dual axis has been added (based on patch by someone who's
annoyed and /david). For each data series you can specify which axes
it belongs to, and there are two more axes, x2axis and y2axis, to
customize. This affects the "selected" event which has been renamed to
"plotselected" and spews out { xaxis: { from: -10, to: 20 } ... },
setSelection in which the parameters are on a new form (backwards
compatible hooks are in place so old code shouldn't break) and
markings (formerly coloredAreas).
Timestamps in time mode are now displayed according to
UTC instead of the time zone of the visitor. This affects the way the
timestamps should be input; you'll probably have to offset the
timestamps according to your local time zone. It also affects any
custom date handling code (which basically now should use the
equivalent UTC date mehods, e.g. .setUTCMonth() instead of
.setMonth().
Added support for specifying the size of tick labels (axis.labelWidth,
axis.labelHeight). Useful for specifying a max label size to keep
multiple plots aligned.
Markings, previously coloredAreas, are now specified as ranges on the
axes, like { xaxis: { from: 0, to: 10 }}. Furthermore with markings
you can now draw horizontal/vertical lines by setting from and to to
the same coordinate (idea from line support patch by by Ryan Funduk).
The "fill" option can now be a number that specifies the opacity of
the fill.
You can now specify a coordinate as null (like [2, null]) and Flot
will take the other coordinate into account when scaling the axes
(based on patch by joebno).
New option for bars "align". Set it to "center" to center the bars on
the value they represent.
setSelection now takes a second parameter which you can use to prevent
the method from firing the "plotselected" handler.
Using the "container" option in legend now overwrites the container
element instead of just appending to it (fixes infinite legend bug,
reported by several people, fix by Brad Dewey).
Fixed a bug in calculating spacing around the plot (reported by
timothytoe). Fixed a bug in finding max values for all-negative data
sets. Prevent the possibility of eternal looping in tick calculations.
Fixed a bug when borderWidth is set to 0 (reported by
Rob/sanchothefat). Fixed a bug with drawing bars extending below 0
(reported by James Hewitt, patch by Ryan Funduk). Fixed a
bug with line widths of bars (reported by MikeM). Fixed a bug with
'nw' and 'sw' legend positions. Improved the handling of axis
auto-scaling with bars. Fixed a bug with multi-line x-axis tick
labels (reported by Luca Ciano). IE-fix help by Savage Zhang.
Flot 0.4
--------
API changes: deprecated axis.noTicks in favor of just specifying the
number as axis.ticks. So "xaxis: { noTicks: 10 }" becomes
"xaxis: { ticks: 10 }"
Time series support. Specify axis.mode: "time", put in Javascript
timestamps as data, and Flot will automatically spit out sensible
ticks. Take a look at the two new examples. The format can be
customized with axis.timeformat and axis.monthNames, or if that fails
with axis.tickFormatter.
Support for colored background areas via grid.coloredAreas. Specify an
array of { x1, y1, x2, y2 } objects or a function that returns these
given { xmin, xmax, ymin, ymax }.
More members on the plot object (report by Chris Davies and others).
"getData" for inspecting the assigned settings on data series (e.g.
color) and "setData", "setupGrid" and "draw" for updating the contents
without a total replot.
The default number of ticks to aim for is now dependent on the size of
the plot in pixels. Support for customizing tick interval sizes
directly with axis.minTickSize and axis.tickSize.
Cleaned up the automatic axis scaling algorithm and fixed how it
interacts with ticks. Also fixed a couple of tick-related corner case
bugs (one reported by mainstreetmark, another reported by timothytoe).
The option axis.tickFormatter now takes a function with two
parameters, the second parameter is an optional object with
information about the axis. It has min, max, tickDecimals, tickSize.
Added support for segmented lines (based on patch from Michael
MacDonald) and for ignoring null and bad values (suggestion from Nick
Konidaris and joshwaihi).
Added support for changing the border width (joebno and safoo).
Label colors can be changed via CSS by selecting the tickLabel class.
Fixed a bug in handling single-item bar series (reported by Emil
Filipov). Fixed erratic behaviour when interacting with the plot
with IE 7 (reported by Lau Bech Lauritzen). Prevent IE/Safari text
selection when selecting stuff on the canvas.
Flot 0.3
--------
This is mostly a quick-fix release because jquery.js wasn't included
in the previous zip/tarball.
Support clicking on the plot. Turn it on with grid: { clickable: true },
then you get a "plotclick" event on the graph placeholder with the
position in units of the plot.
Fixed a bug in dealing with data where min = max, thanks to Michael
Messinides.
Include jquery.js in the zip/tarball.
Flot 0.2
--------
Added support for putting a background behind the default legend. The
default is the partly transparent background color. Added
backgroundColor and backgroundOpacity to the legend options to control
this.
The ticks options can now be a callback function that takes one
parameter, an object with the attributes min and max. The function
should return a ticks array.
Added labelFormatter option in legend, useful for turning the legend
labels into links.
Fixed a couple of bugs.
The API should now be fully documented.
Patch from Guy Fraser to make parts of the code smaller.
API changes: Moved labelMargin option to grid from x/yaxis.
Flot 0.1
--------
First public release.
@@ -1,137 +0,0 @@
Writing plugins
---------------
All you need to do to make a new plugin is creating an init function
and a set of options (if needed), stuffing it into an object and
putting it in the $.plot.plugins array. For example:
function myCoolPluginInit(plot) {
plot.coolstring = "Hello!";
};
$.plot.plugins.push({ init: myCoolPluginInit, options: { ... } });
// if $.plot is called, it will return a plot object with the
// attribute "coolstring"
Now, given that the plugin might run in many different places, it's
a good idea to avoid leaking names. The usual trick here is wrap the
above lines in an anonymous function which is called immediately, like
this: (function () { inner code ... })(). To make it even more robust
in case $ is not bound to jQuery but some other Javascript library, we
can write it as
(function ($) {
// plugin definition
// ...
})(jQuery);
There's a complete example below, but you should also check out the
plugins bundled with Flot.
Complete example
----------------
Here is a simple debug plugin which alerts each of the series in the
plot. It has a single option that control whether it is enabled and
how much info to output:
(function ($) {
function init(plot) {
var debugLevel = 1;
function checkDebugEnabled(plot, options) {
if (options.debug) {
debugLevel = options.debug;
plot.hooks.processDatapoints.push(alertSeries);
}
}
function alertSeries(plot, series, datapoints) {
var msg = "series " + series.label;
if (debugLevel > 1)
msg += " with " + series.data.length + " points";
alert(msg);
}
plot.hooks.processOptions.push(checkDebugEnabled);
}
var options = { debug: 0 };
$.plot.plugins.push({
init: init,
options: options,
name: "simpledebug",
version: "0.1"
});
})(jQuery);
We also define "name" and "version". It's not used by Flot, but might
be helpful for other plugins in resolving dependencies.
Put the above in a file named "jquery.flot.debug.js", include it in an
HTML page and then it can be used with:
$.plot($("#placeholder"), [...], { debug: 2 });
This simple plugin illustrates a couple of points:
- It uses the anonymous function trick to avoid name pollution.
- It can be enabled/disabled through an option.
- Variables in the init function can be used to store plot-specific
state between the hooks.
The two last points are important because there may be multiple plots
on the same page, and you'd want to make sure they are not mixed up.
Shutting down a plugin
----------------------
Each plot object has a shutdown hook which is run when plot.shutdown()
is called. This usually mostly happens in case another plot is made on
top of an existing one.
The purpose of the hook is to give you a chance to unbind any event
handlers you've registered and remove any extra DOM things you've
inserted.
The problem with event handlers is that you can have registered a
handler which is run in some point in the future, e.g. with
setTimeout(). Meanwhile, the plot may have been shutdown and removed,
but because your event handler is still referencing it, it can't be
garbage collected yet, and worse, if your handler eventually runs, it
may overwrite stuff on a completely different plot.
Some hints on the options
-------------------------
Plugins should always support appropriate options to enable/disable
them because the plugin user may have several plots on the same page
where only one should use the plugin. In most cases it's probably a
good idea if the plugin is turned off rather than on per default, just
like most of the powerful features in Flot.
If the plugin needs options that are specific to each series, like the
points or lines options in core Flot, you can put them in "series" in
the options object, e.g.
var options = {
series: {
downsample: {
algorithm: null,
maxpoints: 1000
}
}
}
Then they will be copied by Flot into each series, providing default
values in case none are specified.
Think hard and long about naming the options. These names are going to
be public API, and code is going to depend on them if the plugin is
successful.
@@ -1,90 +0,0 @@
About
-----
Flot is a Javascript plotting library for jQuery. Read more at the
website:
http://code.google.com/p/flot/
Take a look at the examples linked from above, they should give a good
impression of what Flot can do and the source code of the examples is
probably the fastest way to learn how to use Flot.
Installation
------------
Just include the Javascript file after you've included jQuery.
Generally, all browsers that support the HTML5 canvas tag are
supported.
For support for Internet Explorer < 9, you can use Excanvas, a canvas
emulator; this is used in the examples bundled with Flot. You just
include the excanvas script like this:
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="excanvas.min.js"></script><![endif]-->
If it's not working on your development IE 6.0, check that it has
support for VML which Excanvas is relying on. It appears that some
stripped down versions used for test environments on virtual machines
lack the VML support.
You can also try using Flashcanvas (see
http://code.google.com/p/flashcanvas/), which uses Flash to do the
emulation. Although Flash can be a bit slower to load than VML, if
you've got a lot of points, the Flash version can be much faster
overall. Flot contains some wrapper code for activating Excanvas which
Flashcanvas is compatible with.
You need at least jQuery 1.2.6, but try at least 1.3.2 for interactive
charts because of performance improvements in event handling.
Basic usage
-----------
Create a placeholder div to put the graph in:
<div id="placeholder"></div>
You need to set the width and height of this div, otherwise the plot
library doesn't know how to scale the graph. You can do it inline like
this:
<div id="placeholder" style="width:600px;height:300px"></div>
You can also do it with an external stylesheet. Make sure that the
placeholder isn't within something with a display:none CSS property -
in that case, Flot has trouble measuring label dimensions which
results in garbled looks and might have trouble measuring the
placeholder dimensions which is fatal (it'll throw an exception).
Then when the div is ready in the DOM, which is usually on document
ready, run the plot function:
$.plot($("#placeholder"), data, options);
Here, data is an array of data series and options is an object with
settings if you want to customize the plot. Take a look at the
examples for some ideas of what to put in or look at the reference
in the file "API.txt". Here's a quick example that'll draw a line from
(0, 0) to (1, 1):
$.plot($("#placeholder"), [ [[0, 0], [1, 1]] ], { yaxis: { max: 1 } });
The plot function immediately draws the chart and then returns a plot
object with a couple of methods.
What's with the name?
---------------------
First: it's pronounced with a short o, like "plot". Not like "flawed".
So "Flot" rhymes with "plot".
And if you look up "flot" in a Danish-to-English dictionary, some up
the words that come up are "good-looking", "attractive", "stylish",
"smart", "impressive", "extravagant". One of the main goals with Flot
is pretty looks.
@@ -1,143 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>Example of loading data dynamically with AJAX. Percentage change in GDP (source: <a href="http://epp.eurostat.ec.europa.eu/tgm/table.do?tab=table&init=1&plugin=1&language=en&pcode=tsieb020">Eurostat</a>). Click the buttons below.</p>
<p>The data is fetched over HTTP, in this case directly from text
files. Usually the URL would point to some web server handler
(e.g. a PHP page or Java/.NET/Python/Ruby on Rails handler) that
extracts it from a database and serializes it to JSON.</p>
<p>
<input class="fetchSeries" type="button" value="First dataset"> -
<a href="data-eu-gdp-growth.json">data</a> -
<span></span>
</p>
<p>
<input class="fetchSeries" type="button" value="Second dataset"> -
<a href="data-japan-gdp-growth.json">data</a> -
<span></span>
</p>
<p>
<input class="fetchSeries" type="button" value="Third dataset"> -
<a href="data-usa-gdp-growth.json">data</a> -
<span></span>
</p>
<p>If you combine AJAX with setTimeout, you can poll the server
for new data.</p>
<p>
<input class="dataUpdate" type="button" value="Poll for data">
</p>
<script type="text/javascript">
$(function () {
var options = {
lines: { show: true },
points: { show: true },
xaxis: { tickDecimals: 0, tickSize: 1 }
};
var data = [];
var placeholder = $("#placeholder");
$.plot(placeholder, data, options);
// fetch one series, adding to what we got
var alreadyFetched = {};
$("input.fetchSeries").click(function () {
var button = $(this);
// find the URL in the link right next to us
var dataurl = button.siblings('a').attr('href');
// then fetch the data with jQuery
function onDataReceived(series) {
// extract the first coordinate pair so you can see that
// data is now an ordinary Javascript object
var firstcoordinate = '(' + series.data[0][0] + ', ' + series.data[0][1] + ')';
button.siblings('span').text('Fetched ' + series.label + ', first point: ' + firstcoordinate);
// let's add it to our current data
if (!alreadyFetched[series.label]) {
alreadyFetched[series.label] = true;
data.push(series);
}
// and plot all we got
$.plot(placeholder, data, options);
}
$.ajax({
url: dataurl,
method: 'GET',
dataType: 'json',
success: onDataReceived
});
});
// initiate a recurring data update
$("input.dataUpdate").click(function () {
// reset data
data = [];
alreadyFetched = {};
$.plot(placeholder, data, options);
var iteration = 0;
function fetchData() {
++iteration;
function onDataReceived(series) {
// we get all the data in one go, if we only got partial
// data, we could merge it with what we already got
data = [ series ];
$.plot($("#placeholder"), data, options);
}
$.ajax({
// usually, we'll just call the same URL, a script
// connected to a database, but in this case we only
// have static example files so we need to modify the
// URL
url: "data-eu-gdp-growth-" + iteration + ".json",
method: 'GET',
dataType: 'json',
success: onDataReceived
});
if (iteration < 5)
setTimeout(fetchData, 1000);
else {
data = [];
alreadyFetched = {};
}
}
setTimeout(fetchData, 1000);
});
});
</script>
</body>
</html>
@@ -1,75 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>Flot has support for simple background decorations such as
lines and rectangles. They can be useful for marking up certain
areas. You can easily add any HTML you need with standard DOM
manipulation, e.g. for labels. For drawing custom shapes there is
also direct access to the canvas.</p>
<script type="text/javascript">
$(function () {
// generate a dataset
var d1 = [];
for (var i = 0; i < 20; ++i)
d1.push([i, Math.sin(i)]);
var data = [{ data: d1, label: "Pressure", color: "#333" }];
// setup background areas
var markings = [
{ color: '#f6f6f6', yaxis: { from: 1 } },
{ color: '#f6f6f6', yaxis: { to: -1 } },
{ color: '#000', lineWidth: 1, xaxis: { from: 2, to: 2 } },
{ color: '#000', lineWidth: 1, xaxis: { from: 8, to: 8 } }
];
var placeholder = $("#placeholder");
// plot it
var plot = $.plot(placeholder, data, {
bars: { show: true, barWidth: 0.5, fill: 0.9 },
xaxis: { ticks: [], autoscaleMargin: 0.02 },
yaxis: { min: -2, max: 2 },
grid: { markings: markings }
});
// add labels
var o;
o = plot.pointOffset({ x: 2, y: -1.2});
// we just append it to the placeholder which Flot already uses
// for positioning
placeholder.append('<div style="position:absolute;left:' + (o.left + 4) + 'px;top:' + o.top + 'px;color:#666;font-size:smaller">Warming up</div>');
o = plot.pointOffset({ x: 8, y: -1.2});
placeholder.append('<div style="position:absolute;left:' + (o.left + 4) + 'px;top:' + o.top + 'px;color:#666;font-size:smaller">Actual measurements</div>');
// draw a little arrow on top of the last label to demonstrate
// canvas drawing
var ctx = plot.getCanvas().getContext("2d");
ctx.beginPath();
o.left += 4;
ctx.moveTo(o.left, o.top);
ctx.lineTo(o.left, o.top - 10);
ctx.lineTo(o.left + 10, o.top - 5);
ctx.lineTo(o.left, o.top);
ctx.fillStyle = "#000";
ctx.fill();
});
</script>
</body>
</html>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 897 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 916 B

@@ -1,38 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>Simple example. You don't need to specify much to get an
attractive look. Put in a placeholder, make sure you set its
dimensions (otherwise the plot library will barf) and call the
plot function with the data. The axes are automatically
scaled.</p>
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
// a null signifies separate line segments
var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
$.plot($("#placeholder"), [ d1, d2, d3 ]);
});
</script>
</body>
</html>
@@ -1,4 +0,0 @@
{
"label": "Europe (EU27)",
"data": [[1999, 3.0], [2000, 3.9]]
}
@@ -1,4 +0,0 @@
{
"label": "Europe (EU27)",
"data": [[1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2]]
}
@@ -1,4 +0,0 @@
{
"label": "Europe (EU27)",
"data": [[1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3], [2004, 2.5]]
}
@@ -1,4 +0,0 @@
{
"label": "Europe (EU27)",
"data": [[1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3], [2004, 2.5], [2005, 2.0], [2006, 3.1]]
}
@@ -1,4 +0,0 @@
{
"label": "Europe (EU27)",
"data": [[1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3], [2004, 2.5], [2005, 2.0], [2006, 3.1], [2007, 2.9], [2008, 0.9]]
}
@@ -1,4 +0,0 @@
{
"label": "Europe (EU27)",
"data": [[1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3], [2004, 2.5], [2005, 2.0], [2006, 3.1], [2007, 2.9], [2008, 0.9]]
}
@@ -1,4 +0,0 @@
{
"label": "Japan",
"data": [[1999, -0.1], [2000, 2.9], [2001, 0.2], [2002, 0.3], [2003, 1.4], [2004, 2.7], [2005, 1.9], [2006, 2.0], [2007, 2.3], [2008, -0.7]]
}
@@ -1,4 +0,0 @@
{
"label": "USA",
"data": [[1999, 4.4], [2000, 3.7], [2001, 0.8], [2002, 1.6], [2003, 2.5], [2004, 3.6], [2005, 2.9], [2006, 2.8], [2007, 2.0], [2008, 1.1]]
}
@@ -1,75 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px"></div>
<p>Flot supports lines, points, filled areas, bars and any
combinations of these, in the same plot and even on the same data
series.</p>
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
var d3 = [];
for (var i = 0; i < 14; i += 0.5)
d3.push([i, Math.cos(i)]);
var d4 = [];
for (var i = 0; i < 14; i += 0.1)
d4.push([i, Math.sqrt(i * 10)]);
var d5 = [];
for (var i = 0; i < 14; i += 0.5)
d5.push([i, Math.sqrt(i)]);
var d6 = [];
for (var i = 0; i < 14; i += 0.5 + Math.random())
d6.push([i, Math.sqrt(2*i + Math.sin(i) + 5)]);
$.plot($("#placeholder"), [
{
data: d1,
lines: { show: true, fill: true }
},
{
data: d2,
bars: { show: true }
},
{
data: d3,
points: { show: true }
},
{
data: d4,
lines: { show: true }
},
{
data: d5,
lines: { show: true },
points: { show: true }
},
{
data: d6,
lines: { show: true, steps: true }
}
]);
});
</script>
</body>
</html>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

@@ -1,45 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.image.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:400px;height:400px;"></div>
<p>The Cat's Eye Nebula (<a href="http://hubblesite.org/gallery/album/nebula/pr2004027a/">picture from Hubble</a>).</p>
<p>With the image plugin, you can plot images. This is for example
useful for getting ticks on complex prerendered visualizations.
Instead of inputting data points, you put in the images and where
their two opposite corners are supposed to be in plot space.</p>
<p>Images represent a little further complication because you need
to make sure they are loaded before you can use them (Flot skips
incomplete images). The plugin comes with a couple of helpers
for doing that.</p>
<script type="text/javascript">
$(function () {
var data = [ [ ["hs-2004-27-a-large_web.jpg", -10, -10, 10, 10] ] ];
var options = {
series: { images: { show: true } },
xaxis: { min: -8, max: 4 },
yaxis: { min: -8, max: 4 }
};
$.plot.image.loadDataImages(data, options, function () {
$.plot($("#placeholder"), data, options);
});
});
</script>
</body>
</html>
@@ -1,44 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Flot Examples</h1>
<p>Here are some examples for <a href="http://code.google.com/p/flot/">Flot</a>, the Javascript charting library for jQuery:</p>
<ul>
<li><a href="basic.html">Basic example</a></li>
<li><a href="graph-types.html">Different graph types</a></li>
<li><a href="setting-options.html">Setting various options</a> and <a href="annotating.html">annotating a chart</a></li>
<li><a href="ajax.html">Updating graphs with AJAX</a> and <a href="realtime.html">real-time updates</a></li>
</ul>
<p>Being interactive:</p>
<ul>
<li><a href="turning-series.html">Turning series on/off</a></li>
<li><a href="selection.html">Rectangular selection support and zooming</a> and <a href="zooming.html">zooming with overview</a> (both with selection plugin)</li>
<li><a href="interacting.html">Interacting with the data points</a></li>
<li><a href="navigate.html">Panning and zooming</a> (with navigation plugin)</li>
<li><a href="resize.html">Automatically redraw when window is resized</a> (with resize plugin)</li>
</ul>
<p>Various features:</p>
<ul>
<li><a href="symbols.html">Using other symbols than circles for points</a> (with symbol plugin)</li>
<li><a href="time.html">Plotting time series</a> and <a href="visitors.html">visitors per day with zooming and weekends</a> (with selection plugin)</li>
<li><a href="multiple-axes.html">Multiple axes</a> and <a href="interacting-axes.html">interacting with the axes</a></li>
<li><a href="thresholding.html">Thresholding the data</a> (with threshold plugin)</li>
<li><a href="stacking.html">Stacked charts</a> (with stacking plugin)</li>
<li><a href="percentiles.html">Using filled areas to plot percentiles</a> (with fillbetween plugin)</li>
<li><a href="tracking.html">Tracking curves with crosshair</a> (with crosshair plugin)</li>
<li><a href="image.html">Plotting prerendered images</a> (with image plugin)</li>
<li><a href="pie.html">Pie charts</a> (with pie plugin)</li>
</ul>
</body>
</html>
@@ -1,97 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>With multiple axes, you sometimes need to interact with them. A
simple way to do this is to draw the plot, deduce the axis
placements and insert a couple of divs on top to catch events.
Try clicking an axis.</p>
<p id="click"></p>
<script type="text/javascript">
$(function () {
function generate(start, end, fn) {
var res = [];
for (var i = 0; i <= 100; ++i) {
var x = start + i / 100 * (end - start);
res.push([x, fn(x)]);
}
return res;
}
var data = [
{ data: generate(0, 10, function (x) { return Math.sqrt(x)}), xaxis: 1, yaxis:1 },
{ data: generate(0, 10, function (x) { return Math.sin(x)}), xaxis: 1, yaxis:2 },
{ data: generate(0, 10, function (x) { return Math.cos(x)}), xaxis: 1, yaxis:3 },
{ data: generate(2, 10, function (x) { return Math.tan(x)}), xaxis: 2, yaxis: 4 }
];
var plot = $.plot($("#placeholder"),
data,
{
xaxes: [
{ position: 'bottom' },
{ position: 'top'}
],
yaxes: [
{ position: 'left' },
{ position: 'left' },
{ position: 'right' },
{ position: 'left' }
]
});
// now for each axis, create a div
function getBoundingBoxForAxis(plot, axis) {
var left = axis.box.left, top = axis.box.top,
right = left + axis.box.width, bottom = top + axis.box.height;
// some ticks may stick out, enlarge the box to encompass all ticks
var cls = axis.direction + axis.n + 'Axis';
plot.getPlaceholder().find('.' + cls + ' .tickLabel').each(function () {
var pos = $(this).position();
left = Math.min(pos.left, left);
top = Math.min(pos.top, top);
right = Math.max(Math.round(pos.left) + $(this).outerWidth(), right);
bottom = Math.max(Math.round(pos.top) + $(this).outerHeight(), bottom);
});
return { left: left, top: top, width: right - left, height: bottom - top };
}
$.each(plot.getAxes(), function (i, axis) {
if (!axis.show)
return;
var box = getBoundingBoxForAxis(plot, axis);
$('<div class="axisTarget" style="position:absolute;left:' + box.left + 'px;top:' + box.top + 'px;width:' + box.width + 'px;height:' + box.height + 'px"></div>')
.data('axis.direction', axis.direction)
.data('axis.n', axis.n)
.css({ backgroundColor: "#f00", opacity: 0, cursor: "pointer" })
.appendTo(plot.getPlaceholder())
.hover(
function () { $(this).css({ opacity: 0.10 }) },
function () { $(this).css({ opacity: 0 }) }
)
.click(function () {
$("#click").text("You clicked the " + axis.direction + axis.n + "axis!")
});
});
});
</script>
</body>
</html>
@@ -1,93 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px"></div>
<p>One of the goals of Flot is to support user interactions. Try
pointing and clicking on the points.</p>
<p id="hoverdata">Mouse hovers at
(<span id="x">0</span>, <span id="y">0</span>). <span id="clickdata"></span></p>
<p>A tooltip is easy to build with a bit of jQuery code and the
data returned from the plot.</p>
<p><input id="enableTooltip" type="checkbox">Enable tooltip</p>
<script type="text/javascript">
$(function () {
var sin = [], cos = [];
for (var i = 0; i < 14; i += 0.5) {
sin.push([i, Math.sin(i)]);
cos.push([i, Math.cos(i)]);
}
var plot = $.plot($("#placeholder"),
[ { data: sin, label: "sin(x)"}, { data: cos, label: "cos(x)" } ], {
series: {
lines: { show: true },
points: { show: true }
},
grid: { hoverable: true, clickable: true },
yaxis: { min: -1.2, max: 1.2 }
});
function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css( {
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
var previousPoint = null;
$("#placeholder").bind("plothover", function (event, pos, item) {
$("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2));
if ($("#enableTooltip:checked").length > 0) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY,
item.series.label + " of " + x + " = " + y);
}
}
else {
$("#tooltip").remove();
previousPoint = null;
}
}
});
$("#placeholder").bind("plotclick", function (event, pos, item) {
if (item) {
$("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
plot.highlight(item.series, item.datapoint);
}
});
});
</script>
</body>
</html>
@@ -1,6 +0,0 @@
body {
font-family: sans-serif;
font-size: 16px;
margin: 50px;
max-width: 800px;
}
File diff suppressed because one or more lines are too long
@@ -1,118 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.navigate.js"></script>
<style type="text/css">
#placeholder .button {
position: absolute;
cursor: pointer;
}
#placeholder div.button {
font-size: smaller;
color: #999;
background-color: #eee;
padding: 2px;
}
.message {
padding-left: 50px;
font-size: smaller;
}
</style>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p class="message"></p>
<p>With the navigate plugin it is easy to add panning and zooming.
Drag to pan, double click to zoom (or use the mouse scrollwheel).</p>
<p>The plugin fires events (useful for synchronizing several
plots) and adds a couple of public methods so you can easily build
a little user interface around it, like the little buttons at the
top right in the plot.</p>
<script type="text/javascript">
$(function () {
// generate data set from a parametric function with a fractal
// look
function sumf(f, t, m) {
var res = 0;
for (var i = 1; i < m; ++i)
res += f(i * i * t) / (i * i);
return res;
}
var d1 = [];
for (var t = 0; t <= 2 * Math.PI; t += 0.01)
d1.push([sumf(Math.cos, t, 10), sumf(Math.sin, t, 10)]);
var data = [ d1 ];
var placeholder = $("#placeholder");
var options = {
series: { lines: { show: true }, shadowSize: 0 },
xaxis: { zoomRange: [0.1, 10], panRange: [-10, 10] },
yaxis: { zoomRange: [0.1, 10], panRange: [-10, 10] },
zoom: {
interactive: true
},
pan: {
interactive: true
}
};
var plot = $.plot(placeholder, data, options);
// show pan/zoom messages to illustrate events
placeholder.bind('plotpan', function (event, plot) {
var axes = plot.getAxes();
$(".message").html("Panning to x: " + axes.xaxis.min.toFixed(2)
+ " &ndash; " + axes.xaxis.max.toFixed(2)
+ " and y: " + axes.yaxis.min.toFixed(2)
+ " &ndash; " + axes.yaxis.max.toFixed(2));
});
placeholder.bind('plotzoom', function (event, plot) {
var axes = plot.getAxes();
$(".message").html("Zooming to x: " + axes.xaxis.min.toFixed(2)
+ " &ndash; " + axes.xaxis.max.toFixed(2)
+ " and y: " + axes.yaxis.min.toFixed(2)
+ " &ndash; " + axes.yaxis.max.toFixed(2));
});
// add zoom out button
$('<div class="button" style="right:20px;top:20px">zoom out</div>').appendTo(placeholder).click(function (e) {
e.preventDefault();
plot.zoomOut();
});
// and add panning buttons
// little helper for taking the repetitive work out of placing
// panning arrows
function addArrow(dir, right, top, offset) {
$('<img class="button" src="arrow-' + dir + '.gif" style="right:' + right + 'px;top:' + top + 'px">').appendTo(placeholder).click(function (e) {
e.preventDefault();
plot.pan(offset);
});
}
addArrow('left', 55, 60, { left: -100 });
addArrow('right', 25, 60, { left: 100 });
addArrow('up', 40, 45, { top: -100 });
addArrow('down', 40, 75, { top: 100 });
});
</script>
</body>
</html>
@@ -1,57 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.fillbetween.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:400px;"></div>
<p>Height in centimeters of individuals from the US (2003-2006) as function of
age in years (source: <a href="http://www.cdc.gov/nchs/data/nhsr/nhsr010.pdf">CDC</a>).
The 15%-85%, 25%-75% and 50% percentiles are indicated.</p>
<p>For each point of a filled curve, you can specify an arbitrary
bottom. As this example illustrates, this can be useful for
plotting percentiles. If you have the data sets available without
appropriate fill bottoms, you can use the fillbetween plugin to
compute the data point bottoms automatically.</p>
<script type="text/javascript">
$(function () {
var males = {'15%': [[2, 88.0], [3, 93.3], [4, 102.0], [5, 108.5], [6, 115.7], [7, 115.6], [8, 124.6], [9, 130.3], [10, 134.3], [11, 141.4], [12, 146.5], [13, 151.7], [14, 159.9], [15, 165.4], [16, 167.8], [17, 168.7], [18, 169.5], [19, 168.0]], '90%': [[2, 96.8], [3, 105.2], [4, 113.9], [5, 120.8], [6, 127.0], [7, 133.1], [8, 139.1], [9, 143.9], [10, 151.3], [11, 161.1], [12, 164.8], [13, 173.5], [14, 179.0], [15, 182.0], [16, 186.9], [17, 185.2], [18, 186.3], [19, 186.6]], '25%': [[2, 89.2], [3, 94.9], [4, 104.4], [5, 111.4], [6, 117.5], [7, 120.2], [8, 127.1], [9, 132.9], [10, 136.8], [11, 144.4], [12, 149.5], [13, 154.1], [14, 163.1], [15, 169.2], [16, 170.4], [17, 171.2], [18, 172.4], [19, 170.8]], '10%': [[2, 86.9], [3, 92.6], [4, 99.9], [5, 107.0], [6, 114.0], [7, 113.5], [8, 123.6], [9, 129.2], [10, 133.0], [11, 140.6], [12, 145.2], [13, 149.7], [14, 158.4], [15, 163.5], [16, 166.9], [17, 167.5], [18, 167.1], [19, 165.3]], 'mean': [[2, 91.9], [3, 98.5], [4, 107.1], [5, 114.4], [6, 120.6], [7, 124.7], [8, 131.1], [9, 136.8], [10, 142.3], [11, 150.0], [12, 154.7], [13, 161.9], [14, 168.7], [15, 173.6], [16, 175.9], [17, 176.6], [18, 176.8], [19, 176.7]], '75%': [[2, 94.5], [3, 102.1], [4, 110.8], [5, 117.9], [6, 124.0], [7, 129.3], [8, 134.6], [9, 141.4], [10, 147.0], [11, 156.1], [12, 160.3], [13, 168.3], [14, 174.7], [15, 178.0], [16, 180.2], [17, 181.7], [18, 181.3], [19, 182.5]], '85%': [[2, 96.2], [3, 103.8], [4, 111.8], [5, 119.6], [6, 125.6], [7, 131.5], [8, 138.0], [9, 143.3], [10, 149.3], [11, 159.8], [12, 162.5], [13, 171.3], [14, 177.5], [15, 180.2], [16, 183.8], [17, 183.4], [18, 183.5], [19, 185.5]], '50%': [[2, 91.9], [3, 98.2], [4, 106.8], [5, 114.6], [6, 120.8], [7, 125.2], [8, 130.3], [9, 137.1], [10, 141.5], [11, 149.4], [12, 153.9], [13, 162.2], [14, 169.0], [15, 174.8], [16, 176.0], [17, 176.8], [18, 176.4], [19, 177.4]]};
var females = {'15%': [[2, 84.8], [3, 93.7], [4, 100.6], [5, 105.8], [6, 113.3], [7, 119.3], [8, 124.3], [9, 131.4], [10, 136.9], [11, 143.8], [12, 149.4], [13, 151.2], [14, 152.3], [15, 155.9], [16, 154.7], [17, 157.0], [18, 156.1], [19, 155.4]], '90%': [[2, 95.6], [3, 104.1], [4, 111.9], [5, 119.6], [6, 127.6], [7, 133.1], [8, 138.7], [9, 147.1], [10, 152.8], [11, 161.3], [12, 166.6], [13, 167.9], [14, 169.3], [15, 170.1], [16, 172.4], [17, 169.2], [18, 171.1], [19, 172.4]], '25%': [[2, 87.2], [3, 95.9], [4, 101.9], [5, 107.4], [6, 114.8], [7, 121.4], [8, 126.8], [9, 133.4], [10, 138.6], [11, 146.2], [12, 152.0], [13, 153.8], [14, 155.7], [15, 158.4], [16, 157.0], [17, 158.5], [18, 158.4], [19, 158.1]], '10%': [[2, 84.0], [3, 91.9], [4, 99.2], [5, 105.2], [6, 112.7], [7, 118.0], [8, 123.3], [9, 130.2], [10, 135.0], [11, 141.1], [12, 148.3], [13, 150.0], [14, 150.7], [15, 154.3], [16, 153.6], [17, 155.6], [18, 154.7], [19, 153.1]], 'mean': [[2, 90.2], [3, 98.3], [4, 105.2], [5, 112.2], [6, 119.0], [7, 125.8], [8, 131.3], [9, 138.6], [10, 144.2], [11, 151.3], [12, 156.7], [13, 158.6], [14, 160.5], [15, 162.1], [16, 162.9], [17, 162.2], [18, 163.0], [19, 163.1]], '75%': [[2, 93.2], [3, 101.5], [4, 107.9], [5, 116.6], [6, 122.8], [7, 129.3], [8, 135.2], [9, 143.7], [10, 148.7], [11, 156.9], [12, 160.8], [13, 163.0], [14, 165.0], [15, 165.8], [16, 168.7], [17, 166.2], [18, 167.6], [19, 168.0]], '85%': [[2, 94.5], [3, 102.8], [4, 110.4], [5, 119.0], [6, 125.7], [7, 131.5], [8, 137.9], [9, 146.0], [10, 151.3], [11, 159.9], [12, 164.0], [13, 166.5], [14, 167.5], [15, 168.5], [16, 171.5], [17, 168.0], [18, 169.8], [19, 170.3]], '50%': [[2, 90.2], [3, 98.1], [4, 105.2], [5, 111.7], [6, 118.2], [7, 125.6], [8, 130.5], [9, 138.3], [10, 143.7], [11, 151.4], [12, 156.7], [13, 157.7], [14, 161.0], [15, 162.0], [16, 162.8], [17, 162.2], [18, 162.8], [19, 163.3]]};
var dataset = [
{ label: 'Female mean', data: females['mean'], lines: { show: true }, color: "rgb(255,50,50)" },
{ id: 'f15%', data: females['15%'], lines: { show: true, lineWidth: 0, fill: false }, color: "rgb(255,50,50)" },
{ id: 'f25%', data: females['25%'], lines: { show: true, lineWidth: 0, fill: 0.2 }, color: "rgb(255,50,50)", fillBetween: 'f15%' },
{ id: 'f50%', data: females['50%'], lines: { show: true, lineWidth: 0.5, fill: 0.4, shadowSize: 0 }, color: "rgb(255,50,50)", fillBetween: 'f25%' },
{ id: 'f75%', data: females['75%'], lines: { show: true, lineWidth: 0, fill: 0.4 }, color: "rgb(255,50,50)", fillBetween: 'f50%' },
{ id: 'f85%', data: females['85%'], lines: { show: true, lineWidth: 0, fill: 0.2 }, color: "rgb(255,50,50)", fillBetween: 'f75%' },
{ label: 'Male mean', data: males['mean'], lines: { show: true }, color: "rgb(50,50,255)" },
{ id: 'm15%', data: males['15%'], lines: { show: true, lineWidth: 0, fill: false }, color: "rgb(50,50,255)" },
{ id: 'm25%', data: males['25%'], lines: { show: true, lineWidth: 0, fill: 0.2 }, color: "rgb(50,50,255)", fillBetween: 'm15%' },
{ id: 'm50%', data: males['50%'], lines: { show: true, lineWidth: 0.5, fill: 0.4, shadowSize: 0 }, color: "rgb(50,50,255)", fillBetween: 'm25%' },
{ id: 'm75%', data: males['75%'], lines: { show: true, lineWidth: 0, fill: 0.4 }, color: "rgb(50,50,255)", fillBetween: 'm50%' },
{ id: 'm85%', data: males['85%'], lines: { show: true, lineWidth: 0, fill: 0.2 }, color: "rgb(50,50,255)", fillBetween: 'm75%' }
]
$.plot($("#placeholder"), dataset, {
xaxis: { tickDecimals: 0 },
yaxis: { tickFormatter: function (v) { return v + " cm"; } },
legend: { position: 'se' }
});
});
</script>
</body>
</html>
@@ -1,756 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Pie Examples</title>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.pie.js"></script>
<script type="text/javascript">
$(function () {
// data
/*var data = [
{ label: "Series1", data: 10},
{ label: "Series2", data: 30},
{ label: "Series3", data: 90},
{ label: "Series4", data: 70},
{ label: "Series5", data: 80},
{ label: "Series6", data: 110}
];*/
/*var data = [
{ label: "Series1", data: [[1,10]]},
{ label: "Series2", data: [[1,30]]},
{ label: "Series3", data: [[1,90]]},
{ label: "Series4", data: [[1,70]]},
{ label: "Series5", data: [[1,80]]},
{ label: "Series6", data: [[1,0]]}
];*/
var data = [];
var series = Math.floor(Math.random()*10)+1;
for( var i = 0; i<series; i++)
{
data[i] = { label: "Series"+(i+1), data: Math.floor(Math.random()*100)+1 }
}
// DEFAULT
$.plot($("#default"), data,
{
series: {
pie: {
show: true
}
}
});
// GRAPH 1
$.plot($("#graph1"), data,
{
series: {
pie: {
show: true
}
},
legend: {
show: false
}
});
// GRAPH 2
$.plot($("#graph2"), data,
{
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 1,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
},
background: { opacity: 0.8 }
}
}
},
legend: {
show: false
}
});
// GRAPH 3
$.plot($("#graph3"), data,
{
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 3/4,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
},
background: { opacity: 0.5 }
}
}
},
legend: {
show: false
}
});
// GRAPH 4
$.plot($("#graph4"), data,
{
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 3/4,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
},
background: {
opacity: 0.5,
color: '#000'
}
}
}
},
legend: {
show: false
}
});
// GRAPH 5
$.plot($("#graph5"), data,
{
series: {
pie: {
show: true,
radius: 3/4,
label: {
show: true,
radius: 3/4,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
},
background: {
opacity: 0.5,
color: '#000'
}
}
}
},
legend: {
show: false
}
});
// GRAPH 6
$.plot($("#graph6"), data,
{
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 2/3,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
},
threshold: 0.1
}
}
},
legend: {
show: false
}
});
// GRAPH 7
$.plot($("#graph7"), data,
{
series: {
pie: {
show: true,
combine: {
color: '#999',
threshold: 0.1
}
}
},
legend: {
show: false
}
});
// GRAPH 8
$.plot($("#graph8"), data,
{
series: {
pie: {
show: true,
radius:300,
label: {
show: true,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
},
threshold: 0.1
}
}
},
legend: {
show: false
}
});
// GRAPH 9
$.plot($("#graph9"), data,
{
series: {
pie: {
show: true,
radius: 1,
tilt: 0.5,
label: {
show: true,
radius: 1,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
},
background: { opacity: 0.8 }
},
combine: {
color: '#999',
threshold: 0.1
}
}
},
legend: {
show: false
}
});
// DONUT
$.plot($("#donut"), data,
{
series: {
pie: {
innerRadius: 0.5,
show: true
}
}
});
// INTERACTIVE
$.plot($("#interactive"), data,
{
series: {
pie: {
show: true
}
},
grid: {
hoverable: true,
clickable: true
}
});
$("#interactive").bind("plothover", pieHover);
$("#interactive").bind("plotclick", pieClick);
});
function pieHover(event, pos, obj)
{
if (!obj)
return;
percent = parseFloat(obj.series.percent).toFixed(2);
$("#hover").html('<span style="font-weight: bold; color: '+obj.series.color+'">'+obj.series.label+' ('+percent+'%)</span>');
}
function pieClick(event, pos, obj)
{
if (!obj)
return;
percent = parseFloat(obj.series.percent).toFixed(2);
alert(''+obj.series.label+': '+percent+'%');
}
</script>
<style type="text/css">
* {
font-family: sans-serif;
}
body
{
padding: 0 1em 1em 1em;
}
div.graph
{
width: 400px;
height: 300px;
float: left;
border: 1px dashed gainsboro;
}
label
{
display: block;
margin-left: 400px;
padding-left: 1em;
}
h2
{
padding-top: 1em;
margin-bottom: 0;
clear: both;
color: #ccc;
}
code
{
display: block;
background-color: #eee;
border: 1px dashed #999;
padding: 0.5em;
margin: 0.5em;
color: #666;
font-size: 10pt;
}
code b
{
color: black;
}
ul
{
font-size: 10pt;
}
ul li
{
margin-bottom: 0.5em;
}
ul.options li
{
list-style: none;
margin-bottom: 1em;
}
ul li i
{
color: #999;
}
</style>
</head>
<body>
<h1>Flot Pie Examples</h1>
<h2>Default with Legend</h2>
<div id="default" class="graph"></div>
<label for="default">
Default pie graph with no options set.
<code>
$.plot($("#default"), data,<br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Default without Legend</h2>
<div id="graph1" class="graph"></div>
<label for="graph1">
Default pie graph when legend is disabled. Since the labels would normally be outside the container, the graph is resized to fit.
<code>
$.plot($("#graph1"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</b><br/>
});<br/>
</code>
</label>
<h2>Graph2</h2>
<div id="graph2" class="graph"></div>
<label for="graph2">
Added a semi-transparent background to the labels and a custom labelFormatter function.
<code>
$.plot($("#graph2"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 1,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>label: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 1,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter: function(label, series){<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;div style="font-size:8pt;text-align:center;padding:2px;color:white;"&gt;'+label+'&lt;br/&gt;'+Math.round(series.percent)+'%&lt;/div&gt;';<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background: { opacity: 0.8 }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Graph3</h2>
<div id="graph3" class="graph"></div>
<label for="graph3">
Slightly more transparent label backgrounds and adjusted the radius values to place them within the pie.
<code>
$.plot($("#graph3"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 1,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>radius: 3/4,</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter: function(label, series){<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;div style="font-size:8pt;text-align:center;padding:2px;color:white;"&gt;'+label+'&lt;br/&gt;'+Math.round(series.percent)+'%&lt;/div&gt;';<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>background: { opacity: 0.5 }</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Graph4</h2>
<div id="graph4" class="graph"></div>
<label for="graph4">
Semi-transparent, black-colored label background.
<code>
$.plot($("#graph4"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 1,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 3/4,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter: function(label, series){<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;div style="font-size:8pt;text-align:center;padding:2px;color:white;"&gt;'+label+'&lt;br/&gt;'+Math.round(series.percent)+'%&lt;/div&gt;';<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opacity: 0.5,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>color: '#000'</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Graph5</h2>
<div id="graph5" class="graph"></div>
<label for="graph5">
Semi-transparent, black-colored label background placed at pie edge.
<code>
$.plot($("#graph5"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>radius: 3/4,</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 3/4,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter: function(label, series){<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;div style="font-size:8pt;text-align:center;padding:2px;color:white;"&gt;'+label+'&lt;br/&gt;'+Math.round(series.percent)+'%&lt;/div&gt;';<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opacity: 0.5,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color: '#000'<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Graph6</h2>
<div id="graph6" class="graph"></div>
<label for="graph6">
Labels can be hidden if the slice is less than a given percentage of the pie (10% in this case).
<br><span style="color: red">Note: you may need to refresh the page to see this effect.</span>
<code>
$.plot($("#graph6"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>radius: 1,</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>radius: 2/3,</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter: function(label, series){<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;div style="font-size:8pt;text-align:center;padding:2px;color:white;"&gt;'+label+'&lt;br/&gt;'+Math.round(series.percent)+'%&lt;/div&gt;';<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>threshold: 0.1</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Graph7</h2>
<div id="graph7" class="graph"></div>
<label for="graph7">
All slices less than a given percentage of the pie can be combined into a single, larger slice (10% in this case).
<br><span style="color: red">Note: you may need to refresh the page to see this effect.</span>
<code>
$.plot($("#graph7"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>combine: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color: '#999',<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threshold: 0.1<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Graph8</h2>
<div id="graph8" class="graph"></div>
<label for="graph8">
The radius can also be set to a specific size (even larger than the container itself).
<code>
$.plot($("#graph8"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>radius:300,</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter: function(label, series){<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;div style="font-size:8pt;text-align:center;padding:2px;color:white;"&gt;'+label+'&lt;br/&gt;'+Math.round(series.percent)+'%&lt;/div&gt;';<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threshold: 0.1<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Graph9</h2>
<div id="graph9" class="graph" style="height: 250px;"></div>
<label for="graph9">
The pie can be tilted at an angle.
<code>
$.plot($("#graph9"), data, <br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 1,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>tilt: 0.5,</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radius: 1,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter: function(label, series){<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;div style="font-size:8pt;text-align:center;padding:2px;color:white;"&gt;'+label+'&lt;br/&gt;'+Math.round(series.percent)+'%&lt;/div&gt;';<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background: { opacity: 0.8 }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;combine: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color: '#999',<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;threshold: 0.1<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;legend: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Donut</h2>
<div id="donut" class="graph"></div>
<label for="donut">
A donut hole can be added.
<code>
$.plot($("#donut"), data,<br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>innerRadius: 0.5,</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
</code>
</label>
<h2>Interactive</h2>
<div id="interactive" class="graph"></div>
<label for="interactive">
The pie can be made interactive with hover and click events.
<code>
$.plot($("#interactive"), data,<br/>
{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pie: { <br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show: true<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>grid: {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hoverable: true,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clickable: true<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</b><br/>
});<br/>
<b>$("#interactive").bind("plothover", pieHover);<br/>
$("#interactive").bind("plotclick", pieClick);</b><br/>
</code>
<div id="hover"></div>
</label>
<h2>Pie Options</h2>
<ul class="options">
<li style="border-bottom: 1px dotted #ccc;"><b>option:</b> <i>default value</i> - Description of option</li>
<li><b>show:</b> <i>false</i> - Enable the plugin and draw as a pie.</li>
<li><b>radius:</b> <i>'auto'</i> - Sets the radius of the pie. If value is between 0 and 1 (inclusive) then it will use that as a percentage of the available space (size of the container), otherwise it will use the value as a direct pixel length. If set to 'auto', it will be set to 1 if the legend is enabled and 3/4 if not.</li>
<li><b>innerRadius:</b> <i>0</i> - Sets the radius of the donut hole. If value is between 0 and 1 (inclusive) then it will use that as a percentage of the radius, otherwise it will use the value as a direct pixel length.</li>
<li><b>startAngle:</b> <i>3/2</i> - Factor of PI used for the starting angle (in radians) It can range between 0 and 2 (where 0 and 2 have the same result).</li>
<li><b>tilt:</b> <i>1</i> - Percentage of tilt ranging from 0 and 1, where 1 has no change (fully vertical) and 0 is completely flat (fully horizontal -- in which case nothing actually gets drawn).</li>
<li><b>offset:</b> <ul>
<li><b>top:</b> <i>0</i> - Pixel distance to move the pie up and down (relative to the center).</li>
<li><b>left:</b> <i>'auto'</i> - Pixel distance to move the pie left and right (relative to the center).</li>
</ul>
<li><b>stroke:</b> <ul>
<li><b>color:</b> <i>'#FFF'</i> - Color of the border of each slice. Hexadecimal color definitions are prefered (other formats may or may not work).</li>
<li><b>width:</b> <i>1</i> - Pixel width of the border of each slice.</li>
</ul>
<li><b>label:</b> <ul>
<li><b>show:</b> <i>'auto'</i> - Enable/Disable the labels. This can be set to true, false, or 'auto'. When set to 'auto', it will be set to false if the legend is enabled and true if not.</li>
<li><b>radius:</b> <i>1</i> - Sets the radius at which to place the labels. If value is between 0 and 1 (inclusive) then it will use that as a percentage of the available space (size of the container), otherwise it will use the value as a direct pixel length.</li>
<li><b>threshold:</b> <i>0</i> - Hides the labels of any pie slice that is smaller than the specified percentage (ranging from 0 to 1) i.e. a value of '0.03' will hide all slices 3% or less of the total.</li>
<li><b>formatter:</b> <i>[function]</i> - This function specifies how the positioned labels should be formatted, and is applied after the legend's labelFormatter function. The labels can also still be styled using the class "pieLabel" (i.e. ".pieLabel" or "#graph1 .pieLabel").</li>
<li><b>radius:</b> <i>1</i> - Sets the radius at which to place the labels. If value is between 0 and 1 (inclusive) then it will use that as a percentage of the available space (size of the container), otherwise it will use the value as a direct pixel length.</li>
<li><b>background:</b> <ul>
<li><b>color:</b> <i>null</i> - Backgound color of the positioned labels. If null, the plugin will automatically use the color of the slice.</li>
<li><b>opacity:</b> <i>0</i> - Opacity of the background for the positioned labels. Acceptable values range from 0 to 1, where 0 is completely transparent and 1 is completely opaque.</li>
</ul>
</ul>
<li><b>combine:</b> <ul>
<li><b>threshold:</b> <i>0</i> - Combines all slices that are smaller than the specified percentage (ranging from 0 to 1) i.e. a value of '0.03' will combine all slices 3% or less into one slice).</li>
<li><b>color:</b> <i>null</i> - Backgound color of the positioned labels. If null, the plugin will automatically use the color of the first slice to be combined.</li>
<li><b>label:</b> <i>'Other'</i> - Label text for the combined slice.</li>
</ul>
<li><b>highlight:</b> <ul>
<li><b>opacity:</b> <i>0.5</i> - Opacity of the highlight overlay on top of the current pie slice. Currently this just uses a white overlay, but support for changing the color of the overlay will also be added at a later date.
</ul>
</ul>
<h2>Changes/Features</h2>
<ul>
<li style="list-style: none;"><i>v1.0 - November 20th, 2009 - Brian Medendorp</i></li>
<li>The pie plug-in is now part of the Flot repository! This should make it a lot easier to deal with.</li>
<li>Added a new option (innerRadius) to add a "donut hole" to the center of the pie, based on comtributions from Anthony Aragues. I was a little reluctant to add this feature because it doesn't work very well with the shadow created for the tilted pie, but figured it was worthwhile for non-tilted pies. Also, excanvas apparently doesn't support compositing, so it will fall back to using the stroke color to fill in the center (but I recommend setting the stroke color to the background color anyway).</li>
<li>Changed the lineJoin for the border of the pie slices to use the 'round' option. This should make the center of the pie look better, particularly when there are numerous thin slices.</li>
<li>Included a bug fix submitted by btburnett3 to display a slightly smaller slice in the event that the slice is 100% and being rendered with Internet Explorer. I haven't experienced this bug myself, but it doesn't seem to hurt anything so I've included it.</li>
<li>The tilt value is now used when calculating the maximum radius of the pie in relation to the height of the container. This should prevent the pie from being smaller than it needed to in some cases, as well as reducing the amount of extra white space generated above and below the pie.</li>
<li><b>Hover and Click functionality are now availabe!</b><ul>
<li>Thanks to btburnett3 for the original hover functionality and Anthony Aragues for the modification that makes it compatable with excanvas, this was a huge help!</li>
<li>Added a new option (highlight opacity) to modify the highlight created when mousing over a slice. Currently this just uses a white overlay, but an option to change the hightlight color will be added when the appropriate functionality becomes available.
<li>I had a major setback that required me to practically rebuild the hover/click events from scratch one piece at a time (I discovered that it only worked with a single pie on a page at a time), but the end result ended up being virtually identical to the original, so I'm not quite sure what exactly made it work.</li>
<li><span style="color: red;">Warning:</span> There are some minor issues with using this functionality in conjuction with some of the other more advanced features (tilt and donut). When using a donut hole, the inner portion still triggers the events even though that portion of the pie is no longer visible. When tilted, the interactive portions still use the original, untilted version of the pie when determining mouse position (this is because the isPointInPath function apparently doesn't work with transformations), however hover and click both work this way, so the appropriate slice is still highlighted when clicking, and it isn't as noticable of a problem.</li>
</ul></li>
<li>Included a bug fix submitted by Xavi Ivars to fix array issues when other javascript libraries are included in addition to jQuery</li>
<br/>
<li style="list-style: none;"><i>v0.4 - July 1st, 2009 - Brian Medendorp</i></li>
<li>Each series will now be shown in the legend, even if it's value is zero. The series will not get a positioned label because it will overlap with the other labels present and often makes them unreadable.</li>
<li>Data can now be passed in using the standard Flot method using an array of datapoints, the pie plugin will simply use the first y-value that it finds for each series in this case. The plugin uses this datastructure internally, but you can still use the old method of passing in a single numerical value for each series (the plugin will convert it as necessary). This should make it easier to transition from other types of graphs (such as a stacked bar graph) to a pie.</li>
<li>The pie can now be tilted at an angle with a new "tilt" option. Acceptable values range from 0-1, where 1 has no change (fully vertical) and 0 is completely flat (fully horizontal -- in which case nothing actually gets drawn). If the plugin determines that it will fit within the canvas, a drop shadow will be drawn under the tilted pie (this also requires a tilt value of 0.8 or less).</li>
<br/>
<li style="list-style: none;"><i>v0.3.2 - June 25th, 2009 - Brian Medendorp</i></li>
<li>Fixed a bug that was causing the pie to be shifted too far left or right when the legend is showing in some cases.</li>
<br/>
<li style="list-style: none;"><i>v0.3.1 - June 24th, 2009 - Brian Medendorp</i></li>
<li>Fixed a bug that was causing nothing to be drawn and generating a javascript error if any of the data values were set to zero.</li>
<br/>
<li style="list-style: none;"><i>v0.3 - June 23rd, 2009 - Brian Medendorp</i></li>
<li>The legend now works without any modifications! Because of changes made to flot and the plugin system (thanks Ole Laursen!) I was able to simplify a number of things and am now able to use the legend without the direct access hack that was required in the previous version.</li>
<br/>
<li style="list-style: none;"><i>v0.2 - June 22nd, 2009 - Brian Medendorp</i></li>
<li>The legend now works but only if you make the necessary changes to jquery.flot.js. Because of this, I changed the default values for pie.radius and pie.label.show to new 'auto' settings that change the default behavior of the size and labels depending on whether the legend functionality is available or not.</li>
<br/>
<li style="list-style: none;"><i>v0.1 - June 18th, 2009 - Brian Medendorp</i></li>
<li>Rewrote the entire pie code into a flot plugin (since that is now an option), so it should be much easier to use and the code is cleaned up a bit. However, the (standard flot) legend is no longer available because the only way to prevent the grid lines from being displayed also prevents the legend from being displayed. Hopefully this can be fixed at a later date.</li>
<li>Restructured and combined some of the options. It should be much easier to deal with now.</li>
<li>Added the ability to change the starting point of the pie (still defaults to the top).</li>
<li>Modified the default options to show the labels to compensate for the lack of a legend.</li>
<li>Modified this page to use a random dataset. <span style="color: red">Note: you may need to refresh the page to see the effects of some of the examples.</span></li>
<br/>
<li style="list-style: none;"><i>May 21st, 2009 - Brian Medendorp</i></li>
<li>Merged original pie modifications by Sergey Nosenko into the latest SVN version <i>(as of May 15th, 2009)</i> so that it will work with ie8.</li>
<li>Pie graph will now be centered in the canvas unless moved because of the legend or manually via the options. Additionally it prevents the pie from being moved beyond the edge of the canvas.</li>
<li>Modified the code related to the labelFormatter option to apply flot's legend labelFormatter first. This is so that the labels will be consistent, but still provide extra formatting for the positioned labels (such as adding the percentage value).</li>
<li>Positioned labels now have their backgrounds applied as a seperate element (much like the legend background) so that the opacity value can be set independently from the label itself (foreground). Additionally, the background color defaults to that of the matching slice.</li>
<li>As long as the labelOffset and radiusLimit are not set to hard values, the pie will be shrunk if the labels will extend outside the edge of the canvas</li>
<li>Added new options "radiusLimitFactor" and "radiusLimit" which limits how large the (visual) radius of the pie is in relation to the full radius (as calculated from the canvas dimensions) or a hard-pixel value (respectively). This allows for pushing the labels "outside" the pie.</li>
<li>Added a new option "labelHidePercent" that does not show the positioned labels of slices smaller than the specified percentage. This is to help prevent a bunch of overlapping labels from small slices.</li>
<li>Added a new option "sliceCombinePercent" that combines all slices smaller than the specified percentage into one larger slice. This is to help make the pie more attractive when there are a number of tiny slices. The options "sliceCombineColor" and "sliceCombineLabel" have also been added to change the color and name of the new slice if desired.</li>
<li>Tested in Firefox (3.0.10, 3.5b4), Internet Explorer (6.0.2900, 7.0.5730, 8.0.6001), Chrome (1.0.154), Opera (9.64), and Safari (3.1.1, 4 beta 5528.16).
</ul>
</body>
</html>
@@ -1,83 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>You can update a chart periodically to get a real-time effect
by using a timer to insert the new data in the plot and redraw it.</p>
<p>Time between updates: <input id="updateInterval" type="text" value="" style="text-align: right; width:5em"> milliseconds</p>
<script type="text/javascript">
$(function () {
// we use an inline data source in the example, usually data would
// be fetched from a server
var data = [], totalPoints = 300;
function getRandomData() {
if (data.length > 0)
data = data.slice(1);
// do a random walk
while (data.length < totalPoints) {
var prev = data.length > 0 ? data[data.length - 1] : 50;
var y = prev + Math.random() * 10 - 5;
if (y < 0)
y = 0;
if (y > 100)
y = 100;
data.push(y);
}
// zip the generated y values with the x values
var res = [];
for (var i = 0; i < data.length; ++i)
res.push([i, data[i]])
return res;
}
// setup control widget
var updateInterval = 30;
$("#updateInterval").val(updateInterval).change(function () {
var v = $(this).val();
if (v && !isNaN(+v)) {
updateInterval = +v;
if (updateInterval < 1)
updateInterval = 1;
if (updateInterval > 2000)
updateInterval = 2000;
$(this).val("" + updateInterval);
}
});
// setup plot
var options = {
series: { shadowSize: 0 }, // drawing is faster without shadows
yaxis: { min: 0, max: 100 },
xaxis: { show: false }
};
var plot = $.plot($("#placeholder"), [ getRandomData() ], options);
function update() {
plot.setData([ getRandomData() ]);
// since the axes don't change, we don't need to call plot.setupGrid()
plot.draw();
setTimeout(update, updateInterval);
}
update();
});
</script>
</body>
</html>
@@ -1,61 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.resize.js"></script>
<style type="text/css">
html, body {
height: 100%; /* make the percentage height on placeholder work */
}
.message {
padding-left: 50px;
font-size: smaller;
}
</style>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:80%;height:40%;"></div>
<p class="message"></p>
<p>Sometimes it makes more sense to just let the plot take up the
available space. In that case, we need to redraw the plot each
time the placeholder changes its size. If you include the resize
plugin, this is handled automatically.</p>
<p>Try resizing the window.</p>
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
var placeholder = $("#placeholder");
var plot = $.plot(placeholder, [d1, d2, d3]);
// the plugin includes a jQuery plugin for adding resize events to
// any element, let's just add a callback so we can display the
// placeholder size
placeholder.resize(function () {
$(".message").text("Placeholder is now "
+ $(this).width() + "x" + $(this).height()
+ " pixels");
});
});
</script>
</body>
</html>
@@ -1,114 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.selection.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px"></div>
<p>1000 kg. CO<sub>2</sub> emissions per year per capita for various countries (source: <a href="http://en.wikipedia.org/wiki/List_of_countries_by_carbon_dioxide_emissions_per_capita">Wikipedia</a>).</p>
<p>Flot supports selections through the selection plugin.
You can enable rectangular selection
or one-dimensional selection if the user should only be able to
select on one axis. Try left-click and drag on the plot above
where selection on the x axis is enabled.</p>
<p>You selected: <span id="selection"></span></p>
<p>The plot command returns a plot object you can use to control
the selection. Click the buttons below.</p>
<p><input id="clearSelection" type="button" value="Clear selection" />
<input id="setSelection" type="button" value="Select year 1994" /></p>
<p>Selections are really useful for zooming. Just replot the
chart with min and max values for the axes set to the values
in the "plotselected" event triggered. Enable the checkbox
below and select a region again.</p>
<p><label><input id="zoom" type="checkbox" />Zoom to selection.</label></p>
<script type="text/javascript">
$(function () {
var data = [
{
label: "United States",
data: [[1990, 18.9], [1991, 18.7], [1992, 18.4], [1993, 19.3], [1994, 19.5], [1995, 19.3], [1996, 19.4], [1997, 20.2], [1998, 19.8], [1999, 19.9], [2000, 20.4], [2001, 20.1], [2002, 20.0], [2003, 19.8], [2004, 20.4]]
},
{
label: "Russia",
data: [[1992, 13.4], [1993, 12.2], [1994, 10.6], [1995, 10.2], [1996, 10.1], [1997, 9.7], [1998, 9.5], [1999, 9.7], [2000, 9.9], [2001, 9.9], [2002, 9.9], [2003, 10.3], [2004, 10.5]]
},
{
label: "United Kingdom",
data: [[1990, 10.0], [1991, 11.3], [1992, 9.9], [1993, 9.6], [1994, 9.5], [1995, 9.5], [1996, 9.9], [1997, 9.3], [1998, 9.2], [1999, 9.2], [2000, 9.5], [2001, 9.6], [2002, 9.3], [2003, 9.4], [2004, 9.79]]
},
{
label: "Germany",
data: [[1990, 12.4], [1991, 11.2], [1992, 10.8], [1993, 10.5], [1994, 10.4], [1995, 10.2], [1996, 10.5], [1997, 10.2], [1998, 10.1], [1999, 9.6], [2000, 9.7], [2001, 10.0], [2002, 9.7], [2003, 9.8], [2004, 9.79]]
},
{
label: "Denmark",
data: [[1990, 9.7], [1991, 12.1], [1992, 10.3], [1993, 11.3], [1994, 11.7], [1995, 10.6], [1996, 12.8], [1997, 10.8], [1998, 10.3], [1999, 9.4], [2000, 8.7], [2001, 9.0], [2002, 8.9], [2003, 10.1], [2004, 9.80]]
},
{
label: "Sweden",
data: [[1990, 5.8], [1991, 6.0], [1992, 5.9], [1993, 5.5], [1994, 5.7], [1995, 5.3], [1996, 6.1], [1997, 5.4], [1998, 5.4], [1999, 5.1], [2000, 5.2], [2001, 5.4], [2002, 6.2], [2003, 5.9], [2004, 5.89]]
},
{
label: "Norway",
data: [[1990, 8.3], [1991, 8.3], [1992, 7.8], [1993, 8.3], [1994, 8.4], [1995, 5.9], [1996, 6.4], [1997, 6.7], [1998, 6.9], [1999, 7.6], [2000, 7.4], [2001, 8.1], [2002, 12.5], [2003, 9.9], [2004, 19.0]]
}
];
var options = {
series: {
lines: { show: true },
points: { show: true }
},
legend: { noColumns: 2 },
xaxis: { tickDecimals: 0 },
yaxis: { min: 0 },
selection: { mode: "x" }
};
var placeholder = $("#placeholder");
placeholder.bind("plotselected", function (event, ranges) {
$("#selection").text(ranges.xaxis.from.toFixed(1) + " to " + ranges.xaxis.to.toFixed(1));
var zoom = $("#zoom").attr("checked");
if (zoom)
plot = $.plot(placeholder, data,
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
}));
});
placeholder.bind("plotunselected", function (event) {
$("#selection").text("");
});
var plot = $.plot(placeholder, data, options);
$("#clearSelection").click(function () {
plot.clearSelection();
});
$("#setSelection").click(function () {
plot.setSelection({ xaxis: { from: 1994, to: 1995 } });
});
});
</script>
</body>
</html>
@@ -1,61 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px"></div>
<p>There are plenty of options you can set to control the precise
looks of your plot. You can control the ticks on the axes, the
legend, the graph type, etc. The idea is that Flot goes to great
lengths to provide sensible defaults so that you don't have to
customize much for a good result.</p>
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i < Math.PI * 2; i += 0.25)
d1.push([i, Math.sin(i)]);
var d2 = [];
for (var i = 0; i < Math.PI * 2; i += 0.25)
d2.push([i, Math.cos(i)]);
var d3 = [];
for (var i = 0; i < Math.PI * 2; i += 0.1)
d3.push([i, Math.tan(i)]);
$.plot($("#placeholder"), [
{ label: "sin(x)", data: d1},
{ label: "cos(x)", data: d2},
{ label: "tan(x)", data: d3}
], {
series: {
lines: { show: true },
points: { show: true }
},
xaxis: {
ticks: [0, [Math.PI/2, "\u03c0/2"], [Math.PI, "\u03c0"], [Math.PI * 3/2, "3\u03c0/2"], [Math.PI * 2, "2\u03c0"]]
},
yaxis: {
ticks: 10,
min: -2,
max: 2
},
grid: {
backgroundColor: { colors: ["#fff", "#eee"] }
}
});
});
</script>
</body>
</html>
@@ -1,77 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.stack.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>With the stack plugin, you can have Flot stack the
series. This is useful if you wish to display both a total and the
constituents it is made of. The only requirement is that you provide
the input sorted on x.</p>
<p class="stackControls">
<input type="button" value="With stacking">
<input type="button" value="Without stacking">
</p>
<p class="graphControls">
<input type="button" value="Bars">
<input type="button" value="Lines">
<input type="button" value="Lines with steps">
</p>
<script id="source">
$(function () {
var d1 = [];
for (var i = 0; i <= 10; i += 1)
d1.push([i, parseInt(Math.random() * 30)]);
var d2 = [];
for (var i = 0; i <= 10; i += 1)
d2.push([i, parseInt(Math.random() * 30)]);
var d3 = [];
for (var i = 0; i <= 10; i += 1)
d3.push([i, parseInt(Math.random() * 30)]);
var stack = 0, bars = true, lines = false, steps = false;
function plotWithOptions() {
$.plot($("#placeholder"), [ d1, d2, d3 ], {
series: {
stack: stack,
lines: { show: lines, fill: true, steps: steps },
bars: { show: bars, barWidth: 0.6 }
}
});
}
plotWithOptions();
$(".stackControls input").click(function (e) {
e.preventDefault();
stack = $(this).val() == "With stacking" ? true : null;
plotWithOptions();
});
$(".graphControls input").click(function (e) {
e.preventDefault();
bars = $(this).val().indexOf("Bars") != -1;
lines = $(this).val().indexOf("Lines") != -1;
steps = $(this).val().indexOf("steps") != -1;
plotWithOptions();
});
});
</script>
</body>
</html>
@@ -1,49 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.symbol.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px"></div>
<p>Various point types. Circles are built-in. For other
point types, you can define a little callback function to draw the
symbol; some common ones are available in the symbol plugin.</p>
<script type="text/javascript">
$(function () {
function generate(offset, amplitude) {
var res = [];
var start = 0, end = 10;
for (var i = 0; i <= 50; ++i) {
var x = start + i / 50 * (end - start);
res.push([x, amplitude * Math.sin(x + offset)]);
}
return res;
}
var data = [
{ data: generate(2, 1.8), points: { symbol: "circle" } },
{ data: generate(3, 1.5), points: { symbol: "square" } },
{ data: generate(4, 0.9), points: { symbol: "diamond" } },
{ data: generate(6, 1.4), points: { symbol: "triangle" } },
{ data: generate(7, 1.1), points: { symbol: "cross" } }
];
$.plot($("#placeholder"), data, {
series: { points: { show: true, radius: 3 } },
grid: { hoverable: true }
});
});
</script>
</body>
</html>
@@ -1,54 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.threshold.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>With the threshold plugin, you can apply a specific color to
the part of a data series below a threshold. This is can be useful
for highlighting negative values, e.g. when displaying net results
or what's in stock.</p>
<p class="controls">
<input type="button" value="Threshold at 5">
<input type="button" value="Threshold at 0">
<input type="button" value="Threshold at -2.5">
</p>
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i <= 60; i += 1)
d1.push([i, parseInt(Math.random() * 30 - 10)]);
function plotWithOptions(t) {
$.plot($("#placeholder"), [ {
data: d1,
color: "rgb(30, 180, 20)",
threshold: { below: t, color: "rgb(200, 20, 30)" },
lines: { steps: true }
} ]);
}
plotWithOptions(0);
$(".controls input").click(function (e) {
e.preventDefault();
var t = parseFloat($(this).val().replace('Threshold at ', ''));
plotWithOptions(t);
});
});
</script>
</body>
</html>
File diff suppressed because one or more lines are too long
@@ -1,95 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.crosshair.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px"></div>
<p>You can add crosshairs that'll track the mouse position, either
on both axes or as here on only one.</p>
<p>If you combine it with listening on hover events, you can use
it to track the intersection on the curves by interpolating
the data points (look at the legend).</p>
<p id="hoverdata"></p>
<script type="text/javascript">
var plot;
$(function () {
var sin = [], cos = [];
for (var i = 0; i < 14; i += 0.1) {
sin.push([i, Math.sin(i)]);
cos.push([i, Math.cos(i)]);
}
plot = $.plot($("#placeholder"),
[ { data: sin, label: "sin(x) = -0.00"},
{ data: cos, label: "cos(x) = -0.00" } ], {
series: {
lines: { show: true }
},
crosshair: { mode: "x" },
grid: { hoverable: true, autoHighlight: false },
yaxis: { min: -1.2, max: 1.2 }
});
var legends = $("#placeholder .legendLabel");
legends.each(function () {
// fix the widths so they don't jump around
$(this).css('width', $(this).width());
});
var updateLegendTimeout = null;
var latestPosition = null;
function updateLegend() {
updateLegendTimeout = null;
var pos = latestPosition;
var axes = plot.getAxes();
if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max ||
pos.y < axes.yaxis.min || pos.y > axes.yaxis.max)
return;
var i, j, dataset = plot.getData();
for (i = 0; i < dataset.length; ++i) {
var series = dataset[i];
// find the nearest points, x-wise
for (j = 0; j < series.data.length; ++j)
if (series.data[j][0] > pos.x)
break;
// now interpolate
var y, p1 = series.data[j - 1], p2 = series.data[j];
if (p1 == null)
y = p2[1];
else if (p2 == null)
y = p1[1];
else
y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);
legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(2)));
}
}
$("#placeholder").bind("plothover", function (event, pos, item) {
latestPosition = pos;
if (!updateLegendTimeout)
updateLegendTimeout = setTimeout(updateLegend, 50);
});
});
</script>
</body>
</html>
@@ -1,98 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>Here is an example with real data: military budgets for
various countries in constant (2005) million US dollars (source: <a href="http://www.sipri.org/">SIPRI</a>).</p>
<p>Since all data is available client-side, it's pretty easy to
make the plot interactive. Try turning countries on/off with the
checkboxes below.</p>
<p id="choices">Show:</p>
<script type="text/javascript">
$(function () {
var datasets = {
"usa": {
label: "USA",
data: [[1988, 483994], [1989, 479060], [1990, 457648], [1991, 401949], [1992, 424705], [1993, 402375], [1994, 377867], [1995, 357382], [1996, 337946], [1997, 336185], [1998, 328611], [1999, 329421], [2000, 342172], [2001, 344932], [2002, 387303], [2003, 440813], [2004, 480451], [2005, 504638], [2006, 528692]]
},
"russia": {
label: "Russia",
data: [[1988, 218000], [1989, 203000], [1990, 171000], [1992, 42500], [1993, 37600], [1994, 36600], [1995, 21700], [1996, 19200], [1997, 21300], [1998, 13600], [1999, 14000], [2000, 19100], [2001, 21300], [2002, 23600], [2003, 25100], [2004, 26100], [2005, 31100], [2006, 34700]]
},
"uk": {
label: "UK",
data: [[1988, 62982], [1989, 62027], [1990, 60696], [1991, 62348], [1992, 58560], [1993, 56393], [1994, 54579], [1995, 50818], [1996, 50554], [1997, 48276], [1998, 47691], [1999, 47529], [2000, 47778], [2001, 48760], [2002, 50949], [2003, 57452], [2004, 60234], [2005, 60076], [2006, 59213]]
},
"germany": {
label: "Germany",
data: [[1988, 55627], [1989, 55475], [1990, 58464], [1991, 55134], [1992, 52436], [1993, 47139], [1994, 43962], [1995, 43238], [1996, 42395], [1997, 40854], [1998, 40993], [1999, 41822], [2000, 41147], [2001, 40474], [2002, 40604], [2003, 40044], [2004, 38816], [2005, 38060], [2006, 36984]]
},
"denmark": {
label: "Denmark",
data: [[1988, 3813], [1989, 3719], [1990, 3722], [1991, 3789], [1992, 3720], [1993, 3730], [1994, 3636], [1995, 3598], [1996, 3610], [1997, 3655], [1998, 3695], [1999, 3673], [2000, 3553], [2001, 3774], [2002, 3728], [2003, 3618], [2004, 3638], [2005, 3467], [2006, 3770]]
},
"sweden": {
label: "Sweden",
data: [[1988, 6402], [1989, 6474], [1990, 6605], [1991, 6209], [1992, 6035], [1993, 6020], [1994, 6000], [1995, 6018], [1996, 3958], [1997, 5780], [1998, 5954], [1999, 6178], [2000, 6411], [2001, 5993], [2002, 5833], [2003, 5791], [2004, 5450], [2005, 5521], [2006, 5271]]
},
"norway": {
label: "Norway",
data: [[1988, 4382], [1989, 4498], [1990, 4535], [1991, 4398], [1992, 4766], [1993, 4441], [1994, 4670], [1995, 4217], [1996, 4275], [1997, 4203], [1998, 4482], [1999, 4506], [2000, 4358], [2001, 4385], [2002, 5269], [2003, 5066], [2004, 5194], [2005, 4887], [2006, 4891]]
}
};
// hard-code color indices to prevent them from shifting as
// countries are turned on/off
var i = 0;
$.each(datasets, function(key, val) {
val.color = i;
++i;
});
// insert checkboxes
var choiceContainer = $("#choices");
$.each(datasets, function(key, val) {
choiceContainer.append('<br/><input type="checkbox" name="' + key +
'" checked="checked" id="id' + key + '">' +
'<label for="id' + key + '">'
+ val.label + '</label>');
});
choiceContainer.find("input").click(plotAccordingToChoices);
function plotAccordingToChoices() {
var data = [];
choiceContainer.find("input:checked").each(function () {
var key = $(this).attr("name");
if (key && datasets[key])
data.push(datasets[key]);
});
if (data.length > 0)
$.plot($("#placeholder"), data, {
yaxis: { min: 0 },
xaxis: { tickDecimals: 0 }
});
}
plotAccordingToChoices();
});
</script>
</body>
</html>
@@ -1,90 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.selection.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width:600px;height:300px;"></div>
<p>Visitors per day to the Flot homepage. Weekends are colored. Try zooming.
The plot below shows an overview.</p>
<div id="overview" style="margin-left:50px;margin-top:20px;width:400px;height:50px"></div>
<script id="source">
$(function () {
var d = [[1196463600000, 0], [1196550000000, 0], [1196636400000, 0], [1196722800000, 77], [1196809200000, 3636], [1196895600000, 3575], [1196982000000, 2736], [1197068400000, 1086], [1197154800000, 676], [1197241200000, 1205], [1197327600000, 906], [1197414000000, 710], [1197500400000, 639], [1197586800000, 540], [1197673200000, 435], [1197759600000, 301], [1197846000000, 575], [1197932400000, 481], [1198018800000, 591], [1198105200000, 608], [1198191600000, 459], [1198278000000, 234], [1198364400000, 1352], [1198450800000, 686], [1198537200000, 279], [1198623600000, 449], [1198710000000, 468], [1198796400000, 392], [1198882800000, 282], [1198969200000, 208], [1199055600000, 229], [1199142000000, 177], [1199228400000, 374], [1199314800000, 436], [1199401200000, 404], [1199487600000, 253], [1199574000000, 218], [1199660400000, 476], [1199746800000, 462], [1199833200000, 448], [1199919600000, 442], [1200006000000, 403], [1200092400000, 204], [1200178800000, 194], [1200265200000, 327], [1200351600000, 374], [1200438000000, 507], [1200524400000, 546], [1200610800000, 482], [1200697200000, 283], [1200783600000, 221], [1200870000000, 483], [1200956400000, 523], [1201042800000, 528], [1201129200000, 483], [1201215600000, 452], [1201302000000, 270], [1201388400000, 222], [1201474800000, 439], [1201561200000, 559], [1201647600000, 521], [1201734000000, 477], [1201820400000, 442], [1201906800000, 252], [1201993200000, 236], [1202079600000, 525], [1202166000000, 477], [1202252400000, 386], [1202338800000, 409], [1202425200000, 408], [1202511600000, 237], [1202598000000, 193], [1202684400000, 357], [1202770800000, 414], [1202857200000, 393], [1202943600000, 353], [1203030000000, 364], [1203116400000, 215], [1203202800000, 214], [1203289200000, 356], [1203375600000, 399], [1203462000000, 334], [1203548400000, 348], [1203634800000, 243], [1203721200000, 126], [1203807600000, 157], [1203894000000, 288]];
// first correct the timestamps - they are recorded as the daily
// midnights in UTC+0100, but Flot always displays dates in UTC
// so we have to add one hour to hit the midnights in the plot
for (var i = 0; i < d.length; ++i)
d[i][0] += 60 * 60 * 1000;
// helper for returning the weekends in a period
function weekendAreas(axes) {
var markings = [];
var d = new Date(axes.xaxis.min);
// go to the first Saturday
d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
d.setUTCSeconds(0);
d.setUTCMinutes(0);
d.setUTCHours(0);
var i = d.getTime();
do {
// when we don't set yaxis, the rectangle automatically
// extends to infinity upwards and downwards
markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
i += 7 * 24 * 60 * 60 * 1000;
} while (i < axes.xaxis.max);
return markings;
}
var options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" },
grid: { markings: weekendAreas }
};
var plot = $.plot($("#placeholder"), [d], options);
var overview = $.plot($("#overview"), [d], {
series: {
lines: { show: true, lineWidth: 1 },
shadowSize: 0
},
xaxis: { ticks: [], mode: "time" },
yaxis: { ticks: [], min: 0, autoscaleMargin: 0.1 },
selection: { mode: "x" }
});
// now connect the two
$("#placeholder").bind("plotselected", function (event, ranges) {
// do the zooming
plot = $.plot($("#placeholder"), [d],
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
}));
// don't fire event on the overview to prevent eternal loop
overview.setSelection(ranges, true);
});
$("#overview").bind("plotselected", function (event, ranges) {
plot.setSelection(ranges);
});
});
</script>
</body>
</html>
@@ -1,98 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.selection.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
<div style="float:left">
<div id="placeholder" style="width:500px;height:300px"></div>
</div>
<div id="miniature" style="float:left;margin-left:20px">
<div id="overview" style="width:166px;height:100px"></div>
<p id="overviewLegend" style="margin-left:10px"></p>
</div>
<p style="clear:left">The selection support makes it easy to
construct flexible zooming schemes. With a few lines of code, the
small overview plot to the right has been connected to the large
plot. Try selecting a rectangle on either of them.</p>
<script id="source">
$(function () {
// setup plot
function getData(x1, x2) {
var d = [];
for (var i = 0; i <= 100; ++i) {
var x = x1 + i * (x2 - x1) / 100;
d.push([x, Math.sin(x * Math.sin(x))]);
}
return [
{ label: "sin(x sin(x))", data: d }
];
}
var options = {
legend: { show: false },
series: {
lines: { show: true },
points: { show: true }
},
yaxis: { ticks: 10 },
selection: { mode: "xy" }
};
var startData = getData(0, 3 * Math.PI);
var plot = $.plot($("#placeholder"), startData, options);
// setup overview
var overview = $.plot($("#overview"), startData, {
legend: { show: true, container: $("#overviewLegend") },
series: {
lines: { show: true, lineWidth: 1 },
shadowSize: 0
},
xaxis: { ticks: 4 },
yaxis: { ticks: 3, min: -2, max: 2 },
grid: { color: "#999" },
selection: { mode: "xy" }
});
// now connect the two
$("#placeholder").bind("plotselected", function (event, ranges) {
// clamp the zooming to prevent eternal zoom
if (ranges.xaxis.to - ranges.xaxis.from < 0.00001)
ranges.xaxis.to = ranges.xaxis.from + 0.00001;
if (ranges.yaxis.to - ranges.yaxis.from < 0.00001)
ranges.yaxis.to = ranges.yaxis.from + 0.00001;
// do the zooming
plot = $.plot($("#placeholder"), getData(ranges.xaxis.from, ranges.xaxis.to),
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
}));
// don't fire event on the overview to prevent eternal loop
overview.setSelection(ranges, true);
});
$("#overview").bind("plotselected", function (event, ranges) {
plot.setSelection(ranges);
});
});
</script>
</body>
</html>
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -1,179 +0,0 @@
/* Plugin for jQuery for working with colors.
*
* Version 1.1.
*
* Inspiration from jQuery color animation plugin by John Resig.
*
* Released under the MIT license by Ole Laursen, October 2009.
*
* Examples:
*
* $.color.parse("#fff").scale('rgb', 0.25).add('a', -0.5).toString()
* var c = $.color.extract($("#mydiv"), 'background-color');
* console.log(c.r, c.g, c.b, c.a);
* $.color.make(100, 50, 25, 0.4).toString() // returns "rgba(100,50,25,0.4)"
*
* Note that .scale() and .add() return the same modified object
* instead of making a new one.
*
* V. 1.1: Fix error handling so e.g. parsing an empty string does
* produce a color rather than just crashing.
*/
(function($) {
$.color = {};
// construct color object with some convenient chainable helpers
$.color.make = function (r, g, b, a) {
var o = {};
o.r = r || 0;
o.g = g || 0;
o.b = b || 0;
o.a = a != null ? a : 1;
o.add = function (c, d) {
for (var i = 0; i < c.length; ++i)
o[c.charAt(i)] += d;
return o.normalize();
};
o.scale = function (c, f) {
for (var i = 0; i < c.length; ++i)
o[c.charAt(i)] *= f;
return o.normalize();
};
o.toString = function () {
if (o.a >= 1.0) {
return "rgb("+[o.r, o.g, o.b].join(",")+")";
} else {
return "rgba("+[o.r, o.g, o.b, o.a].join(",")+")";
}
};
o.normalize = function () {
function clamp(min, value, max) {
return value < min ? min: (value > max ? max: value);
}
o.r = clamp(0, parseInt(o.r), 255);
o.g = clamp(0, parseInt(o.g), 255);
o.b = clamp(0, parseInt(o.b), 255);
o.a = clamp(0, o.a, 1);
return o;
};
o.clone = function () {
return $.color.make(o.r, o.b, o.g, o.a);
};
return o.normalize();
}
// extract CSS color property from element, going up in the DOM
// if it's "transparent"
$.color.extract = function (elem, css) {
var c;
do {
c = elem.css(css).toLowerCase();
// keep going until we find an element that has color, or
// we hit the body
if (c != '' && c != 'transparent')
break;
elem = elem.parent();
} while (!$.nodeName(elem.get(0), "body"));
// catch Safari's way of signalling transparent
if (c == "rgba(0, 0, 0, 0)")
c = "transparent";
return $.color.parse(c);
}
// parse CSS color string (like "rgb(10, 32, 43)" or "#fff"),
// returns color object, if parsing failed, you get black (0, 0,
// 0) out
$.color.parse = function (str) {
var res, m = $.color.make;
// Look for rgb(num,num,num)
if (res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(str))
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10));
// Look for rgba(num,num,num,num)
if (res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10), parseFloat(res[4]));
// Look for rgb(num%,num%,num%)
if (res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(str))
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55);
// Look for rgba(num%,num%,num%,num)
if (res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55, parseFloat(res[4]));
// Look for #a0b1c2
if (res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(str))
return m(parseInt(res[1], 16), parseInt(res[2], 16), parseInt(res[3], 16));
// Look for #fff
if (res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(str))
return m(parseInt(res[1]+res[1], 16), parseInt(res[2]+res[2], 16), parseInt(res[3]+res[3], 16));
// Otherwise, we're most likely dealing with a named color
var name = $.trim(str).toLowerCase();
if (name == "transparent")
return m(255, 255, 255, 0);
else {
// default to black
res = lookupColors[name] || [0, 0, 0];
return m(res[0], res[1], res[2]);
}
}
var lookupColors = {
aqua:[0,255,255],
azure:[240,255,255],
beige:[245,245,220],
black:[0,0,0],
blue:[0,0,255],
brown:[165,42,42],
cyan:[0,255,255],
darkblue:[0,0,139],
darkcyan:[0,139,139],
darkgrey:[169,169,169],
darkgreen:[0,100,0],
darkkhaki:[189,183,107],
darkmagenta:[139,0,139],
darkolivegreen:[85,107,47],
darkorange:[255,140,0],
darkorchid:[153,50,204],
darkred:[139,0,0],
darksalmon:[233,150,122],
darkviolet:[148,0,211],
fuchsia:[255,0,255],
gold:[255,215,0],
green:[0,128,0],
indigo:[75,0,130],
khaki:[240,230,140],
lightblue:[173,216,230],
lightcyan:[224,255,255],
lightgreen:[144,238,144],
lightgrey:[211,211,211],
lightpink:[255,182,193],
lightyellow:[255,255,224],
lime:[0,255,0],
magenta:[255,0,255],
maroon:[128,0,0],
navy:[0,0,128],
olive:[128,128,0],
orange:[255,165,0],
pink:[255,192,203],
purple:[128,0,128],
violet:[128,0,128],
red:[255,0,0],
silver:[192,192,192],
white:[255,255,255],
yellow:[255,255,0]
};
})(jQuery);
@@ -1 +0,0 @@
(function(b){b.color={};b.color.make=function(f,e,c,d){var h={};h.r=f||0;h.g=e||0;h.b=c||0;h.a=d!=null?d:1;h.add=function(k,j){for(var g=0;g<k.length;++g){h[k.charAt(g)]+=j}return h.normalize()};h.scale=function(k,j){for(var g=0;g<k.length;++g){h[k.charAt(g)]*=j}return h.normalize()};h.toString=function(){if(h.a>=1){return"rgb("+[h.r,h.g,h.b].join(",")+")"}else{return"rgba("+[h.r,h.g,h.b,h.a].join(",")+")"}};h.normalize=function(){function g(j,k,i){return k<j?j:(k>i?i:k)}h.r=g(0,parseInt(h.r),255);h.g=g(0,parseInt(h.g),255);h.b=g(0,parseInt(h.b),255);h.a=g(0,h.a,1);return h};h.clone=function(){return b.color.make(h.r,h.b,h.g,h.a)};return h.normalize()};b.color.extract=function(e,d){var f;do{f=e.css(d).toLowerCase();if(f!=""&&f!="transparent"){break}e=e.parent()}while(!b.nodeName(e.get(0),"body"));if(f=="rgba(0, 0, 0, 0)"){f="transparent"}return b.color.parse(f)};b.color.parse=function(f){var e,c=b.color.make;if(e=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(f)){return c(parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3],10))}if(e=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(f)){return c(parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3],10),parseFloat(e[4]))}if(e=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(f)){return c(parseFloat(e[1])*2.55,parseFloat(e[2])*2.55,parseFloat(e[3])*2.55)}if(e=/rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(f)){return c(parseFloat(e[1])*2.55,parseFloat(e[2])*2.55,parseFloat(e[3])*2.55,parseFloat(e[4]))}if(e=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(f)){return c(parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16))}if(e=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(f)){return c(parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16),parseInt(e[3]+e[3],16))}var d=b.trim(f).toLowerCase();if(d=="transparent"){return c(255,255,255,0)}else{e=a[d]||[0,0,0];return c(e[0],e[1],e[2])}};var a={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);
@@ -1,167 +0,0 @@
/*
Flot plugin for showing crosshairs, thin lines, when the mouse hovers
over the plot.
crosshair: {
mode: null or "x" or "y" or "xy"
color: color
lineWidth: number
}
Set the mode to one of "x", "y" or "xy". The "x" mode enables a
vertical crosshair that lets you trace the values on the x axis, "y"
enables a horizontal crosshair and "xy" enables them both. "color" is
the color of the crosshair (default is "rgba(170, 0, 0, 0.80)"),
"lineWidth" is the width of the drawn lines (default is 1).
The plugin also adds four public methods:
- setCrosshair(pos)
Set the position of the crosshair. Note that this is cleared if
the user moves the mouse. "pos" is in coordinates of the plot and
should be on the form { x: xpos, y: ypos } (you can use x2/x3/...
if you're using multiple axes), which is coincidentally the same
format as what you get from a "plothover" event. If "pos" is null,
the crosshair is cleared.
- clearCrosshair()
Clear the crosshair.
- lockCrosshair(pos)
Cause the crosshair to lock to the current location, no longer
updating if the user moves the mouse. Optionally supply a position
(passed on to setCrosshair()) to move it to.
Example usage:
var myFlot = $.plot( $("#graph"), ..., { crosshair: { mode: "x" } } };
$("#graph").bind("plothover", function (evt, position, item) {
if (item) {
// Lock the crosshair to the data point being hovered
myFlot.lockCrosshair({ x: item.datapoint[0], y: item.datapoint[1] });
}
else {
// Return normal crosshair operation
myFlot.unlockCrosshair();
}
});
- unlockCrosshair()
Free the crosshair to move again after locking it.
*/
(function ($) {
var options = {
crosshair: {
mode: null, // one of null, "x", "y" or "xy",
color: "rgba(170, 0, 0, 0.80)",
lineWidth: 1
}
};
function init(plot) {
// position of crosshair in pixels
var crosshair = { x: -1, y: -1, locked: false };
plot.setCrosshair = function setCrosshair(pos) {
if (!pos)
crosshair.x = -1;
else {
var o = plot.p2c(pos);
crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
}
plot.triggerRedrawOverlay();
};
plot.clearCrosshair = plot.setCrosshair; // passes null for pos
plot.lockCrosshair = function lockCrosshair(pos) {
if (pos)
plot.setCrosshair(pos);
crosshair.locked = true;
}
plot.unlockCrosshair = function unlockCrosshair() {
crosshair.locked = false;
}
function onMouseOut(e) {
if (crosshair.locked)
return;
if (crosshair.x != -1) {
crosshair.x = -1;
plot.triggerRedrawOverlay();
}
}
function onMouseMove(e) {
if (crosshair.locked)
return;
if (plot.getSelection && plot.getSelection()) {
crosshair.x = -1; // hide the crosshair while selecting
return;
}
var offset = plot.offset();
crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
plot.triggerRedrawOverlay();
}
plot.hooks.bindEvents.push(function (plot, eventHolder) {
if (!plot.getOptions().crosshair.mode)
return;
eventHolder.mouseout(onMouseOut);
eventHolder.mousemove(onMouseMove);
});
plot.hooks.drawOverlay.push(function (plot, ctx) {
var c = plot.getOptions().crosshair;
if (!c.mode)
return;
var plotOffset = plot.getPlotOffset();
ctx.save();
ctx.translate(plotOffset.left, plotOffset.top);
if (crosshair.x != -1) {
ctx.strokeStyle = c.color;
ctx.lineWidth = c.lineWidth;
ctx.lineJoin = "round";
ctx.beginPath();
if (c.mode.indexOf("x") != -1) {
ctx.moveTo(crosshair.x, 0);
ctx.lineTo(crosshair.x, plot.height());
}
if (c.mode.indexOf("y") != -1) {
ctx.moveTo(0, crosshair.y);
ctx.lineTo(plot.width(), crosshair.y);
}
ctx.stroke();
}
ctx.restore();
});
plot.hooks.shutdown.push(function (plot, eventHolder) {
eventHolder.unbind("mouseout", onMouseOut);
eventHolder.unbind("mousemove", onMouseMove);
});
}
$.plot.plugins.push({
init: init,
options: options,
name: 'crosshair',
version: '1.0'
});
})(jQuery);
@@ -1 +0,0 @@
(function(b){var a={crosshair:{mode:null,color:"rgba(170, 0, 0, 0.80)",lineWidth:1}};function c(h){var j={x:-1,y:-1,locked:false};h.setCrosshair=function e(l){if(!l){j.x=-1}else{var k=h.p2c(l);j.x=Math.max(0,Math.min(k.left,h.width()));j.y=Math.max(0,Math.min(k.top,h.height()))}h.triggerRedrawOverlay()};h.clearCrosshair=h.setCrosshair;h.lockCrosshair=function f(k){if(k){h.setCrosshair(k)}j.locked=true};h.unlockCrosshair=function g(){j.locked=false};function d(k){if(j.locked){return}if(j.x!=-1){j.x=-1;h.triggerRedrawOverlay()}}function i(k){if(j.locked){return}if(h.getSelection&&h.getSelection()){j.x=-1;return}var l=h.offset();j.x=Math.max(0,Math.min(k.pageX-l.left,h.width()));j.y=Math.max(0,Math.min(k.pageY-l.top,h.height()));h.triggerRedrawOverlay()}h.hooks.bindEvents.push(function(l,k){if(!l.getOptions().crosshair.mode){return}k.mouseout(d);k.mousemove(i)});h.hooks.drawOverlay.push(function(m,k){var n=m.getOptions().crosshair;if(!n.mode){return}var l=m.getPlotOffset();k.save();k.translate(l.left,l.top);if(j.x!=-1){k.strokeStyle=n.color;k.lineWidth=n.lineWidth;k.lineJoin="round";k.beginPath();if(n.mode.indexOf("x")!=-1){k.moveTo(j.x,0);k.lineTo(j.x,m.height())}if(n.mode.indexOf("y")!=-1){k.moveTo(0,j.y);k.lineTo(m.width(),j.y)}k.stroke()}k.restore()});h.hooks.shutdown.push(function(l,k){k.unbind("mouseout",d);k.unbind("mousemove",i)})}b.plot.plugins.push({init:c,options:a,name:"crosshair",version:"1.0"})})(jQuery);
@@ -1,183 +0,0 @@
/*
Flot plugin for computing bottoms for filled line and bar charts.
The case: you've got two series that you want to fill the area
between. In Flot terms, you need to use one as the fill bottom of the
other. You can specify the bottom of each data point as the third
coordinate manually, or you can use this plugin to compute it for you.
In order to name the other series, you need to give it an id, like this
var dataset = [
{ data: [ ... ], id: "foo" } , // use default bottom
{ data: [ ... ], fillBetween: "foo" }, // use first dataset as bottom
];
$.plot($("#placeholder"), dataset, { line: { show: true, fill: true }});
As a convenience, if the id given is a number that doesn't appear as
an id in the series, it is interpreted as the index in the array
instead (so fillBetween: 0 can also mean the first series).
Internally, the plugin modifies the datapoints in each series. For
line series, extra data points might be inserted through
interpolation. Note that at points where the bottom line is not
defined (due to a null point or start/end of line), the current line
will show a gap too. The algorithm comes from the jquery.flot.stack.js
plugin, possibly some code could be shared.
*/
(function ($) {
var options = {
series: { fillBetween: null } // or number
};
function init(plot) {
function findBottomSeries(s, allseries) {
var i;
for (i = 0; i < allseries.length; ++i) {
if (allseries[i].id == s.fillBetween)
return allseries[i];
}
if (typeof s.fillBetween == "number") {
i = s.fillBetween;
if (i < 0 || i >= allseries.length)
return null;
return allseries[i];
}
return null;
}
function computeFillBottoms(plot, s, datapoints) {
if (s.fillBetween == null)
return;
var other = findBottomSeries(s, plot.getData());
if (!other)
return;
var ps = datapoints.pointsize,
points = datapoints.points,
otherps = other.datapoints.pointsize,
otherpoints = other.datapoints.points,
newpoints = [],
px, py, intery, qx, qy, bottom,
withlines = s.lines.show,
withbottom = ps > 2 && datapoints.format[2].y,
withsteps = withlines && s.lines.steps,
fromgap = true,
i = 0, j = 0, l;
while (true) {
if (i >= points.length)
break;
l = newpoints.length;
if (points[i] == null) {
// copy gaps
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
i += ps;
}
else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points
if (!withlines) {
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
}
i += ps;
}
else if (otherpoints[j] == null) {
// oops, got a gap
for (m = 0; m < ps; ++m)
newpoints.push(null);
fromgap = true;
j += otherps;
}
else {
// cases where we actually got two points
px = points[i];
py = points[i + 1];
qx = otherpoints[j];
qy = otherpoints[j + 1];
bottom = 0;
if (px == qx) {
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
//newpoints[l + 1] += qy;
bottom = qy;
i += ps;
j += otherps;
}
else if (px > qx) {
// we got past point below, might need to
// insert interpolated extra point
if (withlines && i > 0 && points[i - ps] != null) {
intery = py + (points[i - ps + 1] - py) * (qx - px) / (points[i - ps] - px);
newpoints.push(qx);
newpoints.push(intery)
for (m = 2; m < ps; ++m)
newpoints.push(points[i + m]);
bottom = qy;
}
j += otherps;
}
else { // px < qx
if (fromgap && withlines) {
// if we come from a gap, we just skip this point
i += ps;
continue;
}
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
// we might be able to interpolate a point below,
// this can give us a better y
if (withlines && j > 0 && otherpoints[j - otherps] != null)
bottom = qy + (otherpoints[j - otherps + 1] - qy) * (px - qx) / (otherpoints[j - otherps] - qx);
//newpoints[l + 1] += bottom;
i += ps;
}
fromgap = false;
if (l != newpoints.length && withbottom)
newpoints[l + 2] = bottom;
}
// maintain the line steps invariant
if (withsteps && l != newpoints.length && l > 0
&& newpoints[l] != null
&& newpoints[l] != newpoints[l - ps]
&& newpoints[l + 1] != newpoints[l - ps + 1]) {
for (m = 0; m < ps; ++m)
newpoints[l + ps + m] = newpoints[l + m];
newpoints[l + 1] = newpoints[l - ps + 1];
}
}
datapoints.points = newpoints;
}
plot.hooks.processDatapoints.push(computeFillBottoms);
}
$.plot.plugins.push({
init: init,
options: options,
name: 'fillbetween',
version: '1.0'
});
})(jQuery);
@@ -1 +0,0 @@
(function(b){var a={series:{fillBetween:null}};function c(f){function d(j,h){var g;for(g=0;g<h.length;++g){if(h[g].id==j.fillBetween){return h[g]}}if(typeof j.fillBetween=="number"){g=j.fillBetween;if(g<0||g>=h.length){return null}return h[g]}return null}function e(B,u,g){if(u.fillBetween==null){return}var p=d(u,B.getData());if(!p){return}var y=g.pointsize,E=g.points,h=p.datapoints.pointsize,x=p.datapoints.points,r=[],w,v,k,G,F,q,t=u.lines.show,o=y>2&&g.format[2].y,n=t&&u.lines.steps,D=true,C=0,A=0,z;while(true){if(C>=E.length){break}z=r.length;if(E[C]==null){for(m=0;m<y;++m){r.push(E[C+m])}C+=y}else{if(A>=x.length){if(!t){for(m=0;m<y;++m){r.push(E[C+m])}}C+=y}else{if(x[A]==null){for(m=0;m<y;++m){r.push(null)}D=true;A+=h}else{w=E[C];v=E[C+1];G=x[A];F=x[A+1];q=0;if(w==G){for(m=0;m<y;++m){r.push(E[C+m])}q=F;C+=y;A+=h}else{if(w>G){if(t&&C>0&&E[C-y]!=null){k=v+(E[C-y+1]-v)*(G-w)/(E[C-y]-w);r.push(G);r.push(k);for(m=2;m<y;++m){r.push(E[C+m])}q=F}A+=h}else{if(D&&t){C+=y;continue}for(m=0;m<y;++m){r.push(E[C+m])}if(t&&A>0&&x[A-h]!=null){q=F+(x[A-h+1]-F)*(w-G)/(x[A-h]-G)}C+=y}}D=false;if(z!=r.length&&o){r[z+2]=q}}}}if(n&&z!=r.length&&z>0&&r[z]!=null&&r[z]!=r[z-y]&&r[z+1]!=r[z-y+1]){for(m=0;m<y;++m){r[z+y+m]=r[z+m]}r[z+1]=r[z-y+1]}}g.points=r}f.hooks.processDatapoints.push(e)}b.plot.plugins.push({init:c,options:a,name:"fillbetween",version:"1.0"})})(jQuery);
@@ -1,238 +0,0 @@
/*
Flot plugin for plotting images, e.g. useful for putting ticks on a
prerendered complex visualization.
The data syntax is [[image, x1, y1, x2, y2], ...] where (x1, y1) and
(x2, y2) are where you intend the two opposite corners of the image to
end up in the plot. Image must be a fully loaded Javascript image (you
can make one with new Image()). If the image is not complete, it's
skipped when plotting.
There are two helpers included for retrieving images. The easiest work
the way that you put in URLs instead of images in the data (like
["myimage.png", 0, 0, 10, 10]), then call $.plot.image.loadData(data,
options, callback) where data and options are the same as you pass in
to $.plot. This loads the images, replaces the URLs in the data with
the corresponding images and calls "callback" when all images are
loaded (or failed loading). In the callback, you can then call $.plot
with the data set. See the included example.
A more low-level helper, $.plot.image.load(urls, callback) is also
included. Given a list of URLs, it calls callback with an object
mapping from URL to Image object when all images are loaded or have
failed loading.
Options for the plugin are
series: {
images: {
show: boolean
anchor: "corner" or "center"
alpha: [0,1]
}
}
which can be specified for a specific series
$.plot($("#placeholder"), [{ data: [ ... ], images: { ... } ])
Note that because the data format is different from usual data points,
you can't use images with anything else in a specific data series.
Setting "anchor" to "center" causes the pixels in the image to be
anchored at the corner pixel centers inside of at the pixel corners,
effectively letting half a pixel stick out to each side in the plot.
A possible future direction could be support for tiling for large
images (like Google Maps).
*/
(function ($) {
var options = {
series: {
images: {
show: false,
alpha: 1,
anchor: "corner" // or "center"
}
}
};
$.plot.image = {};
$.plot.image.loadDataImages = function (series, options, callback) {
var urls = [], points = [];
var defaultShow = options.series.images.show;
$.each(series, function (i, s) {
if (!(defaultShow || s.images.show))
return;
if (s.data)
s = s.data;
$.each(s, function (i, p) {
if (typeof p[0] == "string") {
urls.push(p[0]);
points.push(p);
}
});
});
$.plot.image.load(urls, function (loadedImages) {
$.each(points, function (i, p) {
var url = p[0];
if (loadedImages[url])
p[0] = loadedImages[url];
});
callback();
});
}
$.plot.image.load = function (urls, callback) {
var missing = urls.length, loaded = {};
if (missing == 0)
callback({});
$.each(urls, function (i, url) {
var handler = function () {
--missing;
loaded[url] = this;
if (missing == 0)
callback(loaded);
};
$('<img />').load(handler).error(handler).attr('src', url);
});
}
function drawSeries(plot, ctx, series) {
var plotOffset = plot.getPlotOffset();
if (!series.images || !series.images.show)
return;
var points = series.datapoints.points,
ps = series.datapoints.pointsize;
for (var i = 0; i < points.length; i += ps) {
var img = points[i],
x1 = points[i + 1], y1 = points[i + 2],
x2 = points[i + 3], y2 = points[i + 4],
xaxis = series.xaxis, yaxis = series.yaxis,
tmp;
// actually we should check img.complete, but it
// appears to be a somewhat unreliable indicator in
// IE6 (false even after load event)
if (!img || img.width <= 0 || img.height <= 0)
continue;
if (x1 > x2) {
tmp = x2;
x2 = x1;
x1 = tmp;
}
if (y1 > y2) {
tmp = y2;
y2 = y1;
y1 = tmp;
}
// if the anchor is at the center of the pixel, expand the
// image by 1/2 pixel in each direction
if (series.images.anchor == "center") {
tmp = 0.5 * (x2-x1) / (img.width - 1);
x1 -= tmp;
x2 += tmp;
tmp = 0.5 * (y2-y1) / (img.height - 1);
y1 -= tmp;
y2 += tmp;
}
// clip
if (x1 == x2 || y1 == y2 ||
x1 >= xaxis.max || x2 <= xaxis.min ||
y1 >= yaxis.max || y2 <= yaxis.min)
continue;
var sx1 = 0, sy1 = 0, sx2 = img.width, sy2 = img.height;
if (x1 < xaxis.min) {
sx1 += (sx2 - sx1) * (xaxis.min - x1) / (x2 - x1);
x1 = xaxis.min;
}
if (x2 > xaxis.max) {
sx2 += (sx2 - sx1) * (xaxis.max - x2) / (x2 - x1);
x2 = xaxis.max;
}
if (y1 < yaxis.min) {
sy2 += (sy1 - sy2) * (yaxis.min - y1) / (y2 - y1);
y1 = yaxis.min;
}
if (y2 > yaxis.max) {
sy1 += (sy1 - sy2) * (yaxis.max - y2) / (y2 - y1);
y2 = yaxis.max;
}
x1 = xaxis.p2c(x1);
x2 = xaxis.p2c(x2);
y1 = yaxis.p2c(y1);
y2 = yaxis.p2c(y2);
// the transformation may have swapped us
if (x1 > x2) {
tmp = x2;
x2 = x1;
x1 = tmp;
}
if (y1 > y2) {
tmp = y2;
y2 = y1;
y1 = tmp;
}
tmp = ctx.globalAlpha;
ctx.globalAlpha *= series.images.alpha;
ctx.drawImage(img,
sx1, sy1, sx2 - sx1, sy2 - sy1,
x1 + plotOffset.left, y1 + plotOffset.top,
x2 - x1, y2 - y1);
ctx.globalAlpha = tmp;
}
}
function processRawData(plot, series, data, datapoints) {
if (!series.images.show)
return;
// format is Image, x1, y1, x2, y2 (opposite corners)
datapoints.format = [
{ required: true },
{ x: true, number: true, required: true },
{ y: true, number: true, required: true },
{ x: true, number: true, required: true },
{ y: true, number: true, required: true }
];
}
function init(plot) {
plot.hooks.processRawData.push(processRawData);
plot.hooks.drawSeries.push(drawSeries);
}
$.plot.plugins.push({
init: init,
options: options,
name: 'image',
version: '1.1'
});
})(jQuery);
@@ -1 +0,0 @@
(function(c){var a={series:{images:{show:false,alpha:1,anchor:"corner"}}};c.plot.image={};c.plot.image.loadDataImages=function(g,f,k){var j=[],h=[];var i=f.series.images.show;c.each(g,function(l,m){if(!(i||m.images.show)){return}if(m.data){m=m.data}c.each(m,function(n,o){if(typeof o[0]=="string"){j.push(o[0]);h.push(o)}})});c.plot.image.load(j,function(l){c.each(h,function(n,o){var m=o[0];if(l[m]){o[0]=l[m]}});k()})};c.plot.image.load=function(h,i){var g=h.length,f={};if(g==0){i({})}c.each(h,function(k,j){var l=function(){--g;f[j]=this;if(g==0){i(f)}};c("<img />").load(l).error(l).attr("src",j)})};function d(q,o,l){var m=q.getPlotOffset();if(!l.images||!l.images.show){return}var r=l.datapoints.points,n=l.datapoints.pointsize;for(var t=0;t<r.length;t+=n){var y=r[t],w=r[t+1],g=r[t+2],v=r[t+3],f=r[t+4],h=l.xaxis,u=l.yaxis,x;if(!y||y.width<=0||y.height<=0){continue}if(w>v){x=v;v=w;w=x}if(g>f){x=f;f=g;g=x}if(l.images.anchor=="center"){x=0.5*(v-w)/(y.width-1);w-=x;v+=x;x=0.5*(f-g)/(y.height-1);g-=x;f+=x}if(w==v||g==f||w>=h.max||v<=h.min||g>=u.max||f<=u.min){continue}var k=0,s=0,j=y.width,p=y.height;if(w<h.min){k+=(j-k)*(h.min-w)/(v-w);w=h.min}if(v>h.max){j+=(j-k)*(h.max-v)/(v-w);v=h.max}if(g<u.min){p+=(s-p)*(u.min-g)/(f-g);g=u.min}if(f>u.max){s+=(s-p)*(u.max-f)/(f-g);f=u.max}w=h.p2c(w);v=h.p2c(v);g=u.p2c(g);f=u.p2c(f);if(w>v){x=v;v=w;w=x}if(g>f){x=f;f=g;g=x}x=o.globalAlpha;o.globalAlpha*=l.images.alpha;o.drawImage(y,k,s,j-k,p-s,w+m.left,g+m.top,v-w,f-g);o.globalAlpha=x}}function b(i,f,g,h){if(!f.images.show){return}h.format=[{required:true},{x:true,number:true,required:true},{y:true,number:true,required:true},{x:true,number:true,required:true},{y:true,number:true,required:true}]}function e(f){f.hooks.processRawData.push(b);f.hooks.drawSeries.push(d)}c.plot.plugins.push({init:e,options:a,name:"image",version:"1.1"})})(jQuery);
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -1,336 +0,0 @@
/*
Flot plugin for adding panning and zooming capabilities to a plot.
The default behaviour is double click and scrollwheel up/down to zoom
in, drag to pan. The plugin defines plot.zoom({ center }),
plot.zoomOut() and plot.pan(offset) so you easily can add custom
controls. It also fires a "plotpan" and "plotzoom" event when
something happens, useful for synchronizing plots.
Options:
zoom: {
interactive: false
trigger: "dblclick" // or "click" for single click
amount: 1.5 // 2 = 200% (zoom in), 0.5 = 50% (zoom out)
}
pan: {
interactive: false
cursor: "move" // CSS mouse cursor value used when dragging, e.g. "pointer"
frameRate: 20
}
xaxis, yaxis, x2axis, y2axis: {
zoomRange: null // or [number, number] (min range, max range) or false
panRange: null // or [number, number] (min, max) or false
}
"interactive" enables the built-in drag/click behaviour. If you enable
interactive for pan, then you'll have a basic plot that supports
moving around; the same for zoom.
"amount" specifies the default amount to zoom in (so 1.5 = 150%)
relative to the current viewport.
"cursor" is a standard CSS mouse cursor string used for visual
feedback to the user when dragging.
"frameRate" specifies the maximum number of times per second the plot
will update itself while the user is panning around on it (set to null
to disable intermediate pans, the plot will then not update until the
mouse button is released).
"zoomRange" is the interval in which zooming can happen, e.g. with
zoomRange: [1, 100] the zoom will never scale the axis so that the
difference between min and max is smaller than 1 or larger than 100.
You can set either end to null to ignore, e.g. [1, null]. If you set
zoomRange to false, zooming on that axis will be disabled.
"panRange" confines the panning to stay within a range, e.g. with
panRange: [-10, 20] panning stops at -10 in one end and at 20 in the
other. Either can be null, e.g. [-10, null]. If you set
panRange to false, panning on that axis will be disabled.
Example API usage:
plot = $.plot(...);
// zoom default amount in on the pixel (10, 20)
plot.zoom({ center: { left: 10, top: 20 } });
// zoom out again
plot.zoomOut({ center: { left: 10, top: 20 } });
// zoom 200% in on the pixel (10, 20)
plot.zoom({ amount: 2, center: { left: 10, top: 20 } });
// pan 100 pixels to the left and 20 down
plot.pan({ left: -100, top: 20 })
Here, "center" specifies where the center of the zooming should
happen. Note that this is defined in pixel space, not the space of the
data points (you can use the p2c helpers on the axes in Flot to help
you convert between these).
"amount" is the amount to zoom the viewport relative to the current
range, so 1 is 100% (i.e. no change), 1.5 is 150% (zoom in), 0.7 is
70% (zoom out). You can set the default in the options.
*/
// First two dependencies, jquery.event.drag.js and
// jquery.mousewheel.js, we put them inline here to save people the
// effort of downloading them.
/*
jquery.event.drag.js ~ v1.5 ~ Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt
*/
(function(E){E.fn.drag=function(L,K,J){if(K){this.bind("dragstart",L)}if(J){this.bind("dragend",J)}return !L?this.trigger("drag"):this.bind("drag",K?K:L)};var A=E.event,B=A.special,F=B.drag={not:":input",distance:0,which:1,dragging:false,setup:function(J){J=E.extend({distance:F.distance,which:F.which,not:F.not},J||{});J.distance=I(J.distance);A.add(this,"mousedown",H,J);if(this.attachEvent){this.attachEvent("ondragstart",D)}},teardown:function(){A.remove(this,"mousedown",H);if(this===F.dragging){F.dragging=F.proxy=false}G(this,true);if(this.detachEvent){this.detachEvent("ondragstart",D)}}};B.dragstart=B.dragend={setup:function(){},teardown:function(){}};function H(L){var K=this,J,M=L.data||{};if(M.elem){K=L.dragTarget=M.elem;L.dragProxy=F.proxy||K;L.cursorOffsetX=M.pageX-M.left;L.cursorOffsetY=M.pageY-M.top;L.offsetX=L.pageX-L.cursorOffsetX;L.offsetY=L.pageY-L.cursorOffsetY}else{if(F.dragging||(M.which>0&&L.which!=M.which)||E(L.target).is(M.not)){return }}switch(L.type){case"mousedown":E.extend(M,E(K).offset(),{elem:K,target:L.target,pageX:L.pageX,pageY:L.pageY});A.add(document,"mousemove mouseup",H,M);G(K,false);F.dragging=null;return false;case !F.dragging&&"mousemove":if(I(L.pageX-M.pageX)+I(L.pageY-M.pageY)<M.distance){break}L.target=M.target;J=C(L,"dragstart",K);if(J!==false){F.dragging=K;F.proxy=L.dragProxy=E(J||K)[0]}case"mousemove":if(F.dragging){J=C(L,"drag",K);if(B.drop){B.drop.allowed=(J!==false);B.drop.handler(L)}if(J!==false){break}L.type="mouseup"}case"mouseup":A.remove(document,"mousemove mouseup",H);if(F.dragging){if(B.drop){B.drop.handler(L)}C(L,"dragend",K)}G(K,true);F.dragging=F.proxy=M.elem=false;break}return true}function C(M,K,L){M.type=K;var J=E.event.handle.call(L,M);return J===false?false:J||M.result}function I(J){return Math.pow(J,2)}function D(){return(F.dragging===false)}function G(K,J){if(!K){return }K.unselectable=J?"off":"on";K.onselectstart=function(){return J};if(K.style){K.style.MozUserSelect=J?"":"none"}}})(jQuery);
/* jquery.mousewheel.min.js
* Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
*
* Version: 3.0.2
*
* Requires: 1.2.2+
*/
(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);
(function ($) {
var options = {
xaxis: {
zoomRange: null, // or [number, number] (min range, max range)
panRange: null // or [number, number] (min, max)
},
zoom: {
interactive: false,
trigger: "dblclick", // or "click" for single click
amount: 1.5 // how much to zoom relative to current position, 2 = 200% (zoom in), 0.5 = 50% (zoom out)
},
pan: {
interactive: false,
cursor: "move",
frameRate: 20
}
};
function init(plot) {
function onZoomClick(e, zoomOut) {
var c = plot.offset();
c.left = e.pageX - c.left;
c.top = e.pageY - c.top;
if (zoomOut)
plot.zoomOut({ center: c });
else
plot.zoom({ center: c });
}
function onMouseWheel(e, delta) {
onZoomClick(e, delta < 0);
return false;
}
var prevCursor = 'default', prevPageX = 0, prevPageY = 0,
panTimeout = null;
function onDragStart(e) {
if (e.which != 1) // only accept left-click
return false;
var c = plot.getPlaceholder().css('cursor');
if (c)
prevCursor = c;
plot.getPlaceholder().css('cursor', plot.getOptions().pan.cursor);
prevPageX = e.pageX;
prevPageY = e.pageY;
}
function onDrag(e) {
var frameRate = plot.getOptions().pan.frameRate;
if (panTimeout || !frameRate)
return;
panTimeout = setTimeout(function () {
plot.pan({ left: prevPageX - e.pageX,
top: prevPageY - e.pageY });
prevPageX = e.pageX;
prevPageY = e.pageY;
panTimeout = null;
}, 1 / frameRate * 1000);
}
function onDragEnd(e) {
if (panTimeout) {
clearTimeout(panTimeout);
panTimeout = null;
}
plot.getPlaceholder().css('cursor', prevCursor);
plot.pan({ left: prevPageX - e.pageX,
top: prevPageY - e.pageY });
}
function bindEvents(plot, eventHolder) {
var o = plot.getOptions();
if (o.zoom.interactive) {
eventHolder[o.zoom.trigger](onZoomClick);
eventHolder.mousewheel(onMouseWheel);
}
if (o.pan.interactive) {
eventHolder.bind("dragstart", { distance: 10 }, onDragStart);
eventHolder.bind("drag", onDrag);
eventHolder.bind("dragend", onDragEnd);
}
}
plot.zoomOut = function (args) {
if (!args)
args = {};
if (!args.amount)
args.amount = plot.getOptions().zoom.amount
args.amount = 1 / args.amount;
plot.zoom(args);
}
plot.zoom = function (args) {
if (!args)
args = {};
var c = args.center,
amount = args.amount || plot.getOptions().zoom.amount,
w = plot.width(), h = plot.height();
if (!c)
c = { left: w / 2, top: h / 2 };
var xf = c.left / w,
yf = c.top / h,
minmax = {
x: {
min: c.left - xf * w / amount,
max: c.left + (1 - xf) * w / amount
},
y: {
min: c.top - yf * h / amount,
max: c.top + (1 - yf) * h / amount
}
};
$.each(plot.getAxes(), function(_, axis) {
var opts = axis.options,
min = minmax[axis.direction].min,
max = minmax[axis.direction].max,
zr = opts.zoomRange;
if (zr === false) // no zooming on this axis
return;
min = axis.c2p(min);
max = axis.c2p(max);
if (min > max) {
// make sure min < max
var tmp = min;
min = max;
max = tmp;
}
var range = max - min;
if (zr &&
((zr[0] != null && range < zr[0]) ||
(zr[1] != null && range > zr[1])))
return;
opts.min = min;
opts.max = max;
});
plot.setupGrid();
plot.draw();
if (!args.preventEvent)
plot.getPlaceholder().trigger("plotzoom", [ plot ]);
}
plot.pan = function (args) {
var delta = {
x: +args.left,
y: +args.top
};
if (isNaN(delta.x))
delta.x = 0;
if (isNaN(delta.y))
delta.y = 0;
$.each(plot.getAxes(), function (_, axis) {
var opts = axis.options,
min, max, d = delta[axis.direction];
min = axis.c2p(axis.p2c(axis.min) + d),
max = axis.c2p(axis.p2c(axis.max) + d);
var pr = opts.panRange;
if (pr === false) // no panning on this axis
return;
if (pr) {
// check whether we hit the wall
if (pr[0] != null && pr[0] > min) {
d = pr[0] - min;
min += d;
max += d;
}
if (pr[1] != null && pr[1] < max) {
d = pr[1] - max;
min += d;
max += d;
}
}
opts.min = min;
opts.max = max;
});
plot.setupGrid();
plot.draw();
if (!args.preventEvent)
plot.getPlaceholder().trigger("plotpan", [ plot ]);
}
function shutdown(plot, eventHolder) {
eventHolder.unbind(plot.getOptions().zoom.trigger, onZoomClick);
eventHolder.unbind("mousewheel", onMouseWheel);
eventHolder.unbind("dragstart", onDragStart);
eventHolder.unbind("drag", onDrag);
eventHolder.unbind("dragend", onDragEnd);
if (panTimeout)
clearTimeout(panTimeout);
}
plot.hooks.bindEvents.push(bindEvents);
plot.hooks.shutdown.push(shutdown);
}
$.plot.plugins.push({
init: init,
options: options,
name: 'navigate',
version: '1.3'
});
})(jQuery);
File diff suppressed because one or more lines are too long
@@ -1,750 +0,0 @@
/*
Flot plugin for rendering pie charts. The plugin assumes the data is
coming is as a single data value for each series, and each of those
values is a positive value or zero (negative numbers don't make
any sense and will cause strange effects). The data values do
NOT need to be passed in as percentage values because it
internally calculates the total and percentages.
* Created by Brian Medendorp, June 2009
* Updated November 2009 with contributions from: btburnett3, Anthony Aragues and Xavi Ivars
* Changes:
2009-10-22: lineJoin set to round
2009-10-23: IE full circle fix, donut
2009-11-11: Added basic hover from btburnett3 - does not work in IE, and center is off in Chrome and Opera
2009-11-17: Added IE hover capability submitted by Anthony Aragues
2009-11-18: Added bug fix submitted by Xavi Ivars (issues with arrays when other JS libraries are included as well)
Available options are:
series: {
pie: {
show: true/false
radius: 0-1 for percentage of fullsize, or a specified pixel length, or 'auto'
innerRadius: 0-1 for percentage of fullsize or a specified pixel length, for creating a donut effect
startAngle: 0-2 factor of PI used for starting angle (in radians) i.e 3/2 starts at the top, 0 and 2 have the same result
tilt: 0-1 for percentage to tilt the pie, where 1 is no tilt, and 0 is completely flat (nothing will show)
offset: {
top: integer value to move the pie up or down
left: integer value to move the pie left or right, or 'auto'
},
stroke: {
color: any hexidecimal color value (other formats may or may not work, so best to stick with something like '#FFF')
width: integer pixel width of the stroke
},
label: {
show: true/false, or 'auto'
formatter: a user-defined function that modifies the text/style of the label text
radius: 0-1 for percentage of fullsize, or a specified pixel length
background: {
color: any hexidecimal color value (other formats may or may not work, so best to stick with something like '#000')
opacity: 0-1
},
threshold: 0-1 for the percentage value at which to hide labels (if they're too small)
},
combine: {
threshold: 0-1 for the percentage value at which to combine slices (if they're too small)
color: any hexidecimal color value (other formats may or may not work, so best to stick with something like '#CCC'), if null, the plugin will automatically use the color of the first slice to be combined
label: any text value of what the combined slice should be labeled
}
highlight: {
opacity: 0-1
}
}
}
More detail and specific examples can be found in the included HTML file.
*/
(function ($)
{
function init(plot) // this is the "body" of the plugin
{
var canvas = null;
var target = null;
var maxRadius = null;
var centerLeft = null;
var centerTop = null;
var total = 0;
var redraw = true;
var redrawAttempts = 10;
var shrink = 0.95;
var legendWidth = 0;
var processed = false;
var raw = false;
// interactive variables
var highlights = [];
// add hook to determine if pie plugin in enabled, and then perform necessary operations
plot.hooks.processOptions.push(checkPieEnabled);
plot.hooks.bindEvents.push(bindEvents);
// check to see if the pie plugin is enabled
function checkPieEnabled(plot, options)
{
if (options.series.pie.show)
{
//disable grid
options.grid.show = false;
// set labels.show
if (options.series.pie.label.show=='auto')
if (options.legend.show)
options.series.pie.label.show = false;
else
options.series.pie.label.show = true;
// set radius
if (options.series.pie.radius=='auto')
if (options.series.pie.label.show)
options.series.pie.radius = 3/4;
else
options.series.pie.radius = 1;
// ensure sane tilt
if (options.series.pie.tilt>1)
options.series.pie.tilt=1;
if (options.series.pie.tilt<0)
options.series.pie.tilt=0;
// add processData hook to do transformations on the data
plot.hooks.processDatapoints.push(processDatapoints);
plot.hooks.drawOverlay.push(drawOverlay);
// add draw hook
plot.hooks.draw.push(draw);
}
}
// bind hoverable events
function bindEvents(plot, eventHolder)
{
var options = plot.getOptions();
if (options.series.pie.show && options.grid.hoverable)
eventHolder.unbind('mousemove').mousemove(onMouseMove);
if (options.series.pie.show && options.grid.clickable)
eventHolder.unbind('click').click(onClick);
}
// debugging function that prints out an object
function alertObject(obj)
{
var msg = '';
function traverse(obj, depth)
{
if (!depth)
depth = 0;
for (var i = 0; i < obj.length; ++i)
{
for (var j=0; j<depth; j++)
msg += '\t';
if( typeof obj[i] == "object")
{ // its an object
msg += ''+i+':\n';
traverse(obj[i], depth+1);
}
else
{ // its a value
msg += ''+i+': '+obj[i]+'\n';
}
}
}
traverse(obj);
alert(msg);
}
function calcTotal(data)
{
for (var i = 0; i < data.length; ++i)
{
var item = parseFloat(data[i].data[0][1]);
if (item)
total += item;
}
}
function processDatapoints(plot, series, data, datapoints)
{
if (!processed)
{
processed = true;
canvas = plot.getCanvas();
target = $(canvas).parent();
options = plot.getOptions();
plot.setData(combine(plot.getData()));
}
}
function setupPie()
{
legendWidth = target.children().filter('.legend').children().width();
// calculate maximum radius and center point
maxRadius = Math.min(canvas.width,(canvas.height/options.series.pie.tilt))/2;
centerTop = (canvas.height/2)+options.series.pie.offset.top;
centerLeft = (canvas.width/2);
if (options.series.pie.offset.left=='auto')
if (options.legend.position.match('w'))
centerLeft += legendWidth/2;
else
centerLeft -= legendWidth/2;
else
centerLeft += options.series.pie.offset.left;
if (centerLeft<maxRadius)
centerLeft = maxRadius;
else if (centerLeft>canvas.width-maxRadius)
centerLeft = canvas.width-maxRadius;
}
function fixData(data)
{
for (var i = 0; i < data.length; ++i)
{
if (typeof(data[i].data)=='number')
data[i].data = [[1,data[i].data]];
else if (typeof(data[i].data)=='undefined' || typeof(data[i].data[0])=='undefined')
{
if (typeof(data[i].data)!='undefined' && typeof(data[i].data.label)!='undefined')
data[i].label = data[i].data.label; // fix weirdness coming from flot
data[i].data = [[1,0]];
}
}
return data;
}
function combine(data)
{
data = fixData(data);
calcTotal(data);
var combined = 0;
var numCombined = 0;
var color = options.series.pie.combine.color;
var newdata = [];
for (var i = 0; i < data.length; ++i)
{
// make sure its a number
data[i].data[0][1] = parseFloat(data[i].data[0][1]);
if (!data[i].data[0][1])
data[i].data[0][1] = 0;
if (data[i].data[0][1]/total<=options.series.pie.combine.threshold)
{
combined += data[i].data[0][1];
numCombined++;
if (!color)
color = data[i].color;
}
else
{
newdata.push({
data: [[1,data[i].data[0][1]]],
color: data[i].color,
label: data[i].label,
angle: (data[i].data[0][1]*(Math.PI*2))/total,
percent: (data[i].data[0][1]/total*100)
});
}
}
if (numCombined>0)
newdata.push({
data: [[1,combined]],
color: color,
label: options.series.pie.combine.label,
angle: (combined*(Math.PI*2))/total,
percent: (combined/total*100)
});
return newdata;
}
function draw(plot, newCtx)
{
if (!target) return; // if no series were passed
ctx = newCtx;
setupPie();
var slices = plot.getData();
var attempts = 0;
while (redraw && attempts<redrawAttempts)
{
redraw = false;
if (attempts>0)
maxRadius *= shrink;
attempts += 1;
clear();
if (options.series.pie.tilt<=0.8)
drawShadow();
drawPie();
}
if (attempts >= redrawAttempts) {
clear();
target.prepend('<div class="error">Could not draw pie with labels contained inside canvas</div>');
}
if ( plot.setSeries && plot.insertLegend )
{
plot.setSeries(slices);
plot.insertLegend();
}
// we're actually done at this point, just defining internal functions at this point
function clear()
{
ctx.clearRect(0,0,canvas.width,canvas.height);
target.children().filter('.pieLabel, .pieLabelBackground').remove();
}
function drawShadow()
{
var shadowLeft = 5;
var shadowTop = 15;
var edge = 10;
var alpha = 0.02;
// set radius
if (options.series.pie.radius>1)
var radius = options.series.pie.radius;
else
var radius = maxRadius * options.series.pie.radius;
if (radius>=(canvas.width/2)-shadowLeft || radius*options.series.pie.tilt>=(canvas.height/2)-shadowTop || radius<=edge)
return; // shadow would be outside canvas, so don't draw it
ctx.save();
ctx.translate(shadowLeft,shadowTop);
ctx.globalAlpha = alpha;
ctx.fillStyle = '#000';
// center and rotate to starting position
ctx.translate(centerLeft,centerTop);
ctx.scale(1, options.series.pie.tilt);
//radius -= edge;
for (var i=1; i<=edge; i++)
{
ctx.beginPath();
ctx.arc(0,0,radius,0,Math.PI*2,false);
ctx.fill();
radius -= i;
}
ctx.restore();
}
function drawPie()
{
startAngle = Math.PI*options.series.pie.startAngle;
// set radius
if (options.series.pie.radius>1)
var radius = options.series.pie.radius;
else
var radius = maxRadius * options.series.pie.radius;
// center and rotate to starting position
ctx.save();
ctx.translate(centerLeft,centerTop);
ctx.scale(1, options.series.pie.tilt);
//ctx.rotate(startAngle); // start at top; -- This doesn't work properly in Opera
// draw slices
ctx.save();
var currentAngle = startAngle;
for (var i = 0; i < slices.length; ++i)
{
slices[i].startAngle = currentAngle;
drawSlice(slices[i].angle, slices[i].color, true);
}
ctx.restore();
// draw slice outlines
ctx.save();
ctx.lineWidth = options.series.pie.stroke.width;
currentAngle = startAngle;
for (var i = 0; i < slices.length; ++i)
drawSlice(slices[i].angle, options.series.pie.stroke.color, false);
ctx.restore();
// draw donut hole
drawDonutHole(ctx);
// draw labels
if (options.series.pie.label.show)
drawLabels();
// restore to original state
ctx.restore();
function drawSlice(angle, color, fill)
{
if (angle<=0)
return;
if (fill)
ctx.fillStyle = color;
else
{
ctx.strokeStyle = color;
ctx.lineJoin = 'round';
}
ctx.beginPath();
if (Math.abs(angle - Math.PI*2) > 0.000000001)
ctx.moveTo(0,0); // Center of the pie
else if ($.browser.msie)
angle -= 0.0001;
//ctx.arc(0,0,radius,0,angle,false); // This doesn't work properly in Opera
ctx.arc(0,0,radius,currentAngle,currentAngle+angle,false);
ctx.closePath();
//ctx.rotate(angle); // This doesn't work properly in Opera
currentAngle += angle;
if (fill)
ctx.fill();
else
ctx.stroke();
}
function drawLabels()
{
var currentAngle = startAngle;
// set radius
if (options.series.pie.label.radius>1)
var radius = options.series.pie.label.radius;
else
var radius = maxRadius * options.series.pie.label.radius;
for (var i = 0; i < slices.length; ++i)
{
if (slices[i].percent >= options.series.pie.label.threshold*100)
drawLabel(slices[i], currentAngle, i);
currentAngle += slices[i].angle;
}
function drawLabel(slice, startAngle, index)
{
if (slice.data[0][1]==0)
return;
// format label text
var lf = options.legend.labelFormatter, text, plf = options.series.pie.label.formatter;
if (lf)
text = lf(slice.label, slice);
else
text = slice.label;
if (plf)
text = plf(text, slice);
var halfAngle = ((startAngle+slice.angle) + startAngle)/2;
var x = centerLeft + Math.round(Math.cos(halfAngle) * radius);
var y = centerTop + Math.round(Math.sin(halfAngle) * radius) * options.series.pie.tilt;
var html = '<span class="pieLabel" id="pieLabel'+index+'" style="position:absolute;top:' + y + 'px;left:' + x + 'px;">' + text + "</span>";
target.append(html);
var label = target.children('#pieLabel'+index);
var labelTop = (y - label.height()/2);
var labelLeft = (x - label.width()/2);
label.css('top', labelTop);
label.css('left', labelLeft);
// check to make sure that the label is not outside the canvas
if (0-labelTop>0 || 0-labelLeft>0 || canvas.height-(labelTop+label.height())<0 || canvas.width-(labelLeft+label.width())<0)
redraw = true;
if (options.series.pie.label.background.opacity != 0) {
// put in the transparent background separately to avoid blended labels and label boxes
var c = options.series.pie.label.background.color;
if (c == null) {
c = slice.color;
}
var pos = 'top:'+labelTop+'px;left:'+labelLeft+'px;';
$('<div class="pieLabelBackground" style="position:absolute;width:' + label.width() + 'px;height:' + label.height() + 'px;' + pos +'background-color:' + c + ';"> </div>').insertBefore(label).css('opacity', options.series.pie.label.background.opacity);
}
} // end individual label function
} // end drawLabels function
} // end drawPie function
} // end draw function
// Placed here because it needs to be accessed from multiple locations
function drawDonutHole(layer)
{
// draw donut hole
if(options.series.pie.innerRadius > 0)
{
// subtract the center
layer.save();
innerRadius = options.series.pie.innerRadius > 1 ? options.series.pie.innerRadius : maxRadius * options.series.pie.innerRadius;
layer.globalCompositeOperation = 'destination-out'; // this does not work with excanvas, but it will fall back to using the stroke color
layer.beginPath();
layer.fillStyle = options.series.pie.stroke.color;
layer.arc(0,0,innerRadius,0,Math.PI*2,false);
layer.fill();
layer.closePath();
layer.restore();
// add inner stroke
layer.save();
layer.beginPath();
layer.strokeStyle = options.series.pie.stroke.color;
layer.arc(0,0,innerRadius,0,Math.PI*2,false);
layer.stroke();
layer.closePath();
layer.restore();
// TODO: add extra shadow inside hole (with a mask) if the pie is tilted.
}
}
//-- Additional Interactive related functions --
function isPointInPoly(poly, pt)
{
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) || (poly[j][1] <= pt[1] && pt[1]< poly[i][1]))
&& (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0])
&& (c = !c);
return c;
}
function findNearbySlice(mouseX, mouseY)
{
var slices = plot.getData(),
options = plot.getOptions(),
radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
for (var i = 0; i < slices.length; ++i)
{
var s = slices[i];
if(s.pie.show)
{
ctx.save();
ctx.beginPath();
ctx.moveTo(0,0); // Center of the pie
//ctx.scale(1, options.series.pie.tilt); // this actually seems to break everything when here.
ctx.arc(0,0,radius,s.startAngle,s.startAngle+s.angle,false);
ctx.closePath();
x = mouseX-centerLeft;
y = mouseY-centerTop;
if(ctx.isPointInPath)
{
if (ctx.isPointInPath(mouseX-centerLeft, mouseY-centerTop))
{
//alert('found slice!');
ctx.restore();
return {datapoint: [s.percent, s.data], dataIndex: 0, series: s, seriesIndex: i};
}
}
else
{
// excanvas for IE doesn;t support isPointInPath, this is a workaround.
p1X = (radius * Math.cos(s.startAngle));
p1Y = (radius * Math.sin(s.startAngle));
p2X = (radius * Math.cos(s.startAngle+(s.angle/4)));
p2Y = (radius * Math.sin(s.startAngle+(s.angle/4)));
p3X = (radius * Math.cos(s.startAngle+(s.angle/2)));
p3Y = (radius * Math.sin(s.startAngle+(s.angle/2)));
p4X = (radius * Math.cos(s.startAngle+(s.angle/1.5)));
p4Y = (radius * Math.sin(s.startAngle+(s.angle/1.5)));
p5X = (radius * Math.cos(s.startAngle+s.angle));
p5Y = (radius * Math.sin(s.startAngle+s.angle));
arrPoly = [[0,0],[p1X,p1Y],[p2X,p2Y],[p3X,p3Y],[p4X,p4Y],[p5X,p5Y]];
arrPoint = [x,y];
// TODO: perhaps do some mathmatical trickery here with the Y-coordinate to compensate for pie tilt?
if(isPointInPoly(arrPoly, arrPoint))
{
ctx.restore();
return {datapoint: [s.percent, s.data], dataIndex: 0, series: s, seriesIndex: i};
}
}
ctx.restore();
}
}
return null;
}
function onMouseMove(e)
{
triggerClickHoverEvent('plothover', e);
}
function onClick(e)
{
triggerClickHoverEvent('plotclick', e);
}
// trigger click or hover event (they send the same parameters so we share their code)
function triggerClickHoverEvent(eventname, e)
{
var offset = plot.offset(),
canvasX = parseInt(e.pageX - offset.left),
canvasY = parseInt(e.pageY - offset.top),
item = findNearbySlice(canvasX, canvasY);
if (options.grid.autoHighlight)
{
// clear auto-highlights
for (var i = 0; i < highlights.length; ++i)
{
var h = highlights[i];
if (h.auto == eventname && !(item && h.series == item.series))
unhighlight(h.series);
}
}
// highlight the slice
if (item)
highlight(item.series, eventname);
// trigger any hover bind events
var pos = { pageX: e.pageX, pageY: e.pageY };
target.trigger(eventname, [ pos, item ]);
}
function highlight(s, auto)
{
if (typeof s == "number")
s = series[s];
var i = indexOfHighlight(s);
if (i == -1)
{
highlights.push({ series: s, auto: auto });
plot.triggerRedrawOverlay();
}
else if (!auto)
highlights[i].auto = false;
}
function unhighlight(s)
{
if (s == null)
{
highlights = [];
plot.triggerRedrawOverlay();
}
if (typeof s == "number")
s = series[s];
var i = indexOfHighlight(s);
if (i != -1)
{
highlights.splice(i, 1);
plot.triggerRedrawOverlay();
}
}
function indexOfHighlight(s)
{
for (var i = 0; i < highlights.length; ++i)
{
var h = highlights[i];
if (h.series == s)
return i;
}
return -1;
}
function drawOverlay(plot, octx)
{
//alert(options.series.pie.radius);
var options = plot.getOptions();
//alert(options.series.pie.radius);
var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
octx.save();
octx.translate(centerLeft, centerTop);
octx.scale(1, options.series.pie.tilt);
for (i = 0; i < highlights.length; ++i)
drawHighlight(highlights[i].series);
drawDonutHole(octx);
octx.restore();
function drawHighlight(series)
{
if (series.angle < 0) return;
//octx.fillStyle = parseColor(options.series.pie.highlight.color).scale(null, null, null, options.series.pie.highlight.opacity).toString();
octx.fillStyle = "rgba(255, 255, 255, "+options.series.pie.highlight.opacity+")"; // this is temporary until we have access to parseColor
octx.beginPath();
if (Math.abs(series.angle - Math.PI*2) > 0.000000001)
octx.moveTo(0,0); // Center of the pie
octx.arc(0,0,radius,series.startAngle,series.startAngle+series.angle,false);
octx.closePath();
octx.fill();
}
}
} // end init (plugin body)
// define pie specific options and their default values
var options = {
series: {
pie: {
show: false,
radius: 'auto', // actual radius of the visible pie (based on full calculated radius if <=1, or hard pixel value)
innerRadius:0, /* for donut */
startAngle: 3/2,
tilt: 1,
offset: {
top: 0,
left: 'auto'
},
stroke: {
color: '#FFF',
width: 1
},
label: {
show: 'auto',
formatter: function(label, slice){
return '<div style="font-size:x-small;text-align:center;padding:2px;color:'+slice.color+';">'+label+'<br/>'+Math.round(slice.percent)+'%</div>';
}, // formatter function
radius: 1, // radius at which to place the labels (based on full calculated radius if <=1, or hard pixel value)
background: {
color: null,
opacity: 0
},
threshold: 0 // percentage at which to hide the label (i.e. the slice is too narrow)
},
combine: {
threshold: -1, // percentage at which to combine little slices into one larger slice
color: null, // color to give the new slice (auto-generated if null)
label: 'Other' // label to give the new slice
},
highlight: {
//color: '#FFF', // will add this functionality once parseColor is available
opacity: 0.5
}
}
}
};
$.plot.plugins.push({
init: init,
options: options,
name: "pie",
version: "1.0"
});
})(jQuery);
File diff suppressed because one or more lines are too long
@@ -1,60 +0,0 @@
/*
Flot plugin for automatically redrawing plots when the placeholder
size changes, e.g. on window resizes.
It works by listening for changes on the placeholder div (through the
jQuery resize event plugin) - if the size changes, it will redraw the
plot.
There are no options. If you need to disable the plugin for some
plots, you can just fix the size of their placeholders.
*/
/* Inline dependency:
* jQuery resize event - v1.1 - 3/14/2010
* http://benalman.com/projects/jquery-resize-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);
(function ($) {
var options = { }; // no options
function init(plot) {
function onResize() {
var placeholder = plot.getPlaceholder();
// somebody might have hidden us and we can't plot
// when we don't have the dimensions
if (placeholder.width() == 0 || placeholder.height() == 0)
return;
plot.resize();
plot.setupGrid();
plot.draw();
}
function bindEvents(plot, eventHolder) {
plot.getPlaceholder().resize(onResize);
}
function shutdown(plot, eventHolder) {
plot.getPlaceholder().unbind("resize", onResize);
}
plot.hooks.bindEvents.push(bindEvents);
plot.hooks.shutdown.push(shutdown);
}
$.plot.plugins.push({
init: init,
options: options,
name: 'resize',
version: '1.0'
});
})(jQuery);
@@ -1 +0,0 @@
(function(n,p,u){var w=n([]),s=n.resize=n.extend(n.resize,{}),o,l="setTimeout",m="resize",t=m+"-special-event",v="delay",r="throttleWindow";s[v]=250;s[r]=true;n.event.special[m]={setup:function(){if(!s[r]&&this[l]){return false}var a=n(this);w=w.add(a);n.data(this,t,{w:a.width(),h:a.height()});if(w.length===1){q()}},teardown:function(){if(!s[r]&&this[l]){return false}var a=n(this);w=w.not(a);a.removeData(t);if(!w.length){clearTimeout(o)}},add:function(b){if(!s[r]&&this[l]){return false}var c;function a(d,h,g){var f=n(this),e=n.data(this,t);e.w=h!==u?h:f.width();e.h=g!==u?g:f.height();c.apply(this,arguments)}if(n.isFunction(b)){c=b;return a}else{c=b.handler;b.handler=a}}};function q(){o=p[l](function(){w.each(function(){var d=n(this),a=d.width(),b=d.height(),c=n.data(this,t);if(a!==c.w||b!==c.h){d.trigger(m,[c.w=a,c.h=b])}});q()},s[v])}})(jQuery,this);(function(b){var a={};function c(f){function e(){var h=f.getPlaceholder();if(h.width()==0||h.height()==0){return}f.resize();f.setupGrid();f.draw()}function g(i,h){i.getPlaceholder().resize(e)}function d(i,h){i.getPlaceholder().unbind("resize",e)}f.hooks.bindEvents.push(g);f.hooks.shutdown.push(d)}b.plot.plugins.push({init:c,options:a,name:"resize",version:"1.0"})})(jQuery);
@@ -1,344 +0,0 @@
/*
Flot plugin for selecting regions.
The plugin defines the following options:
selection: {
mode: null or "x" or "y" or "xy",
color: color
}
Selection support is enabled by setting the mode to one of "x", "y" or
"xy". In "x" mode, the user will only be able to specify the x range,
similarly for "y" mode. For "xy", the selection becomes a rectangle
where both ranges can be specified. "color" is color of the selection
(if you need to change the color later on, you can get to it with
plot.getOptions().selection.color).
When selection support is enabled, a "plotselected" event will be
emitted on the DOM element you passed into the plot function. The
event handler gets a parameter with the ranges selected on the axes,
like this:
placeholder.bind("plotselected", function(event, ranges) {
alert("You selected " + ranges.xaxis.from + " to " + ranges.xaxis.to)
// similar for yaxis - with multiple axes, the extra ones are in
// x2axis, x3axis, ...
});
The "plotselected" event is only fired when the user has finished
making the selection. A "plotselecting" event is fired during the
process with the same parameters as the "plotselected" event, in case
you want to know what's happening while it's happening,
A "plotunselected" event with no arguments is emitted when the user
clicks the mouse to remove the selection.
The plugin allso adds the following methods to the plot object:
- setSelection(ranges, preventEvent)
Set the selection rectangle. The passed in ranges is on the same
form as returned in the "plotselected" event. If the selection mode
is "x", you should put in either an xaxis range, if the mode is "y"
you need to put in an yaxis range and both xaxis and yaxis if the
selection mode is "xy", like this:
setSelection({ xaxis: { from: 0, to: 10 }, yaxis: { from: 40, to: 60 } });
setSelection will trigger the "plotselected" event when called. If
you don't want that to happen, e.g. if you're inside a
"plotselected" handler, pass true as the second parameter. If you
are using multiple axes, you can specify the ranges on any of those,
e.g. as x2axis/x3axis/... instead of xaxis, the plugin picks the
first one it sees.
- clearSelection(preventEvent)
Clear the selection rectangle. Pass in true to avoid getting a
"plotunselected" event.
- getSelection()
Returns the current selection in the same format as the
"plotselected" event. If there's currently no selection, the
function returns null.
*/
(function ($) {
function init(plot) {
var selection = {
first: { x: -1, y: -1}, second: { x: -1, y: -1},
show: false,
active: false
};
// FIXME: The drag handling implemented here should be
// abstracted out, there's some similar code from a library in
// the navigation plugin, this should be massaged a bit to fit
// the Flot cases here better and reused. Doing this would
// make this plugin much slimmer.
var savedhandlers = {};
var mouseUpHandler = null;
function onMouseMove(e) {
if (selection.active) {
updateSelection(e);
plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]);
}
}
function onMouseDown(e) {
if (e.which != 1) // only accept left-click
return;
// cancel out any text selections
document.body.focus();
// prevent text selection and drag in old-school browsers
if (document.onselectstart !== undefined && savedhandlers.onselectstart == null) {
savedhandlers.onselectstart = document.onselectstart;
document.onselectstart = function () { return false; };
}
if (document.ondrag !== undefined && savedhandlers.ondrag == null) {
savedhandlers.ondrag = document.ondrag;
document.ondrag = function () { return false; };
}
setSelectionPos(selection.first, e);
selection.active = true;
// this is a bit silly, but we have to use a closure to be
// able to whack the same handler again
mouseUpHandler = function (e) { onMouseUp(e); };
$(document).one("mouseup", mouseUpHandler);
}
function onMouseUp(e) {
mouseUpHandler = null;
// revert drag stuff for old-school browsers
if (document.onselectstart !== undefined)
document.onselectstart = savedhandlers.onselectstart;
if (document.ondrag !== undefined)
document.ondrag = savedhandlers.ondrag;
// no more dragging
selection.active = false;
updateSelection(e);
if (selectionIsSane())
triggerSelectedEvent();
else {
// this counts as a clear
plot.getPlaceholder().trigger("plotunselected", [ ]);
plot.getPlaceholder().trigger("plotselecting", [ null ]);
}
return false;
}
function getSelection() {
if (!selectionIsSane())
return null;
var r = {}, c1 = selection.first, c2 = selection.second;
$.each(plot.getAxes(), function (name, axis) {
if (axis.used) {
var p1 = axis.c2p(c1[axis.direction]), p2 = axis.c2p(c2[axis.direction]);
r[name] = { from: Math.min(p1, p2), to: Math.max(p1, p2) };
}
});
return r;
}
function triggerSelectedEvent() {
var r = getSelection();
plot.getPlaceholder().trigger("plotselected", [ r ]);
// backwards-compat stuff, to be removed in future
if (r.xaxis && r.yaxis)
plot.getPlaceholder().trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]);
}
function clamp(min, value, max) {
return value < min ? min: (value > max ? max: value);
}
function setSelectionPos(pos, e) {
var o = plot.getOptions();
var offset = plot.getPlaceholder().offset();
var plotOffset = plot.getPlotOffset();
pos.x = clamp(0, e.pageX - offset.left - plotOffset.left, plot.width());
pos.y = clamp(0, e.pageY - offset.top - plotOffset.top, plot.height());
if (o.selection.mode == "y")
pos.x = pos == selection.first ? 0 : plot.width();
if (o.selection.mode == "x")
pos.y = pos == selection.first ? 0 : plot.height();
}
function updateSelection(pos) {
if (pos.pageX == null)
return;
setSelectionPos(selection.second, pos);
if (selectionIsSane()) {
selection.show = true;
plot.triggerRedrawOverlay();
}
else
clearSelection(true);
}
function clearSelection(preventEvent) {
if (selection.show) {
selection.show = false;
plot.triggerRedrawOverlay();
if (!preventEvent)
plot.getPlaceholder().trigger("plotunselected", [ ]);
}
}
// function taken from markings support in Flot
function extractRange(ranges, coord) {
var axis, from, to, key, axes = plot.getAxes();
for (var k in axes) {
axis = axes[k];
if (axis.direction == coord) {
key = coord + axis.n + "axis";
if (!ranges[key] && axis.n == 1)
key = coord + "axis"; // support x1axis as xaxis
if (ranges[key]) {
from = ranges[key].from;
to = ranges[key].to;
break;
}
}
}
// backwards-compat stuff - to be removed in future
if (!ranges[key]) {
axis = coord == "x" ? plot.getXAxes()[0] : plot.getYAxes()[0];
from = ranges[coord + "1"];
to = ranges[coord + "2"];
}
// auto-reverse as an added bonus
if (from != null && to != null && from > to) {
var tmp = from;
from = to;
to = tmp;
}
return { from: from, to: to, axis: axis };
}
function setSelection(ranges, preventEvent) {
var axis, range, o = plot.getOptions();
if (o.selection.mode == "y") {
selection.first.x = 0;
selection.second.x = plot.width();
}
else {
range = extractRange(ranges, "x");
selection.first.x = range.axis.p2c(range.from);
selection.second.x = range.axis.p2c(range.to);
}
if (o.selection.mode == "x") {
selection.first.y = 0;
selection.second.y = plot.height();
}
else {
range = extractRange(ranges, "y");
selection.first.y = range.axis.p2c(range.from);
selection.second.y = range.axis.p2c(range.to);
}
selection.show = true;
plot.triggerRedrawOverlay();
if (!preventEvent && selectionIsSane())
triggerSelectedEvent();
}
function selectionIsSane() {
var minSize = 5;
return Math.abs(selection.second.x - selection.first.x) >= minSize &&
Math.abs(selection.second.y - selection.first.y) >= minSize;
}
plot.clearSelection = clearSelection;
plot.setSelection = setSelection;
plot.getSelection = getSelection;
plot.hooks.bindEvents.push(function(plot, eventHolder) {
var o = plot.getOptions();
if (o.selection.mode != null) {
eventHolder.mousemove(onMouseMove);
eventHolder.mousedown(onMouseDown);
}
});
plot.hooks.drawOverlay.push(function (plot, ctx) {
// draw selection
if (selection.show && selectionIsSane()) {
var plotOffset = plot.getPlotOffset();
var o = plot.getOptions();
ctx.save();
ctx.translate(plotOffset.left, plotOffset.top);
var c = $.color.parse(o.selection.color);
ctx.strokeStyle = c.scale('a', 0.8).toString();
ctx.lineWidth = 1;
ctx.lineJoin = "round";
ctx.fillStyle = c.scale('a', 0.4).toString();
var x = Math.min(selection.first.x, selection.second.x),
y = Math.min(selection.first.y, selection.second.y),
w = Math.abs(selection.second.x - selection.first.x),
h = Math.abs(selection.second.y - selection.first.y);
ctx.fillRect(x, y, w, h);
ctx.strokeRect(x, y, w, h);
ctx.restore();
}
});
plot.hooks.shutdown.push(function (plot, eventHolder) {
eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mousedown", onMouseDown);
if (mouseUpHandler)
$(document).unbind("mouseup", mouseUpHandler);
});
}
$.plot.plugins.push({
init: init,
options: {
selection: {
mode: null, // one of null, "x", "y" or "xy"
color: "#e8cfac"
}
},
name: 'selection',
version: '1.1'
});
})(jQuery);
@@ -1 +0,0 @@
(function(a){function b(k){var p={first:{x:-1,y:-1},second:{x:-1,y:-1},show:false,active:false};var m={};var r=null;function e(s){if(p.active){l(s);k.getPlaceholder().trigger("plotselecting",[g()])}}function n(s){if(s.which!=1){return}document.body.focus();if(document.onselectstart!==undefined&&m.onselectstart==null){m.onselectstart=document.onselectstart;document.onselectstart=function(){return false}}if(document.ondrag!==undefined&&m.ondrag==null){m.ondrag=document.ondrag;document.ondrag=function(){return false}}d(p.first,s);p.active=true;r=function(t){j(t)};a(document).one("mouseup",r)}function j(s){r=null;if(document.onselectstart!==undefined){document.onselectstart=m.onselectstart}if(document.ondrag!==undefined){document.ondrag=m.ondrag}p.active=false;l(s);if(f()){i()}else{k.getPlaceholder().trigger("plotunselected",[]);k.getPlaceholder().trigger("plotselecting",[null])}return false}function g(){if(!f()){return null}var u={},t=p.first,s=p.second;a.each(k.getAxes(),function(v,w){if(w.used){var y=w.c2p(t[w.direction]),x=w.c2p(s[w.direction]);u[v]={from:Math.min(y,x),to:Math.max(y,x)}}});return u}function i(){var s=g();k.getPlaceholder().trigger("plotselected",[s]);if(s.xaxis&&s.yaxis){k.getPlaceholder().trigger("selected",[{x1:s.xaxis.from,y1:s.yaxis.from,x2:s.xaxis.to,y2:s.yaxis.to}])}}function h(t,u,s){return u<t?t:(u>s?s:u)}function d(w,t){var v=k.getOptions();var u=k.getPlaceholder().offset();var s=k.getPlotOffset();w.x=h(0,t.pageX-u.left-s.left,k.width());w.y=h(0,t.pageY-u.top-s.top,k.height());if(v.selection.mode=="y"){w.x=w==p.first?0:k.width()}if(v.selection.mode=="x"){w.y=w==p.first?0:k.height()}}function l(s){if(s.pageX==null){return}d(p.second,s);if(f()){p.show=true;k.triggerRedrawOverlay()}else{q(true)}}function q(s){if(p.show){p.show=false;k.triggerRedrawOverlay();if(!s){k.getPlaceholder().trigger("plotunselected",[])}}}function c(s,w){var t,y,z,A,x=k.getAxes();for(var u in x){t=x[u];if(t.direction==w){A=w+t.n+"axis";if(!s[A]&&t.n==1){A=w+"axis"}if(s[A]){y=s[A].from;z=s[A].to;break}}}if(!s[A]){t=w=="x"?k.getXAxes()[0]:k.getYAxes()[0];y=s[w+"1"];z=s[w+"2"]}if(y!=null&&z!=null&&y>z){var v=y;y=z;z=v}return{from:y,to:z,axis:t}}function o(t,s){var v,u,w=k.getOptions();if(w.selection.mode=="y"){p.first.x=0;p.second.x=k.width()}else{u=c(t,"x");p.first.x=u.axis.p2c(u.from);p.second.x=u.axis.p2c(u.to)}if(w.selection.mode=="x"){p.first.y=0;p.second.y=k.height()}else{u=c(t,"y");p.first.y=u.axis.p2c(u.from);p.second.y=u.axis.p2c(u.to)}p.show=true;k.triggerRedrawOverlay();if(!s&&f()){i()}}function f(){var s=5;return Math.abs(p.second.x-p.first.x)>=s&&Math.abs(p.second.y-p.first.y)>=s}k.clearSelection=q;k.setSelection=o;k.getSelection=g;k.hooks.bindEvents.push(function(t,s){var u=t.getOptions();if(u.selection.mode!=null){s.mousemove(e);s.mousedown(n)}});k.hooks.drawOverlay.push(function(v,D){if(p.show&&f()){var t=v.getPlotOffset();var s=v.getOptions();D.save();D.translate(t.left,t.top);var z=a.color.parse(s.selection.color);D.strokeStyle=z.scale("a",0.8).toString();D.lineWidth=1;D.lineJoin="round";D.fillStyle=z.scale("a",0.4).toString();var B=Math.min(p.first.x,p.second.x),A=Math.min(p.first.y,p.second.y),C=Math.abs(p.second.x-p.first.x),u=Math.abs(p.second.y-p.first.y);D.fillRect(B,A,C,u);D.strokeRect(B,A,C,u);D.restore()}});k.hooks.shutdown.push(function(t,s){s.unbind("mousemove",e);s.unbind("mousedown",n);if(r){a(document).unbind("mouseup",r)}})}a.plot.plugins.push({init:b,options:{selection:{mode:null,color:"#e8cfac"}},name:"selection",version:"1.1"})})(jQuery);
@@ -1,184 +0,0 @@
/*
Flot plugin for stacking data sets, i.e. putting them on top of each
other, for accumulative graphs.
The plugin assumes the data is sorted on x (or y if stacking
horizontally). For line charts, it is assumed that if a line has an
undefined gap (from a null point), then the line above it should have
the same gap - insert zeros instead of "null" if you want another
behaviour. This also holds for the start and end of the chart. Note
that stacking a mix of positive and negative values in most instances
doesn't make sense (so it looks weird).
Two or more series are stacked when their "stack" attribute is set to
the same key (which can be any number or string or just "true"). To
specify the default stack, you can set
series: {
stack: null or true or key (number/string)
}
or specify it for a specific series
$.plot($("#placeholder"), [{ data: [ ... ], stack: true }])
The stacking order is determined by the order of the data series in
the array (later series end up on top of the previous).
Internally, the plugin modifies the datapoints in each series, adding
an offset to the y value. For line series, extra data points are
inserted through interpolation. If there's a second y value, it's also
adjusted (e.g for bar charts or filled areas).
*/
(function ($) {
var options = {
series: { stack: null } // or number/string
};
function init(plot) {
function findMatchingSeries(s, allseries) {
var res = null
for (var i = 0; i < allseries.length; ++i) {
if (s == allseries[i])
break;
if (allseries[i].stack == s.stack)
res = allseries[i];
}
return res;
}
function stackData(plot, s, datapoints) {
if (s.stack == null)
return;
var other = findMatchingSeries(s, plot.getData());
if (!other)
return;
var ps = datapoints.pointsize,
points = datapoints.points,
otherps = other.datapoints.pointsize,
otherpoints = other.datapoints.points,
newpoints = [],
px, py, intery, qx, qy, bottom,
withlines = s.lines.show,
horizontal = s.bars.horizontal,
withbottom = ps > 2 && (horizontal ? datapoints.format[2].x : datapoints.format[2].y),
withsteps = withlines && s.lines.steps,
fromgap = true,
keyOffset = horizontal ? 1 : 0,
accumulateOffset = horizontal ? 0 : 1,
i = 0, j = 0, l;
while (true) {
if (i >= points.length)
break;
l = newpoints.length;
if (points[i] == null) {
// copy gaps
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
i += ps;
}
else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points
if (!withlines) {
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
}
i += ps;
}
else if (otherpoints[j] == null) {
// oops, got a gap
for (m = 0; m < ps; ++m)
newpoints.push(null);
fromgap = true;
j += otherps;
}
else {
// cases where we actually got two points
px = points[i + keyOffset];
py = points[i + accumulateOffset];
qx = otherpoints[j + keyOffset];
qy = otherpoints[j + accumulateOffset];
bottom = 0;
if (px == qx) {
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
newpoints[l + accumulateOffset] += qy;
bottom = qy;
i += ps;
j += otherps;
}
else if (px > qx) {
// we got past point below, might need to
// insert interpolated extra point
if (withlines && i > 0 && points[i - ps] != null) {
intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
newpoints.push(qx);
newpoints.push(intery + qy);
for (m = 2; m < ps; ++m)
newpoints.push(points[i + m]);
bottom = qy;
}
j += otherps;
}
else { // px < qx
if (fromgap && withlines) {
// if we come from a gap, we just skip this point
i += ps;
continue;
}
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
// we might be able to interpolate a point below,
// this can give us a better y
if (withlines && j > 0 && otherpoints[j - otherps] != null)
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
newpoints[l + accumulateOffset] += bottom;
i += ps;
}
fromgap = false;
if (l != newpoints.length && withbottom)
newpoints[l + 2] += bottom;
}
// maintain the line steps invariant
if (withsteps && l != newpoints.length && l > 0
&& newpoints[l] != null
&& newpoints[l] != newpoints[l - ps]
&& newpoints[l + 1] != newpoints[l - ps + 1]) {
for (m = 0; m < ps; ++m)
newpoints[l + ps + m] = newpoints[l + m];
newpoints[l + 1] = newpoints[l - ps + 1];
}
}
datapoints.points = newpoints;
}
plot.hooks.processDatapoints.push(stackData);
}
$.plot.plugins.push({
init: init,
options: options,
name: 'stack',
version: '1.2'
});
})(jQuery);
@@ -1 +0,0 @@
(function(b){var a={series:{stack:null}};function c(f){function d(k,j){var h=null;for(var g=0;g<j.length;++g){if(k==j[g]){break}if(j[g].stack==k.stack){h=j[g]}}return h}function e(C,v,g){if(v.stack==null){return}var p=d(v,C.getData());if(!p){return}var z=g.pointsize,F=g.points,h=p.datapoints.pointsize,y=p.datapoints.points,t=[],x,w,k,J,I,r,u=v.lines.show,G=v.bars.horizontal,o=z>2&&(G?g.format[2].x:g.format[2].y),n=u&&v.lines.steps,E=true,q=G?1:0,H=G?0:1,D=0,B=0,A;while(true){if(D>=F.length){break}A=t.length;if(F[D]==null){for(m=0;m<z;++m){t.push(F[D+m])}D+=z}else{if(B>=y.length){if(!u){for(m=0;m<z;++m){t.push(F[D+m])}}D+=z}else{if(y[B]==null){for(m=0;m<z;++m){t.push(null)}E=true;B+=h}else{x=F[D+q];w=F[D+H];J=y[B+q];I=y[B+H];r=0;if(x==J){for(m=0;m<z;++m){t.push(F[D+m])}t[A+H]+=I;r=I;D+=z;B+=h}else{if(x>J){if(u&&D>0&&F[D-z]!=null){k=w+(F[D-z+H]-w)*(J-x)/(F[D-z+q]-x);t.push(J);t.push(k+I);for(m=2;m<z;++m){t.push(F[D+m])}r=I}B+=h}else{if(E&&u){D+=z;continue}for(m=0;m<z;++m){t.push(F[D+m])}if(u&&B>0&&y[B-h]!=null){r=I+(y[B-h+H]-I)*(x-J)/(y[B-h+q]-J)}t[A+H]+=r;D+=z}}E=false;if(A!=t.length&&o){t[A+2]+=r}}}}if(n&&A!=t.length&&A>0&&t[A]!=null&&t[A]!=t[A-z]&&t[A+1]!=t[A-z+1]){for(m=0;m<z;++m){t[A+z+m]=t[A+m]}t[A+1]=t[A-z+1]}}g.points=t}f.hooks.processDatapoints.push(e)}b.plot.plugins.push({init:c,options:a,name:"stack",version:"1.2"})})(jQuery);
@@ -1,70 +0,0 @@
/*
Flot plugin that adds some extra symbols for plotting points.
The symbols are accessed as strings through the standard symbol
choice:
series: {
points: {
symbol: "square" // or "diamond", "triangle", "cross"
}
}
*/
(function ($) {
function processRawData(plot, series, datapoints) {
// we normalize the area of each symbol so it is approximately the
// same as a circle of the given radius
var handlers = {
square: function (ctx, x, y, radius, shadow) {
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2;
ctx.rect(x - size, y - size, size + size, size + size);
},
diamond: function (ctx, x, y, radius, shadow) {
// pi * r^2 = 2s^2 => s = r * sqrt(pi/2)
var size = radius * Math.sqrt(Math.PI / 2);
ctx.moveTo(x - size, y);
ctx.lineTo(x, y - size);
ctx.lineTo(x + size, y);
ctx.lineTo(x, y + size);
ctx.lineTo(x - size, y);
},
triangle: function (ctx, x, y, radius, shadow) {
// pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3))
var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3));
var height = size * Math.sin(Math.PI / 3);
ctx.moveTo(x - size/2, y + height/2);
ctx.lineTo(x + size/2, y + height/2);
if (!shadow) {
ctx.lineTo(x, y - height/2);
ctx.lineTo(x - size/2, y + height/2);
}
},
cross: function (ctx, x, y, radius, shadow) {
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2;
ctx.moveTo(x - size, y - size);
ctx.lineTo(x + size, y + size);
ctx.moveTo(x - size, y + size);
ctx.lineTo(x + size, y - size);
}
}
var s = series.points.symbol;
if (handlers[s])
series.points.symbol = handlers[s];
}
function init(plot) {
plot.hooks.processDatapoints.push(processRawData);
}
$.plot.plugins.push({
init: init,
name: 'symbols',
version: '1.0'
});
})(jQuery);
@@ -1 +0,0 @@
(function(b){function a(h,e,g){var d={square:function(k,j,n,i,m){var l=i*Math.sqrt(Math.PI)/2;k.rect(j-l,n-l,l+l,l+l)},diamond:function(k,j,n,i,m){var l=i*Math.sqrt(Math.PI/2);k.moveTo(j-l,n);k.lineTo(j,n-l);k.lineTo(j+l,n);k.lineTo(j,n+l);k.lineTo(j-l,n)},triangle:function(l,k,o,j,n){var m=j*Math.sqrt(2*Math.PI/Math.sin(Math.PI/3));var i=m*Math.sin(Math.PI/3);l.moveTo(k-m/2,o+i/2);l.lineTo(k+m/2,o+i/2);if(!n){l.lineTo(k,o-i/2);l.lineTo(k-m/2,o+i/2)}},cross:function(k,j,n,i,m){var l=i*Math.sqrt(Math.PI)/2;k.moveTo(j-l,n-l);k.lineTo(j+l,n+l);k.moveTo(j-l,n+l);k.lineTo(j+l,n-l)}};var f=e.points.symbol;if(d[f]){e.points.symbol=d[f]}}function c(d){d.hooks.processDatapoints.push(a)}b.plot.plugins.push({init:c,name:"symbols",version:"1.0"})})(jQuery);
@@ -1,103 +0,0 @@
/*
Flot plugin for thresholding data. Controlled through the option
"threshold" in either the global series options
series: {
threshold: {
below: number
color: colorspec
}
}
or in a specific series
$.plot($("#placeholder"), [{ data: [ ... ], threshold: { ... }}])
The data points below "below" are drawn with the specified color. This
makes it easy to mark points below 0, e.g. for budget data.
Internally, the plugin works by splitting the data into two series,
above and below the threshold. The extra series below the threshold
will have its label cleared and the special "originSeries" attribute
set to the original series. You may need to check for this in hover
events.
*/
(function ($) {
var options = {
series: { threshold: null } // or { below: number, color: color spec}
};
function init(plot) {
function thresholdData(plot, s, datapoints) {
if (!s.threshold)
return;
var ps = datapoints.pointsize, i, x, y, p, prevp,
thresholded = $.extend({}, s); // note: shallow copy
thresholded.datapoints = { points: [], pointsize: ps };
thresholded.label = null;
thresholded.color = s.threshold.color;
thresholded.threshold = null;
thresholded.originSeries = s;
thresholded.data = [];
var below = s.threshold.below,
origpoints = datapoints.points,
addCrossingPoints = s.lines.show;
threspoints = [];
newpoints = [];
for (i = 0; i < origpoints.length; i += ps) {
x = origpoints[i]
y = origpoints[i + 1];
prevp = p;
if (y < below)
p = threspoints;
else
p = newpoints;
if (addCrossingPoints && prevp != p && x != null
&& i > 0 && origpoints[i - ps] != null) {
var interx = (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]) * (below - y) + x;
prevp.push(interx);
prevp.push(below);
for (m = 2; m < ps; ++m)
prevp.push(origpoints[i + m]);
p.push(null); // start new segment
p.push(null);
for (m = 2; m < ps; ++m)
p.push(origpoints[i + m]);
p.push(interx);
p.push(below);
for (m = 2; m < ps; ++m)
p.push(origpoints[i + m]);
}
p.push(x);
p.push(y);
}
datapoints.points = newpoints;
thresholded.datapoints.points = threspoints;
if (thresholded.datapoints.points.length > 0)
plot.getData().push(thresholded);
// FIXME: there are probably some edge cases left in bars
}
plot.hooks.processDatapoints.push(thresholdData);
}
$.plot.plugins.push({
init: init,
options: options,
name: 'threshold',
version: '1.0'
});
})(jQuery);
@@ -1 +0,0 @@
(function(B){var A={series:{threshold:null}};function C(D){function E(L,S,M){if(!S.threshold){return }var F=M.pointsize,I,O,N,G,K,H=B.extend({},S);H.datapoints={points:[],pointsize:F};H.label=null;H.color=S.threshold.color;H.threshold=null;H.originSeries=S;H.data=[];var P=S.threshold.below,Q=M.points,R=S.lines.show;threspoints=[];newpoints=[];for(I=0;I<Q.length;I+=F){O=Q[I];N=Q[I+1];K=G;if(N<P){G=threspoints}else{G=newpoints}if(R&&K!=G&&O!=null&&I>0&&Q[I-F]!=null){var J=(O-Q[I-F])/(N-Q[I-F+1])*(P-N)+O;K.push(J);K.push(P);for(m=2;m<F;++m){K.push(Q[I+m])}G.push(null);G.push(null);for(m=2;m<F;++m){G.push(Q[I+m])}G.push(J);G.push(P);for(m=2;m<F;++m){G.push(Q[I+m])}}G.push(O);G.push(N)}M.points=newpoints;H.datapoints.points=threspoints;if(H.datapoints.points.length>0){L.getData().push(H)}}D.hooks.processDatapoints.push(E)}B.plot.plugins.push({init:C,options:A,name:"threshold",version:"1.0"})})(jQuery);
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
-379
View File
@@ -1,379 +0,0 @@
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
function hex_md5(s) { return rstr2hex(rstr_md5(str2rstr_utf8(s))); }
function b64_md5(s) { return rstr2b64(rstr_md5(str2rstr_utf8(s))); }
function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }
function hex_hmac_md5(k, d)
{ return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
function b64_hmac_md5(k, d)
{ return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
function any_hmac_md5(k, d, e)
{ return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
/*
* Perform a simple self-test to see if the VM is working
*/
function md5_vm_test()
{
return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
}
/*
* Calculate the MD5 of a raw string
*/
function rstr_md5(s)
{
return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
}
/*
* Calculate the HMAC-MD5, of a key and some data (raw strings)
*/
function rstr_hmac_md5(key, data)
{
var bkey = rstr2binl(key);
if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);
var ipad = Array(16), opad = Array(16);
for(var i = 0; i < 16; i++)
{
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5C5C5C5C;
}
var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
}
/*
* Convert a raw string to a hex string
*/
function rstr2hex(input)
{
try { hexcase } catch(e) { hexcase=0; }
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var output = "";
var x;
for(var i = 0; i < input.length; i++)
{
x = input.charCodeAt(i);
output += hex_tab.charAt((x >>> 4) & 0x0F)
+ hex_tab.charAt( x & 0x0F);
}
return output;
}
/*
* Convert a raw string to a base-64 string
*/
function rstr2b64(input)
{
try { b64pad } catch(e) { b64pad=''; }
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var output = "";
var len = input.length;
for(var i = 0; i < len; i += 3)
{
var triplet = (input.charCodeAt(i) << 16)
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
| (i + 2 < len ? input.charCodeAt(i+2) : 0);
for(var j = 0; j < 4; j++)
{
if(i * 8 + j * 6 > input.length * 8) output += b64pad;
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
}
}
return output;
}
/*
* Convert a raw string to an arbitrary string encoding
*/
function rstr2any(input, encoding)
{
var divisor = encoding.length;
var i, j, q, x, quotient;
/* Convert to an array of 16-bit big-endian values, forming the dividend */
var dividend = Array(Math.ceil(input.length / 2));
for(i = 0; i < dividend.length; i++)
{
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
}
/*
* Repeatedly perform a long division. The binary array forms the dividend,
* the length of the encoding is the divisor. Once computed, the quotient
* forms the dividend for the next step. All remainders are stored for later
* use.
*/
var full_length = Math.ceil(input.length * 8 /
(Math.log(encoding.length) / Math.log(2)));
var remainders = Array(full_length);
for(j = 0; j < full_length; j++)
{
quotient = Array();
x = 0;
for(i = 0; i < dividend.length; i++)
{
x = (x << 16) + dividend[i];
q = Math.floor(x / divisor);
x -= q * divisor;
if(quotient.length > 0 || q > 0)
quotient[quotient.length] = q;
}
remainders[j] = x;
dividend = quotient;
}
/* Convert the remainders to the output string */
var output = "";
for(i = remainders.length - 1; i >= 0; i--)
output += encoding.charAt(remainders[i]);
return output;
}
/*
* Encode a string as utf-8.
* For efficiency, this assumes the input is valid utf-16.
*/
function str2rstr_utf8(input)
{
var output = "";
var i = -1;
var x, y;
while(++i < input.length)
{
/* Decode utf-16 surrogate pairs */
x = input.charCodeAt(i);
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
{
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
i++;
}
/* Encode output as utf-8 */
if(x <= 0x7F)
output += String.fromCharCode(x);
else if(x <= 0x7FF)
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
0x80 | ( x & 0x3F));
else if(x <= 0xFFFF)
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
0x80 | ((x >>> 6 ) & 0x3F),
0x80 | ( x & 0x3F));
else if(x <= 0x1FFFFF)
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
0x80 | ((x >>> 12) & 0x3F),
0x80 | ((x >>> 6 ) & 0x3F),
0x80 | ( x & 0x3F));
}
return output;
}
/*
* Encode a string as utf-16
*/
function str2rstr_utf16le(input)
{
var output = "";
for(var i = 0; i < input.length; i++)
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
(input.charCodeAt(i) >>> 8) & 0xFF);
return output;
}
function str2rstr_utf16be(input)
{
var output = "";
for(var i = 0; i < input.length; i++)
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
input.charCodeAt(i) & 0xFF);
return output;
}
/*
* Convert a raw string to an array of little-endian words
* Characters >255 have their high-byte silently ignored.
*/
function rstr2binl(input)
{
var output = Array(input.length >> 2);
for(var i = 0; i < output.length; i++)
output[i] = 0;
for(var i = 0; i < input.length * 8; i += 8)
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
return output;
}
/*
* Convert an array of little-endian words to a string
*/
function binl2rstr(input)
{
var output = "";
for(var i = 0; i < input.length * 32; i += 8)
output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
return output;
}
/*
* Calculate the MD5 of an array of little-endian words, and a bit length.
*/
function binl_md5(x, len)
{
/* append padding */
x[len >> 5] |= 0x80 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
for(var i = 0; i < x.length; i += 16)
{
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
}
return Array(a, b, c, d);
}
/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t)
{
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y)
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt)
{
return (num << cnt) | (num >>> (32 - cnt));
}
-99
View File
@@ -1,99 +0,0 @@
/*
* Copyright (c) 2011, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WSCMD_HPP
#define WSCMD_HPP
#include <map>
#include <string>
namespace wscmd {
// Parses a wscmd string.
// command structure
// command:arg1=val1;arg2=val2;arg3=val3;
// commands
// ack: messages to ack
// example: `ack:e3458d0aceff8b70a3e5c0afec632881=38;e3458d0aceff8b70a3e5c0afec632881=42;`
// send: [vals]
// message; opcode=X; payload="X"
// frame; [fuzzer stuff]
// close:code=1000;reason=msg;
// (instructs the opposite end to close with given optional code/msg)
typedef std::map<std::string,std::string> arg_list;
struct cmd {
// TODO: move semantics
std::string command;
arg_list args;
};
wscmd::cmd parse(const std::string& m);
wscmd::cmd parse(const std::string& m) {
cmd command;
std::string::size_type start;
std::string::size_type end;
start = m.find(":",0);
if (start != std::string::npos) {
command.command = m.substr(0,start);
start++; // skip the colon
end = m.find(";",start);
// find all semicolons
while (end != std::string::npos) {
std::string arg;
std::string val;
std::string::size_type sep = m.find("=",start);
if (sep != std::string::npos) {
arg = m.substr(start,sep-start);
val = m.substr(sep+1,end-sep-1);
} else {
arg = m.substr(start,end-start);
val = "";
}
command.args[arg] = val;
start = end+1;
end = m.find(";",start);
}
}
return command;
}
} // namespace wscmd
#endif // WSCMD_HPP

Some files were not shown because too many files have changed in this diff Show More