Compare commits
453 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0a8aee818 | |||
d5142bf3a6 | |||
a8532dd987 | |||
5d9cc0a953 | |||
e7b3f02f60 | |||
4620459b8e | |||
82a08b133e | |||
d59d3649f5 | |||
d9e28fb5a9 | |||
554a531f57 | |||
e921dbeb5f | |||
ac611b09b2 | |||
5fd9c81451 | |||
b336b38518 | |||
d2c08c2fb3 | |||
69d5f57b90 | |||
5d498adf32 | |||
a664c661ed | |||
61e9f036c1 | |||
7b9302cee2 | |||
5b87a27667 | |||
d9e9e3f2a0 | |||
b436e0aa06 | |||
01a509d348 | |||
6c3f73cd75 | |||
a8672a8656 | |||
4dfbe5dba2 | |||
af05a3d6ba | |||
de5e0482cd | |||
1cf053bc39 | |||
a27f33aabf | |||
bbe4fd7f39 | |||
f5415c3d66 | |||
4b6c52dce6 | |||
ea83ca3610 | |||
280ddf699a | |||
c2dc92bfe1 | |||
c31cb42993 | |||
bd19b67c7d | |||
b317249918 | |||
5b1e3873e3 | |||
82b1d671e6 | |||
b794b2a6c1 | |||
e64ea7b3d1 | |||
e1190c872d | |||
de59dc3bb0 | |||
d013e4cda8 | |||
08bc80aa82 | |||
0cda88693f | |||
3a980262a0 | |||
3804523de4 | |||
64b9935f99 | |||
d9da95aaa0 | |||
666ef171d8 | |||
49197e61ef | |||
a5eeede95e | |||
86d1f942b0 | |||
a9a12086f9 | |||
f51f238be7 | |||
0a6f7e3c2e | |||
4dbb50301c | |||
911a5925b7 | |||
545de91d46 | |||
16684a4938 | |||
b1d7e04a26 | |||
0d61377280 | |||
85468abe58 | |||
36af37d611 | |||
f77843b2bb | |||
3df0af2714 | |||
c5147feee8 | |||
7822550b79 | |||
eb64b9b78d | |||
ed4567eac7 | |||
0a22f2bdda | |||
a4d73234f2 | |||
658ac455d2 | |||
0c54e12445 | |||
3bc428b2a7 | |||
8ec99a2cec | |||
a0fa75a26d | |||
2a689f5c07 | |||
5fa806f29b | |||
06fd86d337 | |||
7947ebd81f | |||
12e646134e | |||
e03c9e7d8b | |||
c042a3647e | |||
d5d71455b4 | |||
13080ad348 | |||
c5a73623cf | |||
17709f8f47 | |||
6fe5085c9f | |||
0ea35808f3 | |||
000fa7fcd2 | |||
1187730b85 | |||
0b01cf04aa | |||
1917fe909d | |||
8357d4befa | |||
94f5b53206 | |||
729a061d02 | |||
12fda9d41c | |||
24bd0ddecc | |||
8f28d14201 | |||
0d65f5318a | |||
5a1f2a9f30 | |||
57b4846948 | |||
9434e598e8 | |||
0d38a12cfb | |||
fe7277bdd7 | |||
55710bd0fd | |||
29bc9ed559 | |||
ea1b5957c0 | |||
b0e7187995 | |||
17e3b56d5c | |||
e38c18c118 | |||
dbf49dcd9f | |||
cfd52305f7 | |||
41d8a202fa | |||
7f4f4b3724 | |||
d95d735ace | |||
071e9c96f4 | |||
dcce124a4d | |||
60386abea4 | |||
fad4b6403c | |||
921713de90 | |||
27fad84f66 | |||
ebaf33845a | |||
60b00b7774 | |||
f5e914510c | |||
f97a4a7655 | |||
1dbc037122 | |||
3c39056544 | |||
e1ed92180d | |||
4a866e7dd1 | |||
b70b070d5c | |||
2fd235bb5f | |||
c8383fcbad | |||
56a037ac7d | |||
919f5efc97 | |||
bb708e81b3 | |||
4b1313e65c | |||
abcdfcf48c | |||
507c69d0b2 | |||
53b961491b | |||
cbd1ad0e49 | |||
9498e3e89e | |||
dae994abe9 | |||
92d3cc1c7d | |||
f961eba9bf | |||
e4c0752a2c | |||
21c98a1dcf | |||
30efb9312a | |||
95902ef1dc | |||
1bff86b31c | |||
5864d4700d | |||
3fd746916c | |||
24ed36cc1b | |||
3927f7e398 | |||
2cccb07c3d | |||
b9c9199c78 | |||
880a57de96 | |||
22fcfb3e42 | |||
02720a3fb6 | |||
cc6f7e2a36 | |||
6ee46c9136 | |||
76205812a0 | |||
1db40c80b6 | |||
832da874c9 | |||
fe525dde46 | |||
2e194fe550 | |||
a1d34c5f4e | |||
e2c8a41ff6 | |||
1202c8180e | |||
11d1c6d679 | |||
cb86fc3680 | |||
7d9b94bc80 | |||
ba665923f6 | |||
d960ac0852 | |||
c9d1abf3e2 | |||
6bcb496215 | |||
abea8a4df3 | |||
3152d141e9 | |||
6a38d62d47 | |||
898ba000bb | |||
8bcabee6dd | |||
d4472925ee | |||
d2cbd55257 | |||
c85cfea154 | |||
cfec9b035f | |||
a49e00c8af | |||
76f9902f0c | |||
ddc9d74cf3 | |||
c4302e9b13 | |||
4d88fef98f | |||
ffcc8843a4 | |||
50887b49cd | |||
a6da594aeb | |||
e348c8d21e | |||
9d6286314d | |||
ca023114fa | |||
95ec90ed19 | |||
7283836ffa | |||
add4871527 | |||
1ec6383287 | |||
2afc7fae92 | |||
0ffc66aba0 | |||
76247fe541 | |||
762efc64c8 | |||
5b43cd763e | |||
ba16a512f3 | |||
447a0f6035 | |||
061787c799 | |||
0cdad8a554 | |||
50a192dbec | |||
41647324ef | |||
c221dbb97c | |||
1e28c369d6 | |||
976a51ef52 | |||
c986cf5186 | |||
ce3181537d | |||
b5a483e8e5 | |||
8868dd18c2 | |||
25885ff3ea | |||
fbefe633f2 | |||
7f97b15532 | |||
82f91805f0 | |||
f4f62e6e0c | |||
156c9a3be2 | |||
ad60e19617 | |||
c819b62246 | |||
7840cfc4ad | |||
499fc2c275 | |||
f22af2977e | |||
20d65f50c3 | |||
c5096ec85c | |||
bbe6d20a9b | |||
ace2e94db4 | |||
f5d627617b | |||
00e4f7437e | |||
efaa9ab2a2 | |||
1d8e82afb2 | |||
281eebbd62 | |||
2884ce78aa | |||
4bd8bb3819 | |||
25f43228dd | |||
a23cb97721 | |||
f602109c53 | |||
803b2baeab | |||
a23d653738 | |||
cf657c1ad7 | |||
08e89bec13 | |||
4bba9ba595 | |||
6fbf56bab0 | |||
ace400ac41 | |||
913b39076e | |||
caa68a7385 | |||
d26f086a43 | |||
51763e0ddf | |||
fe53de1633 | |||
642b8c5b98 | |||
7d2d21deb8 | |||
fb4214f405 | |||
9df93e1ef1 | |||
cf9d15b932 | |||
a54da59dc8 | |||
53ab313da3 | |||
28ab2fd7f3 | |||
7d63176e7e | |||
c7521b67e6 | |||
744056a58d | |||
ee17f7a12f | |||
c4e262e255 | |||
2b443e2826 | |||
c8b4c54742 | |||
d9c1052f5e | |||
edade3cda7 | |||
6dbe266bd5 | |||
6441644adc | |||
9efade745c | |||
e18009b0dd | |||
0b0ca57042 | |||
53cdeabc90 | |||
6a2d796cdb | |||
6821d8d0c6 | |||
bbc8e051f0 | |||
b8ea699f40 | |||
61ef6b19af | |||
83df3b2919 | |||
0048937250 | |||
dad5f10172 | |||
45d585a653 | |||
d09d5ace17 | |||
89b8c7925a | |||
c66e164c8d | |||
eaf96c4b34 | |||
8d0fe7990f | |||
968e8b5976 | |||
3708fc637a | |||
0e32f5f696 | |||
b31e6528ca | |||
5cacb65dbd | |||
6eb135f0b3 | |||
b5e78e5389 | |||
228f537123 | |||
9d9d46fbee | |||
bc933f77f9 | |||
38e5154536 | |||
714cd28742 | |||
7c6fde6893 | |||
d1826334d5 | |||
568cea855f | |||
87276d2762 | |||
ebeb57b15d | |||
1130fa4a6f | |||
feef6dd880 | |||
120e22c1fe | |||
eea61a3a9b | |||
67db964546 | |||
92005e5a56 | |||
f144c8ffc1 | |||
66a635669a | |||
6c9600e47c | |||
fa981d4a32 | |||
2131d1f39a | |||
68ef144474 | |||
f9acff50d1 | |||
278fa7f816 | |||
cc79b39cbb | |||
d52c387912 | |||
6c4d4e474a | |||
d62b9aea66 | |||
6edf83a382 | |||
65718acb5b | |||
78ccef089e | |||
821748b711 | |||
ea58e93f20 | |||
4be249d67d | |||
b983835023 | |||
7b49cec047 | |||
16e5a6e91e | |||
0bdc9d5ef2 | |||
cdd776c7b8 | |||
aa1550afe3 | |||
906430bb5b | |||
be1bba3bc8 | |||
c62941a704 | |||
4a0e05eae8 | |||
af506a3091 | |||
4f29c4c455 | |||
afd3ad005b | |||
c411ce5328 | |||
e1b5d8be43 | |||
9742344361 | |||
f13641fc11 | |||
176cd25eec | |||
069fbe8f8e | |||
6c24fb27be | |||
98843516f7 | |||
5f67b1ffbd | |||
f646831891 | |||
e6b61f97e0 | |||
19d285e1a9 | |||
9fe330f8f9 | |||
e778833808 | |||
48b97d2903 | |||
b81188cb0d | |||
81d8380c4a | |||
99236d60ee | |||
cb8bf24bad | |||
35720dc3a5 | |||
898357d160 | |||
5dd9543b38 | |||
a300db9845 | |||
b19bb5fc7a | |||
f3800d19b0 | |||
0adeda0f4e | |||
9a94d939b8 | |||
b2219b847a | |||
008498f84c | |||
55005ffffc | |||
9b287945b6 | |||
ab4df80963 | |||
d7fd74fb17 | |||
a290c07f61 | |||
39db433854 | |||
1f9e9ee650 | |||
7f2e4b6634 | |||
eeec0db3fa | |||
6aa3e0e77c | |||
3ddd63701e | |||
2a9f5b2500 | |||
01dd38d975 | |||
f969d5dc3e | |||
56f1635c64 | |||
51ee97f020 | |||
25bdf9dbb8 | |||
c4d7bb3f28 | |||
7148754648 | |||
33c0a950db | |||
72b69ebf71 | |||
f50f553817 | |||
1cd4d02701 | |||
1d790fa9d9 | |||
7b9eae28e5 | |||
a52e79b930 | |||
44086f9659 | |||
df34e00c49 | |||
26e7514925 | |||
7d2e3b1e27 | |||
6281e9357b | |||
a37a69888d | |||
338e24792c | |||
fae2ca8fd0 | |||
1e44d67b3f | |||
8807c6ae01 | |||
87a66069ad | |||
59ab18ad74 | |||
43c4e1f61d | |||
65d1b00127 | |||
0a20111f20 | |||
86f071a99a | |||
ef399c82fc | |||
8ca742c2e2 | |||
8062cb4c59 | |||
a7c63c270e | |||
3cd9304689 | |||
e4e74eea9f | |||
2dd63339f3 | |||
4010a7e15b | |||
ed67e0d791 | |||
616d6ca766 | |||
3d91b88971 | |||
817e3ee549 | |||
c83b49658a | |||
688755c542 | |||
26cf3610fe | |||
c60462018e | |||
c7245581e3 | |||
4dfa6ec279 | |||
9e0a5a2ea1 | |||
a576a36d3d | |||
dd38e6036d | |||
c5e7b8c94b | |||
cfef22ee65 | |||
f56e06223f | |||
a7e26e7d96 | |||
48262fbcc8 | |||
f83f700bd2 | |||
f862c242c5 | |||
2916f58ead | |||
962f69295b | |||
7c659f9017 |
126
.gitignore
vendored
Normal file
126
.gitignore
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/vim,python,kate
|
||||
|
||||
### Kate ###
|
||||
# Swap Files #
|
||||
.*.kate-swp
|
||||
.swp.*
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# dotenv
|
||||
.env
|
||||
|
||||
# virtualenv
|
||||
.venv
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
### Vim ###
|
||||
# swap
|
||||
[._]*.s[a-v][a-z]
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-v][a-z]
|
||||
[._]sw[a-p]
|
||||
# session
|
||||
Session.vim
|
||||
# temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# auto-generated tag files
|
||||
tags
|
||||
|
||||
# End of https://www.gitignore.io/api/vim,python,kate
|
||||
|
||||
### Local files ###
|
||||
config.cfg
|
661
LICENSE.txt
Normal file
661
LICENSE.txt
Normal file
@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
38
README.md
Normal file
38
README.md
Normal file
@ -0,0 +1,38 @@
|
||||
PREREQUISITES
|
||||
=============
|
||||
|
||||
Create a Python virtual environment with the following packages:
|
||||
Flask==0.9
|
||||
Flask-SQLAlchemy==0.16
|
||||
Jinja2==2.6
|
||||
SQLAlchemy==0.8.0b2
|
||||
Werkzeug==0.8.3
|
||||
psycopg2==2.4.6
|
||||
python-dateutil==2.1
|
||||
six==1.2.0
|
||||
wsgiref==0.1.2
|
||||
|
||||
DATABASE INSTALLATION
|
||||
=====================
|
||||
Requires a postgresql server, version 9.1 minimum.
|
||||
|
||||
Create a new user:
|
||||
CREATE ROLE accountant WITH PASSWORD 'changeme' LOGIN;
|
||||
|
||||
Create a new database:
|
||||
CREATA DATABASE accountant OWNER acountant ENCODING 'UTF-8';
|
||||
|
||||
Go into src/sql/install ddirectory.
|
||||
Run the script with the user postgres:
|
||||
psql -U postgres accountant -f 001_init.sql
|
||||
|
||||
QUICK RUN
|
||||
=========
|
||||
/path/to/virtualenv/bin/python main.py
|
||||
|
||||
You can now connect on port 5000 with your prefered web browser.
|
||||
|
||||
PRODUCTION RUN
|
||||
==============
|
||||
Install and configure GUnicorn.
|
||||
|
62
accountant/__init__.py
Normal file
62
accountant/__init__.py
Normal file
@ -0,0 +1,62 @@
|
||||
"""The accountant package."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
import click
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from flask_alembic import Alembic
|
||||
from flask_alembic import alembic_click
|
||||
|
||||
from .models import db
|
||||
from .views import api, cors, jwt
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
alembic = Alembic()
|
||||
|
||||
|
||||
def create_app(config_path):
|
||||
"""Create the app using specific config file."""
|
||||
# The app
|
||||
app = Flask(__name__, static_folder=None, template_folder=None)
|
||||
|
||||
# Configure it from configuration file.
|
||||
app.config.from_pyfile(config_path)
|
||||
|
||||
# Database related stuff.
|
||||
app.config['SQLALCHEMY_ECHO'] = app.debug
|
||||
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
alembic.init_app(app)
|
||||
|
||||
# API views related stuff.
|
||||
cors.init_app(app)
|
||||
api.init_app(app)
|
||||
jwt.init_app(app)
|
||||
# Needed to handle correctly JWT exceptions by restplus.
|
||||
jwt._set_error_handler_callbacks(api) # pylint: disable=protected-access
|
||||
|
||||
return app
|
||||
|
||||
|
||||
# Database initialization.
|
||||
@alembic_click.command()
|
||||
def initdb():
|
||||
""" Create the database ans stamp it. """
|
||||
click.echo("Creating database.")
|
||||
db.metadata.create_all(bind=db.engine)
|
||||
click.echo("Stamping database.")
|
||||
alembic.stamp()
|
||||
click.echo("Database created.")
|
||||
|
||||
|
||||
@alembic_click.command()
|
||||
def dropdb():
|
||||
"""Clear database schema. USE CAREFULLY!!"""
|
||||
click.echo("Clearing database.")
|
||||
db.metadata.drop_all(bind=db.engine)
|
||||
click.echo("Database cleared.")
|
12
accountant/config.cfg.dist
Normal file
12
accountant/config.cfg.dist
Normal file
@ -0,0 +1,12 @@
|
||||
# Debug
|
||||
DEBUG=True
|
||||
|
||||
# Secret key
|
||||
SECRET_KEY='toto'
|
||||
|
||||
#WTF_CSRF_ENABLED=False
|
||||
|
||||
# Database connection URI
|
||||
SQLALCHEMY_DATABASE_URI='postgresql://accountant:accountant@localhost/accountant'
|
||||
|
||||
SESSION_TTL=600
|
40
accountant/migrations/1232daf66ac_add_user_support.py
Normal file
40
accountant/migrations/1232daf66ac_add_user_support.py
Normal file
@ -0,0 +1,40 @@
|
||||
"""Add user support.
|
||||
|
||||
Revision ID: 1232daf66ac
|
||||
Revises: 144929e0f5f
|
||||
Create Date: 2015-08-31 10:24:40.578432
|
||||
|
||||
"""
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
# pylint: disable=invalid-name
|
||||
revision = '1232daf66ac'
|
||||
down_revision = '144929e0f5f'
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
from alembic import op # noqa
|
||||
import sqlalchemy as sa # noqa
|
||||
# pylint: enable=wrong-import-position
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrades for revision 1232daf66ac"""
|
||||
op.create_table(
|
||||
'user',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('email', sa.String(length=200), nullable=False),
|
||||
sa.Column('password', sa.String(length=100), nullable=True),
|
||||
sa.Column('active', sa.Boolean(), server_default=sa.text('true'),
|
||||
nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Downgrades for revision 1232daf66ac"""
|
||||
op.drop_index(op.f('ix_user_email'), table_name='user')
|
||||
op.drop_table('user')
|
@ -0,0 +1,148 @@
|
||||
"""Improve operation scheduling.
|
||||
|
||||
Revision ID: 144929e0f5f
|
||||
Revises: None
|
||||
Create Date: 2015-07-17 15:04:01.002581
|
||||
|
||||
"""
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
# pylint: disable=invalid-name
|
||||
revision = '144929e0f5f'
|
||||
down_revision = None
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
from alembic import op # noqa
|
||||
import sqlalchemy as sa # noqa
|
||||
|
||||
from accountant.models.scheduled_operations import ScheduledOperation # noqa
|
||||
# pylint: enable=wrong-import-position
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Upgrades for revision 144929e0f5f"""
|
||||
op.get_bind().execute("DROP VIEW operation")
|
||||
op.rename_table('entry', 'operation')
|
||||
|
||||
# Add column "canceled" in table "entry"
|
||||
op.add_column(
|
||||
'operation',
|
||||
sa.Column(
|
||||
'canceled',
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
default=False,
|
||||
server_default=sa.false()
|
||||
)
|
||||
)
|
||||
|
||||
# Add column "confirmed" in table "entry"
|
||||
op.add_column(
|
||||
'operation',
|
||||
sa.Column(
|
||||
'confirmed',
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
default=True,
|
||||
server_default=sa.true()
|
||||
)
|
||||
)
|
||||
|
||||
# Drop unused table canceled_operation.
|
||||
op.drop_table('canceled_operation')
|
||||
|
||||
op.get_bind().execute(
|
||||
"alter sequence entry_id_seq rename to operation_id_seq"
|
||||
)
|
||||
|
||||
# Get all scheduled operations
|
||||
scheduled_operations = ScheduledOperation.query().all()
|
||||
|
||||
for scheduled_operation in scheduled_operations:
|
||||
scheduled_operation.reschedule()
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Downgrades for revision 144929e0f5f"""
|
||||
|
||||
op.create_table(
|
||||
"canceled_operation",
|
||||
sa.Column("id", sa.Integer, primary_key=True),
|
||||
sa.Column(
|
||||
"scheduled_operation_id", sa.Integer(),
|
||||
sa.ForeignKey("scheduled_operation.id")),
|
||||
sa.Column("operation_date", sa.Date, nullable=False)
|
||||
)
|
||||
|
||||
op.drop_column('operation', 'canceled')
|
||||
op.drop_column('operation', 'confirmed')
|
||||
|
||||
op.get_bind().execute(
|
||||
"alter sequence operation_id_seq rename to entry_id_seq"
|
||||
)
|
||||
op.rename_table('operation', 'entry')
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
op.get_bind().execute(
|
||||
"""
|
||||
CREATE VIEW operation AS
|
||||
SELECT entry.id,
|
||||
entry.operation_date,
|
||||
entry.label,
|
||||
entry.value,
|
||||
entry.account_id,
|
||||
entry.category,
|
||||
entry.pointed,
|
||||
entry.scheduled_operation_id,
|
||||
false AS canceled
|
||||
FROM entry
|
||||
UNION
|
||||
SELECT NULL::bigint AS id,
|
||||
scheduled_operation.operation_date,
|
||||
scheduled_operation.label,
|
||||
scheduled_operation.value,
|
||||
scheduled_operation.account_id,
|
||||
scheduled_operation.category,
|
||||
false AS pointed,
|
||||
scheduled_operation.id AS scheduled_operation_id,
|
||||
false AS canceled
|
||||
FROM (
|
||||
SELECT scheduled_operation_1.id,
|
||||
scheduled_operation_1.start_date,
|
||||
scheduled_operation_1.stop_date,
|
||||
scheduled_operation_1.day,
|
||||
scheduled_operation_1.frequency,
|
||||
scheduled_operation_1.label,
|
||||
scheduled_operation_1.value,
|
||||
scheduled_operation_1.account_id,
|
||||
scheduled_operation_1.category,
|
||||
generate_series(scheduled_operation_1.start_date::timestamp without time zone, scheduled_operation_1.stop_date::timestamp without time zone, scheduled_operation_1.frequency::double precision * '1 mon'::interval) AS operation_date
|
||||
FROM scheduled_operation scheduled_operation_1) scheduled_operation
|
||||
LEFT JOIN (
|
||||
SELECT entry.scheduled_operation_id,
|
||||
date_trunc('MONTH'::text, entry.operation_date::timestamp with time zone) AS operation_date
|
||||
FROM entry
|
||||
UNION
|
||||
SELECT canceled_operation.scheduled_operation_id,
|
||||
date_trunc('MONTH'::text, canceled_operation.operation_date::timestamp with time zone) AS operation_date
|
||||
FROM canceled_operation
|
||||
) saved_operation ON saved_operation.scheduled_operation_id = scheduled_operation.id AND saved_operation.operation_date = date_trunc('MONTH'::text, scheduled_operation.operation_date)
|
||||
WHERE saved_operation.scheduled_operation_id IS NULL
|
||||
UNION
|
||||
SELECT NULL::bigint AS id,
|
||||
canceled_operation.operation_date,
|
||||
scheduled_operation.label,
|
||||
scheduled_operation.value,
|
||||
scheduled_operation.account_id,
|
||||
scheduled_operation.category,
|
||||
false AS pointed,
|
||||
scheduled_operation.id AS scheduled_operation_id,
|
||||
true AS canceled
|
||||
FROM scheduled_operation
|
||||
JOIN canceled_operation ON canceled_operation.scheduled_operation_id = scheduled_operation.id;
|
||||
""" # noqa
|
||||
)
|
||||
# pylint: enable=line-too-long
|
37
accountant/migrations/script.py.mako
Normal file
37
accountant/migrations/script.py.mako
Normal file
@ -0,0 +1,37 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
# pylint: disable=invalid-name
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
from alembic import op # noqa
|
||||
import sqlalchemy as sa # noqa
|
||||
% for imp in imports:
|
||||
% if loop.index == 0:
|
||||
|
||||
% endif
|
||||
${imp} # noqa
|
||||
% endfor
|
||||
# pylint: enable=wrong-import-position
|
||||
|
||||
def upgrade():
|
||||
"""Upgrades for revision ${up_revision}"""
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Downgrades for revision ${up_revision}"""
|
||||
${downgrades if downgrades else "pass"}
|
19
accountant/models/__init__.py
Normal file
19
accountant/models/__init__.py
Normal file
@ -0,0 +1,19 @@
|
||||
"""Package containing models."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
db = SQLAlchemy()
|
||||
|
||||
|
||||
def row_as_dict(row):
|
||||
"""Return a SQLAlchemy row as dict."""
|
||||
return dict(zip(row.keys(), row))
|
||||
|
||||
|
||||
def result_as_dicts(query):
|
||||
"""Return SQLAlchemy query results as dictionnaries."""
|
||||
for row in query.all():
|
||||
yield row_as_dict(row)
|
212
accountant/models/accounts.py
Normal file
212
accountant/models/accounts.py
Normal file
@ -0,0 +1,212 @@
|
||||
"""Module containing account related models."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from . import db
|
||||
|
||||
from .operations import Operation
|
||||
|
||||
|
||||
# pylint: disable=no-member,invalid-name,too-few-public-methods,no-self-use
|
||||
class Account(db.Model):
|
||||
"""Model class to handle accounts."""
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(200), nullable=False)
|
||||
authorized_overdraft = db.Column(db.Integer, nullable=True, default=0)
|
||||
|
||||
def __init__(self, name, authorized_overdraft):
|
||||
self.name = name
|
||||
self.authorized_overdraft = authorized_overdraft
|
||||
|
||||
@classmethod
|
||||
def query(cls):
|
||||
"""Return a query for this class method."""
|
||||
return db.session.query(
|
||||
cls
|
||||
).order_by(
|
||||
cls.name
|
||||
)
|
||||
|
||||
def balances(self):
|
||||
"""Return the balances of this account."""
|
||||
return db.session.query(
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
), 0
|
||||
).label("future"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
Operation.pointed
|
||||
), 0
|
||||
).label("pointed"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value,
|
||||
).filter(
|
||||
Operation.operation_date <= db.func.current_date()
|
||||
), 0
|
||||
).label("current"),
|
||||
).filter(
|
||||
Operation.account_id == self.id
|
||||
).one()
|
||||
|
||||
def income(self, begin, end):
|
||||
"""Return the income for a specific time period."""
|
||||
query = db.session.query(
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == -1
|
||||
), 0
|
||||
).label("expenses"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == 1
|
||||
), 0
|
||||
).label("revenues"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(Operation.value), 0
|
||||
).label("income")
|
||||
).filter(
|
||||
Operation.account_id == self.id,
|
||||
)
|
||||
|
||||
if begin:
|
||||
query = query.filter(Operation.operation_date >= str(begin))
|
||||
|
||||
if end:
|
||||
query = query.filter(Operation.operation_date <= str(end))
|
||||
|
||||
return query.one()
|
||||
|
||||
def category_incomes(self, begin=None, end=None):
|
||||
"""Return a query for categories with expenses, revenues and income for
|
||||
this account and an optional specific time period."""
|
||||
|
||||
query = db.session.query(
|
||||
Operation.category.label('category'),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == -1
|
||||
),
|
||||
0
|
||||
).label("expenses"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == 1
|
||||
),
|
||||
0
|
||||
).label("revenues"),
|
||||
db.func.sum(Operation.value).label("income")
|
||||
).filter(
|
||||
Operation.account_id == self.id
|
||||
).order_by(
|
||||
Operation.category
|
||||
).group_by(
|
||||
Operation.category
|
||||
)
|
||||
|
||||
if begin:
|
||||
query = query.filter(Operation.operation_date >= str(begin))
|
||||
|
||||
if end:
|
||||
query = query.filter(Operation.operation_date <= str(end))
|
||||
|
||||
return query
|
||||
|
||||
def daily_balances(self, begin=None, end=None):
|
||||
"""Return a query for daily balances with expenses, revenues, income
|
||||
and balance per day for this account and an optional specifir range."""
|
||||
|
||||
#end = end if end else arrow.now().ceil('month').date()
|
||||
|
||||
query = db.session.query(
|
||||
Operation.operation_date,
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == -1
|
||||
).over(
|
||||
partition_by=[
|
||||
Operation.account_id,
|
||||
Operation.operation_date
|
||||
],
|
||||
),
|
||||
0
|
||||
).label("expenses"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == 1
|
||||
).over(
|
||||
partition_by=[
|
||||
Operation.account_id,
|
||||
Operation.operation_date
|
||||
],
|
||||
),
|
||||
0
|
||||
).label("revenues"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).over(
|
||||
partition_by=[
|
||||
Operation.account_id,
|
||||
Operation.operation_date
|
||||
],
|
||||
)
|
||||
).label("income"),
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).over(
|
||||
partition_by=Operation.account_id,
|
||||
order_by=Operation.operation_date
|
||||
)
|
||||
).label("balance")
|
||||
).distinct(
|
||||
).order_by(
|
||||
Operation.operation_date
|
||||
).filter(
|
||||
Operation.account_id == self.id
|
||||
)
|
||||
|
||||
if begin:
|
||||
base_query = query.subquery()
|
||||
|
||||
query = db.session.query(
|
||||
base_query
|
||||
).filter(
|
||||
base_query.c.operation_date >= str(begin)
|
||||
).order_by(
|
||||
base_query.c.operation_date
|
||||
)
|
||||
|
||||
if end:
|
||||
query = query.filter(query.c.operation_date <= str(end))
|
||||
|
||||
elif end:
|
||||
query = query.filter(Operation.operation_date <= str(end))
|
||||
|
||||
return query
|
||||
|
||||
@db.validates('authorized_overdraft')
|
||||
def validate_authorized_overdraft(self, key, authorized_overdraft):
|
||||
"""Validator for authorized_overdraft : must be negative."""
|
||||
del key
|
||||
|
||||
assert authorized_overdraft <= 0
|
||||
|
||||
return authorized_overdraft
|
134
accountant/models/operations.py
Normal file
134
accountant/models/operations.py
Normal file
@ -0,0 +1,134 @@
|
||||
"""Module containing operation related models."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from datetime import date
|
||||
|
||||
import arrow
|
||||
|
||||
from . import db
|
||||
|
||||
|
||||
# pylint: disable=no-member,invalid-name,too-many-arguments
|
||||
# pylint: disable=too-few-public-methods,too-many-instance-attributes
|
||||
class Operation(db.Model):
|
||||
"""Class used to handle operations."""
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
operation_date = db.Column(
|
||||
db.Date,
|
||||
nullable=False,
|
||||
default=date.today,
|
||||
server_default=db.func.current_date(),
|
||||
index=True
|
||||
)
|
||||
label = db.Column(db.String(500), nullable=False)
|
||||
value = db.Column(db.Numeric(15, 2), nullable=False)
|
||||
|
||||
scheduled_operation_id = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('scheduled_operation.id'),
|
||||
index=True
|
||||
)
|
||||
|
||||
scheduled_operation = db.relationship(
|
||||
"ScheduledOperation", backref=db.backref('operations', lazy="dynamic")
|
||||
)
|
||||
|
||||
account_id = db.Column(db.Integer, db.ForeignKey('account.id'), index=True)
|
||||
|
||||
account = db.relationship(
|
||||
'Account', backref=db.backref('operations', lazy="dynamic")
|
||||
)
|
||||
|
||||
category = db.Column(db.String(100), nullable=True, index=True)
|
||||
|
||||
pointed = db.Column(
|
||||
db.Boolean,
|
||||
nullable=False,
|
||||
default=False,
|
||||
server_default=db.false()
|
||||
)
|
||||
|
||||
confirmed = db.Column(
|
||||
db.Boolean,
|
||||
nullable=False,
|
||||
default=True,
|
||||
server_default=db.true()
|
||||
)
|
||||
|
||||
canceled = db.Column(
|
||||
db.Boolean,
|
||||
nullable=False,
|
||||
default=False,
|
||||
server_default=db.false()
|
||||
)
|
||||
|
||||
def __init__(self, label, value, account_id, operation_date=None,
|
||||
category=None, pointed=False, confirmed=True, canceled=False,
|
||||
scheduled_operation_id=None):
|
||||
self.operation_date = operation_date
|
||||
self.label = label
|
||||
self.value = value
|
||||
self.category = category
|
||||
self.account_id = account_id
|
||||
self.scheduled_operation_id = scheduled_operation_id
|
||||
self.pointed = pointed
|
||||
self.confirmed = confirmed
|
||||
self.canceled = canceled
|
||||
|
||||
@classmethod
|
||||
def query(cls):
|
||||
"""Return query for this class."""
|
||||
|
||||
query = db.session.query(
|
||||
cls
|
||||
)
|
||||
|
||||
return query
|
||||
|
||||
@classmethod
|
||||
def query_with_balance(cls, account_id, begin=None, end=None):
|
||||
"""Get operations with cumulated balance for a speciific account,
|
||||
optionally for a specific time period."""
|
||||
query = db.session.query(
|
||||
*cls.__table__.columns.keys(),
|
||||
db.func.sum(
|
||||
cls.value
|
||||
).filter(
|
||||
db.not_(cls.canceled)
|
||||
).over(
|
||||
partition_by=[cls.account_id],
|
||||
order_by=[
|
||||
cls.operation_date,
|
||||
db.desc(cls.value),
|
||||
db.desc(cls.label),
|
||||
cls.id
|
||||
]
|
||||
).label("balance")
|
||||
).filter(
|
||||
cls.account_id == account_id
|
||||
)
|
||||
|
||||
if begin:
|
||||
base_query = query.subquery()
|
||||
|
||||
query = db.session.query(
|
||||
base_query
|
||||
).filter(
|
||||
cls.operation_date >= str(begin)
|
||||
).join(
|
||||
cls, base_query.c.id == cls.id
|
||||
)
|
||||
|
||||
if end:
|
||||
query = query.filter(cls.operation_date <= str(end))
|
||||
|
||||
query = query.order_by(
|
||||
cls.operation_date,
|
||||
db.desc(cls.value),
|
||||
db.desc(cls.label),
|
||||
cls.id
|
||||
)
|
||||
|
||||
return query
|
120
accountant/models/scheduled_operations.py
Normal file
120
accountant/models/scheduled_operations.py
Normal file
@ -0,0 +1,120 @@
|
||||
"""Module containing scheduled operation related models."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from calendar import monthrange
|
||||
|
||||
import arrow
|
||||
|
||||
from . import db
|
||||
|
||||
from .accounts import Account
|
||||
from .operations import Operation
|
||||
|
||||
|
||||
# pylint: disable=no-member,invalid-name,too-many-arguments
|
||||
# pylint: disable=too-few-public-methods,too-many-instance-attributes
|
||||
class ScheduledOperation(db.Model):
|
||||
"""Class used to handle scheduled operations."""
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
start_date = db.Column(db.Date, nullable=False)
|
||||
stop_date = db.Column(db.Date, nullable=False)
|
||||
|
||||
day = db.Column(db.Integer, nullable=False)
|
||||
frequency = db.Column(db.Integer, nullable=False)
|
||||
|
||||
label = db.Column(db.String(500), nullable=False)
|
||||
value = db.Column(db.Numeric(15, 2), nullable=False)
|
||||
|
||||
category = db.Column(db.String(100), nullable=True)
|
||||
|
||||
account_id = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('account.id')
|
||||
)
|
||||
|
||||
account = db.relationship(
|
||||
Account,
|
||||
backref=db.backref('scheduled_operation', lazy="dynamic")
|
||||
)
|
||||
|
||||
def __init__(self, start_date, stop_date, day, frequency, label, value,
|
||||
account_id, category=None):
|
||||
self.start_date = start_date
|
||||
self.stop_date = stop_date
|
||||
self.day = day
|
||||
self.frequency = frequency
|
||||
self.label = label
|
||||
self.value = value
|
||||
self.account_id = account_id
|
||||
self.category = category
|
||||
|
||||
@classmethod
|
||||
def query(cls):
|
||||
"""Return base query for this class."""
|
||||
return db.session.query(
|
||||
cls
|
||||
).order_by(
|
||||
db.desc(cls.day),
|
||||
cls.value,
|
||||
cls.label,
|
||||
)
|
||||
|
||||
def reschedule(self):
|
||||
"""Reschedule a scheduled operation."""
|
||||
# 1) delete unconfirmed operations for this account.
|
||||
db.session.query(
|
||||
Operation
|
||||
).filter(
|
||||
Operation.scheduled_operation_id == self.id,
|
||||
Operation.confirmed == db.false()
|
||||
).delete()
|
||||
|
||||
# 2) schedule remaining operations.
|
||||
# Find the first date to have all dates in the range with the right
|
||||
# day.
|
||||
start_date = arrow.get(self.start_date)
|
||||
day = min(self.day, monthrange(start_date.year, start_date.month)[1])
|
||||
|
||||
# First date is in the next month is below the start date day.
|
||||
if day < start_date.day:
|
||||
start_date = start_date.replace(months=+1)
|
||||
start_date = start_date.replace(day=day)
|
||||
|
||||
# Stop date remains the same.
|
||||
stop_date = arrow.get(self.stop_date)
|
||||
|
||||
# Iterate over the range.
|
||||
date_range = arrow.Arrow.range("month", start_date, stop_date)
|
||||
dates = date_range[::self.frequency]
|
||||
for date in dates:
|
||||
# If a date day is below the first date day, next dates will not
|
||||
# have the right day.
|
||||
day = min(self.day, monthrange(
|
||||
date.year, date.month)[1])
|
||||
|
||||
date = date.replace(day=day)
|
||||
|
||||
# Search if a close operation exists.
|
||||
|
||||
if not db.session.query(Operation).filter(
|
||||
Operation.account_id == self.account_id,
|
||||
Operation.scheduled_operation_id == self.id,
|
||||
Operation.operation_date >= date.replace(weeks=-2).date(),
|
||||
Operation.operation_date <= date.replace(weeks=+2).date()
|
||||
).count():
|
||||
# Create not confirmed operation if not found.
|
||||
operation = Operation(
|
||||
operation_date=date.date(),
|
||||
label=self.label,
|
||||
value=self.value,
|
||||
category=self.category,
|
||||
account_id=self.account_id,
|
||||
scheduled_operation_id=self.id,
|
||||
pointed=False,
|
||||
confirmed=False,
|
||||
canceled=False
|
||||
)
|
||||
|
||||
db.session.add(operation)
|
36
accountant/models/users.py
Normal file
36
accountant/models/users.py
Normal file
@ -0,0 +1,36 @@
|
||||
"""Module containing user related models."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from passlib.hash import sha256_crypt as crypt
|
||||
|
||||
from . import db
|
||||
|
||||
|
||||
# pylint: disable=no-member,invalid-name
|
||||
# pylint: disable=too-few-public-methods,too-many-instance-attributes
|
||||
class User(db.Model):
|
||||
"""Class used to handle users."""
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
email = db.Column(db.String(200), nullable=False, unique=True, index=True)
|
||||
password = db.Column(db.String(100), nullable=True)
|
||||
active = db.Column(db.Boolean, nullable=False, default=True,
|
||||
server_default=db.true())
|
||||
|
||||
def is_active(self):
|
||||
"""Return True if user is active."""
|
||||
return self.active
|
||||
|
||||
@classmethod
|
||||
def query(cls):
|
||||
"""Return a query for this class."""
|
||||
return db.session.query(cls)
|
||||
|
||||
@classmethod
|
||||
def hash_password(cls, password):
|
||||
"""Password hash function."""
|
||||
return crypt.encrypt(password)
|
||||
|
||||
def verify_password(self, password):
|
||||
"""Verify password passed in argument with the user's one."""
|
||||
return crypt.verify(password, self.password)
|
35
accountant/run.py
Normal file
35
accountant/run.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""Accountant runner."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from os import path, getcwd
|
||||
|
||||
import click
|
||||
|
||||
from . import create_app
|
||||
|
||||
from .models import db
|
||||
from .models.users import User
|
||||
|
||||
|
||||
config_path = path.join(getcwd(), 'config.cfg') # pylint: disable=invalid-name
|
||||
app = create_app(config_path) # pylint: disable=invalid-name
|
||||
|
||||
|
||||
# Define commands to handle users.
|
||||
@app.cli.group()
|
||||
def users():
|
||||
""" User management. """
|
||||
pass
|
||||
|
||||
|
||||
@users.command()
|
||||
def add(email, password):
|
||||
""" Add a new user. """
|
||||
user = User()
|
||||
user.email = email
|
||||
user.password = User.hash_password(password)
|
||||
|
||||
db.session.add(user) # pylint: disable=no-member
|
||||
|
||||
click.echo("User '%s' successfully added." % email)
|
69
accountant/views/__init__.py
Normal file
69
accountant/views/__init__.py
Normal file
@ -0,0 +1,69 @@
|
||||
"""Package containing views."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from flask_cors import CORS
|
||||
from flask_jwt_extended import JWTManager
|
||||
from flask_restplus import Api
|
||||
|
||||
from .accounts import ns as accounts_ns
|
||||
from .operations import ns as operations_ns
|
||||
from .scheduled_operations import ns as scheduled_operations_ns
|
||||
from .users import ns as users_ns
|
||||
|
||||
# API initialization.
|
||||
# pylint: disable=invalid-name
|
||||
authorizations = {
|
||||
'apikey': {
|
||||
'type': 'apiKey',
|
||||
'in': 'header',
|
||||
'name': 'Authorization',
|
||||
},
|
||||
'basic': {
|
||||
'type': 'basic',
|
||||
}
|
||||
}
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
api = Api(
|
||||
title='Accountant API',
|
||||
version='2.0',
|
||||
description='This is the Accountant API.',
|
||||
authorizations=authorizations,
|
||||
prefix='/api'
|
||||
)
|
||||
|
||||
|
||||
api.add_namespace(accounts_ns)
|
||||
api.add_namespace(operations_ns)
|
||||
api.add_namespace(scheduled_operations_ns)
|
||||
api.add_namespace(users_ns)
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
cors = CORS()
|
||||
|
||||
jwt = JWTManager()
|
||||
|
||||
|
||||
@jwt.user_identity_loader
|
||||
def user_identity_lookup(user):
|
||||
"""Return information to be in token."""
|
||||
return user.id
|
||||
|
||||
|
||||
@jwt.expired_token_loader
|
||||
def expired_token_callback():
|
||||
"""Handler for expired token."""
|
||||
api.abort(401, "Expired token.")
|
||||
|
||||
|
||||
@jwt.unauthorized_loader
|
||||
def unauthorized_callback(message):
|
||||
"""Handler for unauthorized."""
|
||||
api.abort(401, message)
|
||||
|
||||
|
||||
@jwt.invalid_token_loader
|
||||
def invalid_token_callback(message):
|
||||
"""Handler for invalid token."""
|
||||
api.abort(401, message)
|
373
accountant/views/accounts.py
Normal file
373
accountant/views/accounts.py
Normal file
@ -0,0 +1,373 @@
|
||||
"""Module containing account related views."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
import dateutil.parser
|
||||
|
||||
from flask_jwt_extended import jwt_required
|
||||
from flask_restplus import Namespace, Resource, fields
|
||||
|
||||
from ..models import db, row_as_dict, result_as_dicts
|
||||
from ..models.accounts import Account
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
ns = Namespace('account', description='Account management')
|
||||
|
||||
# Account model.
|
||||
account_model = ns.model('Account', {
|
||||
'id': fields.Integer(
|
||||
default=None,
|
||||
readonly=True,
|
||||
description='Id of the account'),
|
||||
'name': fields.String(
|
||||
required=True,
|
||||
description='Name of the account'),
|
||||
'authorized_overdraft': fields.Float(
|
||||
required=True,
|
||||
description='Authorized overdraft')
|
||||
})
|
||||
|
||||
# Account status model.
|
||||
balances_model = ns.model('Account balances', {
|
||||
'current': fields.Float(
|
||||
readonly=True,
|
||||
description='Current balance of the account'),
|
||||
'pointed': fields.Float(
|
||||
readonly=True,
|
||||
description='Pointed balance of the account'),
|
||||
'future': fields.Float(
|
||||
readonly=True,
|
||||
description='Future balance of the account')
|
||||
})
|
||||
|
||||
# Account balance model.
|
||||
income_model = ns.model('Income', {
|
||||
'expenses': fields.Float(
|
||||
readonly=True,
|
||||
description='Total amount of expenses'),
|
||||
'revenues': fields.Float(
|
||||
readonly=True,
|
||||
description='Total amount of revenues'),
|
||||
'income': fields.Float(
|
||||
readonly=True,
|
||||
description='Income'),
|
||||
})
|
||||
|
||||
# Category with expenses and revenues.
|
||||
category_model = ns.model('Category', {
|
||||
'category': fields.String(
|
||||
readonly=True,
|
||||
description='Category name'),
|
||||
'expenses': fields.Float(
|
||||
readonly=True,
|
||||
description='Total amount of expenses for the category'),
|
||||
'revenues': fields.Float(
|
||||
readonly=True,
|
||||
description='Total amount of revenues for the category'),
|
||||
'income': fields.Float(
|
||||
readonly=True,
|
||||
description='Total income for the category')
|
||||
})
|
||||
|
||||
# Daily balance model.
|
||||
daily_balance_model = ns.model('Daily balance', {
|
||||
'operation_date': fields.Date(
|
||||
dt_format='iso8601',
|
||||
readonly=True,
|
||||
required=True,
|
||||
description='Date'
|
||||
),
|
||||
'expenses': fields.Float(
|
||||
readonly=True,
|
||||
required=True,
|
||||
description='Expenses'
|
||||
),
|
||||
'revenues': fields.Float(
|
||||
readonly=True,
|
||||
required=True,
|
||||
description='Revenues'
|
||||
),
|
||||
'income': fields.Float(
|
||||
readonly=True,
|
||||
required=True,
|
||||
description='Income'
|
||||
),
|
||||
'balance': fields.Float(
|
||||
readonly=True,
|
||||
required=True,
|
||||
description='Balance'
|
||||
)
|
||||
})
|
||||
|
||||
# Parser for a date range.
|
||||
range_parser = ns.parser()
|
||||
range_parser.add_argument(
|
||||
'begin',
|
||||
type=lambda a: dateutil.parser.parse(a) if a else None,
|
||||
required=False,
|
||||
default=None,
|
||||
location='args',
|
||||
help='Begin date of the time period'
|
||||
)
|
||||
range_parser.add_argument(
|
||||
'end',
|
||||
type=lambda a: dateutil.parser.parse(a) if a else None,
|
||||
required=False,
|
||||
default=None,
|
||||
location='args',
|
||||
help='End date of the time period'
|
||||
)
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@ns.route('/')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
responses={
|
||||
401: 'Unauthorized'
|
||||
})
|
||||
class AccountListResource(Resource):
|
||||
"""Resource used to handle account lists."""
|
||||
|
||||
@ns.response(200, 'OK', [account_model])
|
||||
@ns.marshal_list_with(account_model)
|
||||
@jwt_required
|
||||
def get(self):
|
||||
""" Returns accounts with their balances."""
|
||||
|
||||
return Account.query().all(), 200
|
||||
|
||||
@ns.expect(account_model)
|
||||
@ns.response(201, 'Account created', account_model)
|
||||
@ns.response(406, 'Invalid account data')
|
||||
@ns.marshal_with(account_model)
|
||||
@jwt_required
|
||||
def post(self):
|
||||
"""Create a new account."""
|
||||
|
||||
data = self.api.payload
|
||||
|
||||
# A new account MUST NOT have an id;
|
||||
if data.get('id') is not None:
|
||||
ns.abort(406, 'Id must not be provided on creation.')
|
||||
|
||||
# Instantiate account with data.
|
||||
account = Account(**data)
|
||||
|
||||
# Add new account in session.
|
||||
db.session.add(account) # pylint: disable=no-member
|
||||
|
||||
# Flush session to have id in account.
|
||||
db.session.flush() # pylint: disable=no-member
|
||||
|
||||
# Return account.
|
||||
return account, 201
|
||||
|
||||
|
||||
@ns.route('/<int:account_id>')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
params={
|
||||
'account_id': 'Id of the account to manage'
|
||||
},
|
||||
responses={
|
||||
401: 'Unauthorized',
|
||||
404: 'Account not found'
|
||||
})
|
||||
class AccountResource(Resource):
|
||||
"""Resource to handle accounts."""
|
||||
|
||||
@ns.response(200, 'OK', account_model)
|
||||
@ns.marshal_with(account_model)
|
||||
@jwt_required
|
||||
def get(self, account_id):
|
||||
"""Get an account."""
|
||||
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
# Note: if we don't pass the code, the result is seen as a tuple and
|
||||
# causes error on marshalling.
|
||||
return account, 200
|
||||
|
||||
@ns.expect(account_model)
|
||||
@ns.response(200, 'OK', account_model)
|
||||
@ns.response(406, 'Invalid account data')
|
||||
@ns.marshal_with(account_model)
|
||||
@jwt_required
|
||||
def post(self, account_id):
|
||||
"""Update an account."""
|
||||
|
||||
data = self.api.payload
|
||||
|
||||
# Check ID consistency.
|
||||
if data.get('id', default=account_id) != account_id:
|
||||
ns.abort(406, 'Id must not be provided or changed on update.')
|
||||
|
||||
# Need to get the object to update it.
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
# SQLAlchemy objects ignore __dict__.update() with merge.
|
||||
for key, value in data.items():
|
||||
setattr(account, key, value)
|
||||
|
||||
db.session.merge(account) # pylint: disable=no-member
|
||||
|
||||
# Return account.
|
||||
return account, 200
|
||||
|
||||
@ns.response(204, 'Account deleted', account_model)
|
||||
@ns.marshal_with(account_model)
|
||||
@jwt_required
|
||||
def delete(self, account_id):
|
||||
"""Delete an account."""
|
||||
|
||||
# Need to get the object to update it.
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
db.session.delete(account) # pylint: disable=no-member
|
||||
|
||||
return None, 204
|
||||
|
||||
|
||||
@ns.route('/<int:account_id>/balances')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
params={
|
||||
'account_id': 'Id of the account to manage'
|
||||
},
|
||||
responses={
|
||||
200: ('OK', balances_model),
|
||||
401: 'Unauthorized',
|
||||
404: 'Account not found'
|
||||
})
|
||||
class BalancesResource(Resource):
|
||||
"""Resource to expose current, pointed and future balances."""
|
||||
|
||||
@ns.marshal_with(balances_model)
|
||||
@jwt_required
|
||||
def get(self, account_id):
|
||||
"""Get current, pointed and future balances for a specific account and
|
||||
date range."""
|
||||
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
# Note: if we don't pass the code, the result is seen as a tuple and
|
||||
# causes error on marshalling.
|
||||
return row_as_dict(
|
||||
account.balances()
|
||||
), 200
|
||||
|
||||
|
||||
@ns.route('/<int:account_id>/income')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
params={
|
||||
'account_id': 'Id of the account to manage'
|
||||
},
|
||||
responses={
|
||||
200: ('OK', income_model),
|
||||
401: 'Unauthorized',
|
||||
404: 'Account not found'
|
||||
})
|
||||
class BalanceResource(Resource):
|
||||
"""Resource to expose balances."""
|
||||
|
||||
@ns.expect(range_parser)
|
||||
@ns.marshal_with(income_model)
|
||||
@jwt_required
|
||||
def get(self, account_id):
|
||||
"""Get account income for a specific date range."""
|
||||
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
data = range_parser.parse_args()
|
||||
|
||||
return row_as_dict(
|
||||
account.income(**data)
|
||||
), 200
|
||||
|
||||
|
||||
@ns.route("/<int:account_id>/category")
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
params={
|
||||
'account_id': 'Id of the account to manage'
|
||||
},
|
||||
responses={
|
||||
200: ('OK', [category_model]),
|
||||
401: 'Unauthorized',
|
||||
404: 'Account not found'
|
||||
})
|
||||
class CategoryResource(Resource):
|
||||
"""Resource to expose categories."""
|
||||
|
||||
@ns.expect(range_parser)
|
||||
@ns.marshal_list_with(category_model)
|
||||
@jwt_required
|
||||
def get(self, account_id):
|
||||
"""Get account category balances for a specific date range."""
|
||||
|
||||
data = range_parser.parse_args()
|
||||
|
||||
# FIXME Alexis Lahouze 2017-05-23 check data.
|
||||
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
return list(result_as_dicts(
|
||||
account.category_incomes(**data)
|
||||
)), 200
|
||||
|
||||
|
||||
@ns.route('/<int:account_id>/daily_balances')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
params={
|
||||
'account_id': 'Id of the account to manage'
|
||||
},
|
||||
responses={
|
||||
200: ('OK', [daily_balance_model]),
|
||||
401: 'Unauthorized',
|
||||
404: 'Account not found'
|
||||
})
|
||||
class DailyBalancesResource(Resource):
|
||||
"""Resource to expose account daily balances."""
|
||||
|
||||
@ns.expect(range_parser)
|
||||
@ns.marshal_list_with(daily_balance_model)
|
||||
@jwt_required
|
||||
def get(self, account_id):
|
||||
"""Get account daily balance data for a specific date range and
|
||||
account."""
|
||||
|
||||
data = range_parser.parse_args()
|
||||
|
||||
# FIXME Alexis Lahouze 2017-05-23 check data.
|
||||
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
return list(result_as_dicts(
|
||||
account.daily_balances(**data)
|
||||
)), 200
|
223
accountant/views/operations.py
Normal file
223
accountant/views/operations.py
Normal file
@ -0,0 +1,223 @@
|
||||
"""Module containing operation related views."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
import dateutil.parser
|
||||
|
||||
from flask_jwt_extended import jwt_required
|
||||
from flask_restplus import Namespace, Resource, fields
|
||||
|
||||
from ..models import db, result_as_dicts
|
||||
from ..models.accounts import Account
|
||||
from ..models.operations import Operation
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
ns = Namespace('operation', description='Operation management')
|
||||
|
||||
# Operation with sold model.
|
||||
operation_model = ns.model('Operation', {
|
||||
'id': fields.Integer(
|
||||
default=None,
|
||||
readonly=True,
|
||||
description='Id of the operation'),
|
||||
'operation_date': fields.Date(
|
||||
dt_format='iso8601',
|
||||
required=True,
|
||||
description='Date of the operation'),
|
||||
'label': fields.String(
|
||||
required=True,
|
||||
description='Label of the operation'),
|
||||
'value': fields.Float(
|
||||
required=True,
|
||||
description='Value of the operation'),
|
||||
'pointed': fields.Boolean(
|
||||
required=True,
|
||||
description='Pointed status of the operation'),
|
||||
'category': fields.String(
|
||||
required=False,
|
||||
default=None,
|
||||
description='Category of the operation'),
|
||||
'account_id': fields.Integer(
|
||||
required=True,
|
||||
readonly=True,
|
||||
description='Account id of the operation'),
|
||||
'scheduled_operation_id': fields.Integer(
|
||||
default=None,
|
||||
readonly=True,
|
||||
description='Scheduled operation ID of the operation'),
|
||||
'confirmed': fields.Boolean(
|
||||
description='Confirmed status of the operation'),
|
||||
'canceled': fields.Boolean(
|
||||
description='Canceled status of the operation (for a scheduled one)')
|
||||
})
|
||||
|
||||
operation_with_balance_model = ns.clone(
|
||||
'OperationWithBalance', operation_model, {
|
||||
'balance': fields.Float(
|
||||
readonly=True,
|
||||
description='Cumulated balance'
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
# Parser for a date range and an account id.
|
||||
account_range_parser = ns.parser()
|
||||
account_range_parser.add_argument(
|
||||
'begin',
|
||||
type=lambda a: dateutil.parser.parse(a) if a else None,
|
||||
required=False,
|
||||
default=None,
|
||||
location='args',
|
||||
help='Begin date of the time period'
|
||||
)
|
||||
account_range_parser.add_argument(
|
||||
'end',
|
||||
type=lambda a: dateutil.parser.parse(a) if a else None,
|
||||
required=False,
|
||||
default=None,
|
||||
location='args',
|
||||
help='End date of the time period'
|
||||
)
|
||||
account_range_parser.add_argument(
|
||||
'account_id',
|
||||
type=int,
|
||||
required=True,
|
||||
location='args',
|
||||
help='Id of the account'
|
||||
)
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@ns.route('/')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
responses={
|
||||
401: 'Unauthorized'
|
||||
})
|
||||
class OperationListResource(Resource):
|
||||
"""Resource to handle operation lists."""
|
||||
|
||||
@ns.response(200, 'OK', [operation_with_balance_model])
|
||||
@ns.expect(account_range_parser)
|
||||
@ns.marshal_list_with(operation_with_balance_model)
|
||||
@jwt_required
|
||||
def get(self):
|
||||
"""Get operations with cumulated balance for a specific account."""
|
||||
|
||||
data = account_range_parser.parse_args()
|
||||
|
||||
account_id = data['account_id']
|
||||
begin = data['begin']
|
||||
end = data['end']
|
||||
|
||||
return list(result_as_dicts(
|
||||
Operation.query_with_balance(account_id, begin=begin, end=end)
|
||||
)), 200
|
||||
|
||||
@ns.response(201, 'Operation created', operation_model)
|
||||
@ns.response(404, 'Account not found')
|
||||
@ns.response(406, 'Invalid operation data')
|
||||
@ns.marshal_with(operation_model)
|
||||
@jwt_required
|
||||
def post(self):
|
||||
"""Create a new operation."""
|
||||
|
||||
data = self.api.payload
|
||||
|
||||
account_id = data['account_id']
|
||||
|
||||
# FIXME Alexis Lahouze 2017-05-19 Check account_id presence.
|
||||
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
# A new operation MUST NOT have an id;
|
||||
if data.get('id') is not None:
|
||||
ns.abort(406, 'Id must not be provided on creation.')
|
||||
|
||||
operation = Operation(**data)
|
||||
|
||||
db.session.add(operation) # pylint: disable=no-member
|
||||
|
||||
return operation, 201
|
||||
|
||||
|
||||
@ns.route('/<int:operation_id>')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
params={
|
||||
'operation_id': 'Id of the operation to manage'
|
||||
},
|
||||
responses={
|
||||
401: 'Unauthorized',
|
||||
404: 'Operation not found'
|
||||
})
|
||||
class OperationResource(Resource):
|
||||
"""Resource to handle operations."""
|
||||
|
||||
@ns.response(200, 'OK', operation_model)
|
||||
@ns.marshal_with(operation_model)
|
||||
@jwt_required
|
||||
def get(self, operation_id):
|
||||
"""Get operation."""
|
||||
|
||||
# pylint: disable=no-member
|
||||
operation = db.session.query(Operation).get(operation_id)
|
||||
# pylint: enable=no-member
|
||||
|
||||
if not operation:
|
||||
ns.abort(404, 'Operation with id %d not found.' % operation_id)
|
||||
|
||||
return operation, 200
|
||||
|
||||
@ns.expect(operation_model)
|
||||
@ns.response(200, 'OK', operation_model)
|
||||
@ns.response(406, 'Invalid operation data')
|
||||
@ns.marshal_with(operation_model)
|
||||
@jwt_required
|
||||
def post(self, operation_id):
|
||||
"""Update an operation."""
|
||||
|
||||
data = self.api.payload
|
||||
|
||||
# Check ID consistency.
|
||||
if data.get('id', default=operation_id) != operation_id:
|
||||
ns.abort(406, 'Id must not be provided or changed on update.')
|
||||
|
||||
# pylint: disable=no-member
|
||||
operation = db.session.query(Operation).get(operation_id)
|
||||
# pylint: enable=no-member
|
||||
|
||||
if not operation:
|
||||
ns.abort(404, 'Operation with id %d not found.' % operation_id)
|
||||
|
||||
# FIXME check account_id consistency.
|
||||
|
||||
# SQLAlchemy objects ignore __dict__.update() with merge.
|
||||
for key, value in data.items():
|
||||
setattr(operation, key, value)
|
||||
|
||||
db.session.merge(operation) # pylint: disable=no-member
|
||||
|
||||
return operation, 200
|
||||
|
||||
@ns.response(204, 'Operation deleted', operation_model)
|
||||
@ns.marshal_with(operation_model)
|
||||
@jwt_required
|
||||
def delete(self, operation_id):
|
||||
"""Delete an operation."""
|
||||
|
||||
# pylint: disable=no-member
|
||||
operation = db.session.query(Operation).get(operation_id)
|
||||
# pylint: enable=no-member
|
||||
|
||||
if not operation:
|
||||
ns.abort(404, 'Operation with id %d not found.' % operation_id)
|
||||
|
||||
db.session.delete(operation) # pylint: disable=no-member
|
||||
|
||||
return None, 204
|
212
accountant/views/scheduled_operations.py
Normal file
212
accountant/views/scheduled_operations.py
Normal file
@ -0,0 +1,212 @@
|
||||
"""Module containing scheduled operation related views."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from flask_jwt_extended import jwt_required
|
||||
from flask_restplus import Namespace, Resource, fields
|
||||
|
||||
from sqlalchemy import true
|
||||
|
||||
from ..models import db
|
||||
from ..models.accounts import Account
|
||||
from ..models.operations import Operation
|
||||
from ..models.scheduled_operations import ScheduledOperation
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
ns = Namespace(
|
||||
'scheduled_operation',
|
||||
description='Scheduled operation management'
|
||||
)
|
||||
|
||||
# Scheduled operation model.
|
||||
scheduled_operation_model = ns.model('ScheduledOperation', {
|
||||
'id': fields.Integer(
|
||||
description='Id of the scheduled operation',
|
||||
readonly=True,
|
||||
default=None),
|
||||
'start_date': fields.Date(
|
||||
dt_format='iso8601',
|
||||
required=True,
|
||||
description='Start date of the scheduled operation'),
|
||||
'stop_date': fields.Date(
|
||||
dt_format='iso8601',
|
||||
required=True,
|
||||
description='End date of the scheduled operation'),
|
||||
'day': fields.Integer(
|
||||
required=True,
|
||||
description='Day of month for the scheduled operation'),
|
||||
'frequency': fields.Integer(
|
||||
required=True,
|
||||
description='Frequency of the scheduling in months'),
|
||||
'label': fields.String(
|
||||
required=True,
|
||||
description='Label of the generated operations'),
|
||||
'value': fields.Float(
|
||||
required=True,
|
||||
description='Value of the generated operations'),
|
||||
'category': fields.String(
|
||||
required=False,
|
||||
description='Category of the generated operations'),
|
||||
'account_id': fields.Integer(
|
||||
default=None,
|
||||
readonly=True,
|
||||
required=True,
|
||||
description='Account id of the scheduled operation'),
|
||||
})
|
||||
|
||||
# Parser for an account id.
|
||||
account_id_parser = ns.parser()
|
||||
account_id_parser.add_argument(
|
||||
'account_id',
|
||||
type=int,
|
||||
required=True,
|
||||
location='args',
|
||||
help='Id of the account'
|
||||
)
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@ns.route('/')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
responses={
|
||||
401: 'Unauthorized',
|
||||
})
|
||||
class ScheduledOperationListResource(Resource):
|
||||
"""Resource to handle scheduled operation lists."""
|
||||
|
||||
@ns.expect(account_id_parser)
|
||||
@ns.response(200, 'OK', [scheduled_operation_model])
|
||||
@ns.marshal_list_with(scheduled_operation_model)
|
||||
@jwt_required
|
||||
def get(self):
|
||||
"""Get all scheduled operation for an account."""
|
||||
|
||||
data = account_id_parser.parse_args()
|
||||
|
||||
return ScheduledOperation.query().filter_by(**data).all(), 200
|
||||
|
||||
@ns.expect(scheduled_operation_model)
|
||||
@ns.response(200, 'OK', scheduled_operation_model)
|
||||
@ns.response(404, 'Account not found')
|
||||
@ns.response(406, 'Invalid operation data')
|
||||
@ns.marshal_with(scheduled_operation_model)
|
||||
@jwt_required
|
||||
def post(self):
|
||||
"""Add a new scheduled operation."""
|
||||
|
||||
data = self.api.payload
|
||||
|
||||
account_id = data['account_id']
|
||||
account = Account.query().get(account_id)
|
||||
|
||||
if not account:
|
||||
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||
|
||||
# A new scheduled operation MUST NOT have an id;
|
||||
if data.get('id') is not None:
|
||||
ns.abort(406, 'Id must not be provided on creation.')
|
||||
|
||||
scheduled_operation = ScheduledOperation(**data)
|
||||
|
||||
db.session.add(scheduled_operation) # pylint: disable=no-member
|
||||
|
||||
scheduled_operation.reschedule()
|
||||
|
||||
db.session.flush() # pylint: disable=no-member
|
||||
|
||||
return scheduled_operation, 201
|
||||
|
||||
|
||||
@ns.route('/<int:scheduled_operation_id>')
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
params={
|
||||
'scheduled_operation_id': 'Id of the scheduled operation to manage'
|
||||
},
|
||||
responses={
|
||||
401: 'Unauthorized',
|
||||
404: 'Scheduled operation not found'
|
||||
})
|
||||
class ScheduledOperationResource(Resource):
|
||||
"""Resource to handle scheduled operations."""
|
||||
|
||||
@ns.response(200, 'OK', scheduled_operation_model)
|
||||
@ns.marshal_with(scheduled_operation_model)
|
||||
@jwt_required
|
||||
def get(self, scheduled_operation_id):
|
||||
"""Get scheduled operation."""
|
||||
|
||||
so_id = scheduled_operation_id
|
||||
|
||||
scheduled_operation = ScheduledOperation.query().get(so_id)
|
||||
|
||||
if not scheduled_operation:
|
||||
ns.abort(404, 'Scheduled operation with id %d not found.' % so_id)
|
||||
|
||||
return scheduled_operation, 200
|
||||
|
||||
@ns.response(200, 'OK', scheduled_operation_model)
|
||||
@ns.response(406, 'Invalid scheduled operation data')
|
||||
@ns.expect(scheduled_operation_model)
|
||||
@ns.marshal_with(scheduled_operation_model)
|
||||
@jwt_required
|
||||
def post(self, scheduled_operation_id):
|
||||
"""Update a scheduled operation."""
|
||||
|
||||
data = self.api.payload
|
||||
so_id = scheduled_operation_id
|
||||
|
||||
# Check ID consistency.
|
||||
if data.get('id', default=so_id) != so_id:
|
||||
ns.abort(406, 'Id must not be provided or changed on update.')
|
||||
|
||||
scheduled_operation = ScheduledOperation.query().get(so_id)
|
||||
|
||||
if not scheduled_operation:
|
||||
ns.abort(404, 'Scheduled operation with id %d not found.' % so_id)
|
||||
|
||||
# FIXME check account_id consistency.
|
||||
|
||||
# SQLAlchemy objects ignore __dict__.update() with merge.
|
||||
for key, value in data.items():
|
||||
setattr(scheduled_operation, key, value)
|
||||
|
||||
db.session.merge(scheduled_operation) # pylint: disable=no-member
|
||||
|
||||
scheduled_operation.reschedule()
|
||||
|
||||
db.session.flush() # pylint: disable=no-member
|
||||
|
||||
return scheduled_operation, 200
|
||||
|
||||
@ns.response(200, 'OK', scheduled_operation_model)
|
||||
@ns.response(409, 'Cannot be deleted')
|
||||
@ns.marshal_with(scheduled_operation_model)
|
||||
@jwt_required
|
||||
def delete(self, scheduled_operation_id):
|
||||
"""Delete a scheduled operation."""
|
||||
|
||||
so_id = scheduled_operation_id
|
||||
|
||||
scheduled_operation = ScheduledOperation.query().get(so_id)
|
||||
|
||||
if not scheduled_operation:
|
||||
ns.abort(404, 'Scheduled operation with id %d not found.' % so_id)
|
||||
|
||||
operations = scheduled_operation.operations.filter(
|
||||
Operation.confirmed == true()
|
||||
).count()
|
||||
|
||||
if operations:
|
||||
ns.abort(409, 'There are still confirmed operations '
|
||||
'associated to this scheduled operation.')
|
||||
|
||||
# Delete unconfirmed operations
|
||||
scheduled_operation.operations.delete()
|
||||
|
||||
db.session.delete(scheduled_operation) # pylint: disable=no-member
|
||||
|
||||
return None, 204
|
98
accountant/views/users.py
Normal file
98
accountant/views/users.py
Normal file
@ -0,0 +1,98 @@
|
||||
"""Module containing user related views."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from flask import request
|
||||
from flask_jwt_extended import (jwt_required, get_jwt_identity,
|
||||
create_access_token, create_refresh_token)
|
||||
from flask_restplus import Namespace, Resource, fields
|
||||
|
||||
from ..models.users import User
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
ns = Namespace('user', description='User management')
|
||||
|
||||
# Token with expiration time and type.
|
||||
token_model = ns.model('Token', {
|
||||
'access_token': fields.String(
|
||||
required=True,
|
||||
readonly=True,
|
||||
description='Access token value'),
|
||||
'refresh_token': fields.String(
|
||||
required=False,
|
||||
readonly=True,
|
||||
description='Refresh token value'),
|
||||
'expiration': fields.DateTime(
|
||||
dt_format='iso8601',
|
||||
required=False,
|
||||
readonly=True,
|
||||
description='Expiration time of the token'),
|
||||
})
|
||||
|
||||
# User model.
|
||||
user_model = ns.model('User', {
|
||||
'id': fields.Integer(
|
||||
default=None,
|
||||
required=True,
|
||||
readonly=True,
|
||||
description='Id of the user'),
|
||||
'email': fields.String(
|
||||
required=True,
|
||||
readonly=True,
|
||||
decription='Email address of the user'),
|
||||
'active': fields.Boolean(
|
||||
required=True,
|
||||
readonly=True,
|
||||
description='Active state of the user')
|
||||
})
|
||||
# pylint: enable=invalid-name
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@ns.route('/login')
|
||||
class LoginResource(Resource):
|
||||
"""Resource to handle login operations."""
|
||||
|
||||
@ns.marshal_with(token_model)
|
||||
@ns.doc(
|
||||
security='basic',
|
||||
responses={
|
||||
200: ('OK', token_model),
|
||||
401: 'Unauthorized'
|
||||
})
|
||||
def post(self):
|
||||
"""Login to retrieve authentication token."""
|
||||
|
||||
if not request.authorization:
|
||||
ns.abort(401, "Missing authorization.")
|
||||
|
||||
email = request.authorization['username']
|
||||
password = request.authorization['password']
|
||||
|
||||
user = User.query().filter(
|
||||
User.email == email
|
||||
).one_or_none()
|
||||
|
||||
if not user or not user.verify_password(password):
|
||||
ns.abort(401, "Bad user or password.")
|
||||
|
||||
return {
|
||||
'access_token': create_access_token(identity=user),
|
||||
'refresh_token': create_refresh_token(identity=user)
|
||||
}, 200
|
||||
|
||||
@ns.doc(
|
||||
security='apikey',
|
||||
responses={
|
||||
200: ('OK', user_model)
|
||||
})
|
||||
@ns.marshal_with(user_model)
|
||||
@jwt_required
|
||||
def get(self):
|
||||
"""Get authenticated user information."""
|
||||
user = User.query().get(get_jwt_identity())
|
||||
|
||||
# FIXME Alexis Lahouze 2017-05-19 Check user presence
|
||||
|
||||
return user, 200
|
12
setup.cfg
Normal file
12
setup.cfg
Normal file
@ -0,0 +1,12 @@
|
||||
[aliases]
|
||||
test=pytest
|
||||
|
||||
[tool:pytest]
|
||||
addopts=
|
||||
--verbose --verbose --capture=no --ignore="virtualenv" --showlocals
|
||||
--flakes
|
||||
--pylint
|
||||
--cov-report term --cov-report html --cov=accountant
|
||||
|
||||
flakes-ignore=
|
||||
accountant/migrations/*.py UnusedImport
|
48
setup.py
Normal file
48
setup.py
Normal file
@ -0,0 +1,48 @@
|
||||
"""Accountant distribution setup."""
|
||||
|
||||
# vim: set tw=80 ts=4 sw=4 sts=4:
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='Accountant',
|
||||
version='0.0.1',
|
||||
license='AGPL',
|
||||
author='Alexis Lahouze',
|
||||
author_email='alexis@lahouze.org',
|
||||
|
||||
long_description=__doc__,
|
||||
|
||||
packages=['accountant', 'accountant.migrations'],
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
|
||||
install_requires=[
|
||||
'Flask~=0.12',
|
||||
'Flask-Alembic~=2.0',
|
||||
'Flask-SQLAlchemy>=2.2',
|
||||
'Flask-restplus~=0.10.1',
|
||||
'Flask-Cors~=3.0.0',
|
||||
'Flask-JWT-Extended~=2.0.0',
|
||||
'passlib~=1.7.1',
|
||||
'arrow~=0.10.0',
|
||||
'psycopg2~=2.7.1'
|
||||
],
|
||||
setup_requires=[
|
||||
'pytest-runner',
|
||||
],
|
||||
tests_require=[
|
||||
'pytest',
|
||||
'pytest-pylint',
|
||||
'pytest-flakes',
|
||||
'pytest-cov',
|
||||
'pytest-mock',
|
||||
],
|
||||
extras_require={
|
||||
'dev': [
|
||||
'ipython',
|
||||
'ipdb',
|
||||
'flask-shell-ipython',
|
||||
],
|
||||
},
|
||||
)
|
@ -1,11 +0,0 @@
|
||||
RewriteEngine On
|
||||
|
||||
# Some hosts may require you to use the `RewriteBase` directive.
|
||||
# If you need to use the `RewriteBase` directive, it should be the
|
||||
# absolute physical path to the directory that contains this htaccess file.
|
||||
#
|
||||
# RewriteBase /
|
||||
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [QSA,L]
|
||||
|
@ -1,237 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim;
|
||||
|
||||
/**
|
||||
* Environment
|
||||
*
|
||||
* This class creates and returns a key/value array of common
|
||||
* environment variables for the current HTTP request.
|
||||
*
|
||||
* This is a singleton class; derived environment variables will
|
||||
* be common across multiple Slim applications.
|
||||
*
|
||||
* This class matches the Rack (Ruby) specification as closely
|
||||
* as possible. More information available below.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Environment implements \ArrayAccess, \IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* @var \Slim\Environment
|
||||
*/
|
||||
protected static $environment;
|
||||
|
||||
/**
|
||||
* Get environment instance (singleton)
|
||||
*
|
||||
* This creates and/or returns an environment instance (singleton)
|
||||
* derived from $_SERVER variables. You may override the global server
|
||||
* variables by using `\Slim\Environment::mock()` instead.
|
||||
*
|
||||
* @param bool $refresh Refresh properties using global server variables?
|
||||
* @return \Slim\Environment
|
||||
*/
|
||||
public static function getInstance($refresh = false)
|
||||
{
|
||||
if (is_null(self::$environment) || $refresh) {
|
||||
self::$environment = new self();
|
||||
}
|
||||
|
||||
return self::$environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mock environment instance
|
||||
*
|
||||
* @param array $userSettings
|
||||
* @return \Slim\Environment
|
||||
*/
|
||||
public static function mock($userSettings = array())
|
||||
{
|
||||
self::$environment = new self(array_merge(array(
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
'SCRIPT_NAME' => '',
|
||||
'PATH_INFO' => '',
|
||||
'QUERY_STRING' => '',
|
||||
'SERVER_NAME' => 'localhost',
|
||||
'SERVER_PORT' => 80,
|
||||
'ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'ACCEPT_LANGUAGE' => 'en-US,en;q=0.8',
|
||||
'ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
|
||||
'USER_AGENT' => 'Slim Framework',
|
||||
'REMOTE_ADDR' => '127.0.0.1',
|
||||
'slim.url_scheme' => 'http',
|
||||
'slim.input' => '',
|
||||
'slim.errors' => @fopen('php://stderr', 'w')
|
||||
), $userSettings));
|
||||
|
||||
return self::$environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor (private access)
|
||||
*
|
||||
* @param array|null $settings If present, these are used instead of global server variables
|
||||
*/
|
||||
private function __construct($settings = null)
|
||||
{
|
||||
if ($settings) {
|
||||
$this->properties = $settings;
|
||||
} else {
|
||||
$env = array();
|
||||
|
||||
//The HTTP request method
|
||||
$env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
//The IP
|
||||
$env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
/**
|
||||
* Application paths
|
||||
*
|
||||
* This derives two paths: SCRIPT_NAME and PATH_INFO. The SCRIPT_NAME
|
||||
* is the real, physical path to the application, be it in the root
|
||||
* directory or a subdirectory of the public document root. The PATH_INFO is the
|
||||
* virtual path to the requested resource within the application context.
|
||||
*
|
||||
* With htaccess, the SCRIPT_NAME will be an absolute path (without file name);
|
||||
* if not using htaccess, it will also include the file name. If it is "/",
|
||||
* it is set to an empty string (since it cannot have a trailing slash).
|
||||
*
|
||||
* The PATH_INFO will be an absolute path with a leading slash; this will be
|
||||
* used for application routing.
|
||||
*/
|
||||
if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) {
|
||||
$env['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME']; //Without URL rewrite
|
||||
} else {
|
||||
$env['SCRIPT_NAME'] = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']) ); //With URL rewrite
|
||||
}
|
||||
$env['PATH_INFO'] = substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen($env['SCRIPT_NAME']));
|
||||
if (strpos($env['PATH_INFO'], '?') !== false) {
|
||||
$env['PATH_INFO'] = substr_replace($env['PATH_INFO'], '', strpos($env['PATH_INFO'], '?')); //query string is not removed automatically
|
||||
}
|
||||
$env['SCRIPT_NAME'] = rtrim($env['SCRIPT_NAME'], '/');
|
||||
$env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/');
|
||||
|
||||
//The portion of the request URI following the '?'
|
||||
$env['QUERY_STRING'] = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
|
||||
|
||||
//Name of server host that is running the script
|
||||
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
|
||||
|
||||
//Number of server port that is running the script
|
||||
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
|
||||
|
||||
//HTTP request headers
|
||||
$specialHeaders = array('CONTENT_TYPE', 'CONTENT_LENGTH', 'PHP_AUTH_USER', 'PHP_AUTH_PW', 'PHP_AUTH_DIGEST', 'AUTH_TYPE');
|
||||
foreach ($_SERVER as $key => $value) {
|
||||
$value = is_string($value) ? trim($value) : $value;
|
||||
if (strpos($key, 'HTTP_') === 0) {
|
||||
$env[substr($key, 5)] = $value;
|
||||
} elseif (strpos($key, 'X_') === 0 || in_array($key, $specialHeaders)) {
|
||||
$env[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
//Is the application running under HTTPS or HTTP protocol?
|
||||
$env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';
|
||||
|
||||
//Input stream (readable one time only; not available for mutipart/form-data requests)
|
||||
$rawInput = @file_get_contents('php://input');
|
||||
if (!$rawInput) {
|
||||
$rawInput = '';
|
||||
}
|
||||
$env['slim.input'] = $rawInput;
|
||||
|
||||
//Error stream
|
||||
$env['slim.errors'] = fopen('php://stderr', 'w');
|
||||
|
||||
$this->properties = $env;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Exists
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->properties[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Get
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
if (isset($this->properties[$offset])) {
|
||||
return $this->properties[$offset];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Set
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->properties[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Unset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->properties[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* IteratorAggregate
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->properties);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Exception;
|
||||
|
||||
/**
|
||||
* Pass Exception
|
||||
*
|
||||
* This Exception will cause the Router::dispatch method
|
||||
* to skip the current matching route and continue to the next
|
||||
* matching route. If no subsequent routes are found, a
|
||||
* HTTP 404 Not Found response will be sent to the client.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Pass extends \Exception
|
||||
{
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Exception;
|
||||
|
||||
/**
|
||||
* Stop Exception
|
||||
*
|
||||
* This Exception is thrown when the Slim application needs to abort
|
||||
* processing and return control flow to the outer PHP script.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Stop extends \Exception
|
||||
{
|
||||
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Http;
|
||||
|
||||
/**
|
||||
* HTTP Headers
|
||||
*
|
||||
* This class is an abstraction of the HTTP response headers and
|
||||
* provides array access to the header list while automatically
|
||||
* stores and retrieves headers with lowercase canonical keys regardless
|
||||
* of the input format.
|
||||
*
|
||||
* This class also implements the `Iterator` and `Countable`
|
||||
* interfaces for even more convenient usage.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Headers implements \ArrayAccess, \Iterator, \Countable
|
||||
{
|
||||
/**
|
||||
* @var array HTTP headers
|
||||
*/
|
||||
protected $headers;
|
||||
|
||||
/**
|
||||
* @var array Map canonical header name to original header name
|
||||
*/
|
||||
protected $map;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($headers = array())
|
||||
{
|
||||
$this->merge($headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge Headers
|
||||
* @param array $headers
|
||||
*/
|
||||
public function merge($headers)
|
||||
{
|
||||
foreach ($headers as $name => $value) {
|
||||
$this[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform header name into canonical form
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function canonical($name)
|
||||
{
|
||||
return strtolower(trim($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Exists
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->headers[$this->canonical($offset)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Get
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$canonical = $this->canonical($offset);
|
||||
if (isset($this->headers[$canonical])) {
|
||||
return $this->headers[$canonical];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Set
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$canonical = $this->canonical($offset);
|
||||
$this->headers[$canonical] = $value;
|
||||
$this->map[$canonical] = $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Unset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
$canonical = $this->canonical($offset);
|
||||
unset($this->headers[$canonical], $this->map[$canonical]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Countable: Count
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator: Rewind
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator: Current
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator: Key
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
$key = key($this->headers);
|
||||
|
||||
return $this->map[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator: Next
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator: Valid
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return current($this->headers) !== false;
|
||||
}
|
||||
}
|
@ -1,585 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Http;
|
||||
|
||||
/**
|
||||
* Slim HTTP Request
|
||||
*
|
||||
* This class provides a human-friendly interface to the Slim environment variables;
|
||||
* environment variables are passed by reference and will be modified directly.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
const METHOD_HEAD = 'HEAD';
|
||||
const METHOD_GET = 'GET';
|
||||
const METHOD_POST = 'POST';
|
||||
const METHOD_PUT = 'PUT';
|
||||
const METHOD_DELETE = 'DELETE';
|
||||
const METHOD_OPTIONS = 'OPTIONS';
|
||||
const METHOD_OVERRIDE = '_METHOD';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $formDataMediaTypes = array('application/x-www-form-urlencoded');
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $env;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param array $env
|
||||
* @see \Slim\Environment
|
||||
*/
|
||||
public function __construct($env)
|
||||
{
|
||||
$this->env = $env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTTP method
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->env['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a GET request?
|
||||
* @return bool
|
||||
*/
|
||||
public function isGet()
|
||||
{
|
||||
return $this->getMethod() === self::METHOD_GET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a POST request?
|
||||
* @return bool
|
||||
*/
|
||||
public function isPost()
|
||||
{
|
||||
return $this->getMethod() === self::METHOD_POST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a PUT request?
|
||||
* @return bool
|
||||
*/
|
||||
public function isPut()
|
||||
{
|
||||
return $this->getMethod() === self::METHOD_PUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a DELETE request?
|
||||
* @return bool
|
||||
*/
|
||||
public function isDelete()
|
||||
{
|
||||
return $this->getMethod() === self::METHOD_DELETE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a HEAD request?
|
||||
* @return bool
|
||||
*/
|
||||
public function isHead()
|
||||
{
|
||||
return $this->getMethod() === self::METHOD_HEAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a OPTIONS request?
|
||||
* @return bool
|
||||
*/
|
||||
public function isOptions()
|
||||
{
|
||||
return $this->getMethod() === self::METHOD_OPTIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this an AJAX request?
|
||||
* @return bool
|
||||
*/
|
||||
public function isAjax()
|
||||
{
|
||||
if ($this->params('isajax')) {
|
||||
return true;
|
||||
} elseif (isset($this->env['X_REQUESTED_WITH']) && $this->env['X_REQUESTED_WITH'] === 'XMLHttpRequest') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this an XHR request? (alias of Slim_Http_Request::isAjax)
|
||||
* @return bool
|
||||
*/
|
||||
public function isXhr()
|
||||
{
|
||||
return $this->isAjax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch GET and POST data
|
||||
*
|
||||
* This method returns a union of GET and POST data as a key-value array, or the value
|
||||
* of the array key if requested; if the array key does not exist, NULL is returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @return array|mixed|null
|
||||
*/
|
||||
public function params($key = null)
|
||||
{
|
||||
$union = array_merge($this->get(), $this->post());
|
||||
if ($key) {
|
||||
if (isset($union[$key])) {
|
||||
return $union[$key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return $union;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch GET data
|
||||
*
|
||||
* This method returns a key-value array of data sent in the HTTP request query string, or
|
||||
* the value of the array key if requested; if the array key does not exist, NULL is returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @return array|mixed|null
|
||||
*/
|
||||
public function get($key = null)
|
||||
{
|
||||
if (!isset($this->env['slim.request.query_hash'])) {
|
||||
$output = array();
|
||||
if (function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte'])) {
|
||||
mb_parse_str($this->env['QUERY_STRING'], $output);
|
||||
} else {
|
||||
parse_str($this->env['QUERY_STRING'], $output);
|
||||
}
|
||||
$this->env['slim.request.query_hash'] = Util::stripSlashesIfMagicQuotes($output);
|
||||
}
|
||||
if ($key) {
|
||||
if (isset($this->env['slim.request.query_hash'][$key])) {
|
||||
return $this->env['slim.request.query_hash'][$key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return $this->env['slim.request.query_hash'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch POST data
|
||||
*
|
||||
* This method returns a key-value array of data sent in the HTTP request body, or
|
||||
* the value of a hash key if requested; if the array key does not exist, NULL is returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @return array|mixed|null
|
||||
* @throws \RuntimeException If environment input is not available
|
||||
*/
|
||||
public function post($key = null)
|
||||
{
|
||||
if (!isset($this->env['slim.input'])) {
|
||||
throw new \RuntimeException('Missing slim.input in environment variables');
|
||||
}
|
||||
if (!isset($this->env['slim.request.form_hash'])) {
|
||||
$this->env['slim.request.form_hash'] = array();
|
||||
if ($this->isFormData() && is_string($this->env['slim.input'])) {
|
||||
$output = array();
|
||||
if (function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte'])) {
|
||||
mb_parse_str($this->env['slim.input'], $output);
|
||||
} else {
|
||||
parse_str($this->env['slim.input'], $output);
|
||||
}
|
||||
$this->env['slim.request.form_hash'] = Util::stripSlashesIfMagicQuotes($output);
|
||||
} else {
|
||||
$this->env['slim.request.form_hash'] = Util::stripSlashesIfMagicQuotes($_POST);
|
||||
}
|
||||
}
|
||||
if ($key) {
|
||||
if (isset($this->env['slim.request.form_hash'][$key])) {
|
||||
return $this->env['slim.request.form_hash'][$key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return $this->env['slim.request.form_hash'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch PUT data (alias for \Slim\Http\Request::post)
|
||||
* @param string $key
|
||||
* @return array|mixed|null
|
||||
*/
|
||||
public function put($key = null)
|
||||
{
|
||||
return $this->post($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch DELETE data (alias for \Slim\Http\Request::post)
|
||||
* @param string $key
|
||||
* @return array|mixed|null
|
||||
*/
|
||||
public function delete($key = null)
|
||||
{
|
||||
return $this->post($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch COOKIE data
|
||||
*
|
||||
* This method returns a key-value array of Cookie data sent in the HTTP request, or
|
||||
* the value of a array key if requested; if the array key does not exist, NULL is returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @return array|string|null
|
||||
*/
|
||||
public function cookies($key = null)
|
||||
{
|
||||
if (!isset($this->env['slim.request.cookie_hash'])) {
|
||||
$cookieHeader = isset($this->env['COOKIE']) ? $this->env['COOKIE'] : '';
|
||||
$this->env['slim.request.cookie_hash'] = Util::parseCookieHeader($cookieHeader);
|
||||
}
|
||||
if ($key) {
|
||||
if (isset($this->env['slim.request.cookie_hash'][$key])) {
|
||||
return $this->env['slim.request.cookie_hash'][$key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return $this->env['slim.request.cookie_hash'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the Request body contain parseable form data?
|
||||
* @return bool
|
||||
*/
|
||||
public function isFormData()
|
||||
{
|
||||
$method = isset($this->env['slim.method_override.original_method']) ? $this->env['slim.method_override.original_method'] : $this->getMethod();
|
||||
|
||||
return ($method === self::METHOD_POST && is_null($this->getContentType())) || in_array($this->getMediaType(), self::$formDataMediaTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Headers
|
||||
*
|
||||
* This method returns a key-value array of headers sent in the HTTP request, or
|
||||
* the value of a hash key if requested; if the array key does not exist, NULL is returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default The default value returned if the requested header is not available
|
||||
* @return mixed
|
||||
*/
|
||||
public function headers($key = null, $default = null)
|
||||
{
|
||||
if ($key) {
|
||||
$key = strtoupper($key);
|
||||
$key = str_replace('-', '_', $key);
|
||||
$key = preg_replace('@^HTTP_@', '', $key);
|
||||
if (isset($this->env[$key])) {
|
||||
return $this->env[$key];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
} else {
|
||||
$headers = array();
|
||||
foreach ($this->env as $key => $value) {
|
||||
if (strpos($key, 'slim.') !== 0) {
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Body
|
||||
* @return string
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->env['slim.input'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content Type
|
||||
* @return string
|
||||
*/
|
||||
public function getContentType()
|
||||
{
|
||||
if (isset($this->env['CONTENT_TYPE'])) {
|
||||
return $this->env['CONTENT_TYPE'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Media Type (type/subtype within Content Type header)
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMediaType()
|
||||
{
|
||||
$contentType = $this->getContentType();
|
||||
if ($contentType) {
|
||||
$contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
|
||||
|
||||
return strtolower($contentTypeParts[0]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Media Type Params
|
||||
* @return array
|
||||
*/
|
||||
public function getMediaTypeParams()
|
||||
{
|
||||
$contentType = $this->getContentType();
|
||||
$contentTypeParams = array();
|
||||
if ($contentType) {
|
||||
$contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
|
||||
$contentTypePartsLength = count($contentTypeParts);
|
||||
for ($i = 1; $i < $contentTypePartsLength; $i++) {
|
||||
$paramParts = explode('=', $contentTypeParts[$i]);
|
||||
$contentTypeParams[strtolower($paramParts[0])] = $paramParts[1];
|
||||
}
|
||||
}
|
||||
|
||||
return $contentTypeParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content Charset
|
||||
* @return string|null
|
||||
*/
|
||||
public function getContentCharset()
|
||||
{
|
||||
$mediaTypeParams = $this->getMediaTypeParams();
|
||||
if (isset($mediaTypeParams['charset'])) {
|
||||
return $mediaTypeParams['charset'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-Length
|
||||
* @return int
|
||||
*/
|
||||
public function getContentLength()
|
||||
{
|
||||
if (isset($this->env['CONTENT_LENGTH'])) {
|
||||
return (int) $this->env['CONTENT_LENGTH'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Host
|
||||
* @return string
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
if (isset($this->env['HOST'])) {
|
||||
if (strpos($this->env['HOST'], ':') !== false) {
|
||||
$hostParts = explode(':', $this->env['HOST']);
|
||||
|
||||
return $hostParts[0];
|
||||
}
|
||||
|
||||
return $this->env['HOST'];
|
||||
} else {
|
||||
return $this->env['SERVER_NAME'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Host with Port
|
||||
* @return string
|
||||
*/
|
||||
public function getHostWithPort()
|
||||
{
|
||||
return sprintf('%s:%s', $this->getHost(), $this->getPort());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Port
|
||||
* @return int
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return (int) $this->env['SERVER_PORT'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Scheme (https or http)
|
||||
* @return string
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->env['slim.url_scheme'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Script Name (physical path)
|
||||
* @return string
|
||||
*/
|
||||
public function getScriptName()
|
||||
{
|
||||
return $this->env['SCRIPT_NAME'];
|
||||
}
|
||||
|
||||
/**
|
||||
* LEGACY: Get Root URI (alias for Slim_Http_Request::getScriptName)
|
||||
* @return string
|
||||
*/
|
||||
public function getRootUri()
|
||||
{
|
||||
return $this->getScriptName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Path (physical path + virtual path)
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->getScriptName() . $this->getPathInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Path Info (virtual path)
|
||||
* @return string
|
||||
*/
|
||||
public function getPathInfo()
|
||||
{
|
||||
return $this->env['PATH_INFO'];
|
||||
}
|
||||
|
||||
/**
|
||||
* LEGACY: Get Resource URI (alias for Slim_Http_Request::getPathInfo)
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceUri()
|
||||
{
|
||||
return $this->getPathInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL (scheme + host [ + port if non-standard ])
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
$url = $this->getScheme() . '://' . $this->getHost();
|
||||
if (($this->getScheme() === 'https' && $this->getPort() !== 443) || ($this->getScheme() === 'http' && $this->getPort() !== 80)) {
|
||||
$url .= sprintf(':%s', $this->getPort());
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IP
|
||||
* @return string
|
||||
*/
|
||||
public function getIp()
|
||||
{
|
||||
if (isset($this->env['X_FORWARDED_FOR'])) {
|
||||
return $this->env['X_FORWARDED_FOR'];
|
||||
} elseif (isset($this->env['CLIENT_IP'])) {
|
||||
return $this->env['CLIENT_IP'];
|
||||
}
|
||||
|
||||
return $this->env['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Referrer
|
||||
* @return string|null
|
||||
*/
|
||||
public function getReferrer()
|
||||
{
|
||||
if (isset($this->env['REFERER'])) {
|
||||
return $this->env['REFERER'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Referer (for those who can't spell)
|
||||
* @return string|null
|
||||
*/
|
||||
public function getReferer()
|
||||
{
|
||||
return $this->getReferrer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get User Agent
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUserAgent()
|
||||
{
|
||||
if (isset($this->env['USER_AGENT'])) {
|
||||
return $this->env['USER_AGENT'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,459 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Http;
|
||||
|
||||
/**
|
||||
* Response
|
||||
*
|
||||
* This is a simple abstraction over top an HTTP response. This
|
||||
* provides methods to set the HTTP status, the HTTP headers,
|
||||
* and the HTTP body.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Response implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var int HTTP status code
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* @var \Slim\Http\Headers List of HTTP response headers
|
||||
*/
|
||||
protected $header;
|
||||
|
||||
/**
|
||||
* @var string HTTP response body
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* @var int Length of HTTP response body
|
||||
*/
|
||||
protected $length;
|
||||
|
||||
/**
|
||||
* @var array HTTP response codes and messages
|
||||
*/
|
||||
protected static $messages = array(
|
||||
//Informational 1xx
|
||||
100 => '100 Continue',
|
||||
101 => '101 Switching Protocols',
|
||||
//Successful 2xx
|
||||
200 => '200 OK',
|
||||
201 => '201 Created',
|
||||
202 => '202 Accepted',
|
||||
203 => '203 Non-Authoritative Information',
|
||||
204 => '204 No Content',
|
||||
205 => '205 Reset Content',
|
||||
206 => '206 Partial Content',
|
||||
//Redirection 3xx
|
||||
300 => '300 Multiple Choices',
|
||||
301 => '301 Moved Permanently',
|
||||
302 => '302 Found',
|
||||
303 => '303 See Other',
|
||||
304 => '304 Not Modified',
|
||||
305 => '305 Use Proxy',
|
||||
306 => '306 (Unused)',
|
||||
307 => '307 Temporary Redirect',
|
||||
//Client Error 4xx
|
||||
400 => '400 Bad Request',
|
||||
401 => '401 Unauthorized',
|
||||
402 => '402 Payment Required',
|
||||
403 => '403 Forbidden',
|
||||
404 => '404 Not Found',
|
||||
405 => '405 Method Not Allowed',
|
||||
406 => '406 Not Acceptable',
|
||||
407 => '407 Proxy Authentication Required',
|
||||
408 => '408 Request Timeout',
|
||||
409 => '409 Conflict',
|
||||
410 => '410 Gone',
|
||||
411 => '411 Length Required',
|
||||
412 => '412 Precondition Failed',
|
||||
413 => '413 Request Entity Too Large',
|
||||
414 => '414 Request-URI Too Long',
|
||||
415 => '415 Unsupported Media Type',
|
||||
416 => '416 Requested Range Not Satisfiable',
|
||||
417 => '417 Expectation Failed',
|
||||
422 => '422 Unprocessable Entity',
|
||||
423 => '423 Locked',
|
||||
//Server Error 5xx
|
||||
500 => '500 Internal Server Error',
|
||||
501 => '501 Not Implemented',
|
||||
502 => '502 Bad Gateway',
|
||||
503 => '503 Service Unavailable',
|
||||
504 => '504 Gateway Timeout',
|
||||
505 => '505 HTTP Version Not Supported'
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $body The HTTP response body
|
||||
* @param int $status The HTTP response status
|
||||
* @param \Slim\Http\Headers|array $header The HTTP response headers
|
||||
*/
|
||||
public function __construct($body = '', $status = 200, $header = array())
|
||||
{
|
||||
$this->status = (int) $status;
|
||||
$headers = array();
|
||||
foreach ($header as $key => $value) {
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
$this->header = new Headers(array_merge(array('Content-Type' => 'text/html'), $headers));
|
||||
$this->body = '';
|
||||
$this->write($body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and set status
|
||||
* @param int|null $status
|
||||
* @return int
|
||||
*/
|
||||
public function status($status = null)
|
||||
{
|
||||
if (!is_null($status)) {
|
||||
$this->status = (int) $status;
|
||||
}
|
||||
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and set header
|
||||
* @param string $name Header name
|
||||
* @param string|null $value Header value
|
||||
* @return string Header value
|
||||
*/
|
||||
public function header($name, $value = null)
|
||||
{
|
||||
if (!is_null($value)) {
|
||||
$this[$name] = $value;
|
||||
}
|
||||
|
||||
return $this[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers
|
||||
* @return \Slim\Http\Headers
|
||||
*/
|
||||
public function headers()
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and set body
|
||||
* @param string|null $body Content of HTTP response body
|
||||
* @return string
|
||||
*/
|
||||
public function body($body = null)
|
||||
{
|
||||
if (!is_null($body)) {
|
||||
$this->write($body, true);
|
||||
}
|
||||
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and set length
|
||||
* @param int|null $length
|
||||
* @return int
|
||||
*/
|
||||
public function length($length = null)
|
||||
{
|
||||
if (!is_null($length)) {
|
||||
$this->length = (int) $length;
|
||||
}
|
||||
|
||||
return $this->length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append HTTP response body
|
||||
* @param string $body Content to append to the current HTTP response body
|
||||
* @param bool $replace Overwrite existing response body?
|
||||
* @return string The updated HTTP response body
|
||||
*/
|
||||
public function write($body, $replace = false)
|
||||
{
|
||||
if ($replace) {
|
||||
$this->body = $body;
|
||||
} else {
|
||||
$this->body .= (string) $body;
|
||||
}
|
||||
$this->length = strlen($this->body);
|
||||
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize
|
||||
*
|
||||
* This prepares this response and returns an array
|
||||
* of [status, headers, body]. This array is passed to outer middleware
|
||||
* if available or directly to the Slim run method.
|
||||
*
|
||||
* @return array[int status, array headers, string body]
|
||||
*/
|
||||
public function finalize()
|
||||
{
|
||||
if (in_array($this->status, array(204, 304))) {
|
||||
unset($this['Content-Type'], $this['Content-Length']);
|
||||
|
||||
return array($this->status, $this->header, '');
|
||||
} else {
|
||||
return array($this->status, $this->header, $this->body);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cookie
|
||||
*
|
||||
* Instead of using PHP's `setcookie()` function, Slim manually constructs the HTTP `Set-Cookie`
|
||||
* header on its own and delegates this responsibility to the `Slim_Http_Util` class. This
|
||||
* response's header is passed by reference to the utility class and is directly modified. By not
|
||||
* relying on PHP's native implementation, Slim allows middleware the opportunity to massage or
|
||||
* analyze the raw header before the response is ultimately delivered to the HTTP client.
|
||||
*
|
||||
* @param string $name The name of the cookie
|
||||
* @param string|array $value If string, the value of cookie; if array, properties for
|
||||
* cookie including: value, expire, path, domain, secure, httponly
|
||||
*/
|
||||
public function setCookie($name, $value)
|
||||
{
|
||||
Util::setCookieHeader($this->header, $name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete cookie
|
||||
*
|
||||
* Instead of using PHP's `setcookie()` function, Slim manually constructs the HTTP `Set-Cookie`
|
||||
* header on its own and delegates this responsibility to the `Slim_Http_Util` class. This
|
||||
* response's header is passed by reference to the utility class and is directly modified. By not
|
||||
* relying on PHP's native implementation, Slim allows middleware the opportunity to massage or
|
||||
* analyze the raw header before the response is ultimately delivered to the HTTP client.
|
||||
*
|
||||
* This method will set a cookie with the given name that has an expiration time in the past; this will
|
||||
* prompt the HTTP client to invalidate and remove the client-side cookie. Optionally, you may
|
||||
* also pass a key/value array as the second argument. If the "domain" key is present in this
|
||||
* array, only the Cookie with the given name AND domain will be removed. The invalidating cookie
|
||||
* sent with this response will adopt all properties of the second argument.
|
||||
*
|
||||
* @param string $name The name of the cookie
|
||||
* @param array $value Properties for cookie including: value, expire, path, domain, secure, httponly
|
||||
*/
|
||||
public function deleteCookie($name, $value = array())
|
||||
{
|
||||
Util::deleteCookieHeader($this->header, $name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* This method prepares this response to return an HTTP Redirect response
|
||||
* to the HTTP client.
|
||||
*
|
||||
* @param string $url The redirect destination
|
||||
* @param int $status The redirect HTTP status code
|
||||
*/
|
||||
public function redirect ($url, $status = 302)
|
||||
{
|
||||
$this->status = $status;
|
||||
$this['Location'] = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Empty?
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return in_array($this->status, array(201, 204, 304));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Informational?
|
||||
* @return bool
|
||||
*/
|
||||
public function isInformational()
|
||||
{
|
||||
return $this->status >= 100 && $this->status < 200;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: OK?
|
||||
* @return bool
|
||||
*/
|
||||
public function isOk()
|
||||
{
|
||||
return $this->status === 200;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Successful?
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccessful()
|
||||
{
|
||||
return $this->status >= 200 && $this->status < 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Redirect?
|
||||
* @return bool
|
||||
*/
|
||||
public function isRedirect()
|
||||
{
|
||||
return in_array($this->status, array(301, 302, 303, 307));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Redirection?
|
||||
* @return bool
|
||||
*/
|
||||
public function isRedirection()
|
||||
{
|
||||
return $this->status >= 300 && $this->status < 400;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Forbidden?
|
||||
* @return bool
|
||||
*/
|
||||
public function isForbidden()
|
||||
{
|
||||
return $this->status === 403;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Not Found?
|
||||
* @return bool
|
||||
*/
|
||||
public function isNotFound()
|
||||
{
|
||||
return $this->status === 404;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Client error?
|
||||
* @return bool
|
||||
*/
|
||||
public function isClientError()
|
||||
{
|
||||
return $this->status >= 400 && $this->status < 500;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpers: Server Error?
|
||||
* @return bool
|
||||
*/
|
||||
public function isServerError()
|
||||
{
|
||||
return $this->status >= 500 && $this->status < 600;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Exists
|
||||
*/
|
||||
public function offsetExists( $offset )
|
||||
{
|
||||
return isset($this->header[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Get
|
||||
*/
|
||||
public function offsetGet( $offset )
|
||||
{
|
||||
if (isset($this->header[$offset])) {
|
||||
return $this->header[$offset];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Set
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->header[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Unset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->header[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Countable: Count
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Iterator
|
||||
*
|
||||
* This returns the contained `\Slim\Http\Headers` instance which
|
||||
* is itself iterable.
|
||||
*
|
||||
* @return \Slim\Http\Headers
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message for HTTP status code
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getMessageForCode($status)
|
||||
{
|
||||
if (isset(self::$messages[$status])) {
|
||||
return self::$messages[$status];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,389 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Http;
|
||||
|
||||
/**
|
||||
* Slim HTTP Utilities
|
||||
*
|
||||
* This class provides useful methods for handling HTTP requests.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Util
|
||||
{
|
||||
/**
|
||||
* Strip slashes from string or array
|
||||
*
|
||||
* This method strips slashes from its input. By default, this method will only
|
||||
* strip slashes from its input if magic quotes are enabled. Otherwise, you may
|
||||
* override the magic quotes setting with either TRUE or FALSE as the send argument
|
||||
* to force this method to strip or not strip slashes from its input.
|
||||
*
|
||||
* @var array|string $rawData
|
||||
* @return array|string
|
||||
*/
|
||||
public static function stripSlashesIfMagicQuotes($rawData, $overrideStripSlashes = null)
|
||||
{
|
||||
$strip = is_null($overrideStripSlashes) ? get_magic_quotes_gpc() : $overrideStripSlashes;
|
||||
if ($strip) {
|
||||
return self::_stripSlashes($rawData);
|
||||
} else {
|
||||
return $rawData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip slashes from string or array
|
||||
* @param array|string $rawData
|
||||
* @return array|string
|
||||
*/
|
||||
protected static function _stripSlashes($rawData)
|
||||
{
|
||||
return is_array($rawData) ? array_map(array('self', '_stripSlashes'), $rawData) : stripslashes($rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt data
|
||||
*
|
||||
* This method will encrypt data using a given key, vector, and cipher.
|
||||
* By default, this will encrypt data using the RIJNDAEL/AES 256 bit cipher. You
|
||||
* may override the default cipher and cipher mode by passing your own desired
|
||||
* cipher and cipher mode as the final key-value array argument.
|
||||
*
|
||||
* @param string $data The unencrypted data
|
||||
* @param string $key The encryption key
|
||||
* @param string $iv The encryption initialization vector
|
||||
* @param array $settings Optional key-value array with custom algorithm and mode
|
||||
* @return string
|
||||
*/
|
||||
public static function encrypt($data, $key, $iv, $settings = array())
|
||||
{
|
||||
if ($data === '' || !extension_loaded('mcrypt')) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
//Merge settings with defaults
|
||||
$settings = array_merge(array(
|
||||
'algorithm' => MCRYPT_RIJNDAEL_256,
|
||||
'mode' => MCRYPT_MODE_CBC
|
||||
), $settings);
|
||||
|
||||
//Get module
|
||||
$module = mcrypt_module_open($settings['algorithm'], '', $settings['mode'], '');
|
||||
|
||||
//Validate IV
|
||||
$ivSize = mcrypt_enc_get_iv_size($module);
|
||||
if (strlen($iv) > $ivSize) {
|
||||
$iv = substr($iv, 0, $ivSize);
|
||||
}
|
||||
|
||||
//Validate key
|
||||
$keySize = mcrypt_enc_get_key_size($module);
|
||||
if (strlen($key) > $keySize) {
|
||||
$key = substr($key, 0, $keySize);
|
||||
}
|
||||
|
||||
//Encrypt value
|
||||
mcrypt_generic_init($module, $key, $iv);
|
||||
$res = @mcrypt_generic($module, $data);
|
||||
mcrypt_generic_deinit($module);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt data
|
||||
*
|
||||
* This method will decrypt data using a given key, vector, and cipher.
|
||||
* By default, this will decrypt data using the RIJNDAEL/AES 256 bit cipher. You
|
||||
* may override the default cipher and cipher mode by passing your own desired
|
||||
* cipher and cipher mode as the final key-value array argument.
|
||||
*
|
||||
* @param string $data The encrypted data
|
||||
* @param string $key The encryption key
|
||||
* @param string $iv The encryption initialization vector
|
||||
* @param array $settings Optional key-value array with custom algorithm and mode
|
||||
* @return string
|
||||
*/
|
||||
public static function decrypt($data, $key, $iv, $settings = array())
|
||||
{
|
||||
if ($data === '' || !extension_loaded('mcrypt')) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
//Merge settings with defaults
|
||||
$settings = array_merge(array(
|
||||
'algorithm' => MCRYPT_RIJNDAEL_256,
|
||||
'mode' => MCRYPT_MODE_CBC
|
||||
), $settings);
|
||||
|
||||
//Get module
|
||||
$module = mcrypt_module_open($settings['algorithm'], '', $settings['mode'], '');
|
||||
|
||||
//Validate IV
|
||||
$ivSize = mcrypt_enc_get_iv_size($module);
|
||||
if (strlen($iv) > $ivSize) {
|
||||
$iv = substr($iv, 0, $ivSize);
|
||||
}
|
||||
|
||||
//Validate key
|
||||
$keySize = mcrypt_enc_get_key_size($module);
|
||||
if (strlen($key) > $keySize) {
|
||||
$key = substr($key, 0, $keySize);
|
||||
}
|
||||
|
||||
//Decrypt value
|
||||
mcrypt_generic_init($module, $key, $iv);
|
||||
$decryptedData = @mdecrypt_generic($module, $data);
|
||||
$res = str_replace("\x0", '', $decryptedData);
|
||||
mcrypt_generic_deinit($module);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode secure cookie value
|
||||
*
|
||||
* This method will create the secure value of an HTTP cookie. The
|
||||
* cookie value is encrypted and hashed so that its value is
|
||||
* secure and checked for integrity when read in subsequent requests.
|
||||
*
|
||||
* @param string $value The unsecure HTTP cookie value
|
||||
* @param int $expires The UNIX timestamp at which this cookie will expire
|
||||
* @param string $secret The secret key used to hash the cookie value
|
||||
* @param int $algorithm The algorithm to use for encryption
|
||||
* @param int $mode The algorithm mode to use for encryption
|
||||
* @param string
|
||||
*/
|
||||
public static function encodeSecureCookie($value, $expires, $secret, $algorithm, $mode)
|
||||
{
|
||||
$key = hash_hmac('sha1', $expires, $secret);
|
||||
$iv = self::get_iv($expires, $secret);
|
||||
$secureString = base64_encode(self::encrypt($value, $key, $iv, array(
|
||||
'algorithm' => $algorithm,
|
||||
'mode' => $mode
|
||||
)));
|
||||
$verificationString = hash_hmac('sha1', $expires . $value, $key);
|
||||
|
||||
return implode('|', array($expires, $secureString, $verificationString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode secure cookie value
|
||||
*
|
||||
* This method will decode the secure value of an HTTP cookie. The
|
||||
* cookie value is encrypted and hashed so that its value is
|
||||
* secure and checked for integrity when read in subsequent requests.
|
||||
*
|
||||
* @param string $value The secure HTTP cookie value
|
||||
* @param int $expires The UNIX timestamp at which this cookie will expire
|
||||
* @param string $secret The secret key used to hash the cookie value
|
||||
* @param int $algorithm The algorithm to use for encryption
|
||||
* @param int $mode The algorithm mode to use for encryption
|
||||
* @param string
|
||||
*/
|
||||
public static function decodeSecureCookie($value, $secret, $algorithm, $mode)
|
||||
{
|
||||
if ($value) {
|
||||
$value = explode('|', $value);
|
||||
if (count($value) === 3 && ((int) $value[0] === 0 || (int) $value[0] > time())) {
|
||||
$key = hash_hmac('sha1', $value[0], $secret);
|
||||
$iv = self::get_iv($value[0], $secret);
|
||||
$data = self::decrypt(base64_decode($value[1]), $key, $iv, array(
|
||||
'algorithm' => $algorithm,
|
||||
'mode' => $mode
|
||||
));
|
||||
$verificationString = hash_hmac('sha1', $value[0] . $data, $key);
|
||||
if ($verificationString === $value[2]) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set HTTP cookie header
|
||||
*
|
||||
* This method will construct and set the HTTP `Set-Cookie` header. Slim
|
||||
* uses this method instead of PHP's native `setcookie` method. This allows
|
||||
* more control of the HTTP header irrespective of the native implementation's
|
||||
* dependency on PHP versions.
|
||||
*
|
||||
* This method accepts the Slim_Http_Headers object by reference as its
|
||||
* first argument; this method directly modifies this object instead of
|
||||
* returning a value.
|
||||
*
|
||||
* @param array $header
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public static function setCookieHeader(&$header, $name, $value)
|
||||
{
|
||||
//Build cookie header
|
||||
if (is_array($value)) {
|
||||
$domain = '';
|
||||
$path = '';
|
||||
$expires = '';
|
||||
$secure = '';
|
||||
$httponly = '';
|
||||
if (isset($value['domain']) && $value['domain']) {
|
||||
$domain = '; domain=' . $value['domain'];
|
||||
}
|
||||
if (isset($value['path']) && $value['path']) {
|
||||
$path = '; path=' . $value['path'];
|
||||
}
|
||||
if (isset($value['expires'])) {
|
||||
if (is_string($value['expires'])) {
|
||||
$timestamp = strtotime($value['expires']);
|
||||
} else {
|
||||
$timestamp = (int) $value['expires'];
|
||||
}
|
||||
if ($timestamp !== 0) {
|
||||
$expires = '; expires=' . gmdate('D, d-M-Y H:i:s e', $timestamp);
|
||||
}
|
||||
}
|
||||
if (isset($value['secure']) && $value['secure']) {
|
||||
$secure = '; secure';
|
||||
}
|
||||
if (isset($value['httponly']) && $value['httponly']) {
|
||||
$httponly = '; HttpOnly';
|
||||
}
|
||||
$cookie = sprintf('%s=%s%s', urlencode($name), urlencode((string) $value['value']), $domain . $path . $expires . $secure . $httponly);
|
||||
} else {
|
||||
$cookie = sprintf('%s=%s', urlencode($name), urlencode((string) $value));
|
||||
}
|
||||
|
||||
//Set cookie header
|
||||
if (!isset($header['Set-Cookie']) || $header['Set-Cookie'] === '') {
|
||||
$header['Set-Cookie'] = $cookie;
|
||||
} else {
|
||||
$header['Set-Cookie'] = implode("\n", array($header['Set-Cookie'], $cookie));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete HTTP cookie header
|
||||
*
|
||||
* This method will construct and set the HTTP `Set-Cookie` header to invalidate
|
||||
* a client-side HTTP cookie. If a cookie with the same name (and, optionally, domain)
|
||||
* is already set in the HTTP response, it will also be removed. Slim uses this method
|
||||
* instead of PHP's native `setcookie` method. This allows more control of the HTTP header
|
||||
* irrespective of PHP's native implementation's dependency on PHP versions.
|
||||
*
|
||||
* This method accepts the Slim_Http_Headers object by reference as its
|
||||
* first argument; this method directly modifies this object instead of
|
||||
* returning a value.
|
||||
*
|
||||
* @param array $header
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public static function deleteCookieHeader(&$header, $name, $value = array())
|
||||
{
|
||||
//Remove affected cookies from current response header
|
||||
$cookiesOld = array();
|
||||
$cookiesNew = array();
|
||||
if (isset($header['Set-Cookie'])) {
|
||||
$cookiesOld = explode("\n", $header['Set-Cookie']);
|
||||
}
|
||||
foreach ($cookiesOld as $c) {
|
||||
if (isset($value['domain']) && $value['domain']) {
|
||||
$regex = sprintf('@%s=.*domain=%s@', urlencode($name), preg_quote($value['domain']));
|
||||
} else {
|
||||
$regex = sprintf('@%s=@', urlencode($name));
|
||||
}
|
||||
if (preg_match($regex, $c) === 0) {
|
||||
$cookiesNew[] = $c;
|
||||
}
|
||||
}
|
||||
if ($cookiesNew) {
|
||||
$header['Set-Cookie'] = implode("\n", $cookiesNew);
|
||||
} else {
|
||||
unset($header['Set-Cookie']);
|
||||
}
|
||||
|
||||
//Set invalidating cookie to clear client-side cookie
|
||||
self::setCookieHeader($header, $name, array_merge(array('value' => '', 'path' => null, 'domain' => null, 'expires' => time() - 100), $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse cookie header
|
||||
*
|
||||
* This method will parse the HTTP requst's `Cookie` header
|
||||
* and extract cookies into an associative array.
|
||||
*
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public static function parseCookieHeader($header)
|
||||
{
|
||||
$cookies = array();
|
||||
$header = rtrim($header, "\r\n");
|
||||
$headerPieces = preg_split('@\s*[;,]\s*@', $header);
|
||||
foreach ($headerPieces as $c) {
|
||||
$cParts = explode('=', $c);
|
||||
if (count($cParts) === 2) {
|
||||
$key = urldecode($cParts[0]);
|
||||
$value = urldecode($cParts[1]);
|
||||
if (!isset($cookies[$key])) {
|
||||
$cookies[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random IV
|
||||
*
|
||||
* This method will generate a non-predictable IV for use with
|
||||
* the cookie encryption
|
||||
*
|
||||
* @param int $expires The UNIX timestamp at which this cookie will expire
|
||||
* @param string $secret The secret key used to hash the cookie value
|
||||
* @return binary string with length 40
|
||||
*/
|
||||
private static function get_iv($expires, $secret)
|
||||
{
|
||||
$data1 = hash_hmac('sha1', 'a'.$expires.'b', $secret);
|
||||
$data2 = hash_hmac('sha1', 'z'.$expires.'y', $secret);
|
||||
|
||||
return pack("h*", $data1.$data2);
|
||||
}
|
||||
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim;
|
||||
|
||||
/**
|
||||
* Log
|
||||
*
|
||||
* This is the primary logger for a Slim application. You may provide
|
||||
* a Log Writer in conjunction with this Log to write to various output
|
||||
* destinations (e.g. a file). This class provides this interface:
|
||||
*
|
||||
* debug( mixed $object )
|
||||
* info( mixed $object )
|
||||
* warn( mixed $object )
|
||||
* error( mixed $object )
|
||||
* fatal( mixed $object )
|
||||
*
|
||||
* This class assumes only that your Log Writer has a public `write()` method
|
||||
* that accepts any object as its one and only argument. The Log Writer
|
||||
* class may write or send its argument anywhere: a file, STDERR,
|
||||
* a remote web API, etc. The possibilities are endless.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Log
|
||||
{
|
||||
const FATAL = 0;
|
||||
const ERROR = 1;
|
||||
const WARN = 2;
|
||||
const INFO = 3;
|
||||
const DEBUG = 4;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $levels = array(
|
||||
self::FATAL => 'FATAL',
|
||||
self::ERROR => 'ERROR',
|
||||
self::WARN => 'WARN',
|
||||
self::INFO => 'INFO',
|
||||
self::DEBUG => 'DEBUG'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $enabled;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $level;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param mixed $writer
|
||||
*/
|
||||
public function __construct($writer)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
$this->enabled = true;
|
||||
$this->level = self::DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is logging enabled?
|
||||
* @return bool
|
||||
*/
|
||||
public function getEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable logging
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
if ($enabled) {
|
||||
$this->enabled = true;
|
||||
} else {
|
||||
$this->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set level
|
||||
* @param int $level
|
||||
* @throws \InvalidArgumentException If invalid log level specified
|
||||
*/
|
||||
public function setLevel($level)
|
||||
{
|
||||
if (!isset(self::$levels[$level])) {
|
||||
throw new \InvalidArgumentException('Invalid log level');
|
||||
}
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get level
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set writer
|
||||
* @param mixed $writer
|
||||
*/
|
||||
public function setWriter($writer)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get writer
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWriter()
|
||||
{
|
||||
return $this->writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is logging enabled?
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log debug message
|
||||
* @param mixed $object
|
||||
* @return mixed|false What the Logger returns, or false if Logger not set or not enabled
|
||||
*/
|
||||
public function debug($object)
|
||||
{
|
||||
return $this->write($object, self::DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log info message
|
||||
* @param mixed $object
|
||||
* @return mixed|false What the Logger returns, or false if Logger not set or not enabled
|
||||
*/
|
||||
public function info($object)
|
||||
{
|
||||
return $this->write($object, self::INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log warn message
|
||||
* @param mixed $object
|
||||
* @return mixed|false What the Logger returns, or false if Logger not set or not enabled
|
||||
*/
|
||||
public function warn($object)
|
||||
{
|
||||
return $this->write($object, self::WARN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log error message
|
||||
* @param mixed $object
|
||||
* @return mixed|false What the Logger returns, or false if Logger not set or not enabled
|
||||
*/
|
||||
public function error($object)
|
||||
{
|
||||
return $this->write($object, self::ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log fatal message
|
||||
* @param mixed $object
|
||||
* @return mixed|false What the Logger returns, or false if Logger not set or not enabled
|
||||
*/
|
||||
public function fatal($object)
|
||||
{
|
||||
return $this->write($object, self::FATAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log message
|
||||
* @param mixed The object to log
|
||||
* @param int The message level
|
||||
* @return int|false
|
||||
*/
|
||||
protected function write($object, $level)
|
||||
{
|
||||
if ($this->enabled && $this->writer && $level <= $this->level) {
|
||||
return $this->writer->write($object, $level);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim;
|
||||
|
||||
/**
|
||||
* Log Writer
|
||||
*
|
||||
* This class is used by Slim_Log to write log messages to a valid, writable
|
||||
* resource handle (e.g. a file or STDERR).
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class LogWriter
|
||||
{
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param resource $resource
|
||||
* @throws \InvalidArgumentException If invalid resource
|
||||
*/
|
||||
public function __construct($resource)
|
||||
{
|
||||
if (!is_resource($resource)) {
|
||||
throw new \InvalidArgumentException('Cannot create LogWriter. Invalid resource handle.');
|
||||
}
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write message
|
||||
* @param mixed $message
|
||||
* @param int $level
|
||||
* @return int|false
|
||||
*/
|
||||
public function write($message, $level = null)
|
||||
{
|
||||
return fwrite($this->resource, (string) $message . PHP_EOL);
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim;
|
||||
|
||||
/**
|
||||
* Middleware
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
abstract class Middleware
|
||||
{
|
||||
/**
|
||||
* @var \Slim Reference to the primary application instance
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @var mixed Reference to the next downstream middleware
|
||||
*/
|
||||
protected $next;
|
||||
|
||||
/**
|
||||
* Set application
|
||||
*
|
||||
* This method injects the primary Slim application instance into
|
||||
* this middleware.
|
||||
*
|
||||
* @param \Slim $application
|
||||
*/
|
||||
final public function setApplication($application)
|
||||
{
|
||||
$this->app = $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get application
|
||||
*
|
||||
* This method retrieves the application previously injected
|
||||
* into this middleware.
|
||||
*
|
||||
* @return \Slim
|
||||
*/
|
||||
final public function getApplication()
|
||||
{
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set next middleware
|
||||
*
|
||||
* This method injects the next downstream middleware into
|
||||
* this middleware so that it may optionally be called
|
||||
* when appropriate.
|
||||
*
|
||||
* @param \Slim|\Slim\Middleware
|
||||
*/
|
||||
final public function setNextMiddleware($nextMiddleware)
|
||||
{
|
||||
$this->next = $nextMiddleware;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next middleware
|
||||
*
|
||||
* This method retrieves the next downstream middleware
|
||||
* previously injected into this middleware.
|
||||
*
|
||||
* @return \Slim|\Slim\Middleware
|
||||
*/
|
||||
final public function getNextMiddleware()
|
||||
{
|
||||
return $this->next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call
|
||||
*
|
||||
* Perform actions specific to this middleware and optionally
|
||||
* call the next downstream middleware.
|
||||
*/
|
||||
abstract public function call();
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Middleware;
|
||||
|
||||
/**
|
||||
* Content Types
|
||||
*
|
||||
* This is middleware for a Slim application that intercepts
|
||||
* the HTTP request body and parses it into the appropriate
|
||||
* PHP data structure if possible; else it returns the HTTP
|
||||
* request body unchanged. This is particularly useful
|
||||
* for preparing the HTTP request body for an XML or JSON API.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class ContentTypes extends \Slim\Middleware
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $contentTypes;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct($settings = array())
|
||||
{
|
||||
$this->contentTypes = array_merge(array(
|
||||
'application/json' => array($this, 'parseJson'),
|
||||
'application/xml' => array($this, 'parseXml'),
|
||||
'text/xml' => array($this, 'parseXml'),
|
||||
'text/csv' => array($this, 'parseCsv')
|
||||
), $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
$mediaType = $this->app->request()->getMediaType();
|
||||
if ($mediaType) {
|
||||
$env = $this->app->environment();
|
||||
$env['slim.input_original'] = $env['slim.input'];
|
||||
$env['slim.input'] = $this->parse($env['slim.input'], $mediaType);
|
||||
}
|
||||
$this->next->call();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse input
|
||||
*
|
||||
* This method will attempt to parse the request body
|
||||
* based on its content type if available.
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $contentType
|
||||
* @return mixed
|
||||
*/
|
||||
protected function parse ($input, $contentType)
|
||||
{
|
||||
if (isset($this->contentTypes[$contentType]) && is_callable($this->contentTypes[$contentType])) {
|
||||
$result = call_user_func($this->contentTypes[$contentType], $input);
|
||||
if ($result) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse JSON
|
||||
*
|
||||
* This method converts the raw JSON input
|
||||
* into an associative array.
|
||||
*
|
||||
* @param string $input
|
||||
* @return array|string
|
||||
*/
|
||||
protected function parseJson($input)
|
||||
{
|
||||
if (function_exists('json_decode')) {
|
||||
$result = json_decode($input, true);
|
||||
if ($result) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse XML
|
||||
*
|
||||
* This method creates a SimpleXMLElement
|
||||
* based upon the XML input. If the SimpleXML
|
||||
* extension is not available, the raw input
|
||||
* will be returned unchanged.
|
||||
*
|
||||
* @param string $input
|
||||
* @return \SimpleXMLElement|string
|
||||
*/
|
||||
protected function parseXml($input)
|
||||
{
|
||||
if (class_exists('SimpleXMLElement')) {
|
||||
try {
|
||||
return new \SimpleXMLElement($input);
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse CSV
|
||||
*
|
||||
* This method parses CSV content into a numeric array
|
||||
* containing an array of data for each CSV line.
|
||||
*
|
||||
* @param string $input
|
||||
* @return array
|
||||
*/
|
||||
protected function parseCsv($input)
|
||||
{
|
||||
$temp = fopen('php://memory', 'rw');
|
||||
fwrite($temp, $input);
|
||||
fseek($temp, 0);
|
||||
$res = array();
|
||||
while (($data = fgetcsv($temp)) !== false) {
|
||||
$res[] = $data;
|
||||
}
|
||||
fclose($temp);
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Middleware;
|
||||
|
||||
/**
|
||||
* Flash
|
||||
*
|
||||
* This is middleware for a Slim application that enables
|
||||
* Flash messaging between HTTP requests. This allows you
|
||||
* set Flash messages for the current request, for the next request,
|
||||
* or to retain messages from the previous request through to
|
||||
* the next request.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Flash extends \Slim\Middleware implements \ArrayAccess, \IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $messages;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param \Slim $app
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct($settings = array())
|
||||
{
|
||||
$this->settings = array_merge(array('key' => 'slim.flash'), $settings);
|
||||
$this->messages = array(
|
||||
'prev' => array(), //flash messages from prev request (loaded when middleware called)
|
||||
'next' => array(), //flash messages for next request
|
||||
'now' => array() //flash messages for current request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
//Read flash messaging from previous request if available
|
||||
$this->loadMessages();
|
||||
|
||||
//Prepare flash messaging for current request
|
||||
$env = $this->app->environment();
|
||||
$env['slim.flash'] = $this;
|
||||
$this->next->call();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Now
|
||||
*
|
||||
* Specify a flash message for a given key to be shown for the current request
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function now($key, $value)
|
||||
{
|
||||
$this->messages['now'][(string) $key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set
|
||||
*
|
||||
* Specify a flash message for a given key to be shown for the next request
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->messages['next'][(string) $key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep
|
||||
*
|
||||
* Retain flash messages from the previous request for the next request
|
||||
*/
|
||||
public function keep()
|
||||
{
|
||||
foreach ($this->messages['prev'] as $key => $val) {
|
||||
$this->messages['next'][$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$_SESSION[$this->settings['key']] = $this->messages['next'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load messages from previous request if available
|
||||
*/
|
||||
public function loadMessages()
|
||||
{
|
||||
if (isset($_SESSION[$this->settings['key']])) {
|
||||
$this->messages['prev'] = $_SESSION[$this->settings['key']];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of flash messages to be shown for the current request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return array_merge($this->messages['prev'], $this->messages['now']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Exists
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
$messages = $this->getMessages();
|
||||
|
||||
return isset($messages[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Get
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$messages = $this->getMessages();
|
||||
|
||||
return isset($messages[$offset]) ? $messages[$offset] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Set
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->now($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array Access: Offset Unset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->messages['prev'][$offset], $this->messages['now'][$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator Aggregate: Get Iterator
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
$messages = $this->getMessages();
|
||||
|
||||
return new \ArrayIterator($messages);
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Middleware;
|
||||
|
||||
/**
|
||||
* HTTP Method Override
|
||||
*
|
||||
* This is middleware for a Slim application that allows traditional
|
||||
* desktop browsers to submit psuedo PUT and DELETE requests by relying
|
||||
* on a pre-determined request parameter. Without this middleware,
|
||||
* desktop browsers are only able to submit GET and POST requests.
|
||||
*
|
||||
* This middleware is included automatically!
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class MethodOverride extends \Slim\Middleware
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param \Slim $app
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct($settings = array())
|
||||
{
|
||||
$this->settings = array_merge(array('key' => '_METHOD'), $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call
|
||||
*
|
||||
* Implements Slim middleware interface. This method is invoked and passed
|
||||
* an array of environment variables. This middleware inspects the environment
|
||||
* variables for the HTTP method override parameter; if found, this middleware
|
||||
* modifies the environment settings so downstream middleware and/or the Slim
|
||||
* application will treat the request with the desired HTTP method.
|
||||
*
|
||||
* @param array $env
|
||||
* @return array[status, header, body]
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
$env = $this->app->environment();
|
||||
if (isset($env['X_HTTP_METHOD_OVERRIDE'])) {
|
||||
// Header commonly used by Backbone.js and others
|
||||
$env['slim.method_override.original_method'] = $env['REQUEST_METHOD'];
|
||||
$env['REQUEST_METHOD'] = strtoupper($env['X_HTTP_METHOD_OVERRIDE']);
|
||||
} elseif (isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'POST') {
|
||||
// HTML Form Override
|
||||
$req = new \Slim\Http\Request($env);
|
||||
$method = $req->post($this->settings['key']);
|
||||
if ($method) {
|
||||
$env['slim.method_override.original_method'] = $env['REQUEST_METHOD'];
|
||||
$env['REQUEST_METHOD'] = strtoupper($method);
|
||||
}
|
||||
}
|
||||
$this->next->call();
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Middleware;
|
||||
|
||||
/**
|
||||
* Pretty Exceptions
|
||||
*
|
||||
* This middleware catches any Exception thrown by the surrounded
|
||||
* application and displays a developer-friendly diagnostic screen.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PrettyExceptions extends \Slim\Middleware
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct($settings = array())
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
try {
|
||||
$this->next->call();
|
||||
} catch (\Exception $e) {
|
||||
$env = $this->app->environment();
|
||||
$env['slim.log']->error($e);
|
||||
$this->app->contentType('text/html');
|
||||
$this->app->response()->status(500);
|
||||
$this->app->response()->body($this->renderBody($env, $e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render response body
|
||||
* @param array $env
|
||||
* @param \Exception $exception
|
||||
* @return string
|
||||
*/
|
||||
protected function renderBody(&$env, $exception)
|
||||
{
|
||||
$title = 'Slim Application Error';
|
||||
$code = $exception->getCode();
|
||||
$message = $exception->getMessage();
|
||||
$file = $exception->getFile();
|
||||
$line = $exception->getLine();
|
||||
$trace = $exception->getTraceAsString();
|
||||
$html = sprintf('<h1>%s</h1>', $title);
|
||||
$html .= '<p>The application could not run because of the following error:</p>';
|
||||
$html .= '<h2>Details</h2>';
|
||||
$html .= sprintf('<div><strong>Type:</strong> %s</div>', get_class($exception));
|
||||
if ($code) {
|
||||
$html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
|
||||
}
|
||||
if ($message) {
|
||||
$html .= sprintf('<div><strong>Message:</strong> %s</div>', $message);
|
||||
}
|
||||
if ($file) {
|
||||
$html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
|
||||
}
|
||||
if ($line) {
|
||||
$html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
|
||||
}
|
||||
if ($trace) {
|
||||
$html .= '<h2>Trace</h2>';
|
||||
$html .= sprintf('<pre>%s</pre>', $trace);
|
||||
}
|
||||
|
||||
return sprintf("<html><head><title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style></head><body>%s</body></html>", $title, $html);
|
||||
}
|
||||
}
|
@ -1,203 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim\Middleware;
|
||||
|
||||
/**
|
||||
* Session Cookie
|
||||
*
|
||||
* This class provides an HTTP cookie storage mechanism
|
||||
* for session data. This class avoids using a PHP session
|
||||
* and instead serializes/unserializes the $_SESSION global
|
||||
* variable to/from an HTTP cookie.
|
||||
*
|
||||
* If a secret key is provided with this middleware, the HTTP
|
||||
* cookie will be checked for integrity to ensure the client-side
|
||||
* cookie is not changed.
|
||||
*
|
||||
* You should NEVER store sensitive data in a client-side cookie
|
||||
* in any format, encrypted or not. If you need to store sensitive
|
||||
* user information in a session, you should rely on PHP's native
|
||||
* session implementation, or use other middleware to store
|
||||
* session data in a database or alternative server-side cache.
|
||||
*
|
||||
* Because this class stores serialized session data in an HTTP cookie,
|
||||
* you are inherently limtied to 4 Kb. If you attempt to store
|
||||
* more than this amount, serialization will fail.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class SessionCookie extends \Slim\Middleware
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct($settings = array())
|
||||
{
|
||||
$this->settings = array_merge(array(
|
||||
'expires' => '20 minutes',
|
||||
'path' => '/',
|
||||
'domain' => null,
|
||||
'secure' => false,
|
||||
'httponly' => false,
|
||||
'name' => 'slim_session',
|
||||
'secret' => 'CHANGE_ME',
|
||||
'cipher' => MCRYPT_RIJNDAEL_256,
|
||||
'cipher_mode' => MCRYPT_MODE_CBC
|
||||
), $settings);
|
||||
if (is_string($this->settings['expires'])) {
|
||||
$this->settings['expires'] = strtotime($this->settings['expires']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Session
|
||||
*
|
||||
* We must start a native PHP session to initialize the $_SESSION superglobal.
|
||||
* However, we won't be using the native session store for persistence, so we
|
||||
* disable the session cookie and cache limiter. We also set the session
|
||||
* handler to this class instance to avoid PHP's native session file locking.
|
||||
*/
|
||||
ini_set('session.use_cookies', 0);
|
||||
session_cache_limiter(false);
|
||||
session_set_save_handler(
|
||||
array($this, 'open'),
|
||||
array($this, 'close'),
|
||||
array($this, 'read'),
|
||||
array($this, 'write'),
|
||||
array($this, 'destroy'),
|
||||
array($this, 'gc')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
$this->loadSession();
|
||||
$this->next->call();
|
||||
$this->saveSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load session
|
||||
* @param array $env
|
||||
*/
|
||||
protected function loadSession()
|
||||
{
|
||||
if (session_id() === '') {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$value = \Slim\Http\Util::decodeSecureCookie(
|
||||
$this->app->request()->cookies($this->settings['name']),
|
||||
$this->settings['secret'],
|
||||
$this->settings['cipher'],
|
||||
$this->settings['cipher_mode']
|
||||
);
|
||||
if ($value) {
|
||||
$_SESSION = unserialize($value);
|
||||
} else {
|
||||
$_SESSION = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save session
|
||||
*/
|
||||
protected function saveSession()
|
||||
{
|
||||
$value = \Slim\Http\Util::encodeSecureCookie(
|
||||
serialize($_SESSION),
|
||||
$this->settings['expires'],
|
||||
$this->settings['secret'],
|
||||
$this->settings['cipher'],
|
||||
$this->settings['cipher_mode']
|
||||
);
|
||||
if (strlen($value) > 4096) {
|
||||
$this->app->getLog()->error('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.');
|
||||
} else {
|
||||
$this->app->response()->setCookie($this->settings['name'], array(
|
||||
'value' => $value,
|
||||
'domain' => $this->settings['domain'],
|
||||
'path' => $this->settings['path'],
|
||||
'expires' => $this->settings['expires'],
|
||||
'secure' => $this->settings['secure'],
|
||||
'httponly' => $this->settings['httponly']
|
||||
));
|
||||
}
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* Session Handler
|
||||
*******************************************************************************/
|
||||
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function write($id, $data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function gc($maxlifetime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,416 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.0.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim;
|
||||
|
||||
/**
|
||||
* Route
|
||||
* @package Slim
|
||||
* @author Josh Lockhart, Thomas Bley
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Route
|
||||
{
|
||||
/**
|
||||
* @var string The route pattern (e.g. "/books/:id")
|
||||
*/
|
||||
protected $pattern;
|
||||
|
||||
/**
|
||||
* @var mixed The route callable
|
||||
*/
|
||||
protected $callable;
|
||||
|
||||
/**
|
||||
* @var array Conditions for this route's URL parameters
|
||||
*/
|
||||
protected $conditions = array();
|
||||
|
||||
/**
|
||||
* @var array Default conditions applied to all route instances
|
||||
*/
|
||||
protected static $defaultConditions = array();
|
||||
|
||||
/**
|
||||
* @var string The name of this route (optional)
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var array Key-value array of URL parameters
|
||||
*/
|
||||
protected $params = array();
|
||||
|
||||
/**
|
||||
* @var array value array of URL parameter names
|
||||
*/
|
||||
protected $paramNames = array();
|
||||
|
||||
/**
|
||||
* @var array key array of URL parameter names with + at the end
|
||||
*/
|
||||
protected $paramNamesPath = array();
|
||||
|
||||
/**
|
||||
* @var array HTTP methods supported by this Route
|
||||
*/
|
||||
protected $methods = array();
|
||||
|
||||
/**
|
||||
* @var array[Callable] Middleware to be run before only this route instance
|
||||
*/
|
||||
protected $middleware = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $pattern The URL pattern (e.g. "/books/:id")
|
||||
* @param mixed $callable Anything that returns TRUE for is_callable()
|
||||
*/
|
||||
public function __construct($pattern, $callable)
|
||||
{
|
||||
$this->setPattern($pattern);
|
||||
$this->setCallable($callable);
|
||||
$this->setConditions(self::getDefaultConditions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default route conditions for all instances
|
||||
* @param array $defaultConditions
|
||||
*/
|
||||
public static function setDefaultConditions(array $defaultConditions)
|
||||
{
|
||||
self::$defaultConditions = $defaultConditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default route conditions for all instances
|
||||
* @return array
|
||||
*/
|
||||
public static function getDefaultConditions()
|
||||
{
|
||||
return self::$defaultConditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get route pattern
|
||||
* @return string
|
||||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set route pattern
|
||||
* @param string $pattern
|
||||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->pattern = $pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get route callable
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCallable()
|
||||
{
|
||||
return $this->callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set route callable
|
||||
* @param mixed $callable
|
||||
* @throws \InvalidArgumentException If argument is not callable
|
||||
*/
|
||||
public function setCallable($callable)
|
||||
{
|
||||
if (!is_callable($callable)) {
|
||||
throw new \InvalidArgumentException('Route callable must be callable');
|
||||
}
|
||||
|
||||
$this->callable = $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get route conditions
|
||||
* @return array
|
||||
*/
|
||||
public function getConditions()
|
||||
{
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set route conditions
|
||||
* @param array $conditions
|
||||
*/
|
||||
public function setConditions(array $conditions)
|
||||
{
|
||||
$this->conditions = $conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get route name
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set route name
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = (string) $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get route parameters
|
||||
* @return array
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set route parameters
|
||||
* @param array $params
|
||||
*/
|
||||
public function setParams($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get route parameter value
|
||||
* @param string $index Name of URL parameter
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException If route parameter does not exist at index
|
||||
*/
|
||||
public function getParam($index)
|
||||
{
|
||||
if (!isset($this->params[$index])) {
|
||||
throw new \InvalidArgumentException('Route parameter does not exist at specified index');
|
||||
}
|
||||
|
||||
return $this->params[$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set route parameter value
|
||||
* @param string $index Name of URL parameter
|
||||
* @param mixed $value The new parameter value
|
||||
* @throws \InvalidArgumentException If route parameter does not exist at index
|
||||
*/
|
||||
public function setParam($index, $value)
|
||||
{
|
||||
if (!isset($this->params[$index])) {
|
||||
throw new \InvalidArgumentException('Route parameter does not exist at specified index');
|
||||
}
|
||||
$this->params[$index] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add supported HTTP method(s)
|
||||
*/
|
||||
public function setHttpMethods()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->methods = $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported HTTP methods
|
||||
* @return array
|
||||
*/
|
||||
public function getHttpMethods()
|
||||
{
|
||||
return $this->methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append supported HTTP methods
|
||||
*/
|
||||
public function appendHttpMethods()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->methods = array_merge($this->methods, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append supported HTTP methods (alias for Route::appendHttpMethods)
|
||||
* @return \Slim\Route
|
||||
*/
|
||||
public function via()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->methods = array_merge($this->methods, $args);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect support for an HTTP method
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsHttpMethod($method)
|
||||
{
|
||||
return in_array($method, $this->methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get middleware
|
||||
* @return array[Callable]
|
||||
*/
|
||||
public function getMiddleware()
|
||||
{
|
||||
return $this->middleware;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set middleware
|
||||
*
|
||||
* This method allows middleware to be assigned to a specific Route.
|
||||
* If the method argument `is_callable` (including callable arrays!),
|
||||
* we directly append the argument to `$this->middleware`. Else, we
|
||||
* assume the argument is an array of callables and merge the array
|
||||
* with `$this->middleware`. Each middleware is checked for is_callable()
|
||||
* and an InvalidArgumentException is thrown immediately if it isn't.
|
||||
*
|
||||
* @param Callable|array[Callable]
|
||||
* @return \Slim\Route
|
||||
* @throws \InvalidArgumentException If argument is not callable or not an array of callables.
|
||||
*/
|
||||
public function setMiddleware($middleware)
|
||||
{
|
||||
if (is_callable($middleware)) {
|
||||
$this->middleware[] = $middleware;
|
||||
} elseif (is_array($middleware)) {
|
||||
foreach($middleware as $callable) {
|
||||
if (!is_callable($callable)) {
|
||||
throw new \InvalidArgumentException('All Route middleware must be callable');
|
||||
}
|
||||
}
|
||||
$this->middleware = array_merge($this->middleware, $middleware);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Route middleware must be callable or an array of callables');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches URI?
|
||||
*
|
||||
* Parse this route's pattern, and then compare it to an HTTP resource URI
|
||||
* This method was modeled after the techniques demonstrated by Dan Sosedoff at:
|
||||
*
|
||||
* http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/
|
||||
*
|
||||
* @param string $resourceUri A Request URI
|
||||
* @return bool
|
||||
*/
|
||||
public function matches($resourceUri)
|
||||
{
|
||||
//Convert URL params into regex patterns, construct a regex for this route, init params
|
||||
$patternAsRegex = preg_replace_callback('#:([\w]+)\+?#', array($this, 'matchesCallback'),
|
||||
str_replace(')', ')?', (string) $this->pattern));
|
||||
if (substr($this->pattern, -1) === '/') {
|
||||
$patternAsRegex .= '?';
|
||||
}
|
||||
|
||||
//Cache URL params' names and values if this route matches the current HTTP request
|
||||
if (!preg_match('#^' . $patternAsRegex . '$#', $resourceUri, $paramValues)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($this->paramNames as $name) {
|
||||
if (isset($paramValues[$name])) {
|
||||
if (isset($this->paramNamesPath[ $name ])) {
|
||||
$this->params[$name] = explode('/', urldecode($paramValues[$name]));
|
||||
} else {
|
||||
$this->params[$name] = urldecode($paramValues[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a URL parameter (e.g. ":id", ":id+") into a regular expression
|
||||
* @param array URL parameters
|
||||
* @return string Regular expression for URL parameter
|
||||
*/
|
||||
protected function matchesCallback($m)
|
||||
{
|
||||
$this->paramNames[] = $m[1];
|
||||
if (isset($this->conditions[ $m[1] ])) {
|
||||
return '(?P<' . $m[1] . '>' . $this->conditions[ $m[1] ] . ')';
|
||||
}
|
||||
if (substr($m[0], -1) === '+') {
|
||||
$this->paramNamesPath[ $m[1] ] = 1;
|
||||
|
||||
return '(?P<' . $m[1] . '>.+)';
|
||||
}
|
||||
|
||||
return '(?P<' . $m[1] . '>[^/]+)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set route name
|
||||
* @param string $name The name of the route
|
||||
* @return \Slim\Route
|
||||
*/
|
||||
public function name($name)
|
||||
{
|
||||
$this->setName($name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge route conditions
|
||||
* @param array $conditions Key-value array of URL parameter conditions
|
||||
* @return \Slim\Route
|
||||
*/
|
||||
public function conditions(array $conditions)
|
||||
{
|
||||
$this->conditions = array_merge($this->conditions, $conditions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -1,235 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim;
|
||||
|
||||
/**
|
||||
* Router
|
||||
*
|
||||
* This class organizes, iterates, and dispatches \Slim\Route objects.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Router
|
||||
{
|
||||
/**
|
||||
* @var Route The current route (most recently dispatched)
|
||||
*/
|
||||
protected $currentRoute;
|
||||
|
||||
/**
|
||||
* @var array Lookup hash of all route objects
|
||||
*/
|
||||
protected $routes;
|
||||
|
||||
/**
|
||||
* @var array Lookup hash of named route objects, keyed by route name (lazy-loaded)
|
||||
*/
|
||||
protected $namedRoutes;
|
||||
|
||||
/**
|
||||
* @var array Array of route objects that match the request URI (lazy-loaded)
|
||||
*/
|
||||
protected $matchedRoutes;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->routes = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current Route object or the first matched one if matching has been performed
|
||||
* @return \Slim\Route|null
|
||||
*/
|
||||
public function getCurrentRoute()
|
||||
{
|
||||
if ($this->currentRoute !== null) {
|
||||
return $this->currentRoute;
|
||||
}
|
||||
|
||||
if (is_array($this->matchedRoutes) && count($this->matchedRoutes) > 0) {
|
||||
return $this->matchedRoutes[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return route objects that match the given HTTP method and URI
|
||||
* @param string $httpMethod The HTTP method to match against
|
||||
* @param string $resourceUri The resource URI to match against
|
||||
* @param bool $reload Should matching routes be re-parsed?
|
||||
* @return array[\Slim\Route]
|
||||
*/
|
||||
public function getMatchedRoutes($httpMethod, $resourceUri, $reload = false)
|
||||
{
|
||||
if ($reload || is_null($this->matchedRoutes)) {
|
||||
$this->matchedRoutes = array();
|
||||
foreach ($this->routes as $route) {
|
||||
if (!$route->supportsHttpMethod($httpMethod)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($route->matches($resourceUri)) {
|
||||
$this->matchedRoutes[] = $route;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->matchedRoutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a route object to a callback function
|
||||
* @param string $pattern The URL pattern (ie. "/books/:id")
|
||||
* @param mixed $callable Anything that returns TRUE for is_callable()
|
||||
* @return \Slim\Route
|
||||
*/
|
||||
public function map($pattern, $callable)
|
||||
{
|
||||
$route = new \Slim\Route($pattern, $callable);
|
||||
$this->routes[] = $route;
|
||||
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL for named route
|
||||
* @param string $name The name of the route
|
||||
* @param array Associative array of URL parameter names and replacement values
|
||||
* @throws RuntimeException If named route not found
|
||||
* @return string The URL for the given route populated with provided replacement values
|
||||
*/
|
||||
public function urlFor($name, $params = array())
|
||||
{
|
||||
if (!$this->hasNamedRoute($name)) {
|
||||
throw new \RuntimeException('Named route not found for name: ' . $name);
|
||||
}
|
||||
$search = array();
|
||||
foreach (array_keys($params) as $key) {
|
||||
$search[] = '#:' . $key . '\+?(?!\w)#';
|
||||
}
|
||||
$pattern = preg_replace($search, $params, $this->getNamedRoute($name)->getPattern());
|
||||
|
||||
//Remove remnants of unpopulated, trailing optional pattern segments
|
||||
return preg_replace('#\(/?:.+\)|\(|\)#', '', $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch route
|
||||
*
|
||||
* This method invokes the route object's callable. If middleware is
|
||||
* registered for the route, each callable middleware is invoked in
|
||||
* the order specified.
|
||||
*
|
||||
* @param \Slim\Route $route The route object
|
||||
* @return bool Was route callable invoked successfully?
|
||||
*/
|
||||
public function dispatch(\Slim\Route $route)
|
||||
{
|
||||
$this->currentRoute = $route;
|
||||
|
||||
//Invoke middleware
|
||||
foreach ($route->getMiddleware() as $mw) {
|
||||
call_user_func_array($mw, array($route));
|
||||
}
|
||||
|
||||
//Invoke callable
|
||||
call_user_func_array($route->getCallable(), array_values($route->getParams()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add named route
|
||||
* @param string $name The route name
|
||||
* @param \Slim\Route $route The route object
|
||||
* @throws \RuntimeException If a named route already exists with the same name
|
||||
*/
|
||||
public function addNamedRoute($name, \Slim\Route $route)
|
||||
{
|
||||
if ($this->hasNamedRoute($name)) {
|
||||
throw new \RuntimeException('Named route already exists with name: ' . $name);
|
||||
}
|
||||
$this->namedRoutes[(string) $name] = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has named route
|
||||
* @param string $name The route name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasNamedRoute($name)
|
||||
{
|
||||
$this->getNamedRoutes();
|
||||
|
||||
return isset($this->namedRoutes[(string) $name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get named route
|
||||
* @param string $name
|
||||
* @return \Slim\Route|null
|
||||
*/
|
||||
public function getNamedRoute($name)
|
||||
{
|
||||
$this->getNamedRoutes();
|
||||
if ($this->hasNamedRoute($name)) {
|
||||
return $this->namedRoutes[(string) $name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get named routes
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getNamedRoutes()
|
||||
{
|
||||
if (is_null($this->namedRoutes)) {
|
||||
$this->namedRoutes = array();
|
||||
foreach ($this->routes as $route) {
|
||||
if ($route->getName() !== null) {
|
||||
$this->addNamedRoute($route->getName(), $route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new \ArrayIterator($this->namedRoutes);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,216 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart <info@slimframework.com>
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.2.0
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
namespace Slim;
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* The view is responsible for rendering a template. The view
|
||||
* should subclass \Slim\View and implement this interface:
|
||||
*
|
||||
* public render(string $template);
|
||||
*
|
||||
* This method should render the specified template and return
|
||||
* the resultant string.
|
||||
*
|
||||
* @package Slim
|
||||
* @author Josh Lockhart
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* @var string Absolute or relative filesystem path to a specific template
|
||||
*
|
||||
* DEPRECATION WARNING!
|
||||
* This variable will be removed in the near future
|
||||
*/
|
||||
protected $templatePath = '';
|
||||
|
||||
/**
|
||||
* @var array Associative array of template variables
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* @var string Absolute or relative path to the application's templates directory
|
||||
*/
|
||||
protected $templatesDirectory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* This is empty but may be implemented in a subclass
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data
|
||||
* @param string|null $key
|
||||
* @return mixed If key is null, array of template data;
|
||||
* If key exists, value of datum with key;
|
||||
* If key does not exist, null;
|
||||
*/
|
||||
public function getData($key = null)
|
||||
{
|
||||
if (!is_null($key)) {
|
||||
return isset($this->data[$key]) ? $this->data[$key] : null;
|
||||
} else {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data
|
||||
*
|
||||
* If two arguments:
|
||||
* A single datum with key is assigned value;
|
||||
*
|
||||
* $view->setData('color', 'red');
|
||||
*
|
||||
* If one argument:
|
||||
* Replace all data with provided array keys and values;
|
||||
*
|
||||
* $view->setData(array('color' => 'red', 'number' => 1));
|
||||
*
|
||||
* @param mixed
|
||||
* @param mixed
|
||||
* @throws InvalidArgumentException If incorrect method signature
|
||||
*/
|
||||
public function setData()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if (count($args) === 1 && is_array($args[0])) {
|
||||
$this->data = $args[0];
|
||||
} elseif (count($args) === 2) {
|
||||
$this->data[(string) $args[0]] = $args[1];
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Cannot set View data with provided arguments. Usage: `View::setData( $key, $value );` or `View::setData([ key => value, ... ]);`');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append new data to existing template data
|
||||
* @param array
|
||||
* @throws InvalidArgumentException If not given an array argument
|
||||
*/
|
||||
public function appendData($data)
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
throw new \InvalidArgumentException('Cannot append view data. Expected array argument.');
|
||||
}
|
||||
$this->data = array_merge($this->data, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get templates directory
|
||||
* @return string|null Path to templates directory without trailing slash;
|
||||
* Returns null if templates directory not set;
|
||||
*/
|
||||
public function getTemplatesDirectory()
|
||||
{
|
||||
return $this->templatesDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set templates directory
|
||||
* @param string $dir
|
||||
*/
|
||||
public function setTemplatesDirectory($dir)
|
||||
{
|
||||
$this->templatesDirectory = rtrim($dir, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set template
|
||||
* @param string $template
|
||||
* @throws RuntimeException If template file does not exist
|
||||
*
|
||||
* DEPRECATION WARNING!
|
||||
* This method will be removed in the near future.
|
||||
*/
|
||||
public function setTemplate($template)
|
||||
{
|
||||
$this->templatePath = $this->getTemplatesDirectory() . '/' . ltrim($template, '/');
|
||||
if (!file_exists($this->templatePath)) {
|
||||
throw new \RuntimeException('View cannot render template `' . $this->templatePath . '`. Template does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display template
|
||||
*
|
||||
* This method echoes the rendered template to the current output buffer
|
||||
*
|
||||
* @param string $template Pathname of template file relative to templates directoy
|
||||
*/
|
||||
public function display($template)
|
||||
{
|
||||
echo $this->fetch($template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch rendered template
|
||||
*
|
||||
* This method returns the rendered template
|
||||
*
|
||||
* @param string $template Pathname of template file relative to templates directory
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($template)
|
||||
{
|
||||
return $this->render($template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render template
|
||||
*
|
||||
* @param string $template Pathname of template file relative to templates directory
|
||||
* @return string
|
||||
*
|
||||
* DEPRECATION WARNING!
|
||||
* Use `\Slim\View::fetch` to return a rendered template instead of `\Slim\View::render`.
|
||||
*/
|
||||
public function render($template)
|
||||
{
|
||||
$this->setTemplate($template);
|
||||
extract($this->data);
|
||||
ob_start();
|
||||
require $this->templatePath;
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
<?php
|
||||
require_once('Slim/Slim.php');
|
||||
\Slim\Slim::registerAutoloader();
|
||||
|
||||
$app=new \Slim\Slim();
|
||||
|
||||
$app->get('/entries/:account_id/:year/:month', 'getEntries');
|
||||
$app->get('/accounts', 'getAccounts');
|
||||
$app->get('/accounts/:account_id/months', 'getMonths');
|
||||
$app->delete('/entries/:id', 'removeEntry');
|
||||
$app->post('/entries/add', 'addEntry');
|
||||
$app->put('/entries/save/:id', 'saveEntry');
|
||||
$app->post('/accounts/add','addAccount');
|
||||
$app->put('/accounts/save/:id','saveAccount');
|
||||
$app->delete('/accounts/:id', 'removeAccount');
|
||||
|
||||
$app->run();
|
||||
|
||||
function getConnection() {
|
||||
$db=new PDO("pgsql:host=localhost;dbname=accountant", "accountant", "accountant");
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
||||
// Return the entries
|
||||
function getEntries($account_id, $year, $month) {
|
||||
|
||||
$day=$year."-".$month."-01";
|
||||
|
||||
$connection=getConnection();
|
||||
|
||||
$sql = <<<EOF
|
||||
select
|
||||
id,
|
||||
value_date,
|
||||
operation_date,
|
||||
label,
|
||||
value,
|
||||
account_id,
|
||||
sold,
|
||||
pointedsold,
|
||||
category
|
||||
from (
|
||||
select
|
||||
*,
|
||||
sum(value) over(order by value_date, operation_date, label desc, value desc) as sold,
|
||||
sum(value) over(partition by operation_date is not null order by value_date, operation_date, label desc, value desc) as pointedSold
|
||||
from entry
|
||||
where account_id=:account_id
|
||||
order by value_date desc, operation_date desc, label, value) as e
|
||||
where
|
||||
date_trunc('month', e.value_date) = :day
|
||||
EOF;
|
||||
|
||||
$statement=$connection->prepare($sql);
|
||||
$statement->bindParam("day", $day);
|
||||
$statement->bindParam("account_id", $account_id);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo(json_encode($statement->fetchAll(PDO::FETCH_ASSOC)));
|
||||
}
|
||||
|
||||
// Add an entry
|
||||
function addEntry() {
|
||||
$request = \Slim\Slim::getInstance()->request();
|
||||
$entry = json_decode($request->getBody(), true);
|
||||
|
||||
$connection=getConnection();
|
||||
|
||||
$statement=$connection->prepare("insert into entry (value_date, operation_date, label, value, account_id, category) values (:value_date, :operation_date, :label, :value, :account_id, :category)");
|
||||
|
||||
$statement->bindParam("value_date", $entry['value_date']);
|
||||
$statement->bindParam("operation_date", array_key_exists("operation_date", $entry) ? $entry['operation_date'] : null);
|
||||
$statement->bindParam("label", $entry['label']);
|
||||
$statement->bindParam("value", $entry['value']);
|
||||
$statement->bindParam("account_id", $entry['account_id']);
|
||||
$statement->bindParam("category", array_key_exists("category", $entry) ? $entry["category"] : null);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo("Entry saved.");
|
||||
}
|
||||
|
||||
// Saves an entry
|
||||
function saveEntry($id) {
|
||||
$request = \Slim\Slim::getInstance()->request();
|
||||
$entry = json_decode($request->getBody(), true);
|
||||
|
||||
$connection=getConnection();
|
||||
|
||||
$statement=$connection->prepare("update entry set value_date=:value_date, operation_date=:operation_date, label=:label, value=:value, account_id=:account_id, category=:category where id=:id");
|
||||
|
||||
$statement->bindParam("value_date", $entry['value_date']);
|
||||
$statement->bindParam("operation_date", array_key_exists("operation_date", $entry) ? $entry['operation_date'] : null);
|
||||
$statement->bindParam("label", $entry['label']);
|
||||
$statement->bindParam("value", $entry['value']);
|
||||
$statement->bindParam("account_id", $entry['account_id']);
|
||||
$statement->bindParam("id", $entry['id']);
|
||||
$statement->bindParam("category", array_key_exists("category", $entry) ? $entry["category"] : null);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo($entry['id'] . " saved.");
|
||||
}
|
||||
|
||||
// Remove an entry
|
||||
function removeEntry($id) {
|
||||
$connection=getConnection();
|
||||
|
||||
$statement=$connection->prepare("delete from entry where id=:id");
|
||||
$statement->bindParam("id", $id);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo("Entry #" . $id . " removed.");
|
||||
}
|
||||
|
||||
// Return the accounts with their solds.
|
||||
function getAccounts() {
|
||||
$connection=getConnection();
|
||||
|
||||
$sql = <<<EOF
|
||||
select
|
||||
account.id,
|
||||
account.name,
|
||||
sum(entry.value) as future,
|
||||
sum(case when entry.operation_date is not null then entry.value else cast(0 as numeric) end) as pointed,
|
||||
sum(case when entry.value_date <= now() then entry.value else cast(0 as numeric) end) as current
|
||||
from
|
||||
account
|
||||
left outer join entry on (account.id = entry.account_id)
|
||||
group by
|
||||
account.id
|
||||
order by
|
||||
account.name
|
||||
EOF;
|
||||
|
||||
$statement=$connection->prepare($sql);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo(json_encode($statement->fetchAll(PDO::FETCH_ASSOC)));
|
||||
}
|
||||
|
||||
// Returns the months for an account.
|
||||
function getMonths($account_id) {
|
||||
$connection=getConnection();
|
||||
|
||||
$sql = <<<EOF
|
||||
select
|
||||
distinct extract(year from value_date) as year,
|
||||
extract(month from value_date) as month
|
||||
from
|
||||
entry
|
||||
where
|
||||
account_id = :account_id
|
||||
order by
|
||||
year,
|
||||
month
|
||||
EOF;
|
||||
|
||||
$statement=$connection->prepare($sql);
|
||||
$statement->bindParam("account_id", $account_id);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo(json_encode($statement->fetchAll(PDO::FETCH_ASSOC)));
|
||||
}
|
||||
|
||||
function addAccount() {
|
||||
$request = \Slim\Slim::getInstance()->request();
|
||||
$account = json_decode($request->getBody(), true);
|
||||
|
||||
$connection=getConnection();
|
||||
|
||||
$statement=$connection->prepare("insert into account (name) values (:name)");
|
||||
|
||||
$statement->bindParam("name", $account['name']);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo("Account saved.");
|
||||
}
|
||||
|
||||
function saveAccount($id) {
|
||||
$request = \Slim\Slim::getInstance()->request();
|
||||
$account = json_decode($request->getBody(), true);
|
||||
|
||||
$connection=getConnection();
|
||||
|
||||
$statement=$connection->prepare("update account set name=:name where id=:id");
|
||||
|
||||
$statement->bindParam("name", $account['name']);
|
||||
$statement->bindParam("id", $id);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo("Account #$id saved.");
|
||||
}
|
||||
|
||||
// Remove an account
|
||||
function removeAccount($id) {
|
||||
$connection=getConnection();
|
||||
|
||||
$statement=$connection->prepare("delete from account where id=:id");
|
||||
$statement->bindParam("id", $id);
|
||||
|
||||
$return=$statement->execute();
|
||||
|
||||
echo("Account #$id removed.");
|
||||
}
|
||||
|
||||
?>
|
||||
|
1092
src/html/bootstrap/css/bootstrap-responsive.css
vendored
1092
src/html/bootstrap/css/bootstrap-responsive.css
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
6039
src/html/bootstrap/css/bootstrap.css
vendored
6039
src/html/bootstrap/css/bootstrap.css
vendored
File diff suppressed because it is too large
Load Diff
9
src/html/bootstrap/css/bootstrap.min.css
vendored
9
src/html/bootstrap/css/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 12 KiB |
2159
src/html/bootstrap/js/bootstrap.js
vendored
2159
src/html/bootstrap/js/bootstrap.js
vendored
File diff suppressed because it is too large
Load Diff
6
src/html/bootstrap/js/bootstrap.min.js
vendored
6
src/html/bootstrap/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,158 +0,0 @@
|
||||
/*!
|
||||
* Datepicker for Bootstrap
|
||||
*
|
||||
* Original Idea: http://www.eyecon.ro/bootstrap-datepicker (Copyright 2012 Stefan Petre)
|
||||
* Updated by AymKdn (http://kodono.info - https://github.com/Aymkdn/Datepicker-for-Bootstrap)
|
||||
* Licensed under the Apache License v2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*/
|
||||
.datepicker {
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding: 4px;
|
||||
margin-top: 1px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
/*.dow {
|
||||
border-top: 1px solid #ddd !important;
|
||||
}*/
|
||||
}
|
||||
.datepicker:before {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
border-left: 7px solid transparent;
|
||||
border-right: 7px solid transparent;
|
||||
border-bottom: 7px solid #ccc;
|
||||
border-bottom-color: rgba(0, 0, 0, 0.2);
|
||||
position: absolute;
|
||||
top: -7px;
|
||||
left: 6px;
|
||||
}
|
||||
.datepicker:after {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
border-left: 6px solid transparent;
|
||||
border-right: 6px solid transparent;
|
||||
border-bottom: 6px solid #ffffff;
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
left: 7px;
|
||||
}
|
||||
.datepicker > div {
|
||||
display: none;
|
||||
}
|
||||
.datepicker table {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
.datepicker td, .datepicker th {
|
||||
text-align: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.datepicker td.day:hover {
|
||||
background: #eeeeee;
|
||||
cursor: pointer;
|
||||
}
|
||||
.datepicker td.old, .datepicker td.new {
|
||||
color: #999999;
|
||||
}
|
||||
.datepicker td.active, .datepicker td.active:hover {
|
||||
background-color: #006dcc;
|
||||
background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
|
||||
background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: -o-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: linear-gradient(top, #0088cc, #0044cc);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
|
||||
border-color: #0044cc #0044cc #002a80;
|
||||
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
|
||||
color: #fff;
|
||||
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.datepicker td.active:hover,
|
||||
.datepicker td.active:hover:hover,
|
||||
.datepicker td.active:active,
|
||||
.datepicker td.active:hover:active,
|
||||
.datepicker td.active.active,
|
||||
.datepicker td.active:hover.active,
|
||||
.datepicker td.active.disabled,
|
||||
.datepicker td.active:hover.disabled,
|
||||
.datepicker td.active[disabled],
|
||||
.datepicker td.active:hover[disabled] {
|
||||
background-color: #0044cc;
|
||||
}
|
||||
.datepicker td.active:active,
|
||||
.datepicker td.active:hover:active,
|
||||
.datepicker td.active.active,
|
||||
.datepicker td.active:hover.active {
|
||||
background-color: #003399 \9;
|
||||
}
|
||||
.datepicker td span {
|
||||
display: block;
|
||||
width: 47px;
|
||||
height: 54px;
|
||||
line-height: 54px;
|
||||
float: left;
|
||||
margin: 2px;
|
||||
cursor: pointer;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.datepicker td span:hover {
|
||||
background: #eeeeee;
|
||||
}
|
||||
.datepicker td span.active {
|
||||
background-color: #006dcc;
|
||||
background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
|
||||
background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: -o-linear-gradient(top, #0088cc, #0044cc);
|
||||
background-image: linear-gradient(top, #0088cc, #0044cc);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
|
||||
border-color: #0044cc #0044cc #002a80;
|
||||
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
|
||||
color: #fff;
|
||||
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.datepicker td span.active:hover,
|
||||
.datepicker td span.active:active,
|
||||
.datepicker td span.active.active,
|
||||
.datepicker td span.active.disabled,
|
||||
.datepicker td span.active[disabled] {
|
||||
background-color: #0044cc;
|
||||
}
|
||||
.datepicker td span.active:active, .datepicker td span.active.active {
|
||||
background-color: #003399 \9;
|
||||
}
|
||||
.datepicker td span.old {
|
||||
color: #999999;
|
||||
}
|
||||
.datepicker th.switch {
|
||||
width: 145px;
|
||||
}
|
||||
.datepicker thead tr:first-child th {
|
||||
cursor: pointer;
|
||||
}
|
||||
.datepicker thead tr:first-child th:hover {
|
||||
background: #eeeeee;
|
||||
}
|
||||
.input-append.date .add-on i, .input-prepend.date .add-on i {
|
||||
display: block;
|
||||
cursor: pointer;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
.dropdown-menu.datepicker { max-width:220px }
|
417
src/html/datepicker/js/bootstrap-datepicker.js
vendored
417
src/html/datepicker/js/bootstrap-datepicker.js
vendored
@ -1,417 +0,0 @@
|
||||
/*! =========================================================
|
||||
* bootstrap-datepicker.js
|
||||
* Original Idea: http://www.eyecon.ro/bootstrap-datepicker (Copyright 2012 Stefan Petre)
|
||||
* Updated by AymKdn (http://kodono.info - https://github.com/Aymkdn/Datepicker-for-Bootstrap)
|
||||
* =========================================================
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ========================================================= */
|
||||
|
||||
!function( $ ) {
|
||||
|
||||
// Picker object
|
||||
|
||||
var Datepicker = function(element, options){
|
||||
this.element = $(element);
|
||||
this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
|
||||
this.picker = $(DPGlobal.template).appendTo('body').hide().on('mousedown.Datepicker',$.proxy(this.mousedown, this)).on('click.Datepicker',$.proxy(this.click, this));
|
||||
|
||||
this.isInput = this.element.is('input') || this.element.is('textarea');
|
||||
this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
|
||||
|
||||
if (this.isInput) {
|
||||
this.element.on({
|
||||
"focus.Datepicker": $.proxy(this.show, this),
|
||||
"click.Datepicker": $.proxy(this.show, this),
|
||||
"blur.Datepicker": $.proxy(this.blur, this),
|
||||
"keyup.Datepicker": $.proxy(this.update, this),
|
||||
"keydown.Datepicker": $.proxy(this.keydown, this)
|
||||
});
|
||||
} else {
|
||||
if (this.component){
|
||||
this.component.on('click.Datepicker', $.proxy(this.show, this));
|
||||
} else {
|
||||
this.element.on('click.Datepicker', $.proxy(this.show, this));
|
||||
}
|
||||
}
|
||||
|
||||
this.viewMode = 0;
|
||||
this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
|
||||
this.scroll = (options.scroll != undefined ? options.scroll : true);
|
||||
this.weekEnd = this.weekStart == 0 ? 6 : this.weekStart - 1;
|
||||
this.fillDow();
|
||||
this.fillMonths();
|
||||
this.update();
|
||||
this.showMode();
|
||||
};
|
||||
|
||||
Datepicker.prototype = {
|
||||
constructor: Datepicker,
|
||||
|
||||
show: function(e) {
|
||||
$('div.datepicker.dropdown-menu').hide(); //make sure to hide all other calendars
|
||||
this.picker.show();
|
||||
this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
|
||||
this.place();
|
||||
$(window).on('resize.Datepicker', $.proxy(this.place, this));
|
||||
$('body').on('click.Datepicker', $.proxy(this.hide, this));
|
||||
if (e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
if (!this.isInput) {
|
||||
$(document).on('mousedown.Datepicker', $.proxy(this.hide, this));
|
||||
}
|
||||
this.element.trigger({
|
||||
type: 'show',
|
||||
date: this.date
|
||||
});
|
||||
// make sure we see the datepicker
|
||||
var elem = this.picker;
|
||||
var docScrollTop = $(document).scrollTop();
|
||||
var winHeight = $(window).height();
|
||||
var elemTop = elem.position().top;
|
||||
var elemHeight = elem.height();
|
||||
if (this.scroll && docScrollTop+winHeight<elemTop+elemHeight)
|
||||
$(document).scrollTop(elemTop-elemHeight);
|
||||
},
|
||||
|
||||
setValue: function() {
|
||||
var formated = DPGlobal.formatDate(this.date, this.format);
|
||||
if (!this.isInput) {
|
||||
if (this.component){
|
||||
this.element.find('input').prop('value', formated);
|
||||
}
|
||||
this.element.data('date', formated);
|
||||
} else {
|
||||
this.element.prop('value', formated);
|
||||
}
|
||||
},
|
||||
|
||||
place: function(){
|
||||
var offset = this.component ? this.component.offset() : this.element.offset();
|
||||
this.picker.css({
|
||||
top: offset.top + this.height,
|
||||
left: offset.left
|
||||
});
|
||||
},
|
||||
|
||||
update: function(){
|
||||
var date = this.element.val();
|
||||
this.date = DPGlobal.parseDate(
|
||||
date ? date : this.element.data('date'),
|
||||
this.format
|
||||
);
|
||||
this.viewDate = new Date(this.date);
|
||||
this.fill();
|
||||
},
|
||||
|
||||
fillDow: function(){
|
||||
var dowCnt = this.weekStart;
|
||||
var html = '<tr>';
|
||||
while (dowCnt < this.weekStart + 7) {
|
||||
html += '<th class="dow">'+DPGlobal.dates.daysMin[(dowCnt++)%7]+'</th>';
|
||||
}
|
||||
html += '</tr>';
|
||||
this.picker.find('.datepicker-days thead').append(html);
|
||||
},
|
||||
|
||||
fillMonths: function(){
|
||||
var html = '';
|
||||
var i = 0
|
||||
while (i < 12) {
|
||||
html += '<span class="month">'+DPGlobal.dates.monthsShort[i++]+'</span>';
|
||||
}
|
||||
this.picker.find('.datepicker-months td').append(html);
|
||||
},
|
||||
|
||||
fill: function() {
|
||||
var d = new Date(this.viewDate),
|
||||
year = d.getFullYear(),
|
||||
month = d.getMonth(),
|
||||
currentDate = this.date.valueOf();
|
||||
this.picker.find('.datepicker-days th:eq(1)')
|
||||
.text(DPGlobal.dates.months[month]+' '+year);
|
||||
var prevMonth = new Date(year, month-1, 28,0,0,0,0),
|
||||
day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
|
||||
prevMonth.setDate(day);
|
||||
prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
|
||||
var nextMonth = new Date(prevMonth);
|
||||
nextMonth.setDate(nextMonth.getDate() + 42);
|
||||
nextMonth = nextMonth.valueOf();
|
||||
html = [];
|
||||
var clsName;
|
||||
while(prevMonth.valueOf() < nextMonth) {
|
||||
if (prevMonth.getDay() == this.weekStart) {
|
||||
html.push('<tr>');
|
||||
}
|
||||
clsName = '';
|
||||
if (prevMonth.getMonth() < month) {
|
||||
clsName += ' old';
|
||||
} else if (prevMonth.getMonth() > month) {
|
||||
clsName += ' new';
|
||||
}
|
||||
if (prevMonth.valueOf() == currentDate) {
|
||||
clsName += ' active';
|
||||
}
|
||||
html.push('<td class="day'+clsName+'">'+prevMonth.getDate() + '</td>');
|
||||
if (prevMonth.getDay() == this.weekEnd) {
|
||||
html.push('</tr>');
|
||||
}
|
||||
prevMonth.setDate(prevMonth.getDate()+1);
|
||||
}
|
||||
this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
|
||||
var currentYear = this.date.getFullYear();
|
||||
|
||||
var months = this.picker.find('.datepicker-months')
|
||||
.find('th:eq(1)')
|
||||
.text(year)
|
||||
.end()
|
||||
.find('span').removeClass('active');
|
||||
if (currentYear == year) {
|
||||
months.eq(this.date.getMonth()).addClass('active');
|
||||
}
|
||||
|
||||
html = '';
|
||||
year = parseInt(year/10, 10) * 10;
|
||||
var yearCont = this.picker.find('.datepicker-years')
|
||||
.find('th:eq(1)')
|
||||
.text(year + '-' + (year + 9))
|
||||
.end()
|
||||
.find('td');
|
||||
year -= 1;
|
||||
for (var i = -1; i < 11; i++) {
|
||||
html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+'">'+year+'</span>';
|
||||
year += 1;
|
||||
}
|
||||
yearCont.html(html);
|
||||
},
|
||||
|
||||
blur:function(e) {
|
||||
},
|
||||
|
||||
hide: function(e){
|
||||
this.picker.hide();
|
||||
$(window).off('resize.Datepicker', this.place);
|
||||
this.viewMode = 0;
|
||||
this.showMode();
|
||||
if (!this.isInput) {
|
||||
$(document).off('mousedown.Datepicker', this.hide);
|
||||
}
|
||||
$('body').off('click.Datepicker',$.proxy(this.click, this));
|
||||
},
|
||||
click:function(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
},
|
||||
mousedown: function(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
var target = $(e.target).closest('span, td, th');
|
||||
if (target.length == 1) {
|
||||
switch(target[0].nodeName.toLowerCase()) {
|
||||
case 'th':
|
||||
switch(target[0].className) {
|
||||
case 'switch':
|
||||
this.showMode(1);
|
||||
break;
|
||||
case 'prev':
|
||||
case 'next':
|
||||
this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
|
||||
this.viewDate,
|
||||
this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
|
||||
DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1)
|
||||
);
|
||||
this.fill();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'span':
|
||||
if (target.is('.month')) {
|
||||
var month = target.parent().find('span').index(target);
|
||||
this.viewDate.setMonth(month);
|
||||
} else {
|
||||
var year = parseInt(target.text(), 10)||0;
|
||||
this.viewDate.setFullYear(year);
|
||||
}
|
||||
this.showMode(-1);
|
||||
this.fill();
|
||||
break;
|
||||
case 'td':
|
||||
if (target.is('.day')){
|
||||
var day = parseInt(target.text(), 10)||1;
|
||||
var month = this.viewDate.getMonth();
|
||||
if (target.is('.old')) {
|
||||
month -= 1;
|
||||
} else if (target.is('.new')) {
|
||||
month += 1;
|
||||
}
|
||||
var year = this.viewDate.getFullYear();
|
||||
this.date = new Date(year, month, day,0,0,0,0);
|
||||
this.viewDate = new Date(year, month, day,0,0,0,0);
|
||||
this.fill();
|
||||
this.setValue();
|
||||
this.element.trigger({
|
||||
type: 'changeDate',
|
||||
date: this.date
|
||||
});
|
||||
this.hide();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
keydown:function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
if (keyCode == 9) this.hide(); // when hiting TAB, for accessibility
|
||||
},
|
||||
|
||||
showMode: function(dir) {
|
||||
if (dir) {
|
||||
this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
|
||||
}
|
||||
this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
|
||||
},
|
||||
|
||||
destroy: function() { this.element.removeData("datepicker").off(".Datepicker"); this.picker.remove() }
|
||||
};
|
||||
|
||||
$.fn.datepicker = function ( option ) {
|
||||
return this.each(function () {
|
||||
var $this = $(this),
|
||||
data = $this.data('datepicker'),
|
||||
options = typeof option == 'object' && option;
|
||||
if (!data) {
|
||||
$this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
|
||||
}
|
||||
if (typeof option == 'string') data[option]();
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.datepicker.defaults = {
|
||||
};
|
||||
$.fn.datepicker.Constructor = Datepicker;
|
||||
|
||||
var DPGlobal = {
|
||||
modes: [
|
||||
{
|
||||
clsName: 'days',
|
||||
navFnc: 'Month',
|
||||
navStep: 1
|
||||
},
|
||||
{
|
||||
clsName: 'months',
|
||||
navFnc: 'FullYear',
|
||||
navStep: 1
|
||||
},
|
||||
{
|
||||
clsName: 'years',
|
||||
navFnc: 'FullYear',
|
||||
navStep: 10
|
||||
}],
|
||||
dates:{
|
||||
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
||||
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
||||
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
|
||||
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
||||
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
||||
},
|
||||
isLeapYear: function (year) {
|
||||
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
|
||||
},
|
||||
getDaysInMonth: function (year, month) {
|
||||
return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
|
||||
},
|
||||
parseFormat: function(format){
|
||||
var separator = format.match(/[.\/-].*?/),
|
||||
parts = format.split(/\W+/);
|
||||
if (!separator || !parts || parts.length == 0){
|
||||
throw new Error("Invalid date format.");
|
||||
}
|
||||
return {separator: separator, parts: parts};
|
||||
},
|
||||
parseDate: function(date, format) {
|
||||
var today=new Date();
|
||||
if (!date) date="";
|
||||
var parts = date.split(format.separator),
|
||||
date = new Date(today.getFullYear(),today.getMonth(),today.getDate(),0,0,0),
|
||||
val;
|
||||
if (parts.length == format.parts.length) {
|
||||
for (var i=0, cnt = format.parts.length; i < cnt; i++) {
|
||||
val = parseInt(parts[i], 10)||1;
|
||||
switch(format.parts[i]) {
|
||||
case 'dd':
|
||||
case 'd':
|
||||
date.setDate(val);
|
||||
break;
|
||||
case 'mm':
|
||||
case 'm':
|
||||
date.setMonth(val - 1);
|
||||
break;
|
||||
case 'yy':
|
||||
date.setFullYear(2000 + val);
|
||||
break;
|
||||
case 'yyyy':
|
||||
date.setFullYear(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return date;
|
||||
},
|
||||
formatDate: function(date, format){
|
||||
var val = {
|
||||
d: date.getDate(),
|
||||
m: date.getMonth() + 1,
|
||||
yy: date.getFullYear().toString().substring(2),
|
||||
yyyy: date.getFullYear()
|
||||
};
|
||||
val.dd = (val.d < 10 ? '0' : '') + val.d;
|
||||
val.mm = (val.m < 10 ? '0' : '') + val.m;
|
||||
var date = [];
|
||||
for (var i=0, cnt = format.parts.length; i < cnt; i++) {
|
||||
date.push(val[format.parts[i]]);
|
||||
}
|
||||
return date.join(format.separator);
|
||||
},
|
||||
headTemplate: '<thead>'+
|
||||
'<tr>'+
|
||||
'<th class="prev"><i class="icon-arrow-left"/></th>'+
|
||||
'<th colspan="5" class="switch"></th>'+
|
||||
'<th class="next"><i class="icon-arrow-right"/></th>'+
|
||||
'</tr>'+
|
||||
'</thead>',
|
||||
contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
|
||||
};
|
||||
DPGlobal.template = '<div class="datepicker dropdown-menu">'+
|
||||
'<div class="datepicker-days">'+
|
||||
'<table class=" table-condensed">'+
|
||||
DPGlobal.headTemplate+
|
||||
'<tbody></tbody>'+
|
||||
'</table>'+
|
||||
'</div>'+
|
||||
'<div class="datepicker-months">'+
|
||||
'<table class="table-condensed">'+
|
||||
DPGlobal.headTemplate+
|
||||
DPGlobal.contTemplate+
|
||||
'</table>'+
|
||||
'</div>'+
|
||||
'<div class="datepicker-years">'+
|
||||
'<table class="table-condensed">'+
|
||||
DPGlobal.headTemplate+
|
||||
DPGlobal.contTemplate+
|
||||
'</table>'+
|
||||
'</div>'+
|
||||
'</div>';
|
||||
|
||||
}( window.jQuery )
|
@ -1,190 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Entries</title>
|
||||
<!-- Bootstrap -->
|
||||
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<link href="datepicker/css/datepicker.css" rel="stylesheet" media="screen">
|
||||
<link href="jqplot/jquery.jqplot.min.css" rel="stylesheet" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div class="navbar navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<a class="brand" href="#"> Comptes</a>
|
||||
|
||||
<div class="nav" data-bind="foreach: accounts, value: account">
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-nav" data-bind="css: { active: $data === $root.account() }, click: $parent.selectAccount"><span data-bind="text: name"></span> (<span data-bind="text: current, css: {'text-error': $data.current < 0 }"></span>)</button>
|
||||
<button class="btn btn-nav dropdown-toggle" data-toggle="dropdown"><b class="caret"></b></button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#" data-bind="click: $root.editAccount">Modifier</a></li>
|
||||
<li><a href="#" data-bind="click: $root.removeAccount">Supprimer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="btn btn-nav">
|
||||
<a data-bind="click: $root.addAccount" href="#"><i class="icon-plus"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="navbar navbar-fixed-bottom">
|
||||
<div class="navbar-inner">
|
||||
<ul data-bind="foreach: months()" class="nav">
|
||||
<li data-bind="css: {'active': $data == $root.month()}"><a href="#" data-bind="click: $parent.selectMonth"><span data-bind="text: $data.year"></span>-<span data-bind="text: $data.month"></span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid" style="margin-top: 46px"></div>
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span8">
|
||||
<div id="entries-chart-placeholder" data-bind="chart: $root.entriesChart"></div>
|
||||
</div>
|
||||
|
||||
<div class="span4">
|
||||
<div id="expense-categories-chart-placeholder" data-bind="pieChart: $root.expenseCategoriesChart"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row-fluid">
|
||||
<div id="message-placeholder"></div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
<a class="btn btn-primary" data-bind="click: $root.add" href="#" title="Add entry"><i class="icon-plus"></i> Ajouter une entrée</a>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
<table class="table table-striped table-condensed table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 100px">Date de valeur</th>
|
||||
<th style="width: 100px">Date de l'opération</th>
|
||||
<th>Libellé de l'opération</th>
|
||||
<th style="width: 50px">Montant</th>
|
||||
<th style="width: 50px">Solde</th>
|
||||
<th style="width: 50px">Solde pointé</th>
|
||||
<th style="width: 100px">Catégorie</th>
|
||||
<th style="width: 60px">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody data-bind="template:{name: templateToUse, foreach: entries}">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid" style="margin-bottom: 21px"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-confirm" class="modal hide fade">
|
||||
<div class="modal-header">
|
||||
<h3>Confirmer la suppression</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Confirmez-vous la suppression de cette entrée ?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Non</a>
|
||||
<a href="#" class="btn" data-bind="click: confirmRemove">Oui</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-account-confirm" class="modal hide fade">
|
||||
<div class="modal-header">
|
||||
<h3>Confirmer la suppression</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Confirmez-vous la suppression de ce compte ?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Non</a>
|
||||
<a href="#" class="btn" data-bind="click: confirmAccountRemove">Oui</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="edit-account" class="modal hide fade">
|
||||
<div class="modal-header">
|
||||
<h3>Éditer le compte</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal" data-bind="with: editingAccount">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="inputName">Nom du compte</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="inputName" data-bind="value: name"></input>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-bind="click: saveAccount">OK</a>
|
||||
<a href="#" class="btn" data-bind="click: cancelEditAccount">Annuler</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script id="itemsTmpl" type="text/html">
|
||||
<tr data-bind="css: { 'error': sold() < 0 }">
|
||||
<td data-bind="text: value_date"></td>
|
||||
<td data-bind="text: operation_date"></td>
|
||||
<td data-bind="text: label"></td>
|
||||
<td data-bind="text: value, css: {'text-error': value() < 0 }"></td>
|
||||
<td data-bind="text: sold, css: {'text-error': sold() < 0 }"></td>
|
||||
<td data-bind="text: operation_date() ? pointedsold : '', css: {'text-error': operation_date() && pointedsold() < 0 }"></td>
|
||||
<td data-bind="text: category"></td>
|
||||
<td class="buttons">
|
||||
<a class="btn btn-mini" data-bind="click: $root.edit" href="#" title="edit"><i class="icon-edit"></i></a>
|
||||
<a class="btn btn-mini" data-bind="click: $root.remove" href="#" title="remove"><i class="icon-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
</script>
|
||||
|
||||
<script id="editTmpl" type="text/html">
|
||||
<tr data-bind="css: { 'error': sold() < 0 }">
|
||||
<td><div class="date"><input type="text" class="input-small" data-bind="value: value_date" data-date-format="yyyy-mm-dd" id="value_date"></input></div></td>
|
||||
<td><div class="input-append date"><input type="text" class="input-small" data-bind="value: operation_date" data-date-format="yyyy-mm-dd" id="operation_date"></input><button class="btn" type="button" data-bind="click: function(item) { item.operation_date(null)}"><i class="icon-remove"></i></button></div></td>
|
||||
<td><input type="text" class="input-xxlarge" data-bind="value: label"/></td>
|
||||
<td><input type="text" class="input-mini" data-bind="value: value"/></td>
|
||||
<td data-bind="text: sold"></td>
|
||||
<td data-bind="text: pointedsold"></td>
|
||||
<td><input type="text" class="input-small" data-bind="value: category"/></td>
|
||||
<td class="buttons">
|
||||
<a class="btn btn-mini btn-success" data-bind="click: $root.save" href="#" title="save"><i class="icon-ok"></i></a>
|
||||
<a class="btn btn-mini" data-bind="click: $root.cancel" href="#" title="cancel"><i class="icon-ban-circle"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="jquery/jquery.js"></script>
|
||||
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="datepicker/js/bootstrap-datepicker.js"></script>
|
||||
|
||||
<script type="text/javascript" src="knockout/knockout.js"></script>
|
||||
<script type="text/javascript" src="knockout/knockout-mapping.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="jqplot/jquery.jqplot.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.dateAxisRenderer.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.canvasTextRenderer.min.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.ohlcRenderer.min.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.pieRenderer.min.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.highlighter.min.js"></script>
|
||||
<script type="text/javascript" src="jqplot/plugins/jqplot.canvasOverlay.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/date.js"></script>
|
||||
<script type="text/javascript" src="js/entries.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
File diff suppressed because it is too large
Load Diff
57
src/html/jqplot/excanvas.min.js
vendored
57
src/html/jqplot/excanvas.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,259 +0,0 @@
|
||||
/*rules for the plot target div. These will be cascaded down to all plot elements according to css rules*/
|
||||
.jqplot-target {
|
||||
position: relative;
|
||||
color: #666666;
|
||||
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
|
||||
font-size: 1em;
|
||||
/* height: 300px;
|
||||
width: 400px;*/
|
||||
}
|
||||
|
||||
/*rules applied to all axes*/
|
||||
.jqplot-axis {
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.jqplot-xaxis {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.jqplot-x2axis {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.jqplot-yaxis {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.jqplot-y2axis, .jqplot-y3axis, .jqplot-y4axis, .jqplot-y5axis, .jqplot-y6axis, .jqplot-y7axis, .jqplot-y8axis, .jqplot-y9axis, .jqplot-yMidAxis {
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
/*rules applied to all axis tick divs*/
|
||||
.jqplot-axis-tick, .jqplot-xaxis-tick, .jqplot-yaxis-tick, .jqplot-x2axis-tick, .jqplot-y2axis-tick, .jqplot-y3axis-tick, .jqplot-y4axis-tick, .jqplot-y5axis-tick, .jqplot-y6axis-tick, .jqplot-y7axis-tick, .jqplot-y8axis-tick, .jqplot-y9axis-tick, .jqplot-yMidAxis-tick {
|
||||
position: absolute;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
|
||||
.jqplot-xaxis-tick {
|
||||
top: 0px;
|
||||
/* initial position untill tick is drawn in proper place */
|
||||
left: 15px;
|
||||
/* padding-top: 10px;*/
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.jqplot-x2axis-tick {
|
||||
bottom: 0px;
|
||||
/* initial position untill tick is drawn in proper place */
|
||||
left: 15px;
|
||||
/* padding-bottom: 10px;*/
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
.jqplot-yaxis-tick {
|
||||
right: 0px;
|
||||
/* initial position untill tick is drawn in proper place */
|
||||
top: 15px;
|
||||
/* padding-right: 10px;*/
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.jqplot-yaxis-tick.jqplot-breakTick {
|
||||
right: -20px;
|
||||
margin-right: 0px;
|
||||
padding:1px 5px 1px 5px;
|
||||
/* background-color: white;*/
|
||||
z-index: 2;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.jqplot-y2axis-tick, .jqplot-y3axis-tick, .jqplot-y4axis-tick, .jqplot-y5axis-tick, .jqplot-y6axis-tick, .jqplot-y7axis-tick, .jqplot-y8axis-tick, .jqplot-y9axis-tick {
|
||||
left: 0px;
|
||||
/* initial position untill tick is drawn in proper place */
|
||||
top: 15px;
|
||||
/* padding-left: 10px;*/
|
||||
/* padding-right: 15px;*/
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.jqplot-yMidAxis-tick {
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.jqplot-xaxis-label {
|
||||
margin-top: 10px;
|
||||
font-size: 11pt;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.jqplot-x2axis-label {
|
||||
margin-bottom: 10px;
|
||||
font-size: 11pt;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.jqplot-yaxis-label {
|
||||
margin-right: 10px;
|
||||
/* text-align: center;*/
|
||||
font-size: 11pt;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.jqplot-yMidAxis-label {
|
||||
font-size: 11pt;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.jqplot-y2axis-label, .jqplot-y3axis-label, .jqplot-y4axis-label, .jqplot-y5axis-label, .jqplot-y6axis-label, .jqplot-y7axis-label, .jqplot-y8axis-label, .jqplot-y9axis-label {
|
||||
/* text-align: center;*/
|
||||
font-size: 11pt;
|
||||
margin-left: 10px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.jqplot-meterGauge-tick {
|
||||
font-size: 0.75em;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.jqplot-meterGauge-label {
|
||||
font-size: 1em;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
table.jqplot-table-legend {
|
||||
margin-top: 12px;
|
||||
margin-bottom: 12px;
|
||||
margin-left: 12px;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
table.jqplot-table-legend, table.jqplot-cursor-legend {
|
||||
background-color: rgba(255,255,255,0.6);
|
||||
border: 1px solid #cccccc;
|
||||
position: absolute;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
td.jqplot-table-legend {
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
/*
|
||||
These rules could be used instead of assigning
|
||||
element styles and relying on js object properties.
|
||||
*/
|
||||
|
||||
/*
|
||||
td.jqplot-table-legend-swatch {
|
||||
padding-top: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
tr.jqplot-table-legend:first td.jqplot-table-legend-swatch {
|
||||
padding-top: 0px;
|
||||
}
|
||||
*/
|
||||
|
||||
td.jqplot-seriesToggle:hover, td.jqplot-seriesToggle:active {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jqplot-table-legend .jqplot-series-hidden {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
div.jqplot-table-legend-swatch-outline {
|
||||
border: 1px solid #cccccc;
|
||||
padding:1px;
|
||||
}
|
||||
|
||||
div.jqplot-table-legend-swatch {
|
||||
width:0px;
|
||||
height:0px;
|
||||
border-top-width: 5px;
|
||||
border-bottom-width: 5px;
|
||||
border-left-width: 6px;
|
||||
border-right-width: 6px;
|
||||
border-top-style: solid;
|
||||
border-bottom-style: solid;
|
||||
border-left-style: solid;
|
||||
border-right-style: solid;
|
||||
}
|
||||
|
||||
.jqplot-title {
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
padding-bottom: 0.5em;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
table.jqplot-cursor-tooltip {
|
||||
border: 1px solid #cccccc;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
|
||||
.jqplot-cursor-tooltip {
|
||||
border: 1px solid #cccccc;
|
||||
font-size: 0.75em;
|
||||
white-space: nowrap;
|
||||
background: rgba(208,208,208,0.5);
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
.jqplot-highlighter-tooltip, .jqplot-canvasOverlay-tooltip {
|
||||
border: 1px solid #cccccc;
|
||||
font-size: 0.75em;
|
||||
white-space: nowrap;
|
||||
background: rgba(208,208,208,0.5);
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
.jqplot-point-label {
|
||||
font-size: 0.75em;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
td.jqplot-cursor-legend-swatch {
|
||||
vertical-align: middle;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.jqplot-cursor-legend-swatch {
|
||||
width: 1.2em;
|
||||
height: 0.7em;
|
||||
}
|
||||
|
||||
.jqplot-error {
|
||||
/* Styles added to the plot target container when there is an error go here.*/
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.jqplot-error-message {
|
||||
/* Styling of the custom error message div goes here.*/
|
||||
position: relative;
|
||||
top: 46%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
div.jqplot-bubble-label {
|
||||
font-size: 0.8em;
|
||||
/* background: rgba(90%, 90%, 90%, 0.15);*/
|
||||
padding-left: 2px;
|
||||
padding-right: 2px;
|
||||
color: rgb(20%, 20%, 20%);
|
||||
}
|
||||
|
||||
div.jqplot-bubble-label.jqplot-bubble-label-highlight {
|
||||
background: rgba(90%, 90%, 90%, 0.7);
|
||||
}
|
||||
|
||||
div.jqplot-noData-container {
|
||||
text-align: center;
|
||||
background-color: rgba(96%, 96%, 96%, 0.3);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
1
src/html/jqplot/jquery.jqplot.min.css
vendored
1
src/html/jqplot/jquery.jqplot.min.css
vendored
@ -1 +0,0 @@
|
||||
.jqplot-target{position:relative;color:#666;font-family:"Trebuchet MS",Arial,Helvetica,sans-serif;font-size:1em;}.jqplot-axis{font-size:.75em;}.jqplot-xaxis{margin-top:10px;}.jqplot-x2axis{margin-bottom:10px;}.jqplot-yaxis{margin-right:10px;}.jqplot-y2axis,.jqplot-y3axis,.jqplot-y4axis,.jqplot-y5axis,.jqplot-y6axis,.jqplot-y7axis,.jqplot-y8axis,.jqplot-y9axis,.jqplot-yMidAxis{margin-left:10px;margin-right:10px;}.jqplot-axis-tick,.jqplot-xaxis-tick,.jqplot-yaxis-tick,.jqplot-x2axis-tick,.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick,.jqplot-yMidAxis-tick{position:absolute;white-space:pre;}.jqplot-xaxis-tick{top:0;left:15px;vertical-align:top;}.jqplot-x2axis-tick{bottom:0;left:15px;vertical-align:bottom;}.jqplot-yaxis-tick{right:0;top:15px;text-align:right;}.jqplot-yaxis-tick.jqplot-breakTick{right:-20px;margin-right:0;padding:1px 5px 1px 5px;z-index:2;font-size:1.5em;}.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick{left:0;top:15px;text-align:left;}.jqplot-yMidAxis-tick{text-align:center;white-space:nowrap;}.jqplot-xaxis-label{margin-top:10px;font-size:11pt;position:absolute;}.jqplot-x2axis-label{margin-bottom:10px;font-size:11pt;position:absolute;}.jqplot-yaxis-label{margin-right:10px;font-size:11pt;position:absolute;}.jqplot-yMidAxis-label{font-size:11pt;position:absolute;}.jqplot-y2axis-label,.jqplot-y3axis-label,.jqplot-y4axis-label,.jqplot-y5axis-label,.jqplot-y6axis-label,.jqplot-y7axis-label,.jqplot-y8axis-label,.jqplot-y9axis-label{font-size:11pt;margin-left:10px;position:absolute;}.jqplot-meterGauge-tick{font-size:.75em;color:#999;}.jqplot-meterGauge-label{font-size:1em;color:#999;}table.jqplot-table-legend{margin-top:12px;margin-bottom:12px;margin-left:12px;margin-right:12px;}table.jqplot-table-legend,table.jqplot-cursor-legend{background-color:rgba(255,255,255,0.6);border:1px solid #ccc;position:absolute;font-size:.75em;}td.jqplot-table-legend{vertical-align:middle;}td.jqplot-seriesToggle:hover,td.jqplot-seriesToggle:active{cursor:pointer;}.jqplot-table-legend .jqplot-series-hidden{text-decoration:line-through;}div.jqplot-table-legend-swatch-outline{border:1px solid #ccc;padding:1px;}div.jqplot-table-legend-swatch{width:0;height:0;border-top-width:5px;border-bottom-width:5px;border-left-width:6px;border-right-width:6px;border-top-style:solid;border-bottom-style:solid;border-left-style:solid;border-right-style:solid;}.jqplot-title{top:0;left:0;padding-bottom:.5em;font-size:1.2em;}table.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em;}.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px;}.jqplot-highlighter-tooltip,.jqplot-canvasOverlay-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px;}.jqplot-point-label{font-size:.75em;z-index:2;}td.jqplot-cursor-legend-swatch{vertical-align:middle;text-align:center;}div.jqplot-cursor-legend-swatch{width:1.2em;height:.7em;}.jqplot-error{text-align:center;}.jqplot-error-message{position:relative;top:46%;display:inline-block;}div.jqplot-bubble-label{font-size:.8em;padding-left:2px;padding-right:2px;color:rgb(20%,20%,20%);}div.jqplot-bubble-label.jqplot-bubble-label-highlight{background:rgba(90%,90%,90%,0.7);}div.jqplot-noData-container{text-align:center;background-color:rgba(96%,96%,96%,0.3);}
|
57
src/html/jqplot/jquery.jqplot.min.js
vendored
57
src/html/jqplot/jquery.jqplot.min.js
vendored
File diff suppressed because one or more lines are too long
9046
src/html/jqplot/jquery.js
vendored
9046
src/html/jqplot/jquery.js
vendored
File diff suppressed because it is too large
Load Diff
4
src/html/jqplot/jquery.min.js
vendored
4
src/html/jqplot/jquery.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,313 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
// Class: $.jqplot.BezierCurveRenderer.js
|
||||
// Renderer which draws lines as stacked bezier curves.
|
||||
// Data for the line will not be specified as an array of
|
||||
// [x, y] data point values, but as a an array of [start piont, bezier curve]
|
||||
// So, the line is specified as: [[xstart, ystart], [cp1x, cp1y, cp2x, cp2y, xend, yend]].
|
||||
$.jqplot.BezierCurveRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.BezierCurveRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.BezierCurveRenderer.prototype.constructor = $.jqplot.BezierCurveRenderer;
|
||||
|
||||
|
||||
// Method: setGridData
|
||||
// converts the user data values to grid coordinates and stores them
|
||||
// in the gridData array.
|
||||
// Called with scope of a series.
|
||||
$.jqplot.BezierCurveRenderer.prototype.setGridData = function(plot) {
|
||||
// recalculate the grid data
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
// this._plotData should be same as this.data
|
||||
var data = this.data;
|
||||
this.gridData = [];
|
||||
this._prevGridData = [];
|
||||
// if seriesIndex = 0, fill to x axis.
|
||||
// if seriesIndex > 0, fill to previous series data.
|
||||
var idx = this.index;
|
||||
if (data.length == 2) {
|
||||
if (idx == 0) {
|
||||
this.gridData = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
|
||||
xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
|
||||
[xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, this._yaxis.min)],
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
|
||||
];
|
||||
}
|
||||
else {
|
||||
var psd = plot.series[idx-1].data;
|
||||
this.gridData = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
|
||||
xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
|
||||
[xp.call(this._xaxis, psd[1][4]), yp.call(this._yaxis, psd[1][5])],
|
||||
[xp.call(this._xaxis, psd[1][2]), yp.call(this._yaxis, psd[1][3]),
|
||||
xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
|
||||
xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (idx == 0) {
|
||||
this.gridData = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
|
||||
xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
|
||||
[xp.call(this._xaxis, data[3][1]), yp.call(this._yaxis, this._yaxis.min)],
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
|
||||
];
|
||||
}
|
||||
else {
|
||||
var psd = plot.series[idx-1].data;
|
||||
this.gridData = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
|
||||
xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
|
||||
[xp.call(this._xaxis, psd[3][0]), yp.call(this._yaxis, psd[3][1])],
|
||||
[xp.call(this._xaxis, psd[2][0]), yp.call(this._yaxis, psd[2][1]),
|
||||
xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
|
||||
xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
|
||||
];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Method: makeGridData
|
||||
// converts any arbitrary data values to grid coordinates and
|
||||
// returns them. This method exists so that plugins can use a series'
|
||||
// linerenderer to generate grid data points without overwriting the
|
||||
// grid data associated with that series.
|
||||
// Called with scope of a series.
|
||||
$.jqplot.BezierCurveRenderer.prototype.makeGridData = function(data, plot) {
|
||||
// recalculate the grid data
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var gd = [];
|
||||
var pgd = [];
|
||||
// if seriesIndex = 0, fill to x axis.
|
||||
// if seriesIndex > 0, fill to previous series data.
|
||||
var idx = this.index;
|
||||
if (data.length == 2) {
|
||||
if (idx == 0) {
|
||||
gd = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
|
||||
xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
|
||||
[xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, this._yaxis.min)],
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
|
||||
];
|
||||
}
|
||||
else {
|
||||
var psd = plot.series[idx-1].data;
|
||||
gd = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
|
||||
xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
|
||||
[xp.call(this._xaxis, psd[1][4]), yp.call(this._yaxis, psd[1][5])],
|
||||
[xp.call(this._xaxis, psd[1][2]), yp.call(this._yaxis, psd[1][3]),
|
||||
xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
|
||||
xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (idx == 0) {
|
||||
gd = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
|
||||
xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
|
||||
[xp.call(this._xaxis, data[3][1]), yp.call(this._yaxis, this._yaxis.min)],
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
|
||||
];
|
||||
}
|
||||
else {
|
||||
var psd = plot.series[idx-1].data;
|
||||
gd = [
|
||||
[xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
|
||||
[xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
|
||||
xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
|
||||
xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
|
||||
[xp.call(this._xaxis, psd[3][0]), yp.call(this._yaxis, psd[3][1])],
|
||||
[xp.call(this._xaxis, psd[2][0]), yp.call(this._yaxis, psd[2][1]),
|
||||
xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
|
||||
xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
|
||||
];
|
||||
}
|
||||
}
|
||||
return gd;
|
||||
};
|
||||
|
||||
|
||||
// called within scope of series.
|
||||
$.jqplot.BezierCurveRenderer.prototype.draw = function(ctx, gd, options) {
|
||||
var i;
|
||||
ctx.save();
|
||||
if (gd.length) {
|
||||
if (this.showLine) {
|
||||
ctx.save();
|
||||
var opts = (options != null) ? options : {};
|
||||
ctx.fillStyle = opts.fillStyle || this.color;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(gd[0][0], gd[0][1]);
|
||||
ctx.bezierCurveTo(gd[1][0], gd[1][1], gd[1][2], gd[1][3], gd[1][4], gd[1][5]);
|
||||
ctx.lineTo(gd[2][0], gd[2][1]);
|
||||
if (gd[3].length == 2) {
|
||||
ctx.lineTo(gd[3][0], gd[3][1]);
|
||||
}
|
||||
else {
|
||||
ctx.bezierCurveTo(gd[3][0], gd[3][1], gd[3][2], gd[3][3], gd[3][4], gd[3][5]);
|
||||
}
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
$.jqplot.BezierCurveRenderer.prototype.drawShadow = function(ctx, gd, options) {
|
||||
// This is a no-op, shadows drawn with lines.
|
||||
};
|
||||
|
||||
$.jqplot.BezierAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.BezierAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.BezierAxisRenderer.prototype.constructor = $.jqplot.BezierAxisRenderer;
|
||||
|
||||
|
||||
// Axes on a plot with Bezier Curves
|
||||
$.jqplot.BezierAxisRenderer.prototype.init = function(options){
|
||||
$.extend(true, this, options);
|
||||
var db = this._dataBounds;
|
||||
// Go through all the series attached to this axis and find
|
||||
// the min/max bounds for this axis.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
var d = s.data;
|
||||
if (d.length == 4) {
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
if (d[j][0] < db.min || db.min == null) {
|
||||
db.min = d[j][0];
|
||||
}
|
||||
if (d[j][0] > db.max || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (d[j][1] < db.min || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
}
|
||||
if (d[j][1] > db.max || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
if (d[0][0] < db.min || db.min == null) {
|
||||
db.min = d[0][0];
|
||||
}
|
||||
if (d[0][0] > db.max || db.max == null) {
|
||||
db.max = d[0][0];
|
||||
}
|
||||
for (var j=0; j<5; j+=2) {
|
||||
if (d[1][j] < db.min || db.min == null) {
|
||||
db.min = d[1][j];
|
||||
}
|
||||
if (d[1][j] > db.max || db.max == null) {
|
||||
db.max = d[1][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (d[0][1] < db.min || db.min == null) {
|
||||
db.min = d[0][1];
|
||||
}
|
||||
if (d[0][1] > db.max || db.max == null) {
|
||||
db.max = d[0][1];
|
||||
}
|
||||
for (var j=1; j<6; j+=2) {
|
||||
if (d[1][j] < db.min || db.min == null) {
|
||||
db.min = d[1][j];
|
||||
}
|
||||
if (d[1][j] > db.max || db.max == null) {
|
||||
db.max = d[1][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// setup default renderers for axes and legend so user doesn't have to
|
||||
// called with scope of plot
|
||||
function preInit(target, data, options) {
|
||||
options = options || {};
|
||||
options.axesDefaults = $.extend(true, {pad:0}, options.axesDefaults);
|
||||
options.legend = $.extend(true, {placement:'outside'}, options.legend);
|
||||
// only set these if there is a pie series
|
||||
var setopts = false;
|
||||
if (options.seriesDefaults.renderer == $.jqplot.BezierCurveRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
else if (options.series) {
|
||||
for (var i=0; i < options.series.length; i++) {
|
||||
if (options.series[i].renderer == $.jqplot.BezierCurveRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setopts) {
|
||||
options.axesDefaults.renderer = $.jqplot.BezierAxisRenderer;
|
||||
}
|
||||
}
|
||||
|
||||
$.jqplot.preInitHooks.push(preInit);
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -1,797 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
// Class: $.jqplot.BarRenderer
|
||||
// A plugin renderer for jqPlot to draw a bar plot.
|
||||
// Draws series as a line.
|
||||
|
||||
$.jqplot.BarRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.BarRenderer.prototype.constructor = $.jqplot.BarRenderer;
|
||||
|
||||
// called with scope of series.
|
||||
$.jqplot.BarRenderer.prototype.init = function(options, plot) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: barPadding
|
||||
// Number of pixels between adjacent bars at the same axis value.
|
||||
this.barPadding = 8;
|
||||
// prop: barMargin
|
||||
// Number of pixels between groups of bars at adjacent axis values.
|
||||
this.barMargin = 10;
|
||||
// prop: barDirection
|
||||
// 'vertical' = up and down bars, 'horizontal' = side to side bars
|
||||
this.barDirection = 'vertical';
|
||||
// prop: barWidth
|
||||
// Width of the bar in pixels (auto by devaul). null = calculated automatically.
|
||||
this.barWidth = null;
|
||||
// prop: shadowOffset
|
||||
// offset of the shadow from the slice and offset of
|
||||
// each succesive stroke of the shadow from the last.
|
||||
this.shadowOffset = 2;
|
||||
// prop: shadowDepth
|
||||
// number of strokes to apply to the shadow,
|
||||
// each stroke offset shadowOffset from the last.
|
||||
this.shadowDepth = 5;
|
||||
// prop: shadowAlpha
|
||||
// transparency of the shadow (0 = transparent, 1 = opaque)
|
||||
this.shadowAlpha = 0.08;
|
||||
// prop: waterfall
|
||||
// true to enable waterfall plot.
|
||||
this.waterfall = false;
|
||||
// prop: groups
|
||||
// group bars into this many groups
|
||||
this.groups = 1;
|
||||
// prop: varyBarColor
|
||||
// true to color each bar of a series separately rather than
|
||||
// have every bar of a given series the same color.
|
||||
// If used for non-stacked multiple series bar plots, user should
|
||||
// specify a separate 'seriesColors' array for each series.
|
||||
// Otherwise, each series will set their bars to the same color array.
|
||||
// This option has no Effect for stacked bar charts and is disabled.
|
||||
this.varyBarColor = false;
|
||||
// prop: highlightMouseOver
|
||||
// True to highlight slice when moused over.
|
||||
// This must be false to enable highlightMouseDown to highlight when clicking on a slice.
|
||||
this.highlightMouseOver = true;
|
||||
// prop: highlightMouseDown
|
||||
// True to highlight when a mouse button is pressed over a slice.
|
||||
// This will be disabled if highlightMouseOver is true.
|
||||
this.highlightMouseDown = false;
|
||||
// prop: highlightColors
|
||||
// an array of colors to use when highlighting a bar.
|
||||
this.highlightColors = [];
|
||||
// prop: transposedData
|
||||
// NOT IMPLEMENTED YET. True if this is a horizontal bar plot and
|
||||
// x and y values are "transposed". Tranposed, or "swapped", data is
|
||||
// required prior to rev. 894 builds of jqPlot with horizontal bars.
|
||||
// Allows backward compatability of bar renderer horizontal bars with
|
||||
// old style data sets.
|
||||
this.transposedData = true;
|
||||
this.renderer.animation = {
|
||||
show: false,
|
||||
direction: 'down',
|
||||
speed: 3000,
|
||||
_supported: true
|
||||
};
|
||||
this._type = 'bar';
|
||||
|
||||
// if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
|
||||
if (options.highlightMouseDown && options.highlightMouseOver == null) {
|
||||
options.highlightMouseOver = false;
|
||||
}
|
||||
|
||||
//////
|
||||
// This is probably wrong here.
|
||||
// After going back and forth on wether renderer should be the thing
|
||||
// or extend the thing, it seems that it it best if it is a property
|
||||
// on the thing. This should be something that is commonized
|
||||
// among series renderers in the future.
|
||||
//////
|
||||
$.extend(true, this, options);
|
||||
|
||||
// really should probably do this
|
||||
$.extend(true, this.renderer, options);
|
||||
// fill is still needed to properly draw the legend.
|
||||
// bars have to be filled.
|
||||
this.fill = true;
|
||||
|
||||
// if horizontal bar and animating, reset the default direction
|
||||
if (this.barDirection === 'horizontal' && this.rendererOptions.animation && this.rendererOptions.animation.direction == null) {
|
||||
this.renderer.animation.direction = 'left';
|
||||
}
|
||||
|
||||
if (this.waterfall) {
|
||||
this.fillToZero = false;
|
||||
this.disableStack = true;
|
||||
}
|
||||
|
||||
if (this.barDirection == 'vertical' ) {
|
||||
this._primaryAxis = '_xaxis';
|
||||
this._stackAxis = 'y';
|
||||
this.fillAxis = 'y';
|
||||
}
|
||||
else {
|
||||
this._primaryAxis = '_yaxis';
|
||||
this._stackAxis = 'x';
|
||||
this.fillAxis = 'x';
|
||||
}
|
||||
// index of the currenty highlighted point, if any
|
||||
this._highlightedPoint = null;
|
||||
// total number of values for all bar series, total number of bar series, and position of this series
|
||||
this._plotSeriesInfo = null;
|
||||
// Array of actual data colors used for each data point.
|
||||
this._dataColors = [];
|
||||
this._barPoints = [];
|
||||
|
||||
// set the shape renderer options
|
||||
var opts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, strokeStyle:this.color, fillStyle:this.color, closePath:this.fill};
|
||||
this.renderer.shapeRenderer.init(opts);
|
||||
// set the shadow renderer options
|
||||
var sopts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, closePath:this.fill};
|
||||
this.renderer.shadowRenderer.init(sopts);
|
||||
|
||||
plot.postInitHooks.addOnce(postInit);
|
||||
plot.postDrawHooks.addOnce(postPlotDraw);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
|
||||
plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
|
||||
plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
function barPreInit(target, data, seriesDefaults, options) {
|
||||
if (this.rendererOptions.barDirection == 'horizontal') {
|
||||
this._stackAxis = 'x';
|
||||
this._primaryAxis = '_yaxis';
|
||||
}
|
||||
if (this.rendererOptions.waterfall == true) {
|
||||
this._data = $.extend(true, [], this.data);
|
||||
var sum = 0;
|
||||
var pos = (!this.rendererOptions.barDirection || this.rendererOptions.barDirection === 'vertical' || this.transposedData === false) ? 1 : 0;
|
||||
for(var i=0; i<this.data.length; i++) {
|
||||
sum += this.data[i][pos];
|
||||
if (i>0) {
|
||||
this.data[i][pos] += this.data[i-1][pos];
|
||||
}
|
||||
}
|
||||
this.data[this.data.length] = (pos == 1) ? [this.data.length+1, sum] : [sum, this.data.length+1];
|
||||
this._data[this._data.length] = (pos == 1) ? [this._data.length+1, sum] : [sum, this._data.length+1];
|
||||
}
|
||||
if (this.rendererOptions.groups > 1) {
|
||||
this.breakOnNull = true;
|
||||
var l = this.data.length;
|
||||
var skip = parseInt(l/this.rendererOptions.groups, 10);
|
||||
var count = 0;
|
||||
for (var i=skip; i<l; i+=skip) {
|
||||
this.data.splice(i+count, 0, [null, null]);
|
||||
this._plotData.splice(i+count, 0, [null, null]);
|
||||
this._stackData.splice(i+count, 0, [null, null]);
|
||||
count++;
|
||||
}
|
||||
for (i=0; i<this.data.length; i++) {
|
||||
if (this._primaryAxis == '_xaxis') {
|
||||
this.data[i][0] = i+1;
|
||||
this._plotData[i][0] = i+1;
|
||||
this._stackData[i][0] = i+1;
|
||||
}
|
||||
else {
|
||||
this.data[i][1] = i+1;
|
||||
this._plotData[i][1] = i+1;
|
||||
this._stackData[i][1] = i+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.jqplot.preSeriesInitHooks.push(barPreInit);
|
||||
|
||||
// needs to be called with scope of series, not renderer.
|
||||
$.jqplot.BarRenderer.prototype.calcSeriesNumbers = function() {
|
||||
var nvals = 0;
|
||||
var nseries = 0;
|
||||
var paxis = this[this._primaryAxis];
|
||||
var s, series, pos;
|
||||
// loop through all series on this axis
|
||||
for (var i=0; i < paxis._series.length; i++) {
|
||||
series = paxis._series[i];
|
||||
if (series === this) {
|
||||
pos = i;
|
||||
}
|
||||
// is the series rendered as a bar?
|
||||
if (series.renderer.constructor == $.jqplot.BarRenderer) {
|
||||
// gridData may not be computed yet, use data length insted
|
||||
nvals += series.data.length;
|
||||
nseries += 1;
|
||||
}
|
||||
}
|
||||
// return total number of values for all bar series, total number of bar series, and position of this series
|
||||
return [nvals, nseries, pos];
|
||||
};
|
||||
|
||||
$.jqplot.BarRenderer.prototype.setBarWidth = function() {
|
||||
// need to know how many data values we have on the approprate axis and figure it out.
|
||||
var i;
|
||||
var nvals = 0;
|
||||
var nseries = 0;
|
||||
var paxis = this[this._primaryAxis];
|
||||
var s, series, pos;
|
||||
var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
|
||||
nvals = temp[0];
|
||||
nseries = temp[1];
|
||||
var nticks = paxis.numberTicks;
|
||||
var nbins = (nticks-1)/2;
|
||||
// so, now we have total number of axis values.
|
||||
if (paxis.name == 'xaxis' || paxis.name == 'x2axis') {
|
||||
if (this._stack) {
|
||||
this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals * nseries - this.barMargin;
|
||||
}
|
||||
else {
|
||||
this.barWidth = ((paxis._offsets.max - paxis._offsets.min)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
|
||||
// this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding - this.barMargin/nseries;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this._stack) {
|
||||
this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals * nseries - this.barMargin;
|
||||
}
|
||||
else {
|
||||
this.barWidth = ((paxis._offsets.min - paxis._offsets.max)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
|
||||
// this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding - this.barMargin/nseries;
|
||||
}
|
||||
}
|
||||
return [nvals, nseries];
|
||||
};
|
||||
|
||||
function computeHighlightColors (colors) {
|
||||
var ret = [];
|
||||
for (var i=0; i<colors.length; i++){
|
||||
var rgba = $.jqplot.getColorComponents(colors[i]);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var sum = newrgb[0] + newrgb[1] + newrgb[2];
|
||||
for (var j=0; j<3; j++) {
|
||||
// when darkening, lowest color component can be is 60.
|
||||
newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
|
||||
newrgb[j] = parseInt(newrgb[j], 10);
|
||||
}
|
||||
ret.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getStart(sidx, didx, comp, plot, axis) {
|
||||
// check if sign change
|
||||
var seriesIndex = sidx,
|
||||
prevSeriesIndex = sidx - 1,
|
||||
start,
|
||||
prevVal,
|
||||
aidx = (axis === 'x') ? 0 : 1;
|
||||
|
||||
// is this not the first series?
|
||||
if (seriesIndex > 0) {
|
||||
prevVal = plot.series[prevSeriesIndex]._plotData[didx][aidx];
|
||||
|
||||
// is there a sign change
|
||||
if ((comp * prevVal) < 0) {
|
||||
start = getStart(prevSeriesIndex, didx, comp, plot, axis);
|
||||
}
|
||||
|
||||
// no sign change.
|
||||
else {
|
||||
start = plot.series[prevSeriesIndex].gridData[didx][aidx];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if first series, return value at 0
|
||||
else {
|
||||
|
||||
start = (aidx === 0) ? plot.series[seriesIndex]._xaxis.series_u2p(0) : plot.series[seriesIndex]._yaxis.series_u2p(0);
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
|
||||
$.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options, plot) {
|
||||
var i;
|
||||
// Ughhh, have to make a copy of options b/c it may be modified later.
|
||||
var opts = $.extend({}, options);
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var xaxis = this.xaxis;
|
||||
var yaxis = this.yaxis;
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var pointx, pointy;
|
||||
// clear out data colors.
|
||||
this._dataColors = [];
|
||||
this._barPoints = [];
|
||||
|
||||
if (this.barWidth == null) {
|
||||
this.renderer.setBarWidth.call(this);
|
||||
}
|
||||
|
||||
var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
|
||||
var nvals = temp[0];
|
||||
var nseries = temp[1];
|
||||
var pos = temp[2];
|
||||
var points = [];
|
||||
|
||||
if (this._stack) {
|
||||
this._barNudge = 0;
|
||||
}
|
||||
else {
|
||||
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
|
||||
}
|
||||
if (showLine) {
|
||||
var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
|
||||
var positiveColors = new $.jqplot.ColorGenerator(this.seriesColors);
|
||||
var negativeColor = negativeColors.get(this.index);
|
||||
if (! this.useNegativeColors) {
|
||||
negativeColor = opts.fillStyle;
|
||||
}
|
||||
var positiveColor = opts.fillStyle;
|
||||
var base;
|
||||
var xstart;
|
||||
var ystart;
|
||||
|
||||
if (this.barDirection == 'vertical') {
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
if (!this._stack && this.data[i][1] == null) {
|
||||
continue;
|
||||
}
|
||||
points = [];
|
||||
base = gridData[i][0] + this._barNudge;
|
||||
|
||||
// stacked
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
ystart = getStart(this.index, i, this._plotData[i][1], plot, 'y');
|
||||
}
|
||||
|
||||
// not stacked
|
||||
else {
|
||||
if (this.fillToZero) {
|
||||
ystart = this._yaxis.series_u2p(0);
|
||||
}
|
||||
else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
|
||||
ystart = this.gridData[i-1][1];
|
||||
}
|
||||
else if (this.waterfall && i == 0 && i < this.gridData.length-1) {
|
||||
if (this._yaxis.min <= 0 && this._yaxis.max >= 0) {
|
||||
ystart = this._yaxis.series_u2p(0);
|
||||
}
|
||||
else if (this._yaxis.min > 0) {
|
||||
ystart = ctx.canvas.height;
|
||||
}
|
||||
else {
|
||||
ystart = 0;
|
||||
}
|
||||
}
|
||||
else if (this.waterfall && i == this.gridData.length - 1) {
|
||||
if (this._yaxis.min <= 0 && this._yaxis.max >= 0) {
|
||||
ystart = this._yaxis.series_u2p(0);
|
||||
}
|
||||
else if (this._yaxis.min > 0) {
|
||||
ystart = ctx.canvas.height;
|
||||
}
|
||||
else {
|
||||
ystart = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ystart = ctx.canvas.height;
|
||||
}
|
||||
}
|
||||
if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
|
||||
if (this.varyBarColor && !this._stack) {
|
||||
if (this.useNegativeColors) {
|
||||
opts.fillStyle = negativeColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = negativeColor;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.varyBarColor && !this._stack) {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.fillToZero || this._plotData[i][1] >= 0) {
|
||||
points.push([base-this.barWidth/2, ystart]);
|
||||
points.push([base-this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, ystart]);
|
||||
}
|
||||
// for negative bars make sure points are always ordered clockwise
|
||||
else {
|
||||
points.push([base-this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base-this.barWidth/2, ystart]);
|
||||
points.push([base+this.barWidth/2, ystart]);
|
||||
points.push([base+this.barWidth/2, gridData[i][1]]);
|
||||
}
|
||||
this._barPoints.push(points);
|
||||
// now draw the shadows if not stacked.
|
||||
// for stacked plots, they are predrawn by drawShadow
|
||||
if (shadow && !this._stack) {
|
||||
var sopts = $.extend(true, {}, opts);
|
||||
// need to get rid of fillStyle on shadow.
|
||||
delete sopts.fillStyle;
|
||||
this.renderer.shadowRenderer.draw(ctx, points, sopts);
|
||||
}
|
||||
var clr = opts.fillStyle || this.color;
|
||||
this._dataColors.push(clr);
|
||||
this.renderer.shapeRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.barDirection == 'horizontal'){
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
if (!this._stack && this.data[i][0] == null) {
|
||||
continue;
|
||||
}
|
||||
points = [];
|
||||
base = gridData[i][1] - this._barNudge;
|
||||
xstart;
|
||||
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
xstart = getStart(this.index, i, this._plotData[i][0], plot, 'x');
|
||||
}
|
||||
// not stacked
|
||||
else {
|
||||
if (this.fillToZero) {
|
||||
xstart = this._xaxis.series_u2p(0);
|
||||
}
|
||||
else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
|
||||
xstart = this.gridData[i-1][0];
|
||||
}
|
||||
else if (this.waterfall && i == 0 && i < this.gridData.length-1) {
|
||||
if (this._xaxis.min <= 0 && this._xaxis.max >= 0) {
|
||||
xstart = this._xaxis.series_u2p(0);
|
||||
}
|
||||
else if (this._xaxis.min > 0) {
|
||||
xstart = 0;
|
||||
}
|
||||
else {
|
||||
xstart = 0;
|
||||
}
|
||||
}
|
||||
else if (this.waterfall && i == this.gridData.length - 1) {
|
||||
if (this._xaxis.min <= 0 && this._xaxis.max >= 0) {
|
||||
xstart = this._xaxis.series_u2p(0);
|
||||
}
|
||||
else if (this._xaxis.min > 0) {
|
||||
xstart = 0;
|
||||
}
|
||||
else {
|
||||
xstart = ctx.canvas.width;
|
||||
}
|
||||
}
|
||||
else {
|
||||
xstart = 0;
|
||||
}
|
||||
}
|
||||
if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
|
||||
if (this.varyBarColor && !this._stack) {
|
||||
if (this.useNegativeColors) {
|
||||
opts.fillStyle = negativeColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.varyBarColor && !this._stack) {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!this.fillToZero || this._plotData[i][0] >= 0) {
|
||||
points.push([xstart, base + this.barWidth / 2]);
|
||||
points.push([xstart, base - this.barWidth / 2]);
|
||||
points.push([gridData[i][0], base - this.barWidth / 2]);
|
||||
points.push([gridData[i][0], base + this.barWidth / 2]);
|
||||
}
|
||||
else {
|
||||
points.push([gridData[i][0], base + this.barWidth / 2]);
|
||||
points.push([gridData[i][0], base - this.barWidth / 2]);
|
||||
points.push([xstart, base - this.barWidth / 2]);
|
||||
points.push([xstart, base + this.barWidth / 2]);
|
||||
}
|
||||
|
||||
this._barPoints.push(points);
|
||||
// now draw the shadows if not stacked.
|
||||
// for stacked plots, they are predrawn by drawShadow
|
||||
if (shadow && !this._stack) {
|
||||
var sopts = $.extend(true, {}, opts);
|
||||
delete sopts.fillStyle;
|
||||
this.renderer.shadowRenderer.draw(ctx, points, sopts);
|
||||
}
|
||||
var clr = opts.fillStyle || this.color;
|
||||
this._dataColors.push(clr);
|
||||
this.renderer.shapeRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.highlightColors.length == 0) {
|
||||
this.highlightColors = $.jqplot.computeHighlightColors(this._dataColors);
|
||||
}
|
||||
|
||||
else if (typeof(this.highlightColors) == 'string') {
|
||||
var temp = this.highlightColors;
|
||||
this.highlightColors = [];
|
||||
for (var i=0; i<this._dataColors.length; i++) {
|
||||
this.highlightColors.push(temp);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// for stacked plots, shadows will be pre drawn by drawShadow.
|
||||
$.jqplot.BarRenderer.prototype.drawShadow = function(ctx, gridData, options, plot) {
|
||||
var i;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var xaxis = this.xaxis;
|
||||
var yaxis = this.yaxis;
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var pointx, points, pointy, nvals, nseries, pos;
|
||||
|
||||
if (this._stack && this.shadow) {
|
||||
if (this.barWidth == null) {
|
||||
this.renderer.setBarWidth.call(this);
|
||||
}
|
||||
|
||||
var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
|
||||
nvals = temp[0];
|
||||
nseries = temp[1];
|
||||
pos = temp[2];
|
||||
|
||||
if (this._stack) {
|
||||
this._barNudge = 0;
|
||||
}
|
||||
else {
|
||||
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
|
||||
}
|
||||
if (showLine) {
|
||||
|
||||
if (this.barDirection == 'vertical') {
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
if (this.data[i][1] == null) {
|
||||
continue;
|
||||
}
|
||||
points = [];
|
||||
var base = gridData[i][0] + this._barNudge;
|
||||
var ystart;
|
||||
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
ystart = getStart(this.index, i, this._plotData[i][1], plot, 'y');
|
||||
}
|
||||
else {
|
||||
if (this.fillToZero) {
|
||||
ystart = this._yaxis.series_u2p(0);
|
||||
}
|
||||
else {
|
||||
ystart = ctx.canvas.height;
|
||||
}
|
||||
}
|
||||
|
||||
points.push([base-this.barWidth/2, ystart]);
|
||||
points.push([base-this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, ystart]);
|
||||
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.barDirection == 'horizontal'){
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
if (this.data[i][0] == null) {
|
||||
continue;
|
||||
}
|
||||
points = [];
|
||||
var base = gridData[i][1] - this._barNudge;
|
||||
var xstart;
|
||||
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
xstart = getStart(this.index, i, this._plotData[i][0], plot, 'x');
|
||||
}
|
||||
else {
|
||||
if (this.fillToZero) {
|
||||
xstart = this._xaxis.series_u2p(0);
|
||||
}
|
||||
else {
|
||||
xstart = 0;
|
||||
}
|
||||
}
|
||||
|
||||
points.push([xstart, base+this.barWidth/2]);
|
||||
points.push([gridData[i][0], base+this.barWidth/2]);
|
||||
points.push([gridData[i][0], base-this.barWidth/2]);
|
||||
points.push([xstart, base-this.barWidth/2]);
|
||||
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
function postInit(target, data, options) {
|
||||
for (var i=0; i<this.series.length; i++) {
|
||||
if (this.series[i].renderer.constructor == $.jqplot.BarRenderer) {
|
||||
// don't allow mouseover and mousedown at same time.
|
||||
if (this.series[i].highlightMouseOver) {
|
||||
this.series[i].highlightMouseDown = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
function postPlotDraw() {
|
||||
// Memory Leaks patch
|
||||
if (this.plugins.barRenderer && this.plugins.barRenderer.highlightCanvas) {
|
||||
|
||||
this.plugins.barRenderer.highlightCanvas.resetCanvas();
|
||||
this.plugins.barRenderer.highlightCanvas = null;
|
||||
}
|
||||
|
||||
this.plugins.barRenderer = {highlightedSeriesIndex:null};
|
||||
this.plugins.barRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
|
||||
|
||||
this.eventCanvas._elem.before(this.plugins.barRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-barRenderer-highlight-canvas', this._plotDimensions, this));
|
||||
this.plugins.barRenderer.highlightCanvas.setContext();
|
||||
this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
|
||||
}
|
||||
|
||||
function highlight (plot, sidx, pidx, points) {
|
||||
var s = plot.series[sidx];
|
||||
var canvas = plot.plugins.barRenderer.highlightCanvas;
|
||||
canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
|
||||
s._highlightedPoint = pidx;
|
||||
plot.plugins.barRenderer.highlightedSeriesIndex = sidx;
|
||||
var opts = {fillStyle: s.highlightColors[pidx]};
|
||||
s.renderer.shapeRenderer.draw(canvas._ctx, points, opts);
|
||||
canvas = null;
|
||||
}
|
||||
|
||||
function unhighlight (plot) {
|
||||
var canvas = plot.plugins.barRenderer.highlightCanvas;
|
||||
canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
|
||||
for (var i=0; i<plot.series.length; i++) {
|
||||
plot.series[i]._highlightedPoint = null;
|
||||
}
|
||||
plot.plugins.barRenderer.highlightedSeriesIndex = null;
|
||||
plot.target.trigger('jqplotDataUnhighlight');
|
||||
canvas = null;
|
||||
}
|
||||
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var evt1 = jQuery.Event('jqplotDataMouseOver');
|
||||
evt1.pageX = ev.pageX;
|
||||
evt1.pageY = ev.pageY;
|
||||
plot.target.trigger(evt1, ins);
|
||||
if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
|
||||
var idx = plot.plugins.barRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var evt = jQuery.Event('jqplotDataClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var idx = plot.plugins.barRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
var evt = jQuery.Event('jqplotDataRightClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -1,235 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.BlockRenderer
|
||||
* Plugin renderer to draw a x-y block chart. A Block chart has data points displayed as
|
||||
* colored squares with a text label inside. Data must be supplied in the form:
|
||||
*
|
||||
* > [[x1, y1, "label 1", {css}], [x2, y2, "label 2", {css}], ...]
|
||||
*
|
||||
* The label and css object are optional. If the label is ommitted, the
|
||||
* box will collapse unless a css height and/or width is specified.
|
||||
*
|
||||
* The css object is an object specifying css properties
|
||||
* such as:
|
||||
*
|
||||
* > {background:'#4f98a5', border:'3px solid gray', padding:'1px'}
|
||||
*
|
||||
* Note that css properties specified with the data point override defaults
|
||||
* specified with the series.
|
||||
*
|
||||
*/
|
||||
$.jqplot.BlockRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.BlockRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.BlockRenderer.prototype.constructor = $.jqplot.BlockRenderer;
|
||||
|
||||
// called with scope of a series
|
||||
$.jqplot.BlockRenderer.prototype.init = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: css
|
||||
// default css styles that will be applied to all data blocks.
|
||||
// these values will be overridden by css styles supplied with the
|
||||
// individulal data points.
|
||||
this.css = {padding:'2px', border:'1px solid #999', textAlign:'center'};
|
||||
// prop: escapeHtml
|
||||
// true to escape html in the box label.
|
||||
this.escapeHtml = false;
|
||||
// prop: insertBreaks
|
||||
// true to turn spaces in data block label into html breaks <br />.
|
||||
this.insertBreaks = true;
|
||||
// prop: varyBlockColors
|
||||
// true to vary the color of each block in this series according to
|
||||
// the seriesColors array. False to set each block to the color
|
||||
// specified on this series. This has no effect if a css background color
|
||||
// option is specified in the renderer css options.
|
||||
this.varyBlockColors = false;
|
||||
$.extend(true, this, options);
|
||||
if (this.css.backgroundColor) {
|
||||
this.color = this.css.backgroundColor;
|
||||
}
|
||||
else if (this.css.background) {
|
||||
this.color = this.css.background;
|
||||
}
|
||||
else if (!this.varyBlockColors) {
|
||||
this.css.background = this.color;
|
||||
}
|
||||
this.canvas = new $.jqplot.BlockCanvas();
|
||||
this.shadowCanvas = new $.jqplot.BlockCanvas();
|
||||
this.canvas._plotDimensions = this._plotDimensions;
|
||||
this.shadowCanvas._plotDimensions = this._plotDimensions;
|
||||
this._type = 'block';
|
||||
|
||||
// group: Methods
|
||||
//
|
||||
// Method: moveBlock
|
||||
// Moves an individual block. More efficient than redrawing
|
||||
// the whole series by calling plot.drawSeries().
|
||||
// Properties:
|
||||
// idx - the 0 based index of the block or point in this series.
|
||||
// x - the x coordinate in data units (value on x axis) to move the block to.
|
||||
// y - the y coordinate in data units (value on the y axis) to move the block to.
|
||||
// duration - optional parameter to create an animated movement. Can be a
|
||||
// number (higher is slower animation) or 'fast', 'normal' or 'slow'. If not
|
||||
// provided, the element is moved without any animation.
|
||||
this.moveBlock = function (idx, x, y, duration) {
|
||||
// update plotData, stackData, data and gridData
|
||||
// x and y are in data coordinates.
|
||||
var el = this.canvas._elem.children(':eq('+idx+')');
|
||||
this.data[idx][0] = x;
|
||||
this.data[idx][1] = y;
|
||||
this._plotData[idx][0] = x;
|
||||
this._plotData[idx][1] = y;
|
||||
this._stackData[idx][0] = x;
|
||||
this._stackData[idx][1] = y;
|
||||
this.gridData[idx][0] = this._xaxis.series_u2p(x);
|
||||
this.gridData[idx][1] = this._yaxis.series_u2p(y);
|
||||
var w = el.outerWidth();
|
||||
var h = el.outerHeight();
|
||||
var left = this.gridData[idx][0] - w/2 + 'px';
|
||||
var top = this.gridData[idx][1] - h/2 + 'px';
|
||||
if (duration) {
|
||||
if (parseInt(duration, 10)) {
|
||||
duration = parseInt(duration, 10);
|
||||
}
|
||||
el.animate({left:left, top:top}, duration);
|
||||
}
|
||||
else {
|
||||
el.css({left:left, top:top});
|
||||
}
|
||||
el = null;
|
||||
};
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
$.jqplot.BlockRenderer.prototype.draw = function (ctx, gd, options) {
|
||||
if (this.plugins.pointLabels) {
|
||||
this.plugins.pointLabels.show = false;
|
||||
}
|
||||
var i, el, d, gd, t, css, w, h, left, top;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
var colorGenerator = new $.jqplot.ColorGenerator(this.seriesColors);
|
||||
this.canvas._elem.empty();
|
||||
for (i=0; i<this.gridData.length; i++) {
|
||||
d = this.data[i];
|
||||
gd = this.gridData[i];
|
||||
t = '';
|
||||
css = {};
|
||||
if (typeof d[2] == 'string') {
|
||||
t = d[2];
|
||||
}
|
||||
else if (typeof d[2] == 'object') {
|
||||
css = d[2];
|
||||
}
|
||||
if (typeof d[3] == 'object') {
|
||||
css = d[3];
|
||||
}
|
||||
if (this.insertBreaks){
|
||||
t = t.replace(/ /g, '<br />');
|
||||
}
|
||||
css = $.extend(true, {}, this.css, css);
|
||||
// create a div
|
||||
el = $('<div style="position:absolute;margin-left:auto;margin-right:auto;"></div>');
|
||||
this.canvas._elem.append(el);
|
||||
// set text
|
||||
this.escapeHtml ? el.text(t) : el.html(t);
|
||||
// style it
|
||||
// remove styles we don't want overridden.
|
||||
delete css.position;
|
||||
delete css.marginRight;
|
||||
delete css.marginLeft;
|
||||
if (!css.background && !css.backgroundColor && !css.backgroundImage){
|
||||
css.background = colorGenerator.next();
|
||||
}
|
||||
el.css(css);
|
||||
w = el.outerWidth();
|
||||
h = el.outerHeight();
|
||||
left = gd[0] - w/2 + 'px';
|
||||
top = gd[1] - h/2 + 'px';
|
||||
el.css({left:left, top:top});
|
||||
el = null;
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.BlockCanvas = function() {
|
||||
$.jqplot.ElemContainer.call(this);
|
||||
this._ctx;
|
||||
};
|
||||
|
||||
$.jqplot.BlockCanvas.prototype = new $.jqplot.ElemContainer();
|
||||
$.jqplot.BlockCanvas.prototype.constructor = $.jqplot.BlockCanvas;
|
||||
|
||||
$.jqplot.BlockCanvas.prototype.createElement = function(offsets, clss, plotDimensions) {
|
||||
this._offsets = offsets;
|
||||
var klass = 'jqplot-blockCanvas';
|
||||
if (clss != undefined) {
|
||||
klass = clss;
|
||||
}
|
||||
var elem;
|
||||
// if this canvas already has a dom element, don't make a new one.
|
||||
if (this._elem) {
|
||||
elem = this._elem.get(0);
|
||||
}
|
||||
else {
|
||||
elem = document.createElement('div');
|
||||
}
|
||||
// if new plotDimensions supplied, use them.
|
||||
if (plotDimensions != undefined) {
|
||||
this._plotDimensions = plotDimensions;
|
||||
}
|
||||
|
||||
var w = this._plotDimensions.width - this._offsets.left - this._offsets.right + 'px';
|
||||
var h = this._plotDimensions.height - this._offsets.top - this._offsets.bottom + 'px';
|
||||
this._elem = $(elem);
|
||||
this._elem.css({ position: 'absolute', width:w, height:h, left: this._offsets.left, top: this._offsets.top });
|
||||
|
||||
this._elem.addClass(klass);
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.BlockCanvas.prototype.setContext = function() {
|
||||
this._ctx = {
|
||||
canvas:{
|
||||
width:0,
|
||||
height:0
|
||||
},
|
||||
clearRect:function(){return null;}
|
||||
};
|
||||
return this._ctx;
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4r1121
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2011 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function(a){a.jqplot.BlockRenderer=function(){a.jqplot.LineRenderer.call(this)};a.jqplot.BlockRenderer.prototype=new a.jqplot.LineRenderer();a.jqplot.BlockRenderer.prototype.constructor=a.jqplot.BlockRenderer;a.jqplot.BlockRenderer.prototype.init=function(b){this.css={padding:"2px",border:"1px solid #999",textAlign:"center"};this.escapeHtml=false;this.insertBreaks=true;this.varyBlockColors=false;a.extend(true,this,b);if(this.css.backgroundColor){this.color=this.css.backgroundColor}else{if(this.css.background){this.color=this.css.background}else{if(!this.varyBlockColors){this.css.background=this.color}}}this.canvas=new a.jqplot.BlockCanvas();this.shadowCanvas=new a.jqplot.BlockCanvas();this.canvas._plotDimensions=this._plotDimensions;this.shadowCanvas._plotDimensions=this._plotDimensions;this._type="block";this.moveBlock=function(l,j,i,e){var c=this.canvas._elem.children(":eq("+l+")");this.data[l][0]=j;this.data[l][1]=i;this._plotData[l][0]=j;this._plotData[l][1]=i;this._stackData[l][0]=j;this._stackData[l][1]=i;this.gridData[l][0]=this._xaxis.series_u2p(j);this.gridData[l][1]=this._yaxis.series_u2p(i);var k=c.outerWidth();var f=c.outerHeight();var d=this.gridData[l][0]-k/2+"px";var g=this.gridData[l][1]-f/2+"px";if(e){if(parseInt(e,10)){e=parseInt(e,10)}c.animate({left:d,top:g},e)}else{c.css({left:d,top:g})}c=null}};a.jqplot.BlockRenderer.prototype.draw=function(q,o,r){if(this.plugins.pointLabels){this.plugins.pointLabels.show=false}var f,c,l,o,p,k,n,g,e,m;var b=(r!=undefined)?r:{};var j=new a.jqplot.ColorGenerator(this.seriesColors);this.canvas._elem.empty();for(f=0;f<this.gridData.length;f++){l=this.data[f];o=this.gridData[f];p="";k={};if(typeof l[2]=="string"){p=l[2]}else{if(typeof l[2]=="object"){k=l[2]}}if(typeof l[3]=="object"){k=l[3]}if(this.insertBreaks){p=p.replace(/ /g,"<br />")}k=a.extend(true,{},this.css,k);c=a('<div style="position:absolute;margin-left:auto;margin-right:auto;"></div>');this.canvas._elem.append(c);this.escapeHtml?c.text(p):c.html(p);delete k.position;delete k.marginRight;delete k.marginLeft;if(!k.background&&!k.backgroundColor&&!k.backgroundImage){k.background=j.next()}c.css(k);n=c.outerWidth();g=c.outerHeight();e=o[0]-n/2+"px";m=o[1]-g/2+"px";c.css({left:e,top:m});c=null}};a.jqplot.BlockCanvas=function(){a.jqplot.ElemContainer.call(this);this._ctx};a.jqplot.BlockCanvas.prototype=new a.jqplot.ElemContainer();a.jqplot.BlockCanvas.prototype.constructor=a.jqplot.BlockCanvas;a.jqplot.BlockCanvas.prototype.createElement=function(i,e,c){this._offsets=i;var b="jqplot-blockCanvas";if(e!=undefined){b=e}var g;if(this._elem){g=this._elem.get(0)}else{g=document.createElement("div")}if(c!=undefined){this._plotDimensions=c}var d=this._plotDimensions.width-this._offsets.left-this._offsets.right+"px";var f=this._plotDimensions.height-this._offsets.top-this._offsets.bottom+"px";this._elem=a(g);this._elem.css({position:"absolute",width:d,height:f,left:this._offsets.left,top:this._offsets.top});this._elem.addClass(b);return this._elem};a.jqplot.BlockCanvas.prototype.setContext=function(){this._ctx={canvas:{width:0,height:0},clearRect:function(){return null}};return this._ctx}})(jQuery);
|
@ -1,759 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
var arrayMax = function( array ){
|
||||
return Math.max.apply( Math, array );
|
||||
};
|
||||
var arrayMin = function( array ){
|
||||
return Math.min.apply( Math, array );
|
||||
};
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.BubbleRenderer
|
||||
* Plugin renderer to draw a bubble chart. A Bubble chart has data points displayed as
|
||||
* colored circles with an optional text label inside. To use
|
||||
* the bubble renderer, you must include the bubble renderer like:
|
||||
*
|
||||
* > <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.bubbleRenderer.js"></script>
|
||||
*
|
||||
* Data must be supplied in
|
||||
* the form:
|
||||
*
|
||||
* > [[x1, y1, r1, <label or {label:'text', color:color}>], ...]
|
||||
*
|
||||
* where the label or options
|
||||
* object is optional.
|
||||
*
|
||||
* Note that all bubble colors will be the same
|
||||
* unless the "varyBubbleColors" option is set to true. Colors can be specified in the data array
|
||||
* or in the seriesColors array option on the series. If no colors are defined, the default jqPlot
|
||||
* series of 16 colors are used. Colors are automatically cycled around again if there are more
|
||||
* bubbles than colors.
|
||||
*
|
||||
* Bubbles are autoscaled by default to fit within the chart area while maintaining
|
||||
* relative sizes. If the "autoscaleBubbles" option is set to false, the r(adius) values
|
||||
* in the data array a treated as literal pixel values for the radii of the bubbles.
|
||||
*
|
||||
* Properties are passed into the bubble renderer in the rendererOptions object of
|
||||
* the series options like:
|
||||
*
|
||||
* > seriesDefaults: {
|
||||
* > renderer: $.jqplot.BubbleRenderer,
|
||||
* > rendererOptions: {
|
||||
* > bubbleAlpha: 0.7,
|
||||
* > varyBubbleColors: false
|
||||
* > }
|
||||
* > }
|
||||
*
|
||||
*/
|
||||
$.jqplot.BubbleRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.BubbleRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.BubbleRenderer.prototype.constructor = $.jqplot.BubbleRenderer;
|
||||
|
||||
// called with scope of a series
|
||||
$.jqplot.BubbleRenderer.prototype.init = function(options, plot) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: varyBubbleColors
|
||||
// True to vary the color of each bubble in this series according to
|
||||
// the seriesColors array. False to set each bubble to the color
|
||||
// specified on this series. This has no effect if a css background color
|
||||
// option is specified in the renderer css options.
|
||||
this.varyBubbleColors = true;
|
||||
// prop: autoscaleBubbles
|
||||
// True to scale the bubble radius based on plot size.
|
||||
// False will use the radius value as provided as a raw pixel value for
|
||||
// bubble radius.
|
||||
this.autoscaleBubbles = true;
|
||||
// prop: autoscaleMultiplier
|
||||
// Multiplier the bubble size if autoscaleBubbles is true.
|
||||
this.autoscaleMultiplier = 1.0;
|
||||
// prop: autoscalePointsFactor
|
||||
// Factor which decreases bubble size based on how many bubbles on on the chart.
|
||||
// 0 means no adjustment for number of bubbles. Negative values will decrease
|
||||
// size of bubbles as more bubbles are added. Values between 0 and -0.2
|
||||
// should work well.
|
||||
this.autoscalePointsFactor = -0.07;
|
||||
// prop: escapeHtml
|
||||
// True to escape html in bubble label text.
|
||||
this.escapeHtml = true;
|
||||
// prop: highlightMouseOver
|
||||
// True to highlight bubbles when moused over.
|
||||
// This must be false to enable highlightMouseDown to highlight when clicking on a slice.
|
||||
this.highlightMouseOver = true;
|
||||
// prop: highlightMouseDown
|
||||
// True to highlight when a mouse button is pressed over a bubble.
|
||||
// This will be disabled if highlightMouseOver is true.
|
||||
this.highlightMouseDown = false;
|
||||
// prop: highlightColors
|
||||
// An array of colors to use when highlighting a slice. Calculated automatically
|
||||
// if not supplied.
|
||||
this.highlightColors = [];
|
||||
// prop: bubbleAlpha
|
||||
// Alpha transparency to apply to all bubbles in this series.
|
||||
this.bubbleAlpha = 1.0;
|
||||
// prop: highlightAlpha
|
||||
// Alpha transparency to apply when highlighting bubble.
|
||||
// Set to value of bubbleAlpha by default.
|
||||
this.highlightAlpha = null;
|
||||
// prop: bubbleGradients
|
||||
// True to color the bubbles with gradient fills instead of flat colors.
|
||||
// NOT AVAILABLE IN IE due to lack of excanvas support for radial gradient fills.
|
||||
// will be ignored in IE.
|
||||
this.bubbleGradients = false;
|
||||
// prop: showLabels
|
||||
// True to show labels on bubbles (if any), false to not show.
|
||||
this.showLabels = true;
|
||||
// array of [point index, radius] which will be sorted in descending order to plot
|
||||
// largest points below smaller points.
|
||||
this.radii = [];
|
||||
this.maxRadius = 0;
|
||||
// index of the currenty highlighted point, if any
|
||||
this._highlightedPoint = null;
|
||||
// array of jQuery labels.
|
||||
this.labels = [];
|
||||
this.bubbleCanvases = [];
|
||||
this._type = 'bubble';
|
||||
|
||||
// if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
|
||||
if (options.highlightMouseDown && options.highlightMouseOver == null) {
|
||||
options.highlightMouseOver = false;
|
||||
}
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
if (this.highlightAlpha == null) {
|
||||
this.highlightAlpha = this.bubbleAlpha;
|
||||
if (this.bubbleGradients) {
|
||||
this.highlightAlpha = 0.35;
|
||||
}
|
||||
}
|
||||
|
||||
this.autoscaleMultiplier = this.autoscaleMultiplier * Math.pow(this.data.length, this.autoscalePointsFactor);
|
||||
|
||||
// index of the currenty highlighted point, if any
|
||||
this._highlightedPoint = null;
|
||||
|
||||
// adjust the series colors for options colors passed in with data or for alpha.
|
||||
// note, this can leave undefined holes in the seriesColors array.
|
||||
var comps;
|
||||
for (var i=0; i<this.data.length; i++) {
|
||||
var color = null;
|
||||
var d = this.data[i];
|
||||
this.maxRadius = Math.max(this.maxRadius, d[2]);
|
||||
if (d[3]) {
|
||||
if (typeof(d[3]) == 'object') {
|
||||
color = d[3]['color'];
|
||||
}
|
||||
}
|
||||
|
||||
if (color == null) {
|
||||
if (this.seriesColors[i] != null) {
|
||||
color = this.seriesColors[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (color && this.bubbleAlpha < 1.0) {
|
||||
comps = $.jqplot.getColorComponents(color);
|
||||
color = 'rgba('+comps[0]+', '+comps[1]+', '+comps[2]+', '+this.bubbleAlpha+')';
|
||||
}
|
||||
|
||||
if (color) {
|
||||
this.seriesColors[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.varyBubbleColors) {
|
||||
this.seriesColors = [this.color];
|
||||
}
|
||||
|
||||
this.colorGenerator = new $.jqplot.ColorGenerator(this.seriesColors);
|
||||
|
||||
// set highlight colors if none provided
|
||||
if (this.highlightColors.length == 0) {
|
||||
for (var i=0; i<this.seriesColors.length; i++){
|
||||
var rgba = $.jqplot.getColorComponents(this.seriesColors[i]);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var sum = newrgb[0] + newrgb[1] + newrgb[2];
|
||||
for (var j=0; j<3; j++) {
|
||||
// when darkening, lowest color component can be is 60.
|
||||
newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
|
||||
newrgb[j] = parseInt(newrgb[j], 10);
|
||||
}
|
||||
this.highlightColors.push('rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+', '+this.highlightAlpha+')');
|
||||
}
|
||||
}
|
||||
|
||||
this.highlightColorGenerator = new $.jqplot.ColorGenerator(this.highlightColors);
|
||||
|
||||
var sopts = {fill:true, isarc:true, angle:this.shadowAngle, alpha:this.shadowAlpha, closePath:true};
|
||||
|
||||
this.renderer.shadowRenderer.init(sopts);
|
||||
|
||||
this.canvas = new $.jqplot.DivCanvas();
|
||||
this.canvas._plotDimensions = this._plotDimensions;
|
||||
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
|
||||
plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
|
||||
plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
|
||||
plot.postDrawHooks.addOnce(postPlotDraw);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// converts the user data values to grid coordinates and stores them
|
||||
// in the gridData array.
|
||||
// Called with scope of a series.
|
||||
$.jqplot.BubbleRenderer.prototype.setGridData = function(plot) {
|
||||
// recalculate the grid data
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var data = this._plotData;
|
||||
this.gridData = [];
|
||||
var radii = [];
|
||||
this.radii = [];
|
||||
var dim = Math.min(plot._height, plot._width);
|
||||
for (var i=0; i<this.data.length; i++) {
|
||||
if (data[i] != null) {
|
||||
this.gridData.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1]), data[i][2]]);
|
||||
this.radii.push([i, data[i][2]]);
|
||||
radii.push(data[i][2]);
|
||||
}
|
||||
}
|
||||
var r, val, maxr = this.maxRadius = arrayMax(radii);
|
||||
var l = this.gridData.length;
|
||||
if (this.autoscaleBubbles) {
|
||||
for (var i=0; i<l; i++) {
|
||||
val = radii[i]/maxr;
|
||||
r = this.autoscaleMultiplier * dim / 6;
|
||||
this.gridData[i][2] = r * val;
|
||||
}
|
||||
}
|
||||
|
||||
this.radii.sort(function(a, b) { return b[1] - a[1]; });
|
||||
};
|
||||
|
||||
// converts any arbitrary data values to grid coordinates and
|
||||
// returns them. This method exists so that plugins can use a series'
|
||||
// linerenderer to generate grid data points without overwriting the
|
||||
// grid data associated with that series.
|
||||
// Called with scope of a series.
|
||||
$.jqplot.BubbleRenderer.prototype.makeGridData = function(data, plot) {
|
||||
// recalculate the grid data
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var gd = [];
|
||||
var radii = [];
|
||||
this.radii = [];
|
||||
var dim = Math.min(plot._height, plot._width);
|
||||
for (var i=0; i<data.length; i++) {
|
||||
if (data[i] != null) {
|
||||
gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1]), data[i][2]]);
|
||||
radii.push(data[i][2]);
|
||||
this.radii.push([i, data[i][2]]);
|
||||
}
|
||||
}
|
||||
var r, val, maxr = this.maxRadius = arrayMax(radii);
|
||||
var l = this.gridData.length;
|
||||
if (this.autoscaleBubbles) {
|
||||
for (var i=0; i<l; i++) {
|
||||
val = radii[i]/maxr;
|
||||
r = this.autoscaleMultiplier * dim / 6;
|
||||
gd[i][2] = r * val;
|
||||
}
|
||||
}
|
||||
this.radii.sort(function(a, b) { return b[1] - a[1]; });
|
||||
return gd;
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
$.jqplot.BubbleRenderer.prototype.draw = function (ctx, gd, options) {
|
||||
if (this.plugins.pointLabels) {
|
||||
this.plugins.pointLabels.show = false;
|
||||
}
|
||||
var opts = (options != undefined) ? options : {};
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
this.canvas._elem.empty();
|
||||
for (var i=0; i<this.radii.length; i++) {
|
||||
var idx = this.radii[i][0];
|
||||
var t=null;
|
||||
var color = null;
|
||||
var el = null;
|
||||
var tel = null;
|
||||
var d = this.data[idx];
|
||||
var gd = this.gridData[idx];
|
||||
if (d[3]) {
|
||||
if (typeof(d[3]) == 'object') {
|
||||
t = d[3]['label'];
|
||||
}
|
||||
else if (typeof(d[3]) == 'string') {
|
||||
t = d[3];
|
||||
}
|
||||
}
|
||||
|
||||
// color = (this.varyBubbleColors) ? this.colorGenerator.get(idx) : this.color;
|
||||
color = this.colorGenerator.get(idx);
|
||||
|
||||
// If we're drawing a shadow, expand the canvas dimensions to accomodate.
|
||||
var canvasRadius = gd[2];
|
||||
var offset, depth;
|
||||
if (this.shadow) {
|
||||
offset = (0.7 + gd[2]/40).toFixed(1);
|
||||
depth = 1 + Math.ceil(gd[2]/15);
|
||||
canvasRadius += offset*depth;
|
||||
}
|
||||
this.bubbleCanvases[idx] = new $.jqplot.BubbleCanvas();
|
||||
this.canvas._elem.append(this.bubbleCanvases[idx].createElement(gd[0], gd[1], canvasRadius));
|
||||
this.bubbleCanvases[idx].setContext();
|
||||
var ctx = this.bubbleCanvases[idx]._ctx;
|
||||
var x = ctx.canvas.width/2;
|
||||
var y = ctx.canvas.height/2;
|
||||
if (this.shadow) {
|
||||
this.renderer.shadowRenderer.draw(ctx, [x, y, gd[2], 0, 2*Math.PI], {offset: offset, depth: depth});
|
||||
}
|
||||
this.bubbleCanvases[idx].draw(gd[2], color, this.bubbleGradients, this.shadowAngle/180*Math.PI);
|
||||
|
||||
// now draw label.
|
||||
if (t && this.showLabels) {
|
||||
tel = $('<div style="position:absolute;" class="jqplot-bubble-label"></div>');
|
||||
if (this.escapeHtml) {
|
||||
tel.text(t);
|
||||
}
|
||||
else {
|
||||
tel.html(t);
|
||||
}
|
||||
this.canvas._elem.append(tel);
|
||||
var h = $(tel).outerHeight();
|
||||
var w = $(tel).outerWidth();
|
||||
var top = gd[1] - 0.5*h;
|
||||
var left = gd[0] - 0.5*w;
|
||||
tel.css({top: top, left: left});
|
||||
this.labels[idx] = $(tel);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$.jqplot.DivCanvas = function() {
|
||||
$.jqplot.ElemContainer.call(this);
|
||||
this._ctx;
|
||||
};
|
||||
|
||||
$.jqplot.DivCanvas.prototype = new $.jqplot.ElemContainer();
|
||||
$.jqplot.DivCanvas.prototype.constructor = $.jqplot.DivCanvas;
|
||||
|
||||
$.jqplot.DivCanvas.prototype.createElement = function(offsets, clss, plotDimensions) {
|
||||
this._offsets = offsets;
|
||||
var klass = 'jqplot-DivCanvas';
|
||||
if (clss != undefined) {
|
||||
klass = clss;
|
||||
}
|
||||
var elem;
|
||||
// if this canvas already has a dom element, don't make a new one.
|
||||
if (this._elem) {
|
||||
elem = this._elem.get(0);
|
||||
}
|
||||
else {
|
||||
elem = document.createElement('div');
|
||||
}
|
||||
// if new plotDimensions supplied, use them.
|
||||
if (plotDimensions != undefined) {
|
||||
this._plotDimensions = plotDimensions;
|
||||
}
|
||||
|
||||
var w = this._plotDimensions.width - this._offsets.left - this._offsets.right + 'px';
|
||||
var h = this._plotDimensions.height - this._offsets.top - this._offsets.bottom + 'px';
|
||||
this._elem = $(elem);
|
||||
this._elem.css({ position: 'absolute', width:w, height:h, left: this._offsets.left, top: this._offsets.top });
|
||||
|
||||
this._elem.addClass(klass);
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.DivCanvas.prototype.setContext = function() {
|
||||
this._ctx = {
|
||||
canvas:{
|
||||
width:0,
|
||||
height:0
|
||||
},
|
||||
clearRect:function(){return null;}
|
||||
};
|
||||
return this._ctx;
|
||||
};
|
||||
|
||||
$.jqplot.BubbleCanvas = function() {
|
||||
$.jqplot.ElemContainer.call(this);
|
||||
this._ctx;
|
||||
};
|
||||
|
||||
$.jqplot.BubbleCanvas.prototype = new $.jqplot.ElemContainer();
|
||||
$.jqplot.BubbleCanvas.prototype.constructor = $.jqplot.BubbleCanvas;
|
||||
|
||||
// initialize with the x,y pont of bubble center and the bubble radius.
|
||||
$.jqplot.BubbleCanvas.prototype.createElement = function(x, y, r) {
|
||||
var klass = 'jqplot-bubble-point';
|
||||
|
||||
var elem;
|
||||
// if this canvas already has a dom element, don't make a new one.
|
||||
if (this._elem) {
|
||||
elem = this._elem.get(0);
|
||||
}
|
||||
else {
|
||||
elem = document.createElement('canvas');
|
||||
}
|
||||
|
||||
elem.width = (r != null) ? 2*r : elem.width;
|
||||
elem.height = (r != null) ? 2*r : elem.height;
|
||||
this._elem = $(elem);
|
||||
var l = (x != null && r != null) ? x - r : this._elem.css('left');
|
||||
var t = (y != null && r != null) ? y - r : this._elem.css('top');
|
||||
this._elem.css({ position: 'absolute', left: l, top: t });
|
||||
|
||||
this._elem.addClass(klass);
|
||||
if ($.jqplot.use_excanvas) {
|
||||
window.G_vmlCanvasManager.init_(document);
|
||||
elem = window.G_vmlCanvasManager.initElement(elem);
|
||||
}
|
||||
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.BubbleCanvas.prototype.draw = function(r, color, gradients, angle) {
|
||||
var ctx = this._ctx;
|
||||
// r = Math.floor(r*1.04);
|
||||
// var x = Math.round(ctx.canvas.width/2);
|
||||
// var y = Math.round(ctx.canvas.height/2);
|
||||
var x = ctx.canvas.width/2;
|
||||
var y = ctx.canvas.height/2;
|
||||
ctx.save();
|
||||
if (gradients && !$.jqplot.use_excanvas) {
|
||||
r = r*1.04;
|
||||
var comps = $.jqplot.getColorComponents(color);
|
||||
var colorinner = 'rgba('+Math.round(comps[0]+0.8*(255-comps[0]))+', '+Math.round(comps[1]+0.8*(255-comps[1]))+', '+Math.round(comps[2]+0.8*(255-comps[2]))+', '+comps[3]+')';
|
||||
var colorend = 'rgba('+comps[0]+', '+comps[1]+', '+comps[2]+', 0)';
|
||||
// var rinner = Math.round(0.35 * r);
|
||||
// var xinner = Math.round(x - Math.cos(angle) * 0.33 * r);
|
||||
// var yinner = Math.round(y - Math.sin(angle) * 0.33 * r);
|
||||
var rinner = 0.35 * r;
|
||||
var xinner = x - Math.cos(angle) * 0.33 * r;
|
||||
var yinner = y - Math.sin(angle) * 0.33 * r;
|
||||
var radgrad = ctx.createRadialGradient(xinner, yinner, rinner, x, y, r);
|
||||
radgrad.addColorStop(0, colorinner);
|
||||
radgrad.addColorStop(0.93, color);
|
||||
radgrad.addColorStop(0.96, colorend);
|
||||
radgrad.addColorStop(1, colorend);
|
||||
// radgrad.addColorStop(.98, colorend);
|
||||
ctx.fillStyle = radgrad;
|
||||
ctx.fillRect(0,0, ctx.canvas.width, ctx.canvas.height);
|
||||
}
|
||||
else {
|
||||
ctx.fillStyle = color;
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
var ang = 2*Math.PI;
|
||||
ctx.arc(x, y, r, 0, ang, 0);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
}
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
$.jqplot.BubbleCanvas.prototype.setContext = function() {
|
||||
this._ctx = this._elem.get(0).getContext("2d");
|
||||
return this._ctx;
|
||||
};
|
||||
|
||||
$.jqplot.BubbleAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.BubbleAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.BubbleAxisRenderer.prototype.constructor = $.jqplot.BubbleAxisRenderer;
|
||||
|
||||
// called with scope of axis object.
|
||||
$.jqplot.BubbleAxisRenderer.prototype.init = function(options){
|
||||
$.extend(true, this, options);
|
||||
var db = this._dataBounds;
|
||||
var minsidx = 0,
|
||||
minpidx = 0,
|
||||
maxsidx = 0,
|
||||
maxpidx = 0,
|
||||
maxr = 0,
|
||||
minr = 0,
|
||||
minMaxRadius = 0,
|
||||
maxMaxRadius = 0,
|
||||
maxMult = 0,
|
||||
minMult = 0;
|
||||
// Go through all the series attached to this axis and find
|
||||
// the min/max bounds for this axis.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
var d = s._plotData;
|
||||
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
if (d[j][0] < db.min || db.min == null) {
|
||||
db.min = d[j][0];
|
||||
minsidx=i;
|
||||
minpidx=j;
|
||||
minr = d[j][2];
|
||||
minMaxRadius = s.maxRadius;
|
||||
minMult = s.autoscaleMultiplier;
|
||||
}
|
||||
if (d[j][0] > db.max || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
maxsidx=i;
|
||||
maxpidx=j;
|
||||
maxr = d[j][2];
|
||||
maxMaxRadius = s.maxRadius;
|
||||
maxMult = s.autoscaleMultiplier;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (d[j][1] < db.min || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
minsidx=i;
|
||||
minpidx=j;
|
||||
minr = d[j][2];
|
||||
minMaxRadius = s.maxRadius;
|
||||
minMult = s.autoscaleMultiplier;
|
||||
}
|
||||
if (d[j][1] > db.max || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
maxsidx=i;
|
||||
maxpidx=j;
|
||||
maxr = d[j][2];
|
||||
maxMaxRadius = s.maxRadius;
|
||||
maxMult = s.autoscaleMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var minRatio = minr/minMaxRadius;
|
||||
var maxRatio = maxr/maxMaxRadius;
|
||||
|
||||
// need to estimate the effect of the radius on total axis span and adjust axis accordingly.
|
||||
var span = db.max - db.min;
|
||||
// var dim = (this.name == 'xaxis' || this.name == 'x2axis') ? this._plotDimensions.width : this._plotDimensions.height;
|
||||
var dim = Math.min(this._plotDimensions.width, this._plotDimensions.height);
|
||||
|
||||
var minfact = minRatio * minMult/3 * span;
|
||||
var maxfact = maxRatio * maxMult/3 * span;
|
||||
db.max += maxfact;
|
||||
db.min -= minfact;
|
||||
};
|
||||
|
||||
function highlight (plot, sidx, pidx) {
|
||||
plot.plugins.bubbleRenderer.highlightLabelCanvas.empty();
|
||||
var s = plot.series[sidx];
|
||||
var canvas = plot.plugins.bubbleRenderer.highlightCanvas;
|
||||
var ctx = canvas._ctx;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
s._highlightedPoint = pidx;
|
||||
plot.plugins.bubbleRenderer.highlightedSeriesIndex = sidx;
|
||||
|
||||
var color = s.highlightColorGenerator.get(pidx);
|
||||
var x = s.gridData[pidx][0],
|
||||
y = s.gridData[pidx][1],
|
||||
r = s.gridData[pidx][2];
|
||||
ctx.save();
|
||||
ctx.fillStyle = color;
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, r, 0, 2*Math.PI, 0);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
// bring label to front
|
||||
if (s.labels[pidx]) {
|
||||
plot.plugins.bubbleRenderer.highlightLabel = s.labels[pidx].clone();
|
||||
plot.plugins.bubbleRenderer.highlightLabel.appendTo(plot.plugins.bubbleRenderer.highlightLabelCanvas);
|
||||
plot.plugins.bubbleRenderer.highlightLabel.addClass('jqplot-bubble-label-highlight');
|
||||
}
|
||||
}
|
||||
|
||||
function unhighlight (plot) {
|
||||
var canvas = plot.plugins.bubbleRenderer.highlightCanvas;
|
||||
var sidx = plot.plugins.bubbleRenderer.highlightedSeriesIndex;
|
||||
plot.plugins.bubbleRenderer.highlightLabelCanvas.empty();
|
||||
canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
|
||||
for (var i=0; i<plot.series.length; i++) {
|
||||
plot.series[i]._highlightedPoint = null;
|
||||
}
|
||||
plot.plugins.bubbleRenderer.highlightedSeriesIndex = null;
|
||||
plot.target.trigger('jqplotDataUnhighlight');
|
||||
}
|
||||
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var si = neighbor.seriesIndex;
|
||||
var pi = neighbor.pointIndex;
|
||||
var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
|
||||
var evt1 = jQuery.Event('jqplotDataMouseOver');
|
||||
evt1.pageX = ev.pageX;
|
||||
evt1.pageY = ev.pageY;
|
||||
plot.target.trigger(evt1, ins);
|
||||
if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.bubbleRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, ins[0], ins[1]);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var si = neighbor.seriesIndex;
|
||||
var pi = neighbor.pointIndex;
|
||||
var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
|
||||
if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.bubbleRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, ins[0], ins[1]);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
|
||||
var idx = plot.plugins.bubbleRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var si = neighbor.seriesIndex;
|
||||
var pi = neighbor.pointIndex;
|
||||
var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
|
||||
var evt = jQuery.Event('jqplotDataClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var si = neighbor.seriesIndex;
|
||||
var pi = neighbor.pointIndex;
|
||||
var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
|
||||
var idx = plot.plugins.bubbleRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
var evt = jQuery.Event('jqplotDataRightClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
function postPlotDraw() {
|
||||
// Memory Leaks patch
|
||||
if (this.plugins.bubbleRenderer && this.plugins.bubbleRenderer.highlightCanvas) {
|
||||
this.plugins.bubbleRenderer.highlightCanvas.resetCanvas();
|
||||
this.plugins.bubbleRenderer.highlightCanvas = null;
|
||||
}
|
||||
|
||||
this.plugins.bubbleRenderer = {highlightedSeriesIndex:null};
|
||||
this.plugins.bubbleRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
|
||||
this.plugins.bubbleRenderer.highlightLabel = null;
|
||||
this.plugins.bubbleRenderer.highlightLabelCanvas = $('<div style="position:absolute;"></div>');
|
||||
var top = this._gridPadding.top;
|
||||
var left = this._gridPadding.left;
|
||||
var width = this._plotDimensions.width - this._gridPadding.left - this._gridPadding.right;
|
||||
var height = this._plotDimensions.height - this._gridPadding.top - this._gridPadding.bottom;
|
||||
this.plugins.bubbleRenderer.highlightLabelCanvas.css({top:top, left:left, width:width+'px', height:height+'px'});
|
||||
|
||||
this.eventCanvas._elem.before(this.plugins.bubbleRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-bubbleRenderer-highlight-canvas', this._plotDimensions, this));
|
||||
this.eventCanvas._elem.before(this.plugins.bubbleRenderer.highlightLabelCanvas);
|
||||
|
||||
var hctx = this.plugins.bubbleRenderer.highlightCanvas.setContext();
|
||||
}
|
||||
|
||||
|
||||
// setup default renderers for axes and legend so user doesn't have to
|
||||
// called with scope of plot
|
||||
function preInit(target, data, options) {
|
||||
options = options || {};
|
||||
options.axesDefaults = options.axesDefaults || {};
|
||||
options.seriesDefaults = options.seriesDefaults || {};
|
||||
// only set these if there is a Bubble series
|
||||
var setopts = false;
|
||||
if (options.seriesDefaults.renderer == $.jqplot.BubbleRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
else if (options.series) {
|
||||
for (var i=0; i < options.series.length; i++) {
|
||||
if (options.series[i].renderer == $.jqplot.BubbleRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setopts) {
|
||||
options.axesDefaults.renderer = $.jqplot.BubbleAxisRenderer;
|
||||
options.sortData = false;
|
||||
}
|
||||
}
|
||||
|
||||
$.jqplot.preInitHooks.push(preInit);
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,203 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.CanvasAxisLabelRenderer
|
||||
* Renderer to draw axis labels with a canvas element to support advanced
|
||||
* featrues such as rotated text. This renderer uses a separate rendering engine
|
||||
* to draw the text on the canvas. Two modes of rendering the text are available.
|
||||
* If the browser has native font support for canvas fonts (currently Mozila 3.5
|
||||
* and Safari 4), you can enable text rendering with the canvas fillText method.
|
||||
* You do so by setting the "enableFontSupport" option to true.
|
||||
*
|
||||
* Browsers lacking native font support will have the text drawn on the canvas
|
||||
* using the Hershey font metrics. Even if the "enableFontSupport" option is true
|
||||
* non-supporting browsers will still render with the Hershey font.
|
||||
*
|
||||
*/
|
||||
$.jqplot.CanvasAxisLabelRenderer = function(options) {
|
||||
// Group: Properties
|
||||
|
||||
// prop: angle
|
||||
// angle of text, measured clockwise from x axis.
|
||||
this.angle = 0;
|
||||
// name of the axis associated with this tick
|
||||
this.axis;
|
||||
// prop: show
|
||||
// wether or not to show the tick (mark and label).
|
||||
this.show = true;
|
||||
// prop: showLabel
|
||||
// wether or not to show the label.
|
||||
this.showLabel = true;
|
||||
// prop: label
|
||||
// label for the axis.
|
||||
this.label = '';
|
||||
// prop: fontFamily
|
||||
// CSS spec for the font-family css attribute.
|
||||
// Applies only to browsers supporting native font rendering in the
|
||||
// canvas tag. Currently Mozilla 3.5 and Safari 4.
|
||||
this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif';
|
||||
// prop: fontSize
|
||||
// CSS spec for font size.
|
||||
this.fontSize = '11pt';
|
||||
// prop: fontWeight
|
||||
// CSS spec for fontWeight: normal, bold, bolder, lighter or a number 100 - 900
|
||||
this.fontWeight = 'normal';
|
||||
// prop: fontStretch
|
||||
// Multiplier to condense or expand font width.
|
||||
// Applies only to browsers which don't support canvas native font rendering.
|
||||
this.fontStretch = 1.0;
|
||||
// prop: textColor
|
||||
// css spec for the color attribute.
|
||||
this.textColor = '#666666';
|
||||
// prop: enableFontSupport
|
||||
// true to turn on native canvas font support in Mozilla 3.5+ and Safari 4+.
|
||||
// If true, label will be drawn with canvas tag native support for fonts.
|
||||
// If false, label will be drawn with Hershey font metrics.
|
||||
this.enableFontSupport = true;
|
||||
// prop: pt2px
|
||||
// Point to pixel scaling factor, used for computing height of bounding box
|
||||
// around a label. The labels text renderer has a default setting of 1.4, which
|
||||
// should be suitable for most fonts. Leave as null to use default. If tops of
|
||||
// letters appear clipped, increase this. If bounding box seems too big, decrease.
|
||||
// This is an issue only with the native font renderering capabilities of Mozilla
|
||||
// 3.5 and Safari 4 since they do not provide a method to determine the font height.
|
||||
this.pt2px = null;
|
||||
|
||||
this._elem;
|
||||
this._ctx;
|
||||
this._plotWidth;
|
||||
this._plotHeight;
|
||||
this._plotDimensions = {height:null, width:null};
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
if (options.angle == null && this.axis != 'xaxis' && this.axis != 'x2axis') {
|
||||
this.angle = -90;
|
||||
}
|
||||
|
||||
var ropts = {fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily};
|
||||
if (this.pt2px) {
|
||||
ropts.pt2px = this.pt2px;
|
||||
}
|
||||
|
||||
if (this.enableFontSupport) {
|
||||
if ($.jqplot.support_canvas_text()) {
|
||||
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
}
|
||||
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.init = function(options) {
|
||||
$.extend(true, this, options);
|
||||
this._textRenderer.init({fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily});
|
||||
};
|
||||
|
||||
// return width along the x axis
|
||||
// will check first to see if an element exists.
|
||||
// if not, will return the computed text box width.
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.getWidth = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerWidth(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.sin(tr.angle)*h) + Math.abs(Math.cos(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
// return height along the y axis.
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.getHeight = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.cos(tr.angle)*h) + Math.abs(Math.sin(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.getAngleRad = function() {
|
||||
var a = this.angle * Math.PI/180;
|
||||
return a;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.draw = function(ctx, plot) {
|
||||
// Memory Leaks patch
|
||||
if (this._elem) {
|
||||
if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
|
||||
window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
|
||||
}
|
||||
|
||||
this._elem.emptyForce();
|
||||
this._elem = null;
|
||||
}
|
||||
|
||||
// create a canvas here, but can't draw on it untill it is appended
|
||||
// to dom for IE compatability.
|
||||
var elem = plot.canvasManager.getCanvas();
|
||||
|
||||
this._textRenderer.setText(this.label, ctx);
|
||||
var w = this.getWidth(ctx);
|
||||
var h = this.getHeight(ctx);
|
||||
elem.width = w;
|
||||
elem.height = h;
|
||||
elem.style.width = w;
|
||||
elem.style.height = h;
|
||||
|
||||
elem = plot.canvasManager.initCanvas(elem);
|
||||
|
||||
this._elem = $(elem);
|
||||
this._elem.css({ position: 'absolute'});
|
||||
this._elem.addClass('jqplot-'+this.axis+'-label');
|
||||
|
||||
elem = null;
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.pack = function() {
|
||||
this._textRenderer.draw(this._elem.get(0).getContext("2d"), this.label);
|
||||
};
|
||||
|
||||
})(jQuery);
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4r1121
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2011 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function(a){a.jqplot.CanvasAxisLabelRenderer=function(b){this.angle=0;this.axis;this.show=true;this.showLabel=true;this.label="";this.fontFamily='"Trebuchet MS", Arial, Helvetica, sans-serif';this.fontSize="11pt";this.fontWeight="normal";this.fontStretch=1;this.textColor="#666666";this.enableFontSupport=true;this.pt2px=null;this._elem;this._ctx;this._plotWidth;this._plotHeight;this._plotDimensions={height:null,width:null};a.extend(true,this,b);if(b.angle==null&&this.axis!="xaxis"&&this.axis!="x2axis"){this.angle=-90}var c={fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily};if(this.pt2px){c.pt2px=this.pt2px}if(this.enableFontSupport){if(a.jqplot.support_canvas_text()){this._textRenderer=new a.jqplot.CanvasFontRenderer(c)}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}};a.jqplot.CanvasAxisLabelRenderer.prototype.init=function(b){a.extend(true,this,b);this._textRenderer.init({fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily})};a.jqplot.CanvasAxisLabelRenderer.prototype.getWidth=function(d){if(this._elem){return this._elem.outerWidth(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.sin(f.angle)*e)+Math.abs(Math.cos(f.angle)*c);return b}};a.jqplot.CanvasAxisLabelRenderer.prototype.getHeight=function(d){if(this._elem){return this._elem.outerHeight(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.cos(f.angle)*e)+Math.abs(Math.sin(f.angle)*c);return b}};a.jqplot.CanvasAxisLabelRenderer.prototype.getAngleRad=function(){var b=this.angle*Math.PI/180;return b};a.jqplot.CanvasAxisLabelRenderer.prototype.draw=function(c,f){if(this._elem){if(a.jqplot.use_excanvas&&window.G_vmlCanvasManager.uninitElement!==undefined){window.G_vmlCanvasManager.uninitElement(this._elem.get(0))}this._elem.emptyForce();this._elem=null}var e=f.canvasManager.getCanvas();this._textRenderer.setText(this.label,c);var b=this.getWidth(c);var d=this.getHeight(c);e.width=b;e.height=d;e.style.width=b;e.style.height=d;e=f.canvasManager.initCanvas(e);this._elem=a(e);this._elem.css({position:"absolute"});this._elem.addClass("jqplot-"+this.axis+"-label");e=null;return this._elem};a.jqplot.CanvasAxisLabelRenderer.prototype.pack=function(){this._textRenderer.draw(this._elem.get(0).getContext("2d"),this.label)}})(jQuery);
|
@ -1,243 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.CanvasAxisTickRenderer
|
||||
* Renderer to draw axis ticks with a canvas element to support advanced
|
||||
* featrues such as rotated text. This renderer uses a separate rendering engine
|
||||
* to draw the text on the canvas. Two modes of rendering the text are available.
|
||||
* If the browser has native font support for canvas fonts (currently Mozila 3.5
|
||||
* and Safari 4), you can enable text rendering with the canvas fillText method.
|
||||
* You do so by setting the "enableFontSupport" option to true.
|
||||
*
|
||||
* Browsers lacking native font support will have the text drawn on the canvas
|
||||
* using the Hershey font metrics. Even if the "enableFontSupport" option is true
|
||||
* non-supporting browsers will still render with the Hershey font.
|
||||
*/
|
||||
$.jqplot.CanvasAxisTickRenderer = function(options) {
|
||||
// Group: Properties
|
||||
|
||||
// prop: mark
|
||||
// tick mark on the axis. One of 'inside', 'outside', 'cross', '' or null.
|
||||
this.mark = 'outside';
|
||||
// prop: showMark
|
||||
// wether or not to show the mark on the axis.
|
||||
this.showMark = true;
|
||||
// prop: showGridline
|
||||
// wether or not to draw the gridline on the grid at this tick.
|
||||
this.showGridline = true;
|
||||
// prop: isMinorTick
|
||||
// if this is a minor tick.
|
||||
this.isMinorTick = false;
|
||||
// prop: angle
|
||||
// angle of text, measured clockwise from x axis.
|
||||
this.angle = 0;
|
||||
// prop: markSize
|
||||
// Length of the tick marks in pixels. For 'cross' style, length
|
||||
// will be stoked above and below axis, so total length will be twice this.
|
||||
this.markSize = 4;
|
||||
// prop: show
|
||||
// wether or not to show the tick (mark and label).
|
||||
this.show = true;
|
||||
// prop: showLabel
|
||||
// wether or not to show the label.
|
||||
this.showLabel = true;
|
||||
// prop: labelPosition
|
||||
// 'auto', 'start', 'middle' or 'end'.
|
||||
// Whether tick label should be positioned so the start, middle, or end
|
||||
// of the tick mark.
|
||||
this.labelPosition = 'auto';
|
||||
this.label = '';
|
||||
this.value = null;
|
||||
this._styles = {};
|
||||
// prop: formatter
|
||||
// A class of a formatter for the tick text.
|
||||
// The default $.jqplot.DefaultTickFormatter uses sprintf.
|
||||
this.formatter = $.jqplot.DefaultTickFormatter;
|
||||
// prop: formatString
|
||||
// string passed to the formatter.
|
||||
this.formatString = '';
|
||||
// prop: prefix
|
||||
// String to prepend to the tick label.
|
||||
// Prefix is prepended to the formatted tick label.
|
||||
this.prefix = '';
|
||||
// prop: fontFamily
|
||||
// css spec for the font-family css attribute.
|
||||
this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif';
|
||||
// prop: fontSize
|
||||
// CSS spec for font size.
|
||||
this.fontSize = '10pt';
|
||||
// prop: fontWeight
|
||||
// CSS spec for fontWeight
|
||||
this.fontWeight = 'normal';
|
||||
// prop: fontStretch
|
||||
// Multiplier to condense or expand font width.
|
||||
// Applies only to browsers which don't support canvas native font rendering.
|
||||
this.fontStretch = 1.0;
|
||||
// prop: textColor
|
||||
// css spec for the color attribute.
|
||||
this.textColor = '#666666';
|
||||
// prop: enableFontSupport
|
||||
// true to turn on native canvas font support in Mozilla 3.5+ and Safari 4+.
|
||||
// If true, tick label will be drawn with canvas tag native support for fonts.
|
||||
// If false, tick label will be drawn with Hershey font metrics.
|
||||
this.enableFontSupport = true;
|
||||
// prop: pt2px
|
||||
// Point to pixel scaling factor, used for computing height of bounding box
|
||||
// around a label. The labels text renderer has a default setting of 1.4, which
|
||||
// should be suitable for most fonts. Leave as null to use default. If tops of
|
||||
// letters appear clipped, increase this. If bounding box seems too big, decrease.
|
||||
// This is an issue only with the native font renderering capabilities of Mozilla
|
||||
// 3.5 and Safari 4 since they do not provide a method to determine the font height.
|
||||
this.pt2px = null;
|
||||
|
||||
this._elem;
|
||||
this._ctx;
|
||||
this._plotWidth;
|
||||
this._plotHeight;
|
||||
this._plotDimensions = {height:null, width:null};
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
var ropts = {fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily};
|
||||
if (this.pt2px) {
|
||||
ropts.pt2px = this.pt2px;
|
||||
}
|
||||
|
||||
if (this.enableFontSupport) {
|
||||
if ($.jqplot.support_canvas_text()) {
|
||||
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
}
|
||||
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.init = function(options) {
|
||||
$.extend(true, this, options);
|
||||
this._textRenderer.init({fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily});
|
||||
};
|
||||
|
||||
// return width along the x axis
|
||||
// will check first to see if an element exists.
|
||||
// if not, will return the computed text box width.
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.getWidth = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerWidth(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.sin(tr.angle)*h) + Math.abs(Math.cos(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
// return height along the y axis.
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.getHeight = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.cos(tr.angle)*h) + Math.abs(Math.sin(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.getAngleRad = function() {
|
||||
var a = this.angle * Math.PI/180;
|
||||
return a;
|
||||
};
|
||||
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.setTick = function(value, axisName, isMinor) {
|
||||
this.value = value;
|
||||
if (isMinor) {
|
||||
this.isMinorTick = true;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.draw = function(ctx, plot) {
|
||||
if (!this.label) {
|
||||
this.label = this.prefix + this.formatter(this.formatString, this.value);
|
||||
}
|
||||
|
||||
// Memory Leaks patch
|
||||
if (this._elem) {
|
||||
if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
|
||||
window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
|
||||
}
|
||||
|
||||
this._elem.emptyForce();
|
||||
this._elem = null;
|
||||
}
|
||||
|
||||
// create a canvas here, but can't draw on it untill it is appended
|
||||
// to dom for IE compatability.
|
||||
|
||||
var elem = plot.canvasManager.getCanvas();
|
||||
|
||||
this._textRenderer.setText(this.label, ctx);
|
||||
var w = this.getWidth(ctx);
|
||||
var h = this.getHeight(ctx);
|
||||
// canvases seem to need to have width and heigh attributes directly set.
|
||||
elem.width = w;
|
||||
elem.height = h;
|
||||
elem.style.width = w;
|
||||
elem.style.height = h;
|
||||
elem.style.textAlign = 'left';
|
||||
elem.style.position = 'absolute';
|
||||
|
||||
elem = plot.canvasManager.initCanvas(elem);
|
||||
|
||||
this._elem = $(elem);
|
||||
this._elem.css(this._styles);
|
||||
this._elem.addClass('jqplot-'+this.axis+'-tick');
|
||||
|
||||
elem = null;
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.pack = function() {
|
||||
this._textRenderer.draw(this._elem.get(0).getContext("2d"), this.label);
|
||||
};
|
||||
|
||||
})(jQuery);
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4r1121
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2011 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function(a){a.jqplot.CanvasAxisTickRenderer=function(b){this.mark="outside";this.showMark=true;this.showGridline=true;this.isMinorTick=false;this.angle=0;this.markSize=4;this.show=true;this.showLabel=true;this.labelPosition="auto";this.label="";this.value=null;this._styles={};this.formatter=a.jqplot.DefaultTickFormatter;this.formatString="";this.prefix="";this.fontFamily='"Trebuchet MS", Arial, Helvetica, sans-serif';this.fontSize="10pt";this.fontWeight="normal";this.fontStretch=1;this.textColor="#666666";this.enableFontSupport=true;this.pt2px=null;this._elem;this._ctx;this._plotWidth;this._plotHeight;this._plotDimensions={height:null,width:null};a.extend(true,this,b);var c={fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily};if(this.pt2px){c.pt2px=this.pt2px}if(this.enableFontSupport){if(a.jqplot.support_canvas_text()){this._textRenderer=new a.jqplot.CanvasFontRenderer(c)}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}};a.jqplot.CanvasAxisTickRenderer.prototype.init=function(b){a.extend(true,this,b);this._textRenderer.init({fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily})};a.jqplot.CanvasAxisTickRenderer.prototype.getWidth=function(d){if(this._elem){return this._elem.outerWidth(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.sin(f.angle)*e)+Math.abs(Math.cos(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getHeight=function(d){if(this._elem){return this._elem.outerHeight(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.cos(f.angle)*e)+Math.abs(Math.sin(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getAngleRad=function(){var b=this.angle*Math.PI/180;return b};a.jqplot.CanvasAxisTickRenderer.prototype.setTick=function(b,d,c){this.value=b;if(c){this.isMinorTick=true}return this};a.jqplot.CanvasAxisTickRenderer.prototype.draw=function(c,f){if(!this.label){this.label=this.prefix+this.formatter(this.formatString,this.value)}if(this._elem){if(a.jqplot.use_excanvas&&window.G_vmlCanvasManager.uninitElement!==undefined){window.G_vmlCanvasManager.uninitElement(this._elem.get(0))}this._elem.emptyForce();this._elem=null}var e=f.canvasManager.getCanvas();this._textRenderer.setText(this.label,c);var b=this.getWidth(c);var d=this.getHeight(c);e.width=b;e.height=d;e.style.width=b;e.style.height=d;e.style.textAlign="left";e.style.position="absolute";e=f.canvasManager.initCanvas(e);this._elem=a(e);this._elem.css(this._styles);this._elem.addClass("jqplot-"+this.axis+"-tick");e=null;return this._elem};a.jqplot.CanvasAxisTickRenderer.prototype.pack=function(){this._textRenderer.draw(this._elem.get(0).getContext("2d"),this.label)}})(jQuery);
|
@ -1,865 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
var objCounter = 0;
|
||||
// class: $.jqplot.CanvasOverlay
|
||||
$.jqplot.CanvasOverlay = function(opts){
|
||||
var options = opts || {};
|
||||
this.options = {
|
||||
show: $.jqplot.config.enablePlugins,
|
||||
deferDraw: false
|
||||
};
|
||||
// prop: objects
|
||||
this.objects = [];
|
||||
this.objectNames = [];
|
||||
this.canvas = null;
|
||||
this.markerRenderer = new $.jqplot.MarkerRenderer({style:'line'});
|
||||
this.markerRenderer.init();
|
||||
this.highlightObjectIndex = null;
|
||||
if (options.objects) {
|
||||
var objs = options.objects,
|
||||
obj;
|
||||
for (var i=0; i<objs.length; i++) {
|
||||
obj = objs[i];
|
||||
for (var n in obj) {
|
||||
switch (n) {
|
||||
case 'line':
|
||||
this.addLine(obj[n]);
|
||||
break;
|
||||
case 'horizontalLine':
|
||||
this.addHorizontalLine(obj[n]);
|
||||
break;
|
||||
case 'dashedHorizontalLine':
|
||||
this.addDashedHorizontalLine(obj[n]);
|
||||
break;
|
||||
case 'verticalLine':
|
||||
this.addVerticalLine(obj[n]);
|
||||
break;
|
||||
case 'dashedVerticalLine':
|
||||
this.addDashedVerticalLine(obj[n]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$.extend(true, this.options, options);
|
||||
};
|
||||
|
||||
// called with scope of a plot object
|
||||
$.jqplot.CanvasOverlay.postPlotInit = function (target, data, opts) {
|
||||
var options = opts || {};
|
||||
// add a canvasOverlay attribute to the plot
|
||||
this.plugins.canvasOverlay = new $.jqplot.CanvasOverlay(options.canvasOverlay);
|
||||
};
|
||||
|
||||
|
||||
function LineBase() {
|
||||
this.uid = null;
|
||||
this.type = null;
|
||||
this.gridStart = null;
|
||||
this.gridStop = null;
|
||||
this.tooltipWidthFactor = 0;
|
||||
this.options = {
|
||||
// prop: name
|
||||
// Optional name for the overlay object.
|
||||
// Can be later used to retrieve the object by name.
|
||||
name: null,
|
||||
// prop: show
|
||||
// true to show (draw), false to not draw.
|
||||
show: true,
|
||||
// prop: lineWidth
|
||||
// Width of the line.
|
||||
lineWidth: 2,
|
||||
// prop: lineCap
|
||||
// Type of ending placed on the line ['round', 'butt', 'square']
|
||||
lineCap: 'round',
|
||||
// prop: color
|
||||
// color of the line
|
||||
color: '#666666',
|
||||
// prop: shadow
|
||||
// wether or not to draw a shadow on the line
|
||||
shadow: true,
|
||||
// prop: shadowAngle
|
||||
// Shadow angle in degrees
|
||||
shadowAngle: 45,
|
||||
// prop: shadowOffset
|
||||
// Shadow offset from line in pixels
|
||||
shadowOffset: 1,
|
||||
// prop: shadowDepth
|
||||
// Number of times shadow is stroked, each stroke offset shadowOffset from the last.
|
||||
shadowDepth: 3,
|
||||
// prop: shadowAlpha
|
||||
// Alpha channel transparency of shadow. 0 = transparent.
|
||||
shadowAlpha: '0.07',
|
||||
// prop: xaxis
|
||||
// X axis to use for positioning/scaling the line.
|
||||
xaxis: 'xaxis',
|
||||
// prop: yaxis
|
||||
// Y axis to use for positioning/scaling the line.
|
||||
yaxis: 'yaxis',
|
||||
// prop: showTooltip
|
||||
// Show a tooltip with data point values.
|
||||
showTooltip: false,
|
||||
// prop: showTooltipPrecision
|
||||
// Controls how close to line cursor must be to show tooltip.
|
||||
// Higher number = closer to line, lower number = farther from line.
|
||||
// 1.0 = cursor must be over line.
|
||||
showTooltipPrecision: 0.6,
|
||||
// prop: tooltipLocation
|
||||
// Where to position tooltip, 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
|
||||
tooltipLocation: 'nw',
|
||||
// prop: fadeTooltip
|
||||
// true = fade in/out tooltip, flase = show/hide tooltip
|
||||
fadeTooltip: true,
|
||||
// prop: tooltipFadeSpeed
|
||||
// 'slow', 'def', 'fast', or number of milliseconds.
|
||||
tooltipFadeSpeed: "fast",
|
||||
// prop: tooltipOffset
|
||||
// Pixel offset of tooltip from the highlight.
|
||||
tooltipOffset: 4,
|
||||
// prop: tooltipFormatString
|
||||
// Format string passed the x and y values of the cursor on the line.
|
||||
// e.g., 'Dogs: %.2f, Cats: %d'.
|
||||
tooltipFormatString: '%d, %d'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Class: Line
|
||||
* A straight line.
|
||||
*/
|
||||
function Line(options) {
|
||||
LineBase.call(this);
|
||||
this.type = 'line';
|
||||
var opts = {
|
||||
// prop: start
|
||||
// [x, y] coordinates for the start of the line.
|
||||
start: [],
|
||||
// prop: stop
|
||||
// [x, y] coordinates for the end of the line.
|
||||
stop: []
|
||||
};
|
||||
$.extend(true, this.options, opts, options);
|
||||
|
||||
if (this.options.showTooltipPrecision < 0.01) {
|
||||
this.options.showTooltipPrecision = 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
Line.prototype = new LineBase();
|
||||
Line.prototype.constructor = Line;
|
||||
|
||||
|
||||
/**
|
||||
* Class: HorizontalLine
|
||||
* A straight horizontal line.
|
||||
*/
|
||||
function HorizontalLine(options) {
|
||||
LineBase.call(this);
|
||||
this.type = 'horizontalLine';
|
||||
var opts = {
|
||||
// prop: y
|
||||
// y value to position the line
|
||||
y: null,
|
||||
// prop: xmin
|
||||
// x value for the start of the line, null to scale to axis min.
|
||||
xmin: null,
|
||||
// prop: xmax
|
||||
// x value for the end of the line, null to scale to axis max.
|
||||
xmax: null,
|
||||
// prop xOffset
|
||||
// offset ends of the line inside the grid. Number
|
||||
xOffset: '6px', // number or string. Number interpreted as units, string as pixels.
|
||||
xminOffset: null,
|
||||
xmaxOffset: null
|
||||
};
|
||||
$.extend(true, this.options, opts, options);
|
||||
|
||||
if (this.options.showTooltipPrecision < 0.01) {
|
||||
this.options.showTooltipPrecision = 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLine.prototype = new LineBase();
|
||||
HorizontalLine.prototype.constructor = HorizontalLine;
|
||||
|
||||
|
||||
/**
|
||||
* Class: DashedHorizontalLine
|
||||
* A straight dashed horizontal line.
|
||||
*/
|
||||
function DashedHorizontalLine(options) {
|
||||
LineBase.call(this);
|
||||
this.type = 'dashedHorizontalLine';
|
||||
var opts = {
|
||||
y: null,
|
||||
xmin: null,
|
||||
xmax: null,
|
||||
xOffset: '6px', // number or string. Number interpreted as units, string as pixels.
|
||||
xminOffset: null,
|
||||
xmaxOffset: null,
|
||||
// prop: dashPattern
|
||||
// Array of line, space settings in pixels.
|
||||
// Default is 8 pixel of line, 8 pixel of space.
|
||||
// Note, limit to a 2 element array b/c of bug with higher order arrays.
|
||||
dashPattern: [8,8]
|
||||
};
|
||||
$.extend(true, this.options, opts, options);
|
||||
|
||||
if (this.options.showTooltipPrecision < 0.01) {
|
||||
this.options.showTooltipPrecision = 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
DashedHorizontalLine.prototype = new LineBase();
|
||||
DashedHorizontalLine.prototype.constructor = DashedHorizontalLine;
|
||||
|
||||
|
||||
/**
|
||||
* Class: VerticalLine
|
||||
* A straight vertical line.
|
||||
*/
|
||||
function VerticalLine(options) {
|
||||
LineBase.call(this);
|
||||
this.type = 'verticalLine';
|
||||
var opts = {
|
||||
x: null,
|
||||
ymin: null,
|
||||
ymax: null,
|
||||
yOffset: '6px', // number or string. Number interpreted as units, string as pixels.
|
||||
yminOffset: null,
|
||||
ymaxOffset: null
|
||||
};
|
||||
$.extend(true, this.options, opts, options);
|
||||
|
||||
if (this.options.showTooltipPrecision < 0.01) {
|
||||
this.options.showTooltipPrecision = 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
VerticalLine.prototype = new LineBase();
|
||||
VerticalLine.prototype.constructor = VerticalLine;
|
||||
|
||||
|
||||
/**
|
||||
* Class: DashedVerticalLine
|
||||
* A straight dashed vertical line.
|
||||
*/
|
||||
function DashedVerticalLine(options) {
|
||||
LineBase.call(this);
|
||||
this.type = 'dashedVerticalLine';
|
||||
this.start = null;
|
||||
this.stop = null;
|
||||
var opts = {
|
||||
x: null,
|
||||
ymin: null,
|
||||
ymax: null,
|
||||
yOffset: '6px', // number or string. Number interpreted as units, string as pixels.
|
||||
yminOffset: null,
|
||||
ymaxOffset: null,
|
||||
// prop: dashPattern
|
||||
// Array of line, space settings in pixels.
|
||||
// Default is 8 pixel of line, 8 pixel of space.
|
||||
// Note, limit to a 2 element array b/c of bug with higher order arrays.
|
||||
dashPattern: [8,8]
|
||||
};
|
||||
$.extend(true, this.options, opts, options);
|
||||
|
||||
if (this.options.showTooltipPrecision < 0.01) {
|
||||
this.options.showTooltipPrecision = 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
DashedVerticalLine.prototype = new LineBase();
|
||||
DashedVerticalLine.prototype.constructor = DashedVerticalLine;
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.addLine = function(opts) {
|
||||
var line = new Line(opts);
|
||||
line.uid = objCounter++;
|
||||
this.objects.push(line);
|
||||
this.objectNames.push(line.options.name);
|
||||
};
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.addHorizontalLine = function(opts) {
|
||||
var line = new HorizontalLine(opts);
|
||||
line.uid = objCounter++;
|
||||
this.objects.push(line);
|
||||
this.objectNames.push(line.options.name);
|
||||
};
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.addDashedHorizontalLine = function(opts) {
|
||||
var line = new DashedHorizontalLine(opts);
|
||||
line.uid = objCounter++;
|
||||
this.objects.push(line);
|
||||
this.objectNames.push(line.options.name);
|
||||
};
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.addVerticalLine = function(opts) {
|
||||
var line = new VerticalLine(opts);
|
||||
line.uid = objCounter++;
|
||||
this.objects.push(line);
|
||||
this.objectNames.push(line.options.name);
|
||||
};
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.addDashedVerticalLine = function(opts) {
|
||||
var line = new DashedVerticalLine(opts);
|
||||
line.uid = objCounter++;
|
||||
this.objects.push(line);
|
||||
this.objectNames.push(line.options.name);
|
||||
};
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.removeObject = function(idx) {
|
||||
// check if integer, remove by index
|
||||
if ($.type(idx) == 'number') {
|
||||
this.objects.splice(idx, 1);
|
||||
this.objectNames.splice(idx, 1);
|
||||
}
|
||||
// if string, remove by name
|
||||
else {
|
||||
var id = $.inArray(idx, this.objectNames);
|
||||
if (id != -1) {
|
||||
this.objects.splice(id, 1);
|
||||
this.objectNames.splice(id, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.getObject = function(idx) {
|
||||
// check if integer, remove by index
|
||||
if ($.type(idx) == 'number') {
|
||||
return this.objects[idx];
|
||||
}
|
||||
// if string, remove by name
|
||||
else {
|
||||
var id = $.inArray(idx, this.objectNames);
|
||||
if (id != -1) {
|
||||
return this.objects[id];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Set get as alias for getObject.
|
||||
$.jqplot.CanvasOverlay.prototype.get = $.jqplot.CanvasOverlay.prototype.getObject;
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.clear = function(plot) {
|
||||
this.canvas._ctx.clearRect(0,0,this.canvas.getWidth(), this.canvas.getHeight());
|
||||
};
|
||||
|
||||
$.jqplot.CanvasOverlay.prototype.draw = function(plot) {
|
||||
var obj,
|
||||
objs = this.objects,
|
||||
mr = this.markerRenderer,
|
||||
start,
|
||||
stop;
|
||||
if (this.options.show) {
|
||||
this.canvas._ctx.clearRect(0,0,this.canvas.getWidth(), this.canvas.getHeight());
|
||||
for (var k=0; k<objs.length; k++) {
|
||||
obj = objs[k];
|
||||
var opts = $.extend(true, {}, obj.options);
|
||||
if (obj.options.show) {
|
||||
// style and shadow properties should be set before
|
||||
// every draw of marker renderer.
|
||||
mr.shadow = obj.options.shadow;
|
||||
obj.tooltipWidthFactor = obj.options.lineWidth / obj.options.showTooltipPrecision;
|
||||
switch (obj.type) {
|
||||
case 'line':
|
||||
// style and shadow properties should be set before
|
||||
// every draw of marker renderer.
|
||||
mr.style = 'line';
|
||||
opts.closePath = false;
|
||||
start = [plot.axes[obj.options.xaxis].series_u2p(obj.options.start[0]), plot.axes[obj.options.yaxis].series_u2p(obj.options.start[1])];
|
||||
stop = [plot.axes[obj.options.xaxis].series_u2p(obj.options.stop[0]), plot.axes[obj.options.yaxis].series_u2p(obj.options.stop[1])];
|
||||
obj.gridStart = start;
|
||||
obj.gridStop = stop;
|
||||
mr.draw(start, stop, this.canvas._ctx, opts);
|
||||
break;
|
||||
case 'horizontalLine':
|
||||
|
||||
// style and shadow properties should be set before
|
||||
// every draw of marker renderer.
|
||||
if (obj.options.y != null) {
|
||||
mr.style = 'line';
|
||||
opts.closePath = false;
|
||||
var xaxis = plot.axes[obj.options.xaxis],
|
||||
xstart,
|
||||
xstop,
|
||||
y = plot.axes[obj.options.yaxis].series_u2p(obj.options.y),
|
||||
xminoff = obj.options.xminOffset || obj.options.xOffset,
|
||||
xmaxoff = obj.options.xmaxOffset || obj.options.xOffset;
|
||||
if (obj.options.xmin != null) {
|
||||
xstart = xaxis.series_u2p(obj.options.xmin);
|
||||
}
|
||||
else if (xminoff != null) {
|
||||
if ($.type(xminoff) == "number") {
|
||||
xstart = xaxis.series_u2p(xaxis.min + xminoff);
|
||||
}
|
||||
else if ($.type(xminoff) == "string") {
|
||||
xstart = xaxis.series_u2p(xaxis.min) + parseFloat(xminoff);
|
||||
}
|
||||
}
|
||||
if (obj.options.xmax != null) {
|
||||
xstop = xaxis.series_u2p(obj.options.xmax);
|
||||
}
|
||||
else if (xmaxoff != null) {
|
||||
if ($.type(xmaxoff) == "number") {
|
||||
xstop = xaxis.series_u2p(xaxis.max - xmaxoff);
|
||||
}
|
||||
else if ($.type(xmaxoff) == "string") {
|
||||
xstop = xaxis.series_u2p(xaxis.max) - parseFloat(xmaxoff);
|
||||
}
|
||||
}
|
||||
if (xstop != null && xstart != null) {
|
||||
obj.gridStart = [xstart, y];
|
||||
obj.gridStop = [xstop, y];
|
||||
mr.draw([xstart, y], [xstop, y], this.canvas._ctx, opts);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'dashedHorizontalLine':
|
||||
|
||||
var dashPat = obj.options.dashPattern;
|
||||
var dashPatLen = 0;
|
||||
for (var i=0; i<dashPat.length; i++) {
|
||||
dashPatLen += dashPat[i];
|
||||
}
|
||||
|
||||
// style and shadow properties should be set before
|
||||
// every draw of marker renderer.
|
||||
if (obj.options.y != null) {
|
||||
mr.style = 'line';
|
||||
opts.closePath = false;
|
||||
var xaxis = plot.axes[obj.options.xaxis],
|
||||
xstart,
|
||||
xstop,
|
||||
y = plot.axes[obj.options.yaxis].series_u2p(obj.options.y),
|
||||
xminoff = obj.options.xminOffset || obj.options.xOffset,
|
||||
xmaxoff = obj.options.xmaxOffset || obj.options.xOffset;
|
||||
if (obj.options.xmin != null) {
|
||||
xstart = xaxis.series_u2p(obj.options.xmin);
|
||||
}
|
||||
else if (xminoff != null) {
|
||||
if ($.type(xminoff) == "number") {
|
||||
xstart = xaxis.series_u2p(xaxis.min + xminoff);
|
||||
}
|
||||
else if ($.type(xminoff) == "string") {
|
||||
xstart = xaxis.series_u2p(xaxis.min) + parseFloat(xminoff);
|
||||
}
|
||||
}
|
||||
if (obj.options.xmax != null) {
|
||||
xstop = xaxis.series_u2p(obj.options.xmax);
|
||||
}
|
||||
else if (xmaxoff != null) {
|
||||
if ($.type(xmaxoff) == "number") {
|
||||
xstop = xaxis.series_u2p(xaxis.max - xmaxoff);
|
||||
}
|
||||
else if ($.type(xmaxoff) == "string") {
|
||||
xstop = xaxis.series_u2p(xaxis.max) - parseFloat(xmaxoff);
|
||||
}
|
||||
}
|
||||
if (xstop != null && xstart != null) {
|
||||
obj.gridStart = [xstart, y];
|
||||
obj.gridStop = [xstop, y];
|
||||
var numDash = Math.ceil((xstop - xstart)/dashPatLen);
|
||||
var b=xstart, e;
|
||||
for (var i=0; i<numDash; i++) {
|
||||
for (var j=0; j<dashPat.length; j+=2) {
|
||||
e = b+dashPat[j];
|
||||
mr.draw([b, y], [e, y], this.canvas._ctx, opts);
|
||||
b += dashPat[j];
|
||||
if (j < dashPat.length-1) {
|
||||
b += dashPat[j+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'verticalLine':
|
||||
|
||||
// style and shadow properties should be set before
|
||||
// every draw of marker renderer.
|
||||
if (obj.options.x != null) {
|
||||
mr.style = 'line';
|
||||
opts.closePath = false;
|
||||
var yaxis = plot.axes[obj.options.yaxis],
|
||||
ystart,
|
||||
ystop,
|
||||
x = plot.axes[obj.options.xaxis].series_u2p(obj.options.x),
|
||||
yminoff = obj.options.yminOffset || obj.options.yOffset,
|
||||
ymaxoff = obj.options.ymaxOffset || obj.options.yOffset;
|
||||
if (obj.options.ymin != null) {
|
||||
ystart = yaxis.series_u2p(obj.options.ymin);
|
||||
}
|
||||
else if (yminoff != null) {
|
||||
if ($.type(yminoff) == "number") {
|
||||
ystart = yaxis.series_u2p(yaxis.min - yminoff);
|
||||
}
|
||||
else if ($.type(yminoff) == "string") {
|
||||
ystart = yaxis.series_u2p(yaxis.min) - parseFloat(yminoff);
|
||||
}
|
||||
}
|
||||
if (obj.options.ymax != null) {
|
||||
ystop = yaxis.series_u2p(obj.options.ymax);
|
||||
}
|
||||
else if (ymaxoff != null) {
|
||||
if ($.type(ymaxoff) == "number") {
|
||||
ystop = yaxis.series_u2p(yaxis.max + ymaxoff);
|
||||
}
|
||||
else if ($.type(ymaxoff) == "string") {
|
||||
ystop = yaxis.series_u2p(yaxis.max) + parseFloat(ymaxoff);
|
||||
}
|
||||
}
|
||||
if (ystop != null && ystart != null) {
|
||||
obj.gridStart = [x, ystart];
|
||||
obj.gridStop = [x, ystop];
|
||||
mr.draw([x, ystart], [x, ystop], this.canvas._ctx, opts);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'dashedVerticalLine':
|
||||
|
||||
var dashPat = obj.options.dashPattern;
|
||||
var dashPatLen = 0;
|
||||
for (var i=0; i<dashPat.length; i++) {
|
||||
dashPatLen += dashPat[i];
|
||||
}
|
||||
|
||||
// style and shadow properties should be set before
|
||||
// every draw of marker renderer.
|
||||
if (obj.options.x != null) {
|
||||
mr.style = 'line';
|
||||
opts.closePath = false;
|
||||
var yaxis = plot.axes[obj.options.yaxis],
|
||||
ystart,
|
||||
ystop,
|
||||
x = plot.axes[obj.options.xaxis].series_u2p(obj.options.x),
|
||||
yminoff = obj.options.yminOffset || obj.options.yOffset,
|
||||
ymaxoff = obj.options.ymaxOffset || obj.options.yOffset;
|
||||
if (obj.options.ymin != null) {
|
||||
ystart = yaxis.series_u2p(obj.options.ymin);
|
||||
}
|
||||
else if (yminoff != null) {
|
||||
if ($.type(yminoff) == "number") {
|
||||
ystart = yaxis.series_u2p(yaxis.min - yminoff);
|
||||
}
|
||||
else if ($.type(yminoff) == "string") {
|
||||
ystart = yaxis.series_u2p(yaxis.min) - parseFloat(yminoff);
|
||||
}
|
||||
}
|
||||
if (obj.options.ymax != null) {
|
||||
ystop = yaxis.series_u2p(obj.options.ymax);
|
||||
}
|
||||
else if (ymaxoff != null) {
|
||||
if ($.type(ymaxoff) == "number") {
|
||||
ystop = yaxis.series_u2p(yaxis.max + ymaxoff);
|
||||
}
|
||||
else if ($.type(ymaxoff) == "string") {
|
||||
ystop = yaxis.series_u2p(yaxis.max) + parseFloat(ymaxoff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ystop != null && ystart != null) {
|
||||
obj.gridStart = [x, ystart];
|
||||
obj.gridStop = [x, ystop];
|
||||
var numDash = Math.ceil((ystart - ystop)/dashPatLen);
|
||||
var firstDashAdjust = ((numDash * dashPatLen) - (ystart - ystop))/2.0;
|
||||
var b=ystart, e, bs, es;
|
||||
for (var i=0; i<numDash; i++) {
|
||||
for (var j=0; j<dashPat.length; j+=2) {
|
||||
e = b - dashPat[j];
|
||||
if (e < ystop) {
|
||||
e = ystop;
|
||||
}
|
||||
if (b < ystop) {
|
||||
b = ystop;
|
||||
}
|
||||
// es = e;
|
||||
// if (i == 0) {
|
||||
// es += firstDashAdjust;
|
||||
// }
|
||||
mr.draw([x, b], [x, e], this.canvas._ctx, opts);
|
||||
b -= dashPat[j];
|
||||
if (j < dashPat.length-1) {
|
||||
b -= dashPat[j+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
$.jqplot.CanvasOverlay.postPlotDraw = function() {
|
||||
var co = this.plugins.canvasOverlay;
|
||||
// Memory Leaks patch
|
||||
if (co && co.highlightCanvas) {
|
||||
co.highlightCanvas.resetCanvas();
|
||||
co.highlightCanvas = null;
|
||||
}
|
||||
co.canvas = new $.jqplot.GenericCanvas();
|
||||
|
||||
this.eventCanvas._elem.before(co.canvas.createElement(this._gridPadding, 'jqplot-overlayCanvas-canvas', this._plotDimensions, this));
|
||||
co.canvas.setContext();
|
||||
if (!co.deferDraw) {
|
||||
co.draw(this);
|
||||
}
|
||||
|
||||
var elem = document.createElement('div');
|
||||
co._tooltipElem = $(elem);
|
||||
elem = null;
|
||||
co._tooltipElem.addClass('jqplot-canvasOverlay-tooltip');
|
||||
co._tooltipElem.css({position:'absolute', display:'none'});
|
||||
|
||||
this.eventCanvas._elem.before(co._tooltipElem);
|
||||
this.eventCanvas._elem.bind('mouseleave', { elem: co._tooltipElem }, function (ev) { ev.data.elem.hide(); });
|
||||
|
||||
var co = null;
|
||||
};
|
||||
|
||||
|
||||
function showTooltip(plot, obj, gridpos, datapos) {
|
||||
var co = plot.plugins.canvasOverlay;
|
||||
var elem = co._tooltipElem;
|
||||
|
||||
var opts = obj.options, x, y;
|
||||
|
||||
elem.html($.jqplot.sprintf(opts.tooltipFormatString, datapos[0], datapos[1]));
|
||||
|
||||
switch (opts.tooltipLocation) {
|
||||
case 'nw':
|
||||
x = gridpos[0] + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset;
|
||||
y = gridpos[1] + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true);
|
||||
break;
|
||||
case 'n':
|
||||
x = gridpos[0] + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
y = gridpos[1] + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true);
|
||||
break;
|
||||
case 'ne':
|
||||
x = gridpos[0] + plot._gridPadding.left + opts.tooltipOffset;
|
||||
y = gridpos[1] + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true);
|
||||
break;
|
||||
case 'e':
|
||||
x = gridpos[0] + plot._gridPadding.left + opts.tooltipOffset;
|
||||
y = gridpos[1] + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
case 'se':
|
||||
x = gridpos[0] + plot._gridPadding.left + opts.tooltipOffset;
|
||||
y = gridpos[1] + plot._gridPadding.top + opts.tooltipOffset;
|
||||
break;
|
||||
case 's':
|
||||
x = gridpos[0] + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
y = gridpos[1] + plot._gridPadding.top + opts.tooltipOffset;
|
||||
break;
|
||||
case 'sw':
|
||||
x = gridpos[0] + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset;
|
||||
y = gridpos[1] + plot._gridPadding.top + opts.tooltipOffset;
|
||||
break;
|
||||
case 'w':
|
||||
x = gridpos[0] + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset;
|
||||
y = gridpos[1] + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
default: // same as 'nw'
|
||||
x = gridpos[0] + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset;
|
||||
y = gridpos[1] + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true);
|
||||
break;
|
||||
}
|
||||
|
||||
elem.css('left', x);
|
||||
elem.css('top', y);
|
||||
if (opts.fadeTooltip) {
|
||||
// Fix for stacked up animations. Thnanks Trevor!
|
||||
elem.stop(true,true).fadeIn(opts.tooltipFadeSpeed);
|
||||
}
|
||||
else {
|
||||
elem.show();
|
||||
}
|
||||
elem = null;
|
||||
}
|
||||
|
||||
|
||||
function isNearLine(point, lstart, lstop, width) {
|
||||
// r is point to test, p and q are end points.
|
||||
var rx = point[0];
|
||||
var ry = point[1];
|
||||
var px = Math.round(lstop[0]);
|
||||
var py = Math.round(lstop[1]);
|
||||
var qx = Math.round(lstart[0]);
|
||||
var qy = Math.round(lstart[1]);
|
||||
|
||||
var l = Math.sqrt(Math.pow(px-qx, 2) + Math.pow(py-qy, 2));
|
||||
|
||||
// scale error term by length of line.
|
||||
var eps = width*l;
|
||||
var res = Math.abs((qx-px) * (ry-py) - (qy-py) * (rx-px));
|
||||
var ret = (res < eps) ? true : false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
var co = plot.plugins.canvasOverlay;
|
||||
var objs = co.objects;
|
||||
var l = objs.length;
|
||||
var obj, haveHighlight=false;
|
||||
var elem;
|
||||
for (var i=0; i<l; i++) {
|
||||
obj = objs[i];
|
||||
if (obj.options.showTooltip) {
|
||||
var n = isNearLine([gridpos.x, gridpos.y], obj.gridStart, obj.gridStop, obj.tooltipWidthFactor);
|
||||
datapos = [plot.axes[obj.options.xaxis].series_p2u(gridpos.x), plot.axes[obj.options.yaxis].series_p2u(gridpos.y)];
|
||||
|
||||
// cases:
|
||||
// near line, no highlighting
|
||||
// near line, highliting on this line
|
||||
// near line, highlighting another line
|
||||
// not near any line, highlighting
|
||||
// not near any line, no highlighting
|
||||
|
||||
// near line, not currently highlighting
|
||||
if (n && co.highlightObjectIndex == null) {
|
||||
switch (obj.type) {
|
||||
case 'line':
|
||||
showTooltip(plot, obj, [gridpos.x, gridpos.y], datapos);
|
||||
break;
|
||||
|
||||
case 'horizontalLine':
|
||||
case 'dashedHorizontalLine':
|
||||
showTooltip(plot, obj, [gridpos.x, obj.gridStart[1]], [datapos[0], obj.options.y]);
|
||||
break;
|
||||
|
||||
case 'verticalLine':
|
||||
case 'dashedVerticalLine':
|
||||
showTooltip(plot, obj, [obj.gridStart[0], gridpos.y], [obj.options.x, datapos[1]]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
co.highlightObjectIndex = i;
|
||||
haveHighlight = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// near line, highlighting another line.
|
||||
else if (n && co.highlightObjectIndex !== i) {
|
||||
// turn off tooltip.
|
||||
elem = co._tooltipElem;
|
||||
if (obj.fadeTooltip) {
|
||||
elem.fadeOut(obj.tooltipFadeSpeed);
|
||||
}
|
||||
else {
|
||||
elem.hide();
|
||||
}
|
||||
|
||||
// turn on right tooltip.
|
||||
switch (obj.type) {
|
||||
case 'line':
|
||||
showTooltip(plot, obj, [gridpos.x, gridpos.y], datapos);
|
||||
break;
|
||||
|
||||
case 'horizontalLine':
|
||||
case 'dashedHorizontalLine':
|
||||
showTooltip(plot, obj, [gridpos.x, obj.gridStart[1]], [datapos[0], obj.options.y]);
|
||||
break;
|
||||
|
||||
case 'verticalLine':
|
||||
case 'dashedVerticalLine':
|
||||
showTooltip(plot, obj, [obj.gridStart[0], gridpos.y], [obj.options.x, datapos[1]]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
co.highlightObjectIndex = i;
|
||||
haveHighlight = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// near line, already highlighting this line, update
|
||||
else if (n) {
|
||||
switch (obj.type) {
|
||||
case 'line':
|
||||
showTooltip(plot, obj, [gridpos.x, gridpos.y], datapos);
|
||||
break;
|
||||
|
||||
case 'horizontalLine':
|
||||
case 'dashedHorizontalLine':
|
||||
showTooltip(plot, obj, [gridpos.x, obj.gridStart[1]], [datapos[0], obj.options.y]);
|
||||
break;
|
||||
|
||||
case 'verticalLine':
|
||||
case 'dashedVerticalLine':
|
||||
showTooltip(plot, obj, [obj.gridStart[0], gridpos.y], [obj.options.x, datapos[1]]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
haveHighlight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if we are highlighting and not near a line, turn it off.
|
||||
if (!haveHighlight && co.highlightObjectIndex !== null) {
|
||||
elem = co._tooltipElem;
|
||||
obj = co.getObject(co.highlightObjectIndex);
|
||||
if (obj.fadeTooltip) {
|
||||
elem.fadeOut(obj.tooltipFadeSpeed);
|
||||
}
|
||||
else {
|
||||
elem.hide();
|
||||
}
|
||||
co.highlightObjectIndex = null;
|
||||
}
|
||||
}
|
||||
|
||||
$.jqplot.postInitHooks.push($.jqplot.CanvasOverlay.postPlotInit);
|
||||
$.jqplot.postDrawHooks.push($.jqplot.CanvasOverlay.postPlotDraw);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -1,449 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2012 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
// This code is a modified version of the canvastext.js code, copyright below:
|
||||
//
|
||||
// This code is released to the public domain by Jim Studt, 2007.
|
||||
// He may keep some sort of up to date copy at http://www.federated.com/~jim/canvastext/
|
||||
//
|
||||
$.jqplot.CanvasTextRenderer = function(options){
|
||||
this.fontStyle = 'normal'; // normal, italic, oblique [not implemented]
|
||||
this.fontVariant = 'normal'; // normal, small caps [not implemented]
|
||||
this.fontWeight = 'normal'; // normal, bold, bolder, lighter, 100 - 900
|
||||
this.fontSize = '10px';
|
||||
this.fontFamily = 'sans-serif';
|
||||
this.fontStretch = 1.0;
|
||||
this.fillStyle = '#666666';
|
||||
this.angle = 0;
|
||||
this.textAlign = 'start';
|
||||
this.textBaseline = 'alphabetic';
|
||||
this.text;
|
||||
this.width;
|
||||
this.height;
|
||||
this.pt2px = 1.28;
|
||||
|
||||
$.extend(true, this, options);
|
||||
this.normalizedFontSize = this.normalizeFontSize(this.fontSize);
|
||||
this.setHeight();
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.init = function(options) {
|
||||
$.extend(true, this, options);
|
||||
this.normalizedFontSize = this.normalizeFontSize(this.fontSize);
|
||||
this.setHeight();
|
||||
};
|
||||
|
||||
// convert css spec into point size
|
||||
// returns float
|
||||
$.jqplot.CanvasTextRenderer.prototype.normalizeFontSize = function(sz) {
|
||||
sz = String(sz);
|
||||
var n = parseFloat(sz);
|
||||
if (sz.indexOf('px') > -1) {
|
||||
return n/this.pt2px;
|
||||
}
|
||||
else if (sz.indexOf('pt') > -1) {
|
||||
return n;
|
||||
}
|
||||
else if (sz.indexOf('em') > -1) {
|
||||
return n*12;
|
||||
}
|
||||
else if (sz.indexOf('%') > -1) {
|
||||
return n*12/100;
|
||||
}
|
||||
// default to pixels;
|
||||
else {
|
||||
return n/this.pt2px;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.fontWeight2Float = function(w) {
|
||||
// w = normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
||||
// return values adjusted for Hershey font.
|
||||
if (Number(w)) {
|
||||
return w/400;
|
||||
}
|
||||
else {
|
||||
switch (w) {
|
||||
case 'normal':
|
||||
return 1;
|
||||
break;
|
||||
case 'bold':
|
||||
return 1.75;
|
||||
break;
|
||||
case 'bolder':
|
||||
return 2.25;
|
||||
break;
|
||||
case 'lighter':
|
||||
return 0.75;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.getText = function() {
|
||||
return this.text;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.setText = function(t, ctx) {
|
||||
this.text = t;
|
||||
this.setWidth(ctx);
|
||||
return this;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.getWidth = function(ctx) {
|
||||
return this.width;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.setWidth = function(ctx, w) {
|
||||
if (!w) {
|
||||
this.width = this.measure(ctx, this.text);
|
||||
}
|
||||
else {
|
||||
this.width = w;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
// return height in pixels.
|
||||
$.jqplot.CanvasTextRenderer.prototype.getHeight = function(ctx) {
|
||||
return this.height;
|
||||
};
|
||||
|
||||
// w - height in pt
|
||||
// set heigh in px
|
||||
$.jqplot.CanvasTextRenderer.prototype.setHeight = function(w) {
|
||||
if (!w) {
|
||||
//height = this.fontSize /0.75;
|
||||
this.height = this.normalizedFontSize * this.pt2px;
|
||||
}
|
||||
else {
|
||||
this.height = w;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.letter = function (ch)
|
||||
{
|
||||
return this.letters[ch];
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.ascent = function()
|
||||
{
|
||||
return this.normalizedFontSize;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.descent = function()
|
||||
{
|
||||
return 7.0*this.normalizedFontSize/25.0;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.measure = function(ctx, str)
|
||||
{
|
||||
var total = 0;
|
||||
var len = str.length;
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
var c = this.letter(str.charAt(i));
|
||||
if (c) {
|
||||
total += c.width * this.normalizedFontSize / 25.0 * this.fontStretch;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.draw = function(ctx,str)
|
||||
{
|
||||
var x = 0;
|
||||
// leave room at bottom for descenders.
|
||||
var y = this.height*0.72;
|
||||
var total = 0;
|
||||
var len = str.length;
|
||||
var mag = this.normalizedFontSize / 25.0;
|
||||
|
||||
ctx.save();
|
||||
var tx, ty;
|
||||
|
||||
// 1st quadrant
|
||||
if ((-Math.PI/2 <= this.angle && this.angle <= 0) || (Math.PI*3/2 <= this.angle && this.angle <= Math.PI*2)) {
|
||||
tx = 0;
|
||||
ty = -Math.sin(this.angle) * this.width;
|
||||
}
|
||||
// 4th quadrant
|
||||
else if ((0 < this.angle && this.angle <= Math.PI/2) || (-Math.PI*2 <= this.angle && this.angle <= -Math.PI*3/2)) {
|
||||
tx = Math.sin(this.angle) * this.height;
|
||||
ty = 0;
|
||||
}
|
||||
// 2nd quadrant
|
||||
else if ((-Math.PI < this.angle && this.angle < -Math.PI/2) || (Math.PI <= this.angle && this.angle <= Math.PI*3/2)) {
|
||||
tx = -Math.cos(this.angle) * this.width;
|
||||
ty = -Math.sin(this.angle) * this.width - Math.cos(this.angle) * this.height;
|
||||
}
|
||||
// 3rd quadrant
|
||||
else if ((-Math.PI*3/2 < this.angle && this.angle < Math.PI) || (Math.PI/2 < this.angle && this.angle < Math.PI)) {
|
||||
tx = Math.sin(this.angle) * this.height - Math.cos(this.angle)*this.width;
|
||||
ty = -Math.cos(this.angle) * this.height;
|
||||
}
|
||||
|
||||
ctx.strokeStyle = this.fillStyle;
|
||||
ctx.fillStyle = this.fillStyle;
|
||||
ctx.translate(tx, ty);
|
||||
ctx.rotate(this.angle);
|
||||
ctx.lineCap = "round";
|
||||
// multiplier was 2.0
|
||||
var fact = (this.normalizedFontSize > 30) ? 2.0 : 2 + (30 - this.normalizedFontSize)/20;
|
||||
ctx.lineWidth = fact * mag * this.fontWeight2Float(this.fontWeight);
|
||||
|
||||
for ( var i = 0; i < len; i++) {
|
||||
var c = this.letter( str.charAt(i));
|
||||
if ( !c) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx.beginPath();
|
||||
|
||||
var penUp = 1;
|
||||
var needStroke = 0;
|
||||
for ( var j = 0; j < c.points.length; j++) {
|
||||
var a = c.points[j];
|
||||
if ( a[0] == -1 && a[1] == -1) {
|
||||
penUp = 1;
|
||||
continue;
|
||||
}
|
||||
if ( penUp) {
|
||||
ctx.moveTo( x + a[0]*mag*this.fontStretch, y - a[1]*mag);
|
||||
penUp = false;
|
||||
} else {
|
||||
ctx.lineTo( x + a[0]*mag*this.fontStretch, y - a[1]*mag);
|
||||
}
|
||||
}
|
||||
ctx.stroke();
|
||||
x += c.width*mag*this.fontStretch;
|
||||
}
|
||||
ctx.restore();
|
||||
return total;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.letters = {
|
||||
' ': { width: 16, points: [] },
|
||||
'!': { width: 10, points: [[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]] },
|
||||
'"': { width: 16, points: [[4,21],[4,14],[-1,-1],[12,21],[12,14]] },
|
||||
'#': { width: 21, points: [[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]] },
|
||||
'$': { width: 20, points: [[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]] },
|
||||
'%': { width: 24, points: [[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]] },
|
||||
'&': { width: 26, points: [[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]] },
|
||||
'\'': { width: 10, points: [[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]] },
|
||||
'(': { width: 14, points: [[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]] },
|
||||
')': { width: 14, points: [[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]] },
|
||||
'*': { width: 16, points: [[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]] },
|
||||
'+': { width: 26, points: [[13,18],[13,0],[-1,-1],[4,9],[22,9]] },
|
||||
',': { width: 10, points: [[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]] },
|
||||
'-': { width: 18, points: [[6,9],[12,9]] },
|
||||
'.': { width: 10, points: [[5,2],[4,1],[5,0],[6,1],[5,2]] },
|
||||
'/': { width: 22, points: [[20,25],[2,-7]] },
|
||||
'0': { width: 20, points: [[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]] },
|
||||
'1': { width: 20, points: [[6,17],[8,18],[11,21],[11,0]] },
|
||||
'2': { width: 20, points: [[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]] },
|
||||
'3': { width: 20, points: [[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]] },
|
||||
'4': { width: 20, points: [[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]] },
|
||||
'5': { width: 20, points: [[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]] },
|
||||
'6': { width: 20, points: [[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]] },
|
||||
'7': { width: 20, points: [[17,21],[7,0],[-1,-1],[3,21],[17,21]] },
|
||||
'8': { width: 20, points: [[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]] },
|
||||
'9': { width: 20, points: [[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]] },
|
||||
':': { width: 10, points: [[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]] },
|
||||
';': { width: 10, points: [[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]] },
|
||||
'<': { width: 24, points: [[20,18],[4,9],[20,0]] },
|
||||
'=': { width: 26, points: [[4,12],[22,12],[-1,-1],[4,6],[22,6]] },
|
||||
'>': { width: 24, points: [[4,18],[20,9],[4,0]] },
|
||||
'?': { width: 18, points: [[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]] },
|
||||
'@': { width: 27, points: [[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]] },
|
||||
'A': { width: 18, points: [[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]] },
|
||||
'B': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]] },
|
||||
'C': { width: 21, points: [[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]] },
|
||||
'D': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]] },
|
||||
'E': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]] },
|
||||
'F': { width: 18, points: [[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]] },
|
||||
'G': { width: 21, points: [[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]] },
|
||||
'H': { width: 22, points: [[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]] },
|
||||
'I': { width: 8, points: [[4,21],[4,0]] },
|
||||
'J': { width: 16, points: [[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]] },
|
||||
'K': { width: 21, points: [[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]] },
|
||||
'L': { width: 17, points: [[4,21],[4,0],[-1,-1],[4,0],[16,0]] },
|
||||
'M': { width: 24, points: [[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]] },
|
||||
'N': { width: 22, points: [[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]] },
|
||||
'O': { width: 22, points: [[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]] },
|
||||
'P': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]] },
|
||||
'Q': { width: 22, points: [[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]] },
|
||||
'R': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]] },
|
||||
'S': { width: 20, points: [[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]] },
|
||||
'T': { width: 16, points: [[8,21],[8,0],[-1,-1],[1,21],[15,21]] },
|
||||
'U': { width: 22, points: [[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]] },
|
||||
'V': { width: 18, points: [[1,21],[9,0],[-1,-1],[17,21],[9,0]] },
|
||||
'W': { width: 24, points: [[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]] },
|
||||
'X': { width: 20, points: [[3,21],[17,0],[-1,-1],[17,21],[3,0]] },
|
||||
'Y': { width: 18, points: [[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]] },
|
||||
'Z': { width: 20, points: [[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]] },
|
||||
'[': { width: 14, points: [[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]] },
|
||||
'\\': { width: 14, points: [[0,21],[14,-3]] },
|
||||
']': { width: 14, points: [[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]] },
|
||||
'^': { width: 16, points: [[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]] },
|
||||
'_': { width: 16, points: [[0,-2],[16,-2]] },
|
||||
'`': { width: 10, points: [[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]] },
|
||||
'a': { width: 19, points: [[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'b': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]] },
|
||||
'c': { width: 18, points: [[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'd': { width: 19, points: [[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'e': { width: 18, points: [[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'f': { width: 12, points: [[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]] },
|
||||
'g': { width: 19, points: [[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'h': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]] },
|
||||
'i': { width: 8, points: [[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]] },
|
||||
'j': { width: 10, points: [[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]] },
|
||||
'k': { width: 17, points: [[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]] },
|
||||
'l': { width: 8, points: [[4,21],[4,0]] },
|
||||
'm': { width: 30, points: [[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]] },
|
||||
'n': { width: 19, points: [[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]] },
|
||||
'o': { width: 19, points: [[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]] },
|
||||
'p': { width: 19, points: [[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]] },
|
||||
'q': { width: 19, points: [[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'r': { width: 13, points: [[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]] },
|
||||
's': { width: 17, points: [[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]] },
|
||||
't': { width: 12, points: [[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]] },
|
||||
'u': { width: 19, points: [[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]] },
|
||||
'v': { width: 16, points: [[2,14],[8,0],[-1,-1],[14,14],[8,0]] },
|
||||
'w': { width: 22, points: [[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]] },
|
||||
'x': { width: 17, points: [[3,14],[14,0],[-1,-1],[14,14],[3,0]] },
|
||||
'y': { width: 16, points: [[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]] },
|
||||
'z': { width: 17, points: [[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]] },
|
||||
'{': { width: 14, points: [[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]] },
|
||||
'|': { width: 8, points: [[4,25],[4,-7]] },
|
||||
'}': { width: 14, points: [[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]] },
|
||||
'~': { width: 24, points: [[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]] }
|
||||
};
|
||||
|
||||
$.jqplot.CanvasFontRenderer = function(options) {
|
||||
options = options || {};
|
||||
if (!options.pt2px) {
|
||||
options.pt2px = 1.5;
|
||||
}
|
||||
$.jqplot.CanvasTextRenderer.call(this, options);
|
||||
};
|
||||
|
||||
$.jqplot.CanvasFontRenderer.prototype = new $.jqplot.CanvasTextRenderer({});
|
||||
$.jqplot.CanvasFontRenderer.prototype.constructor = $.jqplot.CanvasFontRenderer;
|
||||
|
||||
$.jqplot.CanvasFontRenderer.prototype.measure = function(ctx, str)
|
||||
{
|
||||
// var fstyle = this.fontStyle+' '+this.fontVariant+' '+this.fontWeight+' '+this.fontSize+' '+this.fontFamily;
|
||||
var fstyle = this.fontSize+' '+this.fontFamily;
|
||||
ctx.save();
|
||||
ctx.font = fstyle;
|
||||
var w = ctx.measureText(str).width;
|
||||
ctx.restore();
|
||||
return w;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasFontRenderer.prototype.draw = function(ctx, str)
|
||||
{
|
||||
var x = 0;
|
||||
// leave room at bottom for descenders.
|
||||
var y = this.height*0.72;
|
||||
//var y = 12;
|
||||
|
||||
ctx.save();
|
||||
var tx, ty;
|
||||
|
||||
// 1st quadrant
|
||||
if ((-Math.PI/2 <= this.angle && this.angle <= 0) || (Math.PI*3/2 <= this.angle && this.angle <= Math.PI*2)) {
|
||||
tx = 0;
|
||||
ty = -Math.sin(this.angle) * this.width;
|
||||
}
|
||||
// 4th quadrant
|
||||
else if ((0 < this.angle && this.angle <= Math.PI/2) || (-Math.PI*2 <= this.angle && this.angle <= -Math.PI*3/2)) {
|
||||
tx = Math.sin(this.angle) * this.height;
|
||||
ty = 0;
|
||||
}
|
||||
// 2nd quadrant
|
||||
else if ((-Math.PI < this.angle && this.angle < -Math.PI/2) || (Math.PI <= this.angle && this.angle <= Math.PI*3/2)) {
|
||||
tx = -Math.cos(this.angle) * this.width;
|
||||
ty = -Math.sin(this.angle) * this.width - Math.cos(this.angle) * this.height;
|
||||
}
|
||||
// 3rd quadrant
|
||||
else if ((-Math.PI*3/2 < this.angle && this.angle < Math.PI) || (Math.PI/2 < this.angle && this.angle < Math.PI)) {
|
||||
tx = Math.sin(this.angle) * this.height - Math.cos(this.angle)*this.width;
|
||||
ty = -Math.cos(this.angle) * this.height;
|
||||
}
|
||||
ctx.strokeStyle = this.fillStyle;
|
||||
ctx.fillStyle = this.fillStyle;
|
||||
// var fstyle = this.fontStyle+' '+this.fontVariant+' '+this.fontWeight+' '+this.fontSize+' '+this.fontFamily;
|
||||
var fstyle = this.fontSize+' '+this.fontFamily;
|
||||
ctx.font = fstyle;
|
||||
ctx.translate(tx, ty);
|
||||
ctx.rotate(this.angle);
|
||||
ctx.fillText(str, x, y);
|
||||
// ctx.strokeText(str, x, y);
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -1,673 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* class: $.jqplot.CategoryAxisRenderer
|
||||
* A plugin for jqPlot to render a category style axis, with equal pixel spacing between y data values of a series.
|
||||
*
|
||||
* To use this renderer, include the plugin in your source
|
||||
* > <script type="text/javascript" language="javascript" src="plugins/jqplot.categoryAxisRenderer.js"></script>
|
||||
*
|
||||
* and supply the appropriate options to your plot
|
||||
*
|
||||
* > {axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer}}}
|
||||
**/
|
||||
$.jqplot.CategoryAxisRenderer = function(options) {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
// prop: sortMergedLabels
|
||||
// True to sort tick labels when labels are created by merging
|
||||
// x axis values from multiple series. That is, say you have
|
||||
// two series like:
|
||||
// > line1 = [[2006, 4], [2008, 9], [2009, 16]];
|
||||
// > line2 = [[2006, 3], [2007, 7], [2008, 6]];
|
||||
// If no label array is specified, tick labels will be collected
|
||||
// from the x values of the series. With sortMergedLabels
|
||||
// set to true, tick labels will be:
|
||||
// > [2006, 2007, 2008, 2009]
|
||||
// With sortMergedLabels set to false, tick labels will be:
|
||||
// > [2006, 2008, 2009, 2007]
|
||||
//
|
||||
// Note, this property is specified on the renderOptions for the
|
||||
// axes when creating a plot:
|
||||
// > axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer, rendererOptions:{sortMergedLabels:true}}}
|
||||
this.sortMergedLabels = false;
|
||||
};
|
||||
|
||||
$.jqplot.CategoryAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.CategoryAxisRenderer.prototype.constructor = $.jqplot.CategoryAxisRenderer;
|
||||
|
||||
$.jqplot.CategoryAxisRenderer.prototype.init = function(options){
|
||||
this.groups = 1;
|
||||
this.groupLabels = [];
|
||||
this._groupLabels = [];
|
||||
this._grouped = false;
|
||||
this._barsPerGroup = null;
|
||||
this.reverse = false;
|
||||
// prop: tickRenderer
|
||||
// A class of a rendering engine for creating the ticks labels displayed on the plot,
|
||||
// See <$.jqplot.AxisTickRenderer>.
|
||||
// this.tickRenderer = $.jqplot.AxisTickRenderer;
|
||||
// this.labelRenderer = $.jqplot.AxisLabelRenderer;
|
||||
$.extend(true, this, {tickOptions:{formatString:'%d'}}, options);
|
||||
var db = this._dataBounds;
|
||||
// Go through all the series attached to this axis and find
|
||||
// the min/max bounds for this axis.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
if (s.groups) {
|
||||
this.groups = s.groups;
|
||||
}
|
||||
var d = s.data;
|
||||
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
if (d[j][0] < db.min || db.min == null) {
|
||||
db.min = d[j][0];
|
||||
}
|
||||
if (d[j][0] > db.max || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (d[j][1] < db.min || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
}
|
||||
if (d[j][1] > db.max || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.groupLabels.length) {
|
||||
this.groups = this.groupLabels.length;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$.jqplot.CategoryAxisRenderer.prototype.createTicks = function() {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
// databounds were set on axis initialization.
|
||||
var db = this._dataBounds;
|
||||
var dim, interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var tt, i;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
if (userTicks.length) {
|
||||
// adjust with blanks if we have groups
|
||||
if (this.groups > 1 && !this._grouped) {
|
||||
var l = userTicks.length;
|
||||
var skip = parseInt(l/this.groups, 10);
|
||||
var count = 0;
|
||||
for (var i=skip; i<l; i+=skip) {
|
||||
userTicks.splice(i+count, 0, ' ');
|
||||
count++;
|
||||
}
|
||||
this._grouped = true;
|
||||
}
|
||||
this.min = 0.5;
|
||||
this.max = userTicks.length + 0.5;
|
||||
var range = this.max - this.min;
|
||||
this.numberTicks = 2*userTicks.length + 1;
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
tt = this.min + 2 * i * range / (this.numberTicks-1);
|
||||
// need a marker before and after the tick
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
t.showLabel = false;
|
||||
// t.showMark = true;
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
t.label = userTicks[i];
|
||||
// t.showLabel = true;
|
||||
t.showMark = false;
|
||||
t.showGridline = false;
|
||||
t.setTick(tt+0.5, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
// now add the last tick at the end
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
t.showLabel = false;
|
||||
// t.showMark = true;
|
||||
t.setTick(tt+1, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
// we don't have any ticks yet, let's make some!
|
||||
else {
|
||||
if (name == 'xaxis' || name == 'x2axis') {
|
||||
dim = this._plotDimensions.width;
|
||||
}
|
||||
else {
|
||||
dim = this._plotDimensions.height;
|
||||
}
|
||||
|
||||
// if min, max and number of ticks specified, user can't specify interval.
|
||||
if (this.min != null && this.max != null && this.numberTicks != null) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
|
||||
// if max, min, and interval specified and interval won't fit, ignore interval.
|
||||
if (this.min != null && this.max != null && this.tickInterval != null) {
|
||||
if (parseInt((this.max-this.min)/this.tickInterval, 10) != (this.max-this.min)/this.tickInterval) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
// find out how many categories are in the lines and collect labels
|
||||
var labels = [];
|
||||
var numcats = 0;
|
||||
var min = 0.5;
|
||||
var max, val;
|
||||
var isMerged = false;
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
for (var j=0; j<s.data.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
val = s.data[j][0];
|
||||
}
|
||||
else {
|
||||
val = s.data[j][1];
|
||||
}
|
||||
if ($.inArray(val, labels) == -1) {
|
||||
isMerged = true;
|
||||
numcats += 1;
|
||||
labels.push(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isMerged && this.sortMergedLabels) {
|
||||
labels.sort(function(a,b) { return a - b; });
|
||||
}
|
||||
|
||||
// keep a reference to these tick labels to use for redrawing plot (see bug #57)
|
||||
this.ticks = labels;
|
||||
|
||||
// now bin the data values to the right lables.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
for (var j=0; j<s.data.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
val = s.data[j][0];
|
||||
}
|
||||
else {
|
||||
val = s.data[j][1];
|
||||
}
|
||||
// for category axis, force the values into category bins.
|
||||
// we should have the value in the label array now.
|
||||
var idx = $.inArray(val, labels)+1;
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
s.data[j][0] = idx;
|
||||
}
|
||||
else {
|
||||
s.data[j][1] = idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adjust with blanks if we have groups
|
||||
if (this.groups > 1 && !this._grouped) {
|
||||
var l = labels.length;
|
||||
var skip = parseInt(l/this.groups, 10);
|
||||
var count = 0;
|
||||
for (var i=skip; i<l; i+=skip+1) {
|
||||
labels[i] = ' ';
|
||||
}
|
||||
this._grouped = true;
|
||||
}
|
||||
|
||||
max = numcats + 0.5;
|
||||
if (this.numberTicks == null) {
|
||||
this.numberTicks = 2*numcats + 1;
|
||||
}
|
||||
|
||||
var range = max - min;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
var track = 0;
|
||||
|
||||
// todo: adjust this so more ticks displayed.
|
||||
var maxVisibleTicks = parseInt(3+dim/10, 10);
|
||||
var skip = parseInt(numcats/maxVisibleTicks, 10);
|
||||
|
||||
if (this.tickInterval == null) {
|
||||
|
||||
this.tickInterval = range / (this.numberTicks-1);
|
||||
|
||||
}
|
||||
// if tickInterval is specified, we will ignore any computed maximum.
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
tt = this.min + i * this.tickInterval;
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
// if even tick, it isn't a category, it's a divider
|
||||
if (i/2 == parseInt(i/2, 10)) {
|
||||
t.showLabel = false;
|
||||
t.showMark = true;
|
||||
}
|
||||
else {
|
||||
if (skip>0 && track<skip) {
|
||||
t.showLabel = false;
|
||||
track += 1;
|
||||
}
|
||||
else {
|
||||
t.showLabel = true;
|
||||
track = 0;
|
||||
}
|
||||
t.label = t.formatter(t.formatString, labels[(i-1)/2]);
|
||||
t.showMark = false;
|
||||
t.showGridline = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.CategoryAxisRenderer.prototype.draw = function(ctx, plot) {
|
||||
if (this.show) {
|
||||
// populate the axis label and value properties.
|
||||
// createTicks is a method on the renderer, but
|
||||
// call it within the scope of the axis.
|
||||
this.renderer.createTicks.call(this);
|
||||
// fill a div with axes labels in the right direction.
|
||||
// Need to pregenerate each axis to get it's bounds and
|
||||
// position it and the labels correctly on the plot.
|
||||
var dim=0;
|
||||
var temp;
|
||||
// Added for theming.
|
||||
if (this._elem) {
|
||||
// this._elem.empty();
|
||||
// Memory Leaks patch
|
||||
this._elem.emptyForce();
|
||||
}
|
||||
|
||||
this._elem = this._elem || $('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
this._elem.width(this._plotDimensions.width);
|
||||
}
|
||||
else {
|
||||
this._elem.height(this._plotDimensions.height);
|
||||
}
|
||||
|
||||
// create a _label object.
|
||||
this.labelOptions.axis = this.name;
|
||||
this._label = new this.labelRenderer(this.labelOptions);
|
||||
if (this._label.show) {
|
||||
var elem = this._label.draw(ctx, plot);
|
||||
elem.appendTo(this._elem);
|
||||
}
|
||||
|
||||
var t = this._ticks;
|
||||
for (var i=0; i<t.length; i++) {
|
||||
var tick = t[i];
|
||||
if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
|
||||
var elem = tick.draw(ctx, plot);
|
||||
elem.appendTo(this._elem);
|
||||
}
|
||||
}
|
||||
|
||||
this._groupLabels = [];
|
||||
// now make group labels
|
||||
for (var i=0; i<this.groupLabels.length; i++)
|
||||
{
|
||||
var elem = $('<div style="position:absolute;" class="jqplot-'+this.name+'-groupLabel"></div>');
|
||||
elem.html(this.groupLabels[i]);
|
||||
this._groupLabels.push(elem);
|
||||
elem.appendTo(this._elem);
|
||||
}
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.CategoryAxisRenderer.prototype.set = function() {
|
||||
var dim = 0;
|
||||
var temp;
|
||||
var w = 0;
|
||||
var h = 0;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
if (this.show) {
|
||||
var t = this._ticks;
|
||||
for (var i=0; i<t.length; i++) {
|
||||
var tick = t[i];
|
||||
if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
temp = tick._elem.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
temp = tick._elem.outerWidth(true);
|
||||
}
|
||||
if (temp > dim) {
|
||||
dim = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dim2 = 0;
|
||||
for (var i=0; i<this._groupLabels.length; i++) {
|
||||
var l = this._groupLabels[i];
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
temp = l.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
temp = l.outerWidth(true);
|
||||
}
|
||||
if (temp > dim2) {
|
||||
dim2 = temp;
|
||||
}
|
||||
}
|
||||
|
||||
if (lshow) {
|
||||
w = this._label._elem.outerWidth(true);
|
||||
h = this._label._elem.outerHeight(true);
|
||||
}
|
||||
if (this.name == 'xaxis') {
|
||||
dim += dim2 + h;
|
||||
this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
|
||||
}
|
||||
else if (this.name == 'x2axis') {
|
||||
dim += dim2 + h;
|
||||
this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
|
||||
}
|
||||
else if (this.name == 'yaxis') {
|
||||
dim += dim2 + w;
|
||||
this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
|
||||
if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
|
||||
this._label._elem.css('width', w+'px');
|
||||
}
|
||||
}
|
||||
else {
|
||||
dim += dim2 + w;
|
||||
this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
|
||||
if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
|
||||
this._label._elem.css('width', w+'px');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.CategoryAxisRenderer.prototype.pack = function(pos, offsets) {
|
||||
var ticks = this._ticks;
|
||||
var max = this.max;
|
||||
var min = this.min;
|
||||
var offmax = offsets.max;
|
||||
var offmin = offsets.min;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
var i;
|
||||
|
||||
for (var p in pos) {
|
||||
this._elem.css(p, pos[p]);
|
||||
}
|
||||
|
||||
this._offsets = offsets;
|
||||
// pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
|
||||
var pixellength = offmax - offmin;
|
||||
var unitlength = max - min;
|
||||
|
||||
if (!this.reverse) {
|
||||
// point to unit and unit to point conversions references to Plot DOM element top left corner.
|
||||
|
||||
this.u2p = function(u){
|
||||
return (u - min) * pixellength / unitlength + offmin;
|
||||
};
|
||||
|
||||
this.p2u = function(p){
|
||||
return (p - offmin) * unitlength / pixellength + min;
|
||||
};
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis'){
|
||||
this.series_u2p = function(u){
|
||||
return (u - min) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + min;
|
||||
};
|
||||
}
|
||||
|
||||
else {
|
||||
this.series_u2p = function(u){
|
||||
return (u - max) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + max;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
// point to unit and unit to point conversions references to Plot DOM element top left corner.
|
||||
|
||||
this.u2p = function(u){
|
||||
return offmin + (max - u) * pixellength / unitlength;
|
||||
};
|
||||
|
||||
this.p2u = function(p){
|
||||
return min + (p - offmin) * unitlength / pixellength;
|
||||
};
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis'){
|
||||
this.series_u2p = function(u){
|
||||
return (max - u) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + max;
|
||||
};
|
||||
}
|
||||
|
||||
else {
|
||||
this.series_u2p = function(u){
|
||||
return (min - u) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + min;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (this.show) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
for (i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
// will need to adjust auto positioning based on which axis this is.
|
||||
var temp = (this.name == 'xaxis') ? 1 : -1;
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
if (temp * t.angle < 0) {
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
// position at start
|
||||
else {
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'end':
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'start':
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'middle':
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getWidth()/2;
|
||||
}
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('left', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
|
||||
var labeledge=['bottom', 0];
|
||||
if (lshow) {
|
||||
var w = this._label._elem.outerWidth(true);
|
||||
this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
|
||||
if (this.name == 'xaxis') {
|
||||
this._label._elem.css('bottom', '0px');
|
||||
labeledge = ['bottom', this._label._elem.outerHeight(true)];
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('top', '0px');
|
||||
labeledge = ['top', this._label._elem.outerHeight(true)];
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
|
||||
// draw the group labels
|
||||
var step = parseInt(this._ticks.length/this.groups, 10);
|
||||
for (i=0; i<this._groupLabels.length; i++) {
|
||||
var mid = 0;
|
||||
var count = 0;
|
||||
for (var j=i*step; j<=(i+1)*step; j++) {
|
||||
if (this._ticks[j]._elem && this._ticks[j].label != " ") {
|
||||
var t = this._ticks[j]._elem;
|
||||
var p = t.position();
|
||||
mid += p.left + t.outerWidth(true)/2;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mid = mid/count;
|
||||
this._groupLabels[i].css({'left':(mid - this._groupLabels[i].outerWidth(true)/2)});
|
||||
this._groupLabels[i].css(labeledge[0], labeledge[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
// will need to adjust auto positioning based on which axis this is.
|
||||
var temp = (this.name == 'yaxis') ? 1 : -1;
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
case 'end':
|
||||
if (temp * t.angle < 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'start':
|
||||
if (t.angle > 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'middle':
|
||||
// if (t.angle > 0) {
|
||||
// shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
// }
|
||||
// else {
|
||||
// shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
// }
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight()/2;
|
||||
}
|
||||
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('top', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
|
||||
var labeledge=['left', 0];
|
||||
if (lshow) {
|
||||
var h = this._label._elem.outerHeight(true);
|
||||
this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
|
||||
if (this.name == 'yaxis') {
|
||||
this._label._elem.css('left', '0px');
|
||||
labeledge = ['left', this._label._elem.outerWidth(true)];
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('right', '0px');
|
||||
labeledge = ['right', this._label._elem.outerWidth(true)];
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
|
||||
// draw the group labels, position top here, do left after label position.
|
||||
var step = parseInt(this._ticks.length/this.groups, 10);
|
||||
for (i=0; i<this._groupLabels.length; i++) {
|
||||
var mid = 0;
|
||||
var count = 0;
|
||||
for (var j=i*step; j<=(i+1)*step; j++) {
|
||||
if (this._ticks[j]._elem && this._ticks[j].label != " ") {
|
||||
var t = this._ticks[j]._elem;
|
||||
var p = t.position();
|
||||
mid += p.top + t.outerHeight()/2;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mid = mid/count;
|
||||
this._groupLabels[i].css({'top':mid - this._groupLabels[i].outerHeight()/2});
|
||||
this._groupLabels[i].css(labeledge[0], labeledge[1]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -1,116 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.ciParser
|
||||
* Data Renderer function which converts a custom JSON data object into jqPlot data format.
|
||||
* Set this as a callable on the jqplot dataRenderer plot option:
|
||||
*
|
||||
* > plot = $.jqplot('mychart', [data], { dataRenderer: $.jqplot.ciParser, ... });
|
||||
*
|
||||
* Where data is an object in JSON format or a JSON encoded string conforming to the
|
||||
* City Index API spec.
|
||||
*
|
||||
* Note that calling the renderer function is handled internally by jqPlot. The
|
||||
* user does not have to call the function. The parameters described below will
|
||||
* automatically be passed to the ciParser function.
|
||||
*
|
||||
* Parameters:
|
||||
* data - JSON encoded string or object.
|
||||
* plot - reference to jqPlot Plot object.
|
||||
*
|
||||
* Returns:
|
||||
* data array in jqPlot format.
|
||||
*
|
||||
*/
|
||||
$.jqplot.ciParser = function (data, plot) {
|
||||
var ret = [],
|
||||
line,
|
||||
temp,
|
||||
i, j, k, kk;
|
||||
|
||||
if (typeof(data) == "string") {
|
||||
data = $.jqplot.JSON.parse(data, handleStrings);
|
||||
}
|
||||
|
||||
else if (typeof(data) == "object") {
|
||||
for (k in data) {
|
||||
for (i=0; i<data[k].length; i++) {
|
||||
for (kk in data[k][i]) {
|
||||
data[k][i][kk] = handleStrings(kk, data[k][i][kk]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// function handleStrings
|
||||
// Checks any JSON encoded strings to see if they are
|
||||
// encoded dates. If so, pull out the timestamp.
|
||||
// Expects dates to be represented by js timestamps.
|
||||
|
||||
function handleStrings(key, value) {
|
||||
var a;
|
||||
if (value != null) {
|
||||
if (value.toString().indexOf('Date') >= 0) {
|
||||
//here we will try to extract the ticks from the Date string in the "value" fields of JSON returned data
|
||||
a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
|
||||
if (a) {
|
||||
return parseInt(a[1], 10);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
for (var prop in data) {
|
||||
line = [];
|
||||
temp = data[prop];
|
||||
switch (prop) {
|
||||
case "PriceTicks":
|
||||
for (i=0; i<temp.length; i++) {
|
||||
line.push([temp[i]['TickDate'], temp[i]['Price']]);
|
||||
}
|
||||
break;
|
||||
case "PriceBars":
|
||||
for (i=0; i<temp.length; i++) {
|
||||
line.push([temp[i]['BarDate'], temp[i]['Open'], temp[i]['High'], temp[i]['Low'], temp[i]['Close']]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
ret.push(line);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
})(jQuery);
|
57
src/html/jqplot/plugins/jqplot.ciParser.min.js
vendored
57
src/html/jqplot/plugins/jqplot.ciParser.min.js
vendored
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4r1121
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2011 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function(a){a.jqplot.ciParser=function(g,l){var m=[],o,n,h,f,e,c;if(typeof(g)=="string"){g=a.jqplot.JSON.parse(g,d)}else{if(typeof(g)=="object"){for(e in g){for(h=0;h<g[e].length;h++){for(c in g[e][h]){g[e][h][c]=d(c,g[e][h][c])}}}}else{return null}}function d(j,k){var i;if(k!=null){if(k.toString().indexOf("Date")>=0){i=/^\/Date\((-?[0-9]+)\)\/$/.exec(k);if(i){return parseInt(i[1],10)}}return k}}for(var b in g){o=[];n=g[b];switch(b){case"PriceTicks":for(h=0;h<n.length;h++){o.push([n[h]["TickDate"],n[h]["Price"]])}break;case"PriceBars":for(h=0;h<n.length;h++){o.push([n[h]["BarDate"],n[h]["Open"],n[h]["High"],n[h]["Low"],n[h]["Close"]])}break}m.push(o)}return m}})(jQuery);
|
File diff suppressed because it is too large
Load Diff
57
src/html/jqplot/plugins/jqplot.cursor.min.js
vendored
57
src/html/jqplot/plugins/jqplot.cursor.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,737 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.DateAxisRenderer
|
||||
* A plugin for a jqPlot to render an axis as a series of date values.
|
||||
* This renderer has no options beyond those supplied by the <Axis> class.
|
||||
* It supplies it's own tick formatter, so the tickOptions.formatter option
|
||||
* should not be overridden.
|
||||
*
|
||||
* Thanks to Ken Synder for his enhanced Date instance methods which are
|
||||
* included with this code <http://kendsnyder.com/sandbox/date/>.
|
||||
*
|
||||
* To use this renderer, include the plugin in your source
|
||||
* > <script type="text/javascript" language="javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
|
||||
*
|
||||
* and supply the appropriate options to your plot
|
||||
*
|
||||
* > {axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}}
|
||||
*
|
||||
* Dates can be passed into the axis in almost any recognizable value and
|
||||
* will be parsed. They will be rendered on the axis in the format
|
||||
* specified by tickOptions.formatString. e.g. tickOptions.formatString = '%Y-%m-%d'.
|
||||
*
|
||||
* Accecptable format codes
|
||||
* are:
|
||||
*
|
||||
* > Code Result Description
|
||||
* > == Years ==
|
||||
* > %Y 2008 Four-digit year
|
||||
* > %y 08 Two-digit year
|
||||
* > == Months ==
|
||||
* > %m 09 Two-digit month
|
||||
* > %#m 9 One or two-digit month
|
||||
* > %B September Full month name
|
||||
* > %b Sep Abbreviated month name
|
||||
* > == Days ==
|
||||
* > %d 05 Two-digit day of month
|
||||
* > %#d 5 One or two-digit day of month
|
||||
* > %e 5 One or two-digit day of month
|
||||
* > %A Sunday Full name of the day of the week
|
||||
* > %a Sun Abbreviated name of the day of the week
|
||||
* > %w 0 Number of the day of the week (0 = Sunday, 6 = Saturday)
|
||||
* > %o th The ordinal suffix string following the day of the month
|
||||
* > == Hours ==
|
||||
* > %H 23 Hours in 24-hour format (two digits)
|
||||
* > %#H 3 Hours in 24-hour integer format (one or two digits)
|
||||
* > %I 11 Hours in 12-hour format (two digits)
|
||||
* > %#I 3 Hours in 12-hour integer format (one or two digits)
|
||||
* > %p PM AM or PM
|
||||
* > == Minutes ==
|
||||
* > %M 09 Minutes (two digits)
|
||||
* > %#M 9 Minutes (one or two digits)
|
||||
* > == Seconds ==
|
||||
* > %S 02 Seconds (two digits)
|
||||
* > %#S 2 Seconds (one or two digits)
|
||||
* > %s 1206567625723 Unix timestamp (Seconds past 1970-01-01 00:00:00)
|
||||
* > == Milliseconds ==
|
||||
* > %N 008 Milliseconds (three digits)
|
||||
* > %#N 8 Milliseconds (one to three digits)
|
||||
* > == Timezone ==
|
||||
* > %O 360 difference in minutes between local time and GMT
|
||||
* > %Z Mountain Standard Time Name of timezone as reported by browser
|
||||
* > %G -06:00 Hours and minutes between GMT
|
||||
* > == Shortcuts ==
|
||||
* > %F 2008-03-26 %Y-%m-%d
|
||||
* > %T 05:06:30 %H:%M:%S
|
||||
* > %X 05:06:30 %H:%M:%S
|
||||
* > %x 03/26/08 %m/%d/%y
|
||||
* > %D 03/26/08 %m/%d/%y
|
||||
* > %#c Wed Mar 26 15:31:00 2008 %a %b %e %H:%M:%S %Y
|
||||
* > %v 3-Sep-2008 %e-%b-%Y
|
||||
* > %R 15:31 %H:%M
|
||||
* > %r 3:31:00 PM %I:%M:%S %p
|
||||
* > == Characters ==
|
||||
* > %n \n Newline
|
||||
* > %t \t Tab
|
||||
* > %% % Percent Symbol
|
||||
*/
|
||||
$.jqplot.DateAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
this.date = new $.jsDate();
|
||||
};
|
||||
|
||||
var second = 1000;
|
||||
var minute = 60 * second;
|
||||
var hour = 60 * minute;
|
||||
var day = 24 * hour;
|
||||
var week = 7 * day;
|
||||
|
||||
// these are less definitive
|
||||
var month = 30.4368499 * day;
|
||||
var year = 365.242199 * day;
|
||||
|
||||
var daysInMonths = [31,28,31,30,31,30,31,30,31,30,31,30];
|
||||
// array of consistent nice intervals. Longer intervals
|
||||
// will depend on days in month, days in year, etc.
|
||||
var niceFormatStrings = ['%M:%S.%#N', '%M:%S.%#N', '%M:%S.%#N', '%M:%S', '%M:%S', '%M:%S', '%M:%S', '%H:%M:%S', '%H:%M:%S', '%H:%M', '%H:%M', '%H:%M', '%H:%M', '%H:%M', '%H:%M', '%a %H:%M', '%a %H:%M', '%b %e %H:%M', '%b %e %H:%M', '%b %e %H:%M', '%b %e %H:%M', '%v', '%v', '%v', '%v', '%v', '%v', '%v'];
|
||||
var niceIntervals = [0.1*second, 0.2*second, 0.5*second, second, 2*second, 5*second, 10*second, 15*second, 30*second, minute, 2*minute, 5*minute, 10*minute, 15*minute, 30*minute, hour, 2*hour, 4*hour, 6*hour, 8*hour, 12*hour, day, 2*day, 3*day, 4*day, 5*day, week, 2*week];
|
||||
|
||||
var niceMonthlyIntervals = [];
|
||||
|
||||
function bestDateInterval(min, max, titarget) {
|
||||
// iterate through niceIntervals to find one closest to titarget
|
||||
var badness = Number.MAX_VALUE;
|
||||
var temp, bestTi, bestfmt;
|
||||
for (var i=0, l=niceIntervals.length; i < l; i++) {
|
||||
temp = Math.abs(titarget - niceIntervals[i]);
|
||||
if (temp < badness) {
|
||||
badness = temp;
|
||||
bestTi = niceIntervals[i];
|
||||
bestfmt = niceFormatStrings[i];
|
||||
}
|
||||
}
|
||||
|
||||
return [bestTi, bestfmt];
|
||||
}
|
||||
|
||||
$.jqplot.DateAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.DateAxisRenderer.prototype.constructor = $.jqplot.DateAxisRenderer;
|
||||
|
||||
$.jqplot.DateTickFormatter = function(format, val) {
|
||||
if (!format) {
|
||||
format = '%Y/%m/%d';
|
||||
}
|
||||
return $.jsDate.strftime(val, format);
|
||||
};
|
||||
|
||||
$.jqplot.DateAxisRenderer.prototype.init = function(options){
|
||||
// prop: tickRenderer
|
||||
// A class of a rendering engine for creating the ticks labels displayed on the plot,
|
||||
// See <$.jqplot.AxisTickRenderer>.
|
||||
// this.tickRenderer = $.jqplot.AxisTickRenderer;
|
||||
// this.labelRenderer = $.jqplot.AxisLabelRenderer;
|
||||
this.tickOptions.formatter = $.jqplot.DateTickFormatter;
|
||||
// prop: tickInset
|
||||
// Controls the amount to inset the first and last ticks from
|
||||
// the edges of the grid, in multiples of the tick interval.
|
||||
// 0 is no inset, 0.5 is one half a tick interval, 1 is a full
|
||||
// tick interval, etc.
|
||||
this.tickInset = 0;
|
||||
// prop: drawBaseline
|
||||
// True to draw the axis baseline.
|
||||
this.drawBaseline = true;
|
||||
// prop: baselineWidth
|
||||
// width of the baseline in pixels.
|
||||
this.baselineWidth = null;
|
||||
// prop: baselineColor
|
||||
// CSS color spec for the baseline.
|
||||
this.baselineColor = null;
|
||||
this.daTickInterval = null;
|
||||
this._daTickInterval = null;
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
var db = this._dataBounds,
|
||||
stats,
|
||||
sum,
|
||||
s,
|
||||
d,
|
||||
pd,
|
||||
sd,
|
||||
intv;
|
||||
|
||||
// Go through all the series attached to this axis and find
|
||||
// the min/max bounds for this axis.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
stats = {intervals:[], frequencies:{}, sortedIntervals:[], min:null, max:null, mean:null};
|
||||
sum = 0;
|
||||
s = this._series[i];
|
||||
d = s.data;
|
||||
pd = s._plotData;
|
||||
sd = s._stackData;
|
||||
intv = 0;
|
||||
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
d[j][0] = new $.jsDate(d[j][0]).getTime();
|
||||
pd[j][0] = new $.jsDate(d[j][0]).getTime();
|
||||
sd[j][0] = new $.jsDate(d[j][0]).getTime();
|
||||
if ((d[j][0] != null && d[j][0] < db.min) || db.min == null) {
|
||||
db.min = d[j][0];
|
||||
}
|
||||
if ((d[j][0] != null && d[j][0] > db.max) || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
if (j>0) {
|
||||
intv = Math.abs(d[j][0] - d[j-1][0]);
|
||||
stats.intervals.push(intv);
|
||||
if (stats.frequencies.hasOwnProperty(intv)) {
|
||||
stats.frequencies[intv] += 1;
|
||||
}
|
||||
else {
|
||||
stats.frequencies[intv] = 1;
|
||||
}
|
||||
}
|
||||
sum += intv;
|
||||
|
||||
}
|
||||
else {
|
||||
d[j][1] = new $.jsDate(d[j][1]).getTime();
|
||||
pd[j][1] = new $.jsDate(d[j][1]).getTime();
|
||||
sd[j][1] = new $.jsDate(d[j][1]).getTime();
|
||||
if ((d[j][1] != null && d[j][1] < db.min) || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
}
|
||||
if ((d[j][1] != null && d[j][1] > db.max) || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
if (j>0) {
|
||||
intv = Math.abs(d[j][1] - d[j-1][1]);
|
||||
stats.intervals.push(intv);
|
||||
if (stats.frequencies.hasOwnProperty(intv)) {
|
||||
stats.frequencies[intv] += 1;
|
||||
}
|
||||
else {
|
||||
stats.frequencies[intv] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
sum += intv;
|
||||
}
|
||||
|
||||
if (s.renderer.bands) {
|
||||
if (s.renderer.bands.hiData.length) {
|
||||
var bd = s.renderer.bands.hiData;
|
||||
for (var j=0, l=bd.length; j < l; j++) {
|
||||
if (this.name === 'xaxis' || this.name === 'x2axis') {
|
||||
bd[j][0] = new $.jsDate(bd[j][0]).getTime();
|
||||
if ((bd[j][0] != null && bd[j][0] > db.max) || db.max == null) {
|
||||
db.max = bd[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
bd[j][1] = new $.jsDate(bd[j][1]).getTime();
|
||||
if ((bd[j][1] != null && bd[j][1] > db.max) || db.max == null) {
|
||||
db.max = bd[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s.renderer.bands.lowData.length) {
|
||||
var bd = s.renderer.bands.lowData;
|
||||
for (var j=0, l=bd.length; j < l; j++) {
|
||||
if (this.name === 'xaxis' || this.name === 'x2axis') {
|
||||
bd[j][0] = new $.jsDate(bd[j][0]).getTime();
|
||||
if ((bd[j][0] != null && bd[j][0] < db.min) || db.min == null) {
|
||||
db.min = bd[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
bd[j][1] = new $.jsDate(bd[j][1]).getTime();
|
||||
if ((bd[j][1] != null && bd[j][1] < db.min) || db.min == null) {
|
||||
db.min = bd[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var tempf = 0,
|
||||
tempn=0;
|
||||
for (var n in stats.frequencies) {
|
||||
stats.sortedIntervals.push({interval:n, frequency:stats.frequencies[n]});
|
||||
}
|
||||
stats.sortedIntervals.sort(function(a, b){
|
||||
return b.frequency - a.frequency;
|
||||
});
|
||||
|
||||
stats.min = $.jqplot.arrayMin(stats.intervals);
|
||||
stats.max = $.jqplot.arrayMax(stats.intervals);
|
||||
stats.mean = sum/d.length;
|
||||
this._intervalStats.push(stats);
|
||||
stats = sum = s = d = pd = sd = null;
|
||||
}
|
||||
db = null;
|
||||
|
||||
};
|
||||
|
||||
// called with scope of an axis
|
||||
$.jqplot.DateAxisRenderer.prototype.reset = function() {
|
||||
this.min = this._options.min;
|
||||
this.max = this._options.max;
|
||||
this.tickInterval = this._options.tickInterval;
|
||||
this.numberTicks = this._options.numberTicks;
|
||||
this._autoFormatString = '';
|
||||
if (this._overrideFormatString && this.tickOptions && this.tickOptions.formatString) {
|
||||
this.tickOptions.formatString = '';
|
||||
}
|
||||
this.daTickInterval = this._daTickInterval;
|
||||
// this._ticks = this.__ticks;
|
||||
};
|
||||
|
||||
$.jqplot.DateAxisRenderer.prototype.createTicks = function(plot) {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
// databounds were set on axis initialization.
|
||||
var db = this._dataBounds;
|
||||
var iv = this._intervalStats;
|
||||
var dim = (this.name.charAt(0) === 'x') ? this._plotDimensions.width : this._plotDimensions.height;
|
||||
var interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var tt, i;
|
||||
var threshold = 30;
|
||||
var insetMult = 1;
|
||||
|
||||
var tickInterval = this.tickInterval;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
// ticks must be in order of increasing value.
|
||||
|
||||
min = ((this.min != null) ? new $.jsDate(this.min).getTime() : db.min);
|
||||
max = ((this.max != null) ? new $.jsDate(this.max).getTime() : db.max);
|
||||
|
||||
// see if we're zooming. if we are, don't use the min and max we're given,
|
||||
// but compute some nice ones. They will be reset later.
|
||||
|
||||
var cursor = plot.plugins.cursor;
|
||||
|
||||
if (cursor && cursor._zoom && cursor._zoom.zooming) {
|
||||
this.min = null;
|
||||
this.max = null;
|
||||
}
|
||||
|
||||
var range = max - min;
|
||||
|
||||
if (this.tickOptions == null || !this.tickOptions.formatString) {
|
||||
this._overrideFormatString = true;
|
||||
}
|
||||
|
||||
if (userTicks.length) {
|
||||
// ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
var ut = userTicks[i];
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (ut.constructor == Array) {
|
||||
t.value = new $.jsDate(ut[0]).getTime();
|
||||
t.label = ut[1];
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(t.value, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
else {
|
||||
t.value = new $.jsDate(ut).getTime();
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(t.value, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
this.numberTicks = userTicks.length;
|
||||
this.min = this._ticks[0].value;
|
||||
this.max = this._ticks[this.numberTicks-1].value;
|
||||
this.daTickInterval = [(this.max - this.min) / (this.numberTicks - 1)/1000, 'seconds'];
|
||||
}
|
||||
|
||||
////////
|
||||
// We don't have any ticks yet, let's make some!
|
||||
////////
|
||||
|
||||
// special case when there is only one point, make three tick marks to center the point
|
||||
else if (this.min == null && this.max == null && db.min == db.max)
|
||||
{
|
||||
var onePointOpts = $.extend(true, {}, this.tickOptions, {name: this.name, value: null});
|
||||
var delta = 300000;
|
||||
this.min = db.min - delta;
|
||||
this.max = db.max + delta;
|
||||
this.numberTicks = 3;
|
||||
|
||||
for(var i=this.min;i<=this.max;i+= delta)
|
||||
{
|
||||
onePointOpts.value = i;
|
||||
|
||||
var t = new this.tickRenderer(onePointOpts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
if(this.showTicks) {
|
||||
this._ticks[1].showLabel = true;
|
||||
}
|
||||
if(this.showTickMarks) {
|
||||
this._ticks[1].showTickMarks = true;
|
||||
}
|
||||
}
|
||||
// if user specified min and max are null, we set those to make best ticks.
|
||||
else if (this.min == null && this.max == null) {
|
||||
|
||||
var opts = $.extend(true, {}, this.tickOptions, {name: this.name, value: null});
|
||||
|
||||
// want to find a nice interval
|
||||
var nttarget,
|
||||
titarget;
|
||||
|
||||
// if no tickInterval or numberTicks options specified, make a good guess.
|
||||
if (!this.tickInterval && !this.numberTicks) {
|
||||
var tdim = Math.max(dim, threshold+1);
|
||||
// how many ticks to put on the axis?
|
||||
// date labels tend to be long. If ticks not rotated,
|
||||
// don't use too many and have a high spacing factor.
|
||||
// If we are rotating ticks, use a lower factor.
|
||||
var spacingFactor = 115;
|
||||
if (this.tickRenderer === $.jqplot.CanvasAxisTickRenderer && this.tickOptions.angle) {
|
||||
spacingFactor = 115 - 40 * Math.abs(Math.sin(this.tickOptions.angle/180*Math.PI));
|
||||
}
|
||||
|
||||
nttarget = Math.ceil((tdim-threshold)/spacingFactor + 1);
|
||||
titarget = (max - min) / (nttarget - 1);
|
||||
}
|
||||
|
||||
// If tickInterval is specified, we'll try to honor it.
|
||||
// Not gauranteed to get this interval, but we'll get as close as
|
||||
// we can.
|
||||
// tickInterval will be used before numberTicks, that is if
|
||||
// both are specified, numberTicks will be ignored.
|
||||
else if (this.tickInterval) {
|
||||
titarget = this.tickInterval;
|
||||
}
|
||||
|
||||
// if numberTicks specified, try to honor it.
|
||||
// Not gauranteed, but will try to get close.
|
||||
else if (this.numberTicks) {
|
||||
nttarget = this.numberTicks;
|
||||
titarget = (max - min) / (nttarget - 1);
|
||||
}
|
||||
|
||||
// If we can use an interval of 2 weeks or less, pick best one
|
||||
if (titarget <= 19*day) {
|
||||
var ret = bestDateInterval(min, max, titarget);
|
||||
var tempti = ret[0];
|
||||
this._autoFormatString = ret[1];
|
||||
|
||||
min = Math.floor(min/tempti) * tempti;
|
||||
min = new $.jsDate(min);
|
||||
min = min.getTime() + min.getUtcOffset();
|
||||
|
||||
nttarget = Math.ceil((max - min) / tempti) + 1;
|
||||
this.min = min;
|
||||
this.max = min + (nttarget - 1) * tempti;
|
||||
|
||||
// if max is less than max, add an interval
|
||||
if (this.max < max) {
|
||||
this.max += tempti;
|
||||
nttarget += 1;
|
||||
}
|
||||
this.tickInterval = tempti;
|
||||
this.numberTicks = nttarget;
|
||||
|
||||
for (var i=0; i<nttarget; i++) {
|
||||
opts.value = this.min + i * tempti;
|
||||
t = new this.tickRenderer(opts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
insetMult = this.tickInterval;
|
||||
}
|
||||
|
||||
// should we use a monthly interval?
|
||||
else if (titarget <= 9 * month) {
|
||||
|
||||
this._autoFormatString = '%v';
|
||||
|
||||
// how many months in an interval?
|
||||
var intv = Math.round(titarget/month);
|
||||
if (intv < 1) {
|
||||
intv = 1;
|
||||
}
|
||||
else if (intv > 6) {
|
||||
intv = 6;
|
||||
}
|
||||
|
||||
// figure out the starting month and ending month.
|
||||
var mstart = new $.jsDate(min).setDate(1).setHours(0,0,0,0);
|
||||
|
||||
// See if max ends exactly on a month
|
||||
var tempmend = new $.jsDate(max);
|
||||
var mend = new $.jsDate(max).setDate(1).setHours(0,0,0,0);
|
||||
|
||||
if (tempmend.getTime() !== mend.getTime()) {
|
||||
mend = mend.add(1, 'month');
|
||||
}
|
||||
|
||||
var nmonths = mend.diff(mstart, 'month');
|
||||
|
||||
nttarget = Math.ceil(nmonths/intv) + 1;
|
||||
|
||||
this.min = mstart.getTime();
|
||||
this.max = mstart.clone().add((nttarget - 1) * intv, 'month').getTime();
|
||||
this.numberTicks = nttarget;
|
||||
|
||||
for (var i=0; i<nttarget; i++) {
|
||||
if (i === 0) {
|
||||
opts.value = mstart.getTime();
|
||||
}
|
||||
else {
|
||||
opts.value = mstart.add(intv, 'month').getTime();
|
||||
}
|
||||
t = new this.tickRenderer(opts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
insetMult = intv * month;
|
||||
}
|
||||
|
||||
// use yearly intervals
|
||||
else {
|
||||
|
||||
this._autoFormatString = '%v';
|
||||
|
||||
// how many years in an interval?
|
||||
var intv = Math.round(titarget/year);
|
||||
if (intv < 1) {
|
||||
intv = 1;
|
||||
}
|
||||
|
||||
// figure out the starting and ending years.
|
||||
var mstart = new $.jsDate(min).setMonth(0, 1).setHours(0,0,0,0);
|
||||
var mend = new $.jsDate(max).add(1, 'year').setMonth(0, 1).setHours(0,0,0,0);
|
||||
|
||||
var nyears = mend.diff(mstart, 'year');
|
||||
|
||||
nttarget = Math.ceil(nyears/intv) + 1;
|
||||
|
||||
this.min = mstart.getTime();
|
||||
this.max = mstart.clone().add((nttarget - 1) * intv, 'year').getTime();
|
||||
this.numberTicks = nttarget;
|
||||
|
||||
for (var i=0; i<nttarget; i++) {
|
||||
if (i === 0) {
|
||||
opts.value = mstart.getTime();
|
||||
}
|
||||
else {
|
||||
opts.value = mstart.add(intv, 'year').getTime();
|
||||
}
|
||||
t = new this.tickRenderer(opts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
insetMult = intv * year;
|
||||
}
|
||||
}
|
||||
|
||||
////////
|
||||
// Some option(s) specified, work around that.
|
||||
////////
|
||||
|
||||
else {
|
||||
if (name == 'xaxis' || name == 'x2axis') {
|
||||
dim = this._plotDimensions.width;
|
||||
}
|
||||
else {
|
||||
dim = this._plotDimensions.height;
|
||||
}
|
||||
|
||||
// if min, max and number of ticks specified, user can't specify interval.
|
||||
if (this.min != null && this.max != null && this.numberTicks != null) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
|
||||
// if user specified a tick interval, convert to usable.
|
||||
if (this.tickInterval != null)
|
||||
{
|
||||
// if interval is a number or can be converted to one, use it.
|
||||
// Assume it is in SECONDS!!!
|
||||
if (Number(this.tickInterval)) {
|
||||
this.daTickInterval = [Number(this.tickInterval), 'seconds'];
|
||||
}
|
||||
// else, parse out something we can build from.
|
||||
else if (typeof this.tickInterval == "string") {
|
||||
var parts = this.tickInterval.split(' ');
|
||||
if (parts.length == 1) {
|
||||
this.daTickInterval = [1, parts[0]];
|
||||
}
|
||||
else if (parts.length == 2) {
|
||||
this.daTickInterval = [parts[0], parts[1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if min and max are same, space them out a bit
|
||||
if (min == max) {
|
||||
var adj = 24*60*60*500; // 1/2 day
|
||||
min -= adj;
|
||||
max += adj;
|
||||
}
|
||||
|
||||
range = max - min;
|
||||
|
||||
var optNumTicks = 2 + parseInt(Math.max(0, dim-100)/100, 10);
|
||||
|
||||
|
||||
var rmin, rmax;
|
||||
|
||||
rmin = (this.min != null) ? new $.jsDate(this.min).getTime() : min - range/2*(this.padMin - 1);
|
||||
rmax = (this.max != null) ? new $.jsDate(this.max).getTime() : max + range/2*(this.padMax - 1);
|
||||
this.min = rmin;
|
||||
this.max = rmax;
|
||||
range = this.max - this.min;
|
||||
|
||||
if (this.numberTicks == null){
|
||||
// if tickInterval is specified by user, we will ignore computed maximum.
|
||||
// max will be equal or greater to fit even # of ticks.
|
||||
if (this.daTickInterval != null) {
|
||||
var nc = new $.jsDate(this.max).diff(this.min, this.daTickInterval[1], true);
|
||||
this.numberTicks = Math.ceil(nc/this.daTickInterval[0]) +1;
|
||||
// this.max = new $.jsDate(this.min).add(this.numberTicks-1, this.daTickInterval[1]).getTime();
|
||||
this.max = new $.jsDate(this.min).add((this.numberTicks-1) * this.daTickInterval[0], this.daTickInterval[1]).getTime();
|
||||
}
|
||||
else if (dim > 200) {
|
||||
this.numberTicks = parseInt(3+(dim-200)/100, 10);
|
||||
}
|
||||
else {
|
||||
this.numberTicks = 2;
|
||||
}
|
||||
}
|
||||
|
||||
insetMult = range / (this.numberTicks-1)/1000;
|
||||
|
||||
if (this.daTickInterval == null) {
|
||||
this.daTickInterval = [insetMult, 'seconds'];
|
||||
}
|
||||
|
||||
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
var min = new $.jsDate(this.min);
|
||||
tt = min.add(i*this.daTickInterval[0], this.daTickInterval[1]).getTime();
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
// var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.tickInset) {
|
||||
this.min = this.min - this.tickInset * insetMult;
|
||||
this.max = this.max + this.tickInset * insetMult;
|
||||
}
|
||||
|
||||
if (this._daTickInterval == null) {
|
||||
this._daTickInterval = this.daTickInterval;
|
||||
}
|
||||
|
||||
ticks = null;
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,805 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.DonutRenderer
|
||||
* Plugin renderer to draw a donut chart.
|
||||
* x values, if present, will be used as slice labels.
|
||||
* y values give slice size.
|
||||
*
|
||||
* To use this renderer, you need to include the
|
||||
* donut renderer plugin, for example:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.donutRenderer.js"></script>
|
||||
*
|
||||
* Properties described here are passed into the $.jqplot function
|
||||
* as options on the series renderer. For example:
|
||||
*
|
||||
* > plot2 = $.jqplot('chart2', [s1, s2], {
|
||||
* > seriesDefaults: {
|
||||
* > renderer:$.jqplot.DonutRenderer,
|
||||
* > rendererOptions:{
|
||||
* > sliceMargin: 2,
|
||||
* > innerDiameter: 110,
|
||||
* > startAngle: -90
|
||||
* > }
|
||||
* > }
|
||||
* > });
|
||||
*
|
||||
* A donut plot will trigger events on the plot target
|
||||
* according to user interaction. All events return the event object,
|
||||
* the series index, the point (slice) index, and the point data for
|
||||
* the appropriate slice.
|
||||
*
|
||||
* 'jqplotDataMouseOver' - triggered when user mouseing over a slice.
|
||||
* 'jqplotDataHighlight' - triggered the first time user mouses over a slice,
|
||||
* if highlighting is enabled.
|
||||
* 'jqplotDataUnhighlight' - triggered when a user moves the mouse out of
|
||||
* a highlighted slice.
|
||||
* 'jqplotDataClick' - triggered when the user clicks on a slice.
|
||||
* 'jqplotDataRightClick' - tiggered when the user right clicks on a slice if
|
||||
* the "captureRightClick" option is set to true on the plot.
|
||||
*/
|
||||
$.jqplot.DonutRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.DonutRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.DonutRenderer.prototype.constructor = $.jqplot.DonutRenderer;
|
||||
|
||||
// called with scope of a series
|
||||
$.jqplot.DonutRenderer.prototype.init = function(options, plot) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: diameter
|
||||
// Outer diameter of the donut, auto computed by default
|
||||
this.diameter = null;
|
||||
// prop: innerDiameter
|
||||
// Inner diameter of the donut, auto calculated by default.
|
||||
// If specified will override thickness value.
|
||||
this.innerDiameter = null;
|
||||
// prop: thickness
|
||||
// thickness of the donut, auto computed by default
|
||||
// Overridden by if innerDiameter is specified.
|
||||
this.thickness = null;
|
||||
// prop: padding
|
||||
// padding between the donut and plot edges, legend, etc.
|
||||
this.padding = 20;
|
||||
// prop: sliceMargin
|
||||
// angular spacing between donut slices in degrees.
|
||||
this.sliceMargin = 0;
|
||||
// prop: ringMargin
|
||||
// pixel distance between rings, or multiple series in a donut plot.
|
||||
// null will compute ringMargin based on sliceMargin.
|
||||
this.ringMargin = null;
|
||||
// prop: fill
|
||||
// true or false, wether to fil the slices.
|
||||
this.fill = true;
|
||||
// prop: shadowOffset
|
||||
// offset of the shadow from the slice and offset of
|
||||
// each succesive stroke of the shadow from the last.
|
||||
this.shadowOffset = 2;
|
||||
// prop: shadowAlpha
|
||||
// transparency of the shadow (0 = transparent, 1 = opaque)
|
||||
this.shadowAlpha = 0.07;
|
||||
// prop: shadowDepth
|
||||
// number of strokes to apply to the shadow,
|
||||
// each stroke offset shadowOffset from the last.
|
||||
this.shadowDepth = 5;
|
||||
// prop: highlightMouseOver
|
||||
// True to highlight slice when moused over.
|
||||
// This must be false to enable highlightMouseDown to highlight when clicking on a slice.
|
||||
this.highlightMouseOver = true;
|
||||
// prop: highlightMouseDown
|
||||
// True to highlight when a mouse button is pressed over a slice.
|
||||
// This will be disabled if highlightMouseOver is true.
|
||||
this.highlightMouseDown = false;
|
||||
// prop: highlightColors
|
||||
// an array of colors to use when highlighting a slice.
|
||||
this.highlightColors = [];
|
||||
// prop: dataLabels
|
||||
// Either 'label', 'value', 'percent' or an array of labels to place on the pie slices.
|
||||
// Defaults to percentage of each pie slice.
|
||||
this.dataLabels = 'percent';
|
||||
// prop: showDataLabels
|
||||
// true to show data labels on slices.
|
||||
this.showDataLabels = false;
|
||||
// prop: dataLabelFormatString
|
||||
// Format string for data labels. If none, '%s' is used for "label" and for arrays, '%d' for value and '%d%%' for percentage.
|
||||
this.dataLabelFormatString = null;
|
||||
// prop: dataLabelThreshold
|
||||
// Threshhold in percentage (0 - 100) of pie area, below which no label will be displayed.
|
||||
// This applies to all label types, not just to percentage labels.
|
||||
this.dataLabelThreshold = 3;
|
||||
// prop: dataLabelPositionFactor
|
||||
// A Multiplier (0-1) of the pie radius which controls position of label on slice.
|
||||
// Increasing will slide label toward edge of pie, decreasing will slide label toward center of pie.
|
||||
this.dataLabelPositionFactor = 0.4;
|
||||
// prop: dataLabelNudge
|
||||
// Number of pixels to slide the label away from (+) or toward (-) the center of the pie.
|
||||
this.dataLabelNudge = 0;
|
||||
// prop: startAngle
|
||||
// Angle to start drawing donut in degrees.
|
||||
// According to orientation of canvas coordinate system:
|
||||
// 0 = on the positive x axis
|
||||
// -90 = on the positive y axis.
|
||||
// 90 = on the negaive y axis.
|
||||
// 180 or - 180 = on the negative x axis.
|
||||
this.startAngle = 0;
|
||||
this.tickRenderer = $.jqplot.DonutTickRenderer;
|
||||
// Used as check for conditions where donut shouldn't be drawn.
|
||||
this._drawData = true;
|
||||
this._type = 'donut';
|
||||
|
||||
// if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
|
||||
if (options.highlightMouseDown && options.highlightMouseOver == null) {
|
||||
options.highlightMouseOver = false;
|
||||
}
|
||||
|
||||
$.extend(true, this, options);
|
||||
if (this.diameter != null) {
|
||||
this.diameter = this.diameter - this.sliceMargin;
|
||||
}
|
||||
this._diameter = null;
|
||||
this._innerDiameter = null;
|
||||
this._radius = null;
|
||||
this._innerRadius = null;
|
||||
this._thickness = null;
|
||||
// references to the previous series in the plot to properly calculate diameters
|
||||
// and thicknesses of nested rings.
|
||||
this._previousSeries = [];
|
||||
this._numberSeries = 1;
|
||||
// array of [start,end] angles arrays, one for each slice. In radians.
|
||||
this._sliceAngles = [];
|
||||
// index of the currenty highlighted point, if any
|
||||
this._highlightedPoint = null;
|
||||
|
||||
// set highlight colors if none provided
|
||||
if (this.highlightColors.length == 0) {
|
||||
for (var i=0; i<this.seriesColors.length; i++){
|
||||
var rgba = $.jqplot.getColorComponents(this.seriesColors[i]);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var sum = newrgb[0] + newrgb[1] + newrgb[2];
|
||||
for (var j=0; j<3; j++) {
|
||||
// when darkening, lowest color component can be is 60.
|
||||
newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
|
||||
newrgb[j] = parseInt(newrgb[j], 10);
|
||||
}
|
||||
this.highlightColors.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
|
||||
}
|
||||
}
|
||||
|
||||
plot.postParseOptionsHooks.addOnce(postParseOptions);
|
||||
plot.postInitHooks.addOnce(postInit);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
|
||||
plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
|
||||
plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
|
||||
plot.postDrawHooks.addOnce(postPlotDraw);
|
||||
|
||||
|
||||
};
|
||||
|
||||
$.jqplot.DonutRenderer.prototype.setGridData = function(plot) {
|
||||
// set gridData property. This will hold angle in radians of each data point.
|
||||
var stack = [];
|
||||
var td = [];
|
||||
var sa = this.startAngle/180*Math.PI;
|
||||
var tot = 0;
|
||||
// don't know if we have any valid data yet, so set plot to not draw.
|
||||
this._drawData = false;
|
||||
for (var i=0; i<this.data.length; i++){
|
||||
if (this.data[i][1] != 0) {
|
||||
// we have data, O.K. to draw.
|
||||
this._drawData = true;
|
||||
}
|
||||
stack.push(this.data[i][1]);
|
||||
td.push([this.data[i][0]]);
|
||||
if (i>0) {
|
||||
stack[i] += stack[i-1];
|
||||
}
|
||||
tot += this.data[i][1];
|
||||
}
|
||||
var fact = Math.PI*2/stack[stack.length - 1];
|
||||
|
||||
for (var i=0; i<stack.length; i++) {
|
||||
td[i][1] = stack[i] * fact;
|
||||
td[i][2] = this.data[i][1]/tot;
|
||||
}
|
||||
this.gridData = td;
|
||||
};
|
||||
|
||||
$.jqplot.DonutRenderer.prototype.makeGridData = function(data, plot) {
|
||||
var stack = [];
|
||||
var td = [];
|
||||
var tot = 0;
|
||||
var sa = this.startAngle/180*Math.PI;
|
||||
// don't know if we have any valid data yet, so set plot to not draw.
|
||||
this._drawData = false;
|
||||
for (var i=0; i<data.length; i++){
|
||||
if (this.data[i][1] != 0) {
|
||||
// we have data, O.K. to draw.
|
||||
this._drawData = true;
|
||||
}
|
||||
stack.push(data[i][1]);
|
||||
td.push([data[i][0]]);
|
||||
if (i>0) {
|
||||
stack[i] += stack[i-1];
|
||||
}
|
||||
tot += data[i][1];
|
||||
}
|
||||
var fact = Math.PI*2/stack[stack.length - 1];
|
||||
|
||||
for (var i=0; i<stack.length; i++) {
|
||||
td[i][1] = stack[i] * fact;
|
||||
td[i][2] = data[i][1]/tot;
|
||||
}
|
||||
return td;
|
||||
};
|
||||
|
||||
$.jqplot.DonutRenderer.prototype.drawSlice = function (ctx, ang1, ang2, color, isShadow) {
|
||||
var r = this._diameter / 2;
|
||||
var ri = r - this._thickness;
|
||||
var fill = this.fill;
|
||||
// var lineWidth = this.lineWidth;
|
||||
ctx.save();
|
||||
ctx.translate(this._center[0], this._center[1]);
|
||||
// ctx.translate(this.sliceMargin*Math.cos((ang1+ang2)/2), this.sliceMargin*Math.sin((ang1+ang2)/2));
|
||||
|
||||
if (isShadow) {
|
||||
for (var i=0; i<this.shadowDepth; i++) {
|
||||
ctx.save();
|
||||
ctx.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI), this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));
|
||||
doDraw();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
doDraw();
|
||||
}
|
||||
|
||||
function doDraw () {
|
||||
// Fix for IE and Chrome that can't seem to draw circles correctly.
|
||||
// ang2 should always be <= 2 pi since that is the way the data is converted.
|
||||
if (ang2 > 6.282 + this.startAngle) {
|
||||
ang2 = 6.282 + this.startAngle;
|
||||
if (ang1 > ang2) {
|
||||
ang1 = 6.281 + this.startAngle;
|
||||
}
|
||||
}
|
||||
// Fix for IE, where it can't seem to handle 0 degree angles. Also avoids
|
||||
// ugly line on unfilled donuts.
|
||||
if (ang1 >= ang2) {
|
||||
return;
|
||||
}
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = color;
|
||||
ctx.strokeStyle = color;
|
||||
// ctx.lineWidth = lineWidth;
|
||||
ctx.arc(0, 0, r, ang1, ang2, false);
|
||||
ctx.lineTo(ri*Math.cos(ang2), ri*Math.sin(ang2));
|
||||
ctx.arc(0,0, ri, ang2, ang1, true);
|
||||
ctx.closePath();
|
||||
if (fill) {
|
||||
ctx.fill();
|
||||
}
|
||||
else {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
if (isShadow) {
|
||||
for (var i=0; i<this.shadowDepth; i++) {
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
$.jqplot.DonutRenderer.prototype.draw = function (ctx, gd, options, plot) {
|
||||
var i;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
// offset and direction of offset due to legend placement
|
||||
var offx = 0;
|
||||
var offy = 0;
|
||||
var trans = 1;
|
||||
// var colorGenerator = new this.colorGenerator(this.seriesColors);
|
||||
if (options.legendInfo && options.legendInfo.placement == 'insideGrid') {
|
||||
var li = options.legendInfo;
|
||||
switch (li.location) {
|
||||
case 'nw':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'w':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'sw':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'ne':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'e':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'se':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'n':
|
||||
offy = li.height + li.yoffset;
|
||||
break;
|
||||
case 's':
|
||||
offy = li.height + li.yoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var cw = ctx.canvas.width;
|
||||
var ch = ctx.canvas.height;
|
||||
var w = cw - offx - 2 * this.padding;
|
||||
var h = ch - offy - 2 * this.padding;
|
||||
var mindim = Math.min(w,h);
|
||||
var d = mindim;
|
||||
var ringmargin = (this.ringMargin == null) ? this.sliceMargin * 2.0 : this.ringMargin;
|
||||
|
||||
for (var i=0; i<this._previousSeries.length; i++) {
|
||||
d -= 2.0 * this._previousSeries[i]._thickness + 2.0 * ringmargin;
|
||||
}
|
||||
this._diameter = this.diameter || d;
|
||||
if (this.innerDiameter != null) {
|
||||
var od = (this._numberSeries > 1 && this.index > 0) ? this._previousSeries[0]._diameter : this._diameter;
|
||||
this._thickness = this.thickness || (od - this.innerDiameter - 2.0*ringmargin*this._numberSeries) / this._numberSeries/2.0;
|
||||
}
|
||||
else {
|
||||
this._thickness = this.thickness || mindim / 2 / (this._numberSeries + 1) * 0.85;
|
||||
}
|
||||
|
||||
var r = this._radius = this._diameter/2;
|
||||
this._innerRadius = this._radius - this._thickness;
|
||||
var sa = this.startAngle / 180 * Math.PI;
|
||||
this._center = [(cw - trans * offx)/2 + trans * offx, (ch - trans*offy)/2 + trans * offy];
|
||||
|
||||
if (this.shadow) {
|
||||
var shadowColor = 'rgba(0,0,0,'+this.shadowAlpha+')';
|
||||
for (var i=0; i<gd.length; i++) {
|
||||
var ang1 = (i == 0) ? sa : gd[i-1][1] + sa;
|
||||
// Adjust ang1 and ang2 for sliceMargin
|
||||
ang1 += this.sliceMargin/180*Math.PI;
|
||||
this.renderer.drawSlice.call (this, ctx, ang1, gd[i][1]+sa, shadowColor, true);
|
||||
}
|
||||
|
||||
}
|
||||
for (var i=0; i<gd.length; i++) {
|
||||
var ang1 = (i == 0) ? sa : gd[i-1][1] + sa;
|
||||
// Adjust ang1 and ang2 for sliceMargin
|
||||
ang1 += this.sliceMargin/180*Math.PI;
|
||||
var ang2 = gd[i][1] + sa;
|
||||
this._sliceAngles.push([ang1, ang2]);
|
||||
this.renderer.drawSlice.call (this, ctx, ang1, ang2, this.seriesColors[i], false);
|
||||
|
||||
if (this.showDataLabels && gd[i][2]*100 >= this.dataLabelThreshold) {
|
||||
var fstr, avgang = (ang1+ang2)/2, label;
|
||||
|
||||
if (this.dataLabels == 'label') {
|
||||
fstr = this.dataLabelFormatString || '%s';
|
||||
label = $.jqplot.sprintf(fstr, gd[i][0]);
|
||||
}
|
||||
else if (this.dataLabels == 'value') {
|
||||
fstr = this.dataLabelFormatString || '%d';
|
||||
label = $.jqplot.sprintf(fstr, this.data[i][1]);
|
||||
}
|
||||
else if (this.dataLabels == 'percent') {
|
||||
fstr = this.dataLabelFormatString || '%d%%';
|
||||
label = $.jqplot.sprintf(fstr, gd[i][2]*100);
|
||||
}
|
||||
else if (this.dataLabels.constructor == Array) {
|
||||
fstr = this.dataLabelFormatString || '%s';
|
||||
label = $.jqplot.sprintf(fstr, this.dataLabels[i]);
|
||||
}
|
||||
|
||||
var fact = this._innerRadius + this._thickness * this.dataLabelPositionFactor + this.sliceMargin + this.dataLabelNudge;
|
||||
|
||||
var x = this._center[0] + Math.cos(avgang) * fact + this.canvas._offsets.left;
|
||||
var y = this._center[1] + Math.sin(avgang) * fact + this.canvas._offsets.top;
|
||||
|
||||
var labelelem = $('<span class="jqplot-donut-series jqplot-data-label" style="position:absolute;">' + label + '</span>').insertBefore(plot.eventCanvas._elem);
|
||||
x -= labelelem.width()/2;
|
||||
y -= labelelem.height()/2;
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
labelelem.css({left: x, top: y});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.jqplot.DonutAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.DonutAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.DonutAxisRenderer.prototype.constructor = $.jqplot.DonutAxisRenderer;
|
||||
|
||||
|
||||
// There are no traditional axes on a donut chart. We just need to provide
|
||||
// dummy objects with properties so the plot will render.
|
||||
// called with scope of axis object.
|
||||
$.jqplot.DonutAxisRenderer.prototype.init = function(options){
|
||||
//
|
||||
this.tickRenderer = $.jqplot.DonutTickRenderer;
|
||||
$.extend(true, this, options);
|
||||
// I don't think I'm going to need _dataBounds here.
|
||||
// have to go Axis scaling in a way to fit chart onto plot area
|
||||
// and provide u2p and p2u functionality for mouse cursor, etc.
|
||||
// for convienence set _dataBounds to 0 and 100 and
|
||||
// set min/max to 0 and 100.
|
||||
this._dataBounds = {min:0, max:100};
|
||||
this.min = 0;
|
||||
this.max = 100;
|
||||
this.showTicks = false;
|
||||
this.ticks = [];
|
||||
this.showMark = false;
|
||||
this.show = false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
$.jqplot.DonutLegendRenderer = function(){
|
||||
$.jqplot.TableLegendRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.DonutLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
|
||||
$.jqplot.DonutLegendRenderer.prototype.constructor = $.jqplot.DonutLegendRenderer;
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.DonutLegendRenderer
|
||||
* Legend Renderer specific to donut plots. Set by default
|
||||
* when user creates a donut plot.
|
||||
*/
|
||||
$.jqplot.DonutLegendRenderer.prototype.init = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: numberRows
|
||||
// Maximum number of rows in the legend. 0 or null for unlimited.
|
||||
this.numberRows = null;
|
||||
// prop: numberColumns
|
||||
// Maximum number of columns in the legend. 0 or null for unlimited.
|
||||
this.numberColumns = null;
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
// called with context of legend
|
||||
$.jqplot.DonutLegendRenderer.prototype.draw = function() {
|
||||
var legend = this;
|
||||
if (this.show) {
|
||||
var series = this._series;
|
||||
var ss = 'position:absolute;';
|
||||
ss += (this.background) ? 'background:'+this.background+';' : '';
|
||||
ss += (this.border) ? 'border:'+this.border+';' : '';
|
||||
ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
|
||||
ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
|
||||
ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
|
||||
ss += (this.marginTop != null) ? 'margin-top:'+this.marginTop+';' : '';
|
||||
ss += (this.marginBottom != null) ? 'margin-bottom:'+this.marginBottom+';' : '';
|
||||
ss += (this.marginLeft != null) ? 'margin-left:'+this.marginLeft+';' : '';
|
||||
ss += (this.marginRight != null) ? 'margin-right:'+this.marginRight+';' : '';
|
||||
this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
|
||||
// Donut charts legends don't go by number of series, but by number of data points
|
||||
// in the series. Refactor things here for that.
|
||||
|
||||
var pad = false,
|
||||
reverse = false,
|
||||
nr, nc;
|
||||
var s = series[0];
|
||||
var colorGenerator = new $.jqplot.ColorGenerator(s.seriesColors);
|
||||
|
||||
if (s.show) {
|
||||
var pd = s.data;
|
||||
if (this.numberRows) {
|
||||
nr = this.numberRows;
|
||||
if (!this.numberColumns){
|
||||
nc = Math.ceil(pd.length/nr);
|
||||
}
|
||||
else{
|
||||
nc = this.numberColumns;
|
||||
}
|
||||
}
|
||||
else if (this.numberColumns) {
|
||||
nc = this.numberColumns;
|
||||
nr = Math.ceil(pd.length/this.numberColumns);
|
||||
}
|
||||
else {
|
||||
nr = pd.length;
|
||||
nc = 1;
|
||||
}
|
||||
|
||||
var i, j, tr, td1, td2, lt, rs, color;
|
||||
var idx = 0;
|
||||
|
||||
for (i=0; i<nr; i++) {
|
||||
if (reverse){
|
||||
tr = $('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem);
|
||||
}
|
||||
else{
|
||||
tr = $('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem);
|
||||
}
|
||||
for (j=0; j<nc; j++) {
|
||||
if (idx < pd.length){
|
||||
lt = this.labels[idx] || pd[idx][0].toString();
|
||||
color = colorGenerator.next();
|
||||
if (!reverse){
|
||||
if (i>0){
|
||||
pad = true;
|
||||
}
|
||||
else{
|
||||
pad = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (i == nr -1){
|
||||
pad = false;
|
||||
}
|
||||
else{
|
||||
pad = true;
|
||||
}
|
||||
}
|
||||
rs = (pad) ? this.rowSpacing : '0';
|
||||
|
||||
td1 = $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
|
||||
'<div><div class="jqplot-table-legend-swatch" style="border-color:'+color+';"></div>'+
|
||||
'</div></td>');
|
||||
td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
|
||||
if (this.escapeHtml){
|
||||
td2.text(lt);
|
||||
}
|
||||
else {
|
||||
td2.html(lt);
|
||||
}
|
||||
if (reverse) {
|
||||
td2.prependTo(tr);
|
||||
td1.prependTo(tr);
|
||||
}
|
||||
else {
|
||||
td1.appendTo(tr);
|
||||
td2.appendTo(tr);
|
||||
}
|
||||
pad = true;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
// setup default renderers for axes and legend so user doesn't have to
|
||||
// called with scope of plot
|
||||
function preInit(target, data, options) {
|
||||
options = options || {};
|
||||
options.axesDefaults = options.axesDefaults || {};
|
||||
options.legend = options.legend || {};
|
||||
options.seriesDefaults = options.seriesDefaults || {};
|
||||
// only set these if there is a donut series
|
||||
var setopts = false;
|
||||
if (options.seriesDefaults.renderer == $.jqplot.DonutRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
else if (options.series) {
|
||||
for (var i=0; i < options.series.length; i++) {
|
||||
if (options.series[i].renderer == $.jqplot.DonutRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setopts) {
|
||||
options.axesDefaults.renderer = $.jqplot.DonutAxisRenderer;
|
||||
options.legend.renderer = $.jqplot.DonutLegendRenderer;
|
||||
options.legend.preDraw = true;
|
||||
options.seriesDefaults.pointLabels = {show: false};
|
||||
}
|
||||
}
|
||||
|
||||
// called with scope of plot.
|
||||
function postInit(target, data, options) {
|
||||
// if multiple series, add a reference to the previous one so that
|
||||
// donut rings can nest.
|
||||
for (var i=1; i<this.series.length; i++) {
|
||||
if (!this.series[i]._previousSeries.length){
|
||||
for (var j=0; j<i; j++) {
|
||||
if (this.series[i].renderer.constructor == $.jqplot.DonutRenderer && this.series[j].renderer.constructor == $.jqplot.DonutRenderer) {
|
||||
this.series[i]._previousSeries.push(this.series[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i=0; i<this.series.length; i++) {
|
||||
if (this.series[i].renderer.constructor == $.jqplot.DonutRenderer) {
|
||||
this.series[i]._numberSeries = this.series.length;
|
||||
// don't allow mouseover and mousedown at same time.
|
||||
if (this.series[i].highlightMouseOver) {
|
||||
this.series[i].highlightMouseDown = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var postParseOptionsRun = false;
|
||||
// called with scope of plot
|
||||
function postParseOptions(options) {
|
||||
for (var i=0; i<this.series.length; i++) {
|
||||
this.series[i].seriesColors = this.seriesColors;
|
||||
this.series[i].colorGenerator = $.jqplot.colorGenerator;
|
||||
}
|
||||
}
|
||||
|
||||
function highlight (plot, sidx, pidx) {
|
||||
var s = plot.series[sidx];
|
||||
var canvas = plot.plugins.donutRenderer.highlightCanvas;
|
||||
canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
|
||||
s._highlightedPoint = pidx;
|
||||
plot.plugins.donutRenderer.highlightedSeriesIndex = sidx;
|
||||
s.renderer.drawSlice.call(s, canvas._ctx, s._sliceAngles[pidx][0], s._sliceAngles[pidx][1], s.highlightColors[pidx], false);
|
||||
}
|
||||
|
||||
function unhighlight (plot) {
|
||||
var canvas = plot.plugins.donutRenderer.highlightCanvas;
|
||||
canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
|
||||
for (var i=0; i<plot.series.length; i++) {
|
||||
plot.series[i]._highlightedPoint = null;
|
||||
}
|
||||
plot.plugins.donutRenderer.highlightedSeriesIndex = null;
|
||||
plot.target.trigger('jqplotDataUnhighlight');
|
||||
}
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var evt1 = jQuery.Event('jqplotDataMouseOver');
|
||||
evt1.pageX = ev.pageX;
|
||||
evt1.pageY = ev.pageY;
|
||||
plot.target.trigger(evt1, ins);
|
||||
if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.donutRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, ins[0], ins[1]);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.donutRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, ins[0], ins[1]);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
|
||||
var idx = plot.plugins.donutRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var evt = jQuery.Event('jqplotDataClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var idx = plot.plugins.donutRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
var evt = jQuery.Event('jqplotDataRightClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
function postPlotDraw() {
|
||||
// Memory Leaks patch
|
||||
if (this.plugins.donutRenderer && this.plugins.donutRenderer.highlightCanvas) {
|
||||
this.plugins.donutRenderer.highlightCanvas.resetCanvas();
|
||||
this.plugins.donutRenderer.highlightCanvas = null;
|
||||
}
|
||||
|
||||
this.plugins.donutRenderer = {highlightedSeriesIndex:null};
|
||||
this.plugins.donutRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
|
||||
// do we have any data labels? if so, put highlight canvas before those
|
||||
// Fix for broken jquery :first selector with canvas (VML) elements.
|
||||
var labels = $(this.targetId+' .jqplot-data-label');
|
||||
if (labels.length) {
|
||||
$(labels[0]).before(this.plugins.donutRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-donutRenderer-highlight-canvas', this._plotDimensions, this));
|
||||
}
|
||||
// else put highlight canvas before event canvas.
|
||||
else {
|
||||
this.eventCanvas._elem.before(this.plugins.donutRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-donutRenderer-highlight-canvas', this._plotDimensions, this));
|
||||
}
|
||||
var hctx = this.plugins.donutRenderer.highlightCanvas.setContext();
|
||||
this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
|
||||
}
|
||||
|
||||
$.jqplot.preInitHooks.push(preInit);
|
||||
|
||||
$.jqplot.DonutTickRenderer = function() {
|
||||
$.jqplot.AxisTickRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.DonutTickRenderer.prototype = new $.jqplot.AxisTickRenderer();
|
||||
$.jqplot.DonutTickRenderer.prototype.constructor = $.jqplot.DonutTickRenderer;
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,225 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.Dragable
|
||||
* Plugin to make plotted points dragable by the user.
|
||||
*/
|
||||
$.jqplot.Dragable = function(options) {
|
||||
// Group: Properties
|
||||
this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
|
||||
this.shapeRenderer = new $.jqplot.ShapeRenderer();
|
||||
this.isDragging = false;
|
||||
this.isOver = false;
|
||||
this._ctx;
|
||||
this._elem;
|
||||
this._point;
|
||||
this._gridData;
|
||||
// prop: color
|
||||
// CSS color spec for the dragged point (and adjacent line segment or bar).
|
||||
this.color;
|
||||
// prop: constrainTo
|
||||
// Constrain dragging motion to an axis or to none.
|
||||
// Allowable values are 'none', 'x', 'y'
|
||||
this.constrainTo = 'none'; // 'x', 'y', or 'none';
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
function DragCanvas() {
|
||||
$.jqplot.GenericCanvas.call(this);
|
||||
this.isDragging = false;
|
||||
this.isOver = false;
|
||||
this._neighbor;
|
||||
this._cursors = [];
|
||||
}
|
||||
|
||||
DragCanvas.prototype = new $.jqplot.GenericCanvas();
|
||||
DragCanvas.prototype.constructor = DragCanvas;
|
||||
|
||||
|
||||
// called within scope of series
|
||||
$.jqplot.Dragable.parseOptions = function (defaults, opts) {
|
||||
var options = opts || {};
|
||||
this.plugins.dragable = new $.jqplot.Dragable(options.dragable);
|
||||
// since this function is called before series options are parsed,
|
||||
// we can set this here and it will be overridden if needed.
|
||||
this.isDragable = $.jqplot.config.enablePlugins;
|
||||
};
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
// add a new DragCanvas object to the plot plugins to handle drawing on this new canvas.
|
||||
$.jqplot.Dragable.postPlotDraw = function() {
|
||||
// Memory Leaks patch
|
||||
if (this.plugins.dragable && this.plugins.dragable.highlightCanvas) {
|
||||
this.plugins.dragable.highlightCanvas.resetCanvas();
|
||||
this.plugins.dragable.highlightCanvas = null;
|
||||
}
|
||||
|
||||
this.plugins.dragable = {previousCursor:'auto', isOver:false};
|
||||
this.plugins.dragable.dragCanvas = new DragCanvas();
|
||||
|
||||
this.eventCanvas._elem.before(this.plugins.dragable.dragCanvas.createElement(this._gridPadding, 'jqplot-dragable-canvas', this._plotDimensions, this));
|
||||
var dctx = this.plugins.dragable.dragCanvas.setContext();
|
||||
};
|
||||
|
||||
//$.jqplot.preInitHooks.push($.jqplot.Dragable.init);
|
||||
$.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Dragable.parseOptions);
|
||||
$.jqplot.postDrawHooks.push($.jqplot.Dragable.postPlotDraw);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseDown', handleDown]);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseUp', handleUp]);
|
||||
|
||||
|
||||
function initDragPoint(plot, neighbor) {
|
||||
var s = plot.series[neighbor.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
|
||||
// first, init the mark renderer for the dragged point
|
||||
var smr = s.markerRenderer;
|
||||
var mr = drag.markerRenderer;
|
||||
mr.style = smr.style;
|
||||
mr.lineWidth = smr.lineWidth + 2.5;
|
||||
mr.size = smr.size + 5;
|
||||
if (!drag.color) {
|
||||
var rgba = $.jqplot.getColorComponents(smr.color);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
|
||||
drag.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
|
||||
}
|
||||
mr.color = drag.color;
|
||||
mr.init();
|
||||
|
||||
var start = (neighbor.pointIndex > 0) ? neighbor.pointIndex - 1 : 0;
|
||||
var end = neighbor.pointIndex+2;
|
||||
drag._gridData = s.gridData.slice(start, end);
|
||||
}
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (plot.plugins.dragable.dragCanvas.isDragging) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
var dp = dc._neighbor;
|
||||
var s = plot.series[dp.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
var gd = s.gridData;
|
||||
|
||||
// compute the new grid position with any constraints.
|
||||
var x = (drag.constrainTo == 'y') ? dp.gridData[0] : gridpos.x;
|
||||
var y = (drag.constrainTo == 'x') ? dp.gridData[1] : gridpos.y;
|
||||
|
||||
// compute data values for any listeners.
|
||||
var xu = s._xaxis.series_p2u(x);
|
||||
var yu = s._yaxis.series_p2u(y);
|
||||
|
||||
// clear the canvas then redraw effect at new position.
|
||||
var ctx = dc._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
|
||||
// adjust our gridData for the new mouse position
|
||||
if (dp.pointIndex > 0) {
|
||||
drag._gridData[1] = [x, y];
|
||||
}
|
||||
else {
|
||||
drag._gridData[0] = [x, y];
|
||||
}
|
||||
plot.series[dp.seriesIndex].draw(dc._ctx, {gridData:drag._gridData, shadow:false, preventJqPlotSeriesDrawTrigger:true, color:drag.color, markerOptions:{color:drag.color, shadow:false}, trendline:{show:false}});
|
||||
plot.target.trigger('jqplotSeriesPointChange', [dp.seriesIndex, dp.pointIndex, [xu,yu], [x,y]]);
|
||||
}
|
||||
else if (neighbor != null) {
|
||||
var series = plot.series[neighbor.seriesIndex];
|
||||
if (series.isDragable) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
if (!dc.isOver) {
|
||||
dc._cursors.push(ev.target.style.cursor);
|
||||
ev.target.style.cursor = "pointer";
|
||||
}
|
||||
dc.isOver = true;
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
if (dc.isOver) {
|
||||
ev.target.style.cursor = dc._cursors.pop();
|
||||
dc.isOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDown(ev, gridpos, datapos, neighbor, plot) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
dc._cursors.push(ev.target.style.cursor);
|
||||
if (neighbor != null) {
|
||||
var s = plot.series[neighbor.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
if (s.isDragable && !dc.isDragging) {
|
||||
dc._neighbor = neighbor;
|
||||
dc.isDragging = true;
|
||||
initDragPoint(plot, neighbor);
|
||||
drag.markerRenderer.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], dc._ctx);
|
||||
ev.target.style.cursor = "move";
|
||||
plot.target.trigger('jqplotDragStart', [neighbor.seriesIndex, neighbor.pointIndex, gridpos, datapos]);
|
||||
}
|
||||
}
|
||||
// Just in case of a hickup, we'll clear the drag canvas and reset.
|
||||
else {
|
||||
var ctx = dc._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
dc.isDragging = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleUp(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (plot.plugins.dragable.dragCanvas.isDragging) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
// clear the canvas
|
||||
var ctx = dc._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
dc.isDragging = false;
|
||||
// redraw the series canvas at the new point.
|
||||
var dp = dc._neighbor;
|
||||
var s = plot.series[dp.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
// compute the new grid position with any constraints.
|
||||
var x = (drag.constrainTo == 'y') ? dp.data[0] : datapos[s.xaxis];
|
||||
var y = (drag.constrainTo == 'x') ? dp.data[1] : datapos[s.yaxis];
|
||||
// var x = datapos[s.xaxis];
|
||||
// var y = datapos[s.yaxis];
|
||||
s.data[dp.pointIndex][0] = x;
|
||||
s.data[dp.pointIndex][1] = y;
|
||||
plot.drawSeries({preventJqPlotSeriesDrawTrigger:true}, dp.seriesIndex);
|
||||
dc._neighbor = null;
|
||||
ev.target.style.cursor = dc._cursors.pop();
|
||||
plot.target.trigger('jqplotDragStop', [gridpos, datapos]);
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
57
src/html/jqplot/plugins/jqplot.dragable.min.js
vendored
57
src/html/jqplot/plugins/jqplot.dragable.min.js
vendored
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4r1121
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2011 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function(d){d.jqplot.Dragable=function(g){this.markerRenderer=new d.jqplot.MarkerRenderer({shadow:false});this.shapeRenderer=new d.jqplot.ShapeRenderer();this.isDragging=false;this.isOver=false;this._ctx;this._elem;this._point;this._gridData;this.color;this.constrainTo="none";d.extend(true,this,g)};function b(){d.jqplot.GenericCanvas.call(this);this.isDragging=false;this.isOver=false;this._neighbor;this._cursors=[]}b.prototype=new d.jqplot.GenericCanvas();b.prototype.constructor=b;d.jqplot.Dragable.parseOptions=function(i,h){var g=h||{};this.plugins.dragable=new d.jqplot.Dragable(g.dragable);this.isDragable=d.jqplot.config.enablePlugins};d.jqplot.Dragable.postPlotDraw=function(){if(this.plugins.dragable&&this.plugins.dragable.highlightCanvas){this.plugins.dragable.highlightCanvas.resetCanvas();this.plugins.dragable.highlightCanvas=null}this.plugins.dragable={previousCursor:"auto",isOver:false};this.plugins.dragable.dragCanvas=new b();this.eventCanvas._elem.before(this.plugins.dragable.dragCanvas.createElement(this._gridPadding,"jqplot-dragable-canvas",this._plotDimensions,this));var g=this.plugins.dragable.dragCanvas.setContext()};d.jqplot.preParseSeriesOptionsHooks.push(d.jqplot.Dragable.parseOptions);d.jqplot.postDrawHooks.push(d.jqplot.Dragable.postPlotDraw);d.jqplot.eventListenerHooks.push(["jqplotMouseMove",e]);d.jqplot.eventListenerHooks.push(["jqplotMouseDown",c]);d.jqplot.eventListenerHooks.push(["jqplotMouseUp",a]);function f(n,p){var q=n.series[p.seriesIndex];var m=q.plugins.dragable;var h=q.markerRenderer;var i=m.markerRenderer;i.style=h.style;i.lineWidth=h.lineWidth+2.5;i.size=h.size+5;if(!m.color){var l=d.jqplot.getColorComponents(h.color);var o=[l[0],l[1],l[2]];var k=(l[3]>=0.6)?l[3]*0.6:l[3]*(2-l[3]);m.color="rgba("+o[0]+","+o[1]+","+o[2]+","+k+")"}i.color=m.color;i.init();var g=(p.pointIndex>0)?p.pointIndex-1:0;var j=p.pointIndex+2;m._gridData=q.gridData.slice(g,j)}function e(o,l,h,t,m){if(m.plugins.dragable.dragCanvas.isDragging){var u=m.plugins.dragable.dragCanvas;var i=u._neighbor;var w=m.series[i.seriesIndex];var k=w.plugins.dragable;var r=w.gridData;var p=(k.constrainTo=="y")?i.gridData[0]:l.x;var n=(k.constrainTo=="x")?i.gridData[1]:l.y;var g=w._xaxis.series_p2u(p);var q=w._yaxis.series_p2u(n);var v=u._ctx;v.clearRect(0,0,v.canvas.width,v.canvas.height);if(i.pointIndex>0){k._gridData[1]=[p,n]}else{k._gridData[0]=[p,n]}m.series[i.seriesIndex].draw(u._ctx,{gridData:k._gridData,shadow:false,preventJqPlotSeriesDrawTrigger:true,color:k.color,markerOptions:{color:k.color,shadow:false},trendline:{show:false}});m.target.trigger("jqplotSeriesPointChange",[i.seriesIndex,i.pointIndex,[g,q],[p,n]])}else{if(t!=null){var j=m.series[t.seriesIndex];if(j.isDragable){var u=m.plugins.dragable.dragCanvas;if(!u.isOver){u._cursors.push(o.target.style.cursor);o.target.style.cursor="pointer"}u.isOver=true}}else{if(t==null){var u=m.plugins.dragable.dragCanvas;if(u.isOver){o.target.style.cursor=u._cursors.pop();u.isOver=false}}}}}function c(k,i,g,l,j){var m=j.plugins.dragable.dragCanvas;m._cursors.push(k.target.style.cursor);if(l!=null){var o=j.series[l.seriesIndex];var h=o.plugins.dragable;if(o.isDragable&&!m.isDragging){m._neighbor=l;m.isDragging=true;f(j,l);h.markerRenderer.draw(o.gridData[l.pointIndex][0],o.gridData[l.pointIndex][1],m._ctx);k.target.style.cursor="move";j.target.trigger("jqplotDragStart",[l.seriesIndex,l.pointIndex,i,g])}}else{var n=m._ctx;n.clearRect(0,0,n.canvas.width,n.canvas.height);m.isDragging=false}}function a(m,j,g,o,k){if(k.plugins.dragable.dragCanvas.isDragging){var p=k.plugins.dragable.dragCanvas;var q=p._ctx;q.clearRect(0,0,q.canvas.width,q.canvas.height);p.isDragging=false;var h=p._neighbor;var r=k.series[h.seriesIndex];var i=r.plugins.dragable;var n=(i.constrainTo=="y")?h.data[0]:g[r.xaxis];var l=(i.constrainTo=="x")?h.data[1]:g[r.yaxis];r.data[h.pointIndex][0]=n;r.data[h.pointIndex][1]=l;k.drawSeries({preventJqPlotSeriesDrawTrigger:true},h.seriesIndex);p._neighbor=null;m.target.style.cursor=p._cursors.pop();k.target.trigger("jqplotDragStop",[j,g])}}})(jQuery);
|
@ -1,305 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
// class $.jqplot.EnhancedLegendRenderer
|
||||
// Legend renderer which can specify the number of rows and/or columns in the legend.
|
||||
$.jqplot.EnhancedLegendRenderer = function(){
|
||||
$.jqplot.TableLegendRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.EnhancedLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
|
||||
$.jqplot.EnhancedLegendRenderer.prototype.constructor = $.jqplot.EnhancedLegendRenderer;
|
||||
|
||||
// called with scope of legend.
|
||||
$.jqplot.EnhancedLegendRenderer.prototype.init = function(options) {
|
||||
// prop: numberRows
|
||||
// Maximum number of rows in the legend. 0 or null for unlimited.
|
||||
this.numberRows = null;
|
||||
// prop: numberColumns
|
||||
// Maximum number of columns in the legend. 0 or null for unlimited.
|
||||
this.numberColumns = null;
|
||||
// prop: seriesToggle
|
||||
// false to not enable series on/off toggling on the legend.
|
||||
// true or a fadein/fadeout speed (number of milliseconds or 'fast', 'normal', 'slow')
|
||||
// to enable show/hide of series on click of legend item.
|
||||
this.seriesToggle = 'normal';
|
||||
// prop: seriesToggleReplot
|
||||
// True to replot the chart after toggling series on/off.
|
||||
// This will set the series show property to false.
|
||||
// This allows for rescaling or other maniplation of chart.
|
||||
// Set to an options object (e.g. {resetAxes: true}) for replot options.
|
||||
this.seriesToggleReplot = false;
|
||||
// prop: disableIEFading
|
||||
// true to toggle series with a show/hide method only and not allow fading in/out.
|
||||
// This is to overcome poor performance of fade in some versions of IE.
|
||||
this.disableIEFading = true;
|
||||
$.extend(true, this, options);
|
||||
|
||||
if (this.seriesToggle) {
|
||||
$.jqplot.postDrawHooks.push(postDraw);
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of legend
|
||||
$.jqplot.EnhancedLegendRenderer.prototype.draw = function(offsets, plot) {
|
||||
var legend = this;
|
||||
if (this.show) {
|
||||
var series = this._series;
|
||||
var s;
|
||||
var ss = 'position:absolute;';
|
||||
ss += (this.background) ? 'background:'+this.background+';' : '';
|
||||
ss += (this.border) ? 'border:'+this.border+';' : '';
|
||||
ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
|
||||
ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
|
||||
ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
|
||||
ss += (this.marginTop != null) ? 'margin-top:'+this.marginTop+';' : '';
|
||||
ss += (this.marginBottom != null) ? 'margin-bottom:'+this.marginBottom+';' : '';
|
||||
ss += (this.marginLeft != null) ? 'margin-left:'+this.marginLeft+';' : '';
|
||||
ss += (this.marginRight != null) ? 'margin-right:'+this.marginRight+';' : '';
|
||||
this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
|
||||
if (this.seriesToggle) {
|
||||
this._elem.css('z-index', '3');
|
||||
}
|
||||
|
||||
var pad = false,
|
||||
reverse = false,
|
||||
nr, nc;
|
||||
if (this.numberRows) {
|
||||
nr = this.numberRows;
|
||||
if (!this.numberColumns){
|
||||
nc = Math.ceil(series.length/nr);
|
||||
}
|
||||
else{
|
||||
nc = this.numberColumns;
|
||||
}
|
||||
}
|
||||
else if (this.numberColumns) {
|
||||
nc = this.numberColumns;
|
||||
nr = Math.ceil(series.length/this.numberColumns);
|
||||
}
|
||||
else {
|
||||
nr = series.length;
|
||||
nc = 1;
|
||||
}
|
||||
|
||||
var i, j, tr, td1, td2, lt, rs, div, div0, div1;
|
||||
var idx = 0;
|
||||
// check to see if we need to reverse
|
||||
for (i=series.length-1; i>=0; i--) {
|
||||
if (nc == 1 && series[i]._stack || series[i].renderer.constructor == $.jqplot.BezierCurveRenderer){
|
||||
reverse = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<nr; i++) {
|
||||
tr = $(document.createElement('tr'));
|
||||
tr.addClass('jqplot-table-legend');
|
||||
if (reverse){
|
||||
tr.prependTo(this._elem);
|
||||
}
|
||||
else{
|
||||
tr.appendTo(this._elem);
|
||||
}
|
||||
for (j=0; j<nc; j++) {
|
||||
if (idx < series.length && (series[idx].show || series[idx].showLabel)){
|
||||
s = series[idx];
|
||||
lt = this.labels[idx] || s.label.toString();
|
||||
if (lt) {
|
||||
var color = s.color;
|
||||
if (!reverse){
|
||||
if (i>0){
|
||||
pad = true;
|
||||
}
|
||||
else{
|
||||
pad = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (i == nr -1){
|
||||
pad = false;
|
||||
}
|
||||
else{
|
||||
pad = true;
|
||||
}
|
||||
}
|
||||
rs = (pad) ? this.rowSpacing : '0';
|
||||
|
||||
td1 = $(document.createElement('td'));
|
||||
td1.addClass('jqplot-table-legend jqplot-table-legend-swatch');
|
||||
td1.css({textAlign: 'center', paddingTop: rs});
|
||||
|
||||
div0 = $(document.createElement('div'));
|
||||
div0.addClass('jqplot-table-legend-swatch-outline');
|
||||
div1 = $(document.createElement('div'));
|
||||
div1.addClass('jqplot-table-legend-swatch');
|
||||
div1.css({backgroundColor: color, borderColor: color});
|
||||
|
||||
td1.append(div0.append(div1));
|
||||
|
||||
td2 = $(document.createElement('td'));
|
||||
td2.addClass('jqplot-table-legend jqplot-table-legend-label');
|
||||
td2.css('paddingTop', rs);
|
||||
|
||||
// td1 = $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
|
||||
// '<div><div class="jqplot-table-legend-swatch" style="background-color:'+color+';border-color:'+color+';"></div>'+
|
||||
// '</div></td>');
|
||||
// td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
|
||||
if (this.escapeHtml){
|
||||
td2.text(lt);
|
||||
}
|
||||
else {
|
||||
td2.html(lt);
|
||||
}
|
||||
if (reverse) {
|
||||
if (this.showLabels) {td2.prependTo(tr);}
|
||||
if (this.showSwatches) {td1.prependTo(tr);}
|
||||
}
|
||||
else {
|
||||
if (this.showSwatches) {td1.appendTo(tr);}
|
||||
if (this.showLabels) {td2.appendTo(tr);}
|
||||
}
|
||||
|
||||
if (this.seriesToggle) {
|
||||
|
||||
// add an overlay for clicking series on/off
|
||||
// div0 = $(document.createElement('div'));
|
||||
// div0.addClass('jqplot-table-legend-overlay');
|
||||
// div0.css({position:'relative', left:0, top:0, height:'100%', width:'100%'});
|
||||
// tr.append(div0);
|
||||
|
||||
var speed;
|
||||
if (typeof(this.seriesToggle) === 'string' || typeof(this.seriesToggle) === 'number') {
|
||||
if (!$.jqplot.use_excanvas || !this.disableIEFading) {
|
||||
speed = this.seriesToggle;
|
||||
}
|
||||
}
|
||||
if (this.showSwatches) {
|
||||
td1.bind('click', {series:s, speed:speed, plot: plot, replot:this.seriesToggleReplot}, handleToggle);
|
||||
td1.addClass('jqplot-seriesToggle');
|
||||
}
|
||||
if (this.showLabels) {
|
||||
td2.bind('click', {series:s, speed:speed, plot: plot, replot:this.seriesToggleReplot}, handleToggle);
|
||||
td2.addClass('jqplot-seriesToggle');
|
||||
}
|
||||
|
||||
// for series that are already hidden, add the hidden class
|
||||
if (!s.show && s.showLabel) {
|
||||
td1.addClass('jqplot-series-hidden');
|
||||
td2.addClass('jqplot-series-hidden');
|
||||
}
|
||||
}
|
||||
|
||||
pad = true;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
td1 = td2 = div0 = div1 = null;
|
||||
}
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
var handleToggle = function (ev) {
|
||||
var d = ev.data,
|
||||
s = d.series,
|
||||
replot = d.replot,
|
||||
plot = d.plot,
|
||||
speed = d.speed,
|
||||
sidx = s.index,
|
||||
showing = false;
|
||||
|
||||
if (s.canvas._elem.is(':hidden') || !s.show) {
|
||||
showing = true;
|
||||
}
|
||||
|
||||
var doLegendToggle = function() {
|
||||
|
||||
if (replot) {
|
||||
var opts = {};
|
||||
|
||||
if ($.isPlainObject(replot)) {
|
||||
$.extend(true, opts, replot);
|
||||
}
|
||||
|
||||
plot.replot(opts);
|
||||
// if showing, there was no canvas element to fade in, so hide here
|
||||
// and then do a fade in.
|
||||
if (showing && speed) {
|
||||
var s = plot.series[sidx];
|
||||
|
||||
if (s.shadowCanvas._elem) {
|
||||
s.shadowCanvas._elem.hide().fadeIn(speed);
|
||||
}
|
||||
s.canvas._elem.hide().fadeIn(speed);
|
||||
s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).hide().fadeIn(speed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
var s = plot.series[sidx];
|
||||
|
||||
if (s.canvas._elem.is(':hidden') || !s.show) {
|
||||
// Not sure if there is a better way to check for showSwatches and showLabels === true.
|
||||
// Test for "undefined" since default values for both showSwatches and showLables is true.
|
||||
if (typeof plot.options.legend.showSwatches === 'undefined' || plot.options.legend.showSwatches === true) {
|
||||
plot.legend._elem.find('td').eq(sidx * 2).addClass('jqplot-series-hidden');
|
||||
}
|
||||
if (typeof plot.options.legend.showLabels === 'undefined' || plot.options.legend.showLabels === true) {
|
||||
plot.legend._elem.find('td').eq((sidx * 2) + 1).addClass('jqplot-series-hidden');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (typeof plot.options.legend.showSwatches === 'undefined' || plot.options.legend.showSwatches === true) {
|
||||
plot.legend._elem.find('td').eq(sidx * 2).removeClass('jqplot-series-hidden');
|
||||
}
|
||||
if (typeof plot.options.legend.showLabels === 'undefined' || plot.options.legend.showLabels === true) {
|
||||
plot.legend._elem.find('td').eq((sidx * 2) + 1).removeClass('jqplot-series-hidden');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
s.toggleDisplay(ev, doLegendToggle);
|
||||
};
|
||||
|
||||
// called with scope of plot.
|
||||
var postDraw = function () {
|
||||
if (this.legend.renderer.constructor == $.jqplot.EnhancedLegendRenderer && this.legend.seriesToggle){
|
||||
var e = this.legend._elem.detach();
|
||||
this.eventCanvas._elem.after(e);
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4r1121
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2011 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function(c){c.jqplot.EnhancedLegendRenderer=function(){c.jqplot.TableLegendRenderer.call(this)};c.jqplot.EnhancedLegendRenderer.prototype=new c.jqplot.TableLegendRenderer();c.jqplot.EnhancedLegendRenderer.prototype.constructor=c.jqplot.EnhancedLegendRenderer;c.jqplot.EnhancedLegendRenderer.prototype.init=function(d){this.numberRows=null;this.numberColumns=null;this.seriesToggle="normal";this.seriesToggleReplot=false;this.disableIEFading=true;c.extend(true,this,d);if(this.seriesToggle){c.jqplot.postDrawHooks.push(b)}};c.jqplot.EnhancedLegendRenderer.prototype.draw=function(m,y){var f=this;if(this.show){var r=this._series;var u;var w="position:absolute;";w+=(this.background)?"background:"+this.background+";":"";w+=(this.border)?"border:"+this.border+";":"";w+=(this.fontSize)?"font-size:"+this.fontSize+";":"";w+=(this.fontFamily)?"font-family:"+this.fontFamily+";":"";w+=(this.textColor)?"color:"+this.textColor+";":"";w+=(this.marginTop!=null)?"margin-top:"+this.marginTop+";":"";w+=(this.marginBottom!=null)?"margin-bottom:"+this.marginBottom+";":"";w+=(this.marginLeft!=null)?"margin-left:"+this.marginLeft+";":"";w+=(this.marginRight!=null)?"margin-right:"+this.marginRight+";":"";this._elem=c('<table class="jqplot-table-legend" style="'+w+'"></table>');if(this.seriesToggle){this._elem.css("z-index","3")}var C=false,q=false,d,o;if(this.numberRows){d=this.numberRows;if(!this.numberColumns){o=Math.ceil(r.length/d)}else{o=this.numberColumns}}else{if(this.numberColumns){o=this.numberColumns;d=Math.ceil(r.length/this.numberColumns)}else{d=r.length;o=1}}var B,z,e,l,k,n,p,t,h,g;var v=0;for(B=r.length-1;B>=0;B--){if(o==1&&r[B]._stack||r[B].renderer.constructor==c.jqplot.BezierCurveRenderer){q=true}}for(B=0;B<d;B++){e=c(document.createElement("tr"));e.addClass("jqplot-table-legend");if(q){e.prependTo(this._elem)}else{e.appendTo(this._elem)}for(z=0;z<o;z++){if(v<r.length&&(r[v].show||r[v].showLabel)){u=r[v];n=this.labels[v]||u.label.toString();if(n){var x=u.color;if(!q){if(B>0){C=true}else{C=false}}else{if(B==d-1){C=false}else{C=true}}p=(C)?this.rowSpacing:"0";l=c(document.createElement("td"));l.addClass("jqplot-table-legend jqplot-table-legend-swatch");l.css({textAlign:"center",paddingTop:p});h=c(document.createElement("div"));h.addClass("jqplot-table-legend-swatch-outline");g=c(document.createElement("div"));g.addClass("jqplot-table-legend-swatch");g.css({backgroundColor:x,borderColor:x});l.append(h.append(g));k=c(document.createElement("td"));k.addClass("jqplot-table-legend jqplot-table-legend-label");k.css("paddingTop",p);if(this.escapeHtml){k.text(n)}else{k.html(n)}if(q){if(this.showLabels){k.prependTo(e)}if(this.showSwatches){l.prependTo(e)}}else{if(this.showSwatches){l.appendTo(e)}if(this.showLabels){k.appendTo(e)}}if(this.seriesToggle){var A;if(typeof(this.seriesToggle)==="string"||typeof(this.seriesToggle)==="number"){if(!c.jqplot.use_excanvas||!this.disableIEFading){A=this.seriesToggle}}if(this.showSwatches){l.bind("click",{series:u,speed:A,plot:y,replot:this.seriesToggleReplot},a);l.addClass("jqplot-seriesToggle")}if(this.showLabels){k.bind("click",{series:u,speed:A,plot:y,replot:this.seriesToggleReplot},a);k.addClass("jqplot-seriesToggle")}if(!u.show&&u.showLabel){l.addClass("jqplot-series-hidden");k.addClass("jqplot-series-hidden")}}C=true}}v++}l=k=h=g=null}}return this._elem};var a=function(j){var i=j.data,m=i.series,k=i.replot,h=i.plot,f=i.speed,l=m.index,g=false;if(m.canvas._elem.is(":hidden")||!m.show){g=true}var e=function(){if(k){var n={};if(c.isPlainObject(k)){c.extend(true,n,k)}h.replot(n);if(g&&f){var d=h.series[l];if(d.shadowCanvas._elem){d.shadowCanvas._elem.hide().fadeIn(f)}d.canvas._elem.hide().fadeIn(f);d.canvas._elem.nextAll(".jqplot-point-label.jqplot-series-"+d.index).hide().fadeIn(f)}}else{var d=h.series[l];if(d.canvas._elem.is(":hidden")||!d.show){if(typeof h.options.legend.showSwatches==="undefined"||h.options.legend.showSwatches===true){h.legend._elem.find("td").eq(l*2).addClass("jqplot-series-hidden")}if(typeof h.options.legend.showLabels==="undefined"||h.options.legend.showLabels===true){h.legend._elem.find("td").eq((l*2)+1).addClass("jqplot-series-hidden")}}else{if(typeof h.options.legend.showSwatches==="undefined"||h.options.legend.showSwatches===true){h.legend._elem.find("td").eq(l*2).removeClass("jqplot-series-hidden")}if(typeof h.options.legend.showLabels==="undefined"||h.options.legend.showLabels===true){h.legend._elem.find("td").eq((l*2)+1).removeClass("jqplot-series-hidden")}}}};m.toggleDisplay(j,e)};var b=function(){if(this.legend.renderer.constructor==c.jqplot.EnhancedLegendRenderer&&this.legend.seriesToggle){var d=this.legend._elem.detach();this.eventCanvas._elem.after(d)}}})(jQuery);
|
@ -1,943 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.FunnelRenderer
|
||||
* Plugin renderer to draw a funnel chart.
|
||||
* x values, if present, will be used as labels.
|
||||
* y values give area size.
|
||||
*
|
||||
* Funnel charts will draw a single series
|
||||
* only.
|
||||
*
|
||||
* To use this renderer, you need to include the
|
||||
* funnel renderer plugin, for example:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.funnelRenderer.js"></script>
|
||||
*
|
||||
* Properties described here are passed into the $.jqplot function
|
||||
* as options on the series renderer. For example:
|
||||
*
|
||||
* > plot2 = $.jqplot('chart2', [s1, s2], {
|
||||
* > seriesDefaults: {
|
||||
* > renderer:$.jqplot.FunnelRenderer,
|
||||
* > rendererOptions:{
|
||||
* > sectionMargin: 12,
|
||||
* > widthRatio: 0.3
|
||||
* > }
|
||||
* > }
|
||||
* > });
|
||||
*
|
||||
* IMPORTANT
|
||||
*
|
||||
* *The funnel renderer will reorder data in descending order* so the largest value in
|
||||
* the data set is first and displayed on top of the funnel. Data will then
|
||||
* be displayed in descending order down the funnel. The area of each funnel
|
||||
* section will correspond to the value of each data point relative to the sum
|
||||
* of all values. That is section area is proportional to section value divided by
|
||||
* sum of all section values.
|
||||
*
|
||||
* If your data is not in descending order when passed into the plot, *it will be
|
||||
* reordered* when stored in the series.data property. A copy of the unordered
|
||||
* data is kept in the series._unorderedData property.
|
||||
*
|
||||
* A funnel plot will trigger events on the plot target
|
||||
* according to user interaction. All events return the event object,
|
||||
* the series index, the point (section) index, and the point data for
|
||||
* the appropriate section. *Note* the point index will referr to the ordered
|
||||
* data, not the original unordered data.
|
||||
*
|
||||
* 'jqplotDataMouseOver' - triggered when mousing over a section.
|
||||
* 'jqplotDataHighlight' - triggered the first time user mouses over a section,
|
||||
* if highlighting is enabled.
|
||||
* 'jqplotDataUnhighlight' - triggered when a user moves the mouse out of
|
||||
* a highlighted section.
|
||||
* 'jqplotDataClick' - triggered when the user clicks on a section.
|
||||
* 'jqplotDataRightClick' - tiggered when the user right clicks on a section if
|
||||
* the "captureRightClick" option is set to true on the plot.
|
||||
*/
|
||||
$.jqplot.FunnelRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.FunnelRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.FunnelRenderer.prototype.constructor = $.jqplot.FunnelRenderer;
|
||||
|
||||
// called with scope of a series
|
||||
$.jqplot.FunnelRenderer.prototype.init = function(options, plot) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: padding
|
||||
// padding between the funnel and plot edges, legend, etc.
|
||||
this.padding = {top: 20, right: 20, bottom: 20, left: 20};
|
||||
// prop: sectionMargin
|
||||
// spacing between funnel sections in pixels.
|
||||
this.sectionMargin = 6;
|
||||
// prop: fill
|
||||
// true or false, wether to fill the areas.
|
||||
this.fill = true;
|
||||
// prop: shadowOffset
|
||||
// offset of the shadow from the area and offset of
|
||||
// each succesive stroke of the shadow from the last.
|
||||
this.shadowOffset = 2;
|
||||
// prop: shadowAlpha
|
||||
// transparency of the shadow (0 = transparent, 1 = opaque)
|
||||
this.shadowAlpha = 0.07;
|
||||
// prop: shadowDepth
|
||||
// number of strokes to apply to the shadow,
|
||||
// each stroke offset shadowOffset from the last.
|
||||
this.shadowDepth = 5;
|
||||
// prop: highlightMouseOver
|
||||
// True to highlight area when moused over.
|
||||
// This must be false to enable highlightMouseDown to highlight when clicking on a area.
|
||||
this.highlightMouseOver = true;
|
||||
// prop: highlightMouseDown
|
||||
// True to highlight when a mouse button is pressed over a area.
|
||||
// This will be disabled if highlightMouseOver is true.
|
||||
this.highlightMouseDown = false;
|
||||
// prop: highlightColors
|
||||
// array of colors to use when highlighting an area.
|
||||
this.highlightColors = [];
|
||||
// prop: widthRatio
|
||||
// The ratio of the width of the top of the funnel to the bottom.
|
||||
// a ratio of 0 will make an upside down pyramid.
|
||||
this.widthRatio = 0.2;
|
||||
// prop: lineWidth
|
||||
// width of line if areas are stroked and not filled.
|
||||
this.lineWidth = 2;
|
||||
// prop: dataLabels
|
||||
// Either 'label', 'value', 'percent' or an array of labels to place on the pie slices.
|
||||
// Defaults to percentage of each pie slice.
|
||||
this.dataLabels = 'percent';
|
||||
// prop: showDataLabels
|
||||
// true to show data labels on slices.
|
||||
this.showDataLabels = false;
|
||||
// prop: dataLabelFormatString
|
||||
// Format string for data labels. If none, '%s' is used for "label" and for arrays, '%d' for value and '%d%%' for percentage.
|
||||
this.dataLabelFormatString = null;
|
||||
// prop: dataLabelThreshold
|
||||
// Threshhold in percentage (0 - 100) of pie area, below which no label will be displayed.
|
||||
// This applies to all label types, not just to percentage labels.
|
||||
this.dataLabelThreshold = 3;
|
||||
this._type = 'funnel';
|
||||
|
||||
this.tickRenderer = $.jqplot.FunnelTickRenderer;
|
||||
|
||||
// if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
|
||||
if (options.highlightMouseDown && options.highlightMouseOver == null) {
|
||||
options.highlightMouseOver = false;
|
||||
}
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
// index of the currenty highlighted point, if any
|
||||
this._highlightedPoint = null;
|
||||
|
||||
// lengths of bases, or horizontal sides of areas of trapezoid.
|
||||
this._bases = [];
|
||||
// total area
|
||||
this._atot;
|
||||
// areas of segments.
|
||||
this._areas = [];
|
||||
// vertical lengths of segments.
|
||||
this._lengths = [];
|
||||
// angle of the funnel to vertical.
|
||||
this._angle;
|
||||
this._dataIndices = [];
|
||||
|
||||
// sort data
|
||||
this._unorderedData = $.extend(true, [], this.data);
|
||||
var idxs = $.extend(true, [], this.data);
|
||||
for (var i=0; i<idxs.length; i++) {
|
||||
idxs[i].push(i);
|
||||
}
|
||||
this.data.sort( function (a, b) { return b[1] - a[1]; } );
|
||||
idxs.sort( function (a, b) { return b[1] - a[1]; });
|
||||
for (var i=0; i<idxs.length; i++) {
|
||||
this._dataIndices.push(idxs[i][2]);
|
||||
}
|
||||
|
||||
// set highlight colors if none provided
|
||||
if (this.highlightColors.length == 0) {
|
||||
for (var i=0; i<this.seriesColors.length; i++){
|
||||
var rgba = $.jqplot.getColorComponents(this.seriesColors[i]);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var sum = newrgb[0] + newrgb[1] + newrgb[2];
|
||||
for (var j=0; j<3; j++) {
|
||||
// when darkening, lowest color component can be is 60.
|
||||
newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.4 * (255 - newrgb[j]);
|
||||
newrgb[j] = parseInt(newrgb[j], 10);
|
||||
}
|
||||
this.highlightColors.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
|
||||
}
|
||||
}
|
||||
|
||||
plot.postParseOptionsHooks.addOnce(postParseOptions);
|
||||
plot.postInitHooks.addOnce(postInit);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
|
||||
plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
|
||||
plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
|
||||
plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
|
||||
plot.postDrawHooks.addOnce(postPlotDraw);
|
||||
|
||||
};
|
||||
|
||||
// gridData will be of form [label, percentage of total]
|
||||
$.jqplot.FunnelRenderer.prototype.setGridData = function(plot) {
|
||||
// set gridData property. This will hold angle in radians of each data point.
|
||||
var sum = 0;
|
||||
var td = [];
|
||||
for (var i=0; i<this.data.length; i++){
|
||||
sum += this.data[i][1];
|
||||
td.push([this.data[i][0], this.data[i][1]]);
|
||||
}
|
||||
|
||||
// normalize y values, so areas are proportional.
|
||||
for (var i=0; i<td.length; i++) {
|
||||
td[i][1] = td[i][1]/sum;
|
||||
}
|
||||
|
||||
this._bases = new Array(td.length + 1);
|
||||
this._lengths = new Array(td.length);
|
||||
|
||||
this.gridData = td;
|
||||
};
|
||||
|
||||
$.jqplot.FunnelRenderer.prototype.makeGridData = function(data, plot) {
|
||||
// set gridData property. This will hold angle in radians of each data point.
|
||||
var sum = 0;
|
||||
var td = [];
|
||||
for (var i=0; i<this.data.length; i++){
|
||||
sum += this.data[i][1];
|
||||
td.push([this.data[i][0], this.data[i][1]]);
|
||||
}
|
||||
|
||||
// normalize y values, so areas are proportional.
|
||||
for (var i=0; i<td.length; i++) {
|
||||
td[i][1] = td[i][1]/sum;
|
||||
}
|
||||
|
||||
this._bases = new Array(td.length + 1);
|
||||
this._lengths = new Array(td.length);
|
||||
|
||||
return td;
|
||||
};
|
||||
|
||||
$.jqplot.FunnelRenderer.prototype.drawSection = function (ctx, vertices, color, isShadow) {
|
||||
var fill = this.fill;
|
||||
var lineWidth = this.lineWidth;
|
||||
ctx.save();
|
||||
|
||||
if (isShadow) {
|
||||
for (var i=0; i<this.shadowDepth; i++) {
|
||||
ctx.save();
|
||||
ctx.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI), this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));
|
||||
doDraw();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
doDraw();
|
||||
}
|
||||
|
||||
function doDraw () {
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = color;
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = lineWidth;
|
||||
ctx.moveTo(vertices[0][0], vertices[0][1]);
|
||||
for (var i=1; i<4; i++) {
|
||||
ctx.lineTo(vertices[i][0], vertices[i][1]);
|
||||
}
|
||||
ctx.closePath();
|
||||
if (fill) {
|
||||
ctx.fill();
|
||||
}
|
||||
else {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
if (isShadow) {
|
||||
for (var i=0; i<this.shadowDepth; i++) {
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
$.jqplot.FunnelRenderer.prototype.draw = function (ctx, gd, options, plot) {
|
||||
var i;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
// offset and direction of offset due to legend placement
|
||||
var offx = 0;
|
||||
var offy = 0;
|
||||
var trans = 1;
|
||||
this._areas = [];
|
||||
// var colorGenerator = new this.colorGenerator(this.seriesColors);
|
||||
if (options.legendInfo && options.legendInfo.placement == 'insideGrid') {
|
||||
var li = options.legendInfo;
|
||||
switch (li.location) {
|
||||
case 'nw':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'w':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'sw':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'ne':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'e':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'se':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'n':
|
||||
offy = li.height + li.yoffset;
|
||||
break;
|
||||
case 's':
|
||||
offy = li.height + li.yoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var loff = (trans==1) ? this.padding.left + offx : this.padding.left;
|
||||
var toff = (trans==1) ? this.padding.top + offy : this.padding.top;
|
||||
var roff = (trans==-1) ? this.padding.right + offx : this.padding.right;
|
||||
var boff = (trans==-1) ? this.padding.bottom + offy : this.padding.bottom;
|
||||
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var cw = ctx.canvas.width;
|
||||
var ch = ctx.canvas.height;
|
||||
this._bases[0] = cw - loff - roff;
|
||||
var ltot = this._length = ch - toff - boff;
|
||||
|
||||
var hend = this._bases[0]*this.widthRatio;
|
||||
this._atot = ltot/2 * (this._bases[0] + this._bases[0]*this.widthRatio);
|
||||
|
||||
this._angle = Math.atan((this._bases[0] - hend)/2/ltot);
|
||||
|
||||
for (i=0; i<gd.length; i++) {
|
||||
this._areas.push(gd[i][1] * this._atot);
|
||||
}
|
||||
|
||||
|
||||
var guess, err, count, lsum=0;
|
||||
var tolerance = 0.0001;
|
||||
|
||||
for (i=0; i<this._areas.length; i++) {
|
||||
guess = this._areas[i]/this._bases[i];
|
||||
err = 999999;
|
||||
this._lengths[i] = guess;
|
||||
count = 0;
|
||||
while (err > this._lengths[i]*tolerance && count < 100) {
|
||||
this._lengths[i] = this._areas[i]/(this._bases[i] - this._lengths[i] * Math.tan(this._angle));
|
||||
err = Math.abs(this._lengths[i] - guess);
|
||||
this._bases[i+1] = this._bases[i] - (2*this._lengths[i]*Math.tan(this._angle));
|
||||
guess = this._lengths[i];
|
||||
count++;
|
||||
}
|
||||
lsum += this._lengths[i];
|
||||
}
|
||||
|
||||
// figure out vertices of each section
|
||||
this._vertices = new Array(gd.length);
|
||||
|
||||
// these are 4 coners of entire trapezoid
|
||||
var p0 = [loff, toff],
|
||||
p1 = [loff+this._bases[0], toff],
|
||||
p2 = [loff + (this._bases[0] - this._bases[this._bases.length-1])/2, toff + this._length],
|
||||
p3 = [p2[0] + this._bases[this._bases.length-1], p2[1]];
|
||||
|
||||
// equations of right and left sides, returns x, y values given height of section (y value)
|
||||
function findleft (l) {
|
||||
var m = (p0[1] - p2[1])/(p0[0] - p2[0]);
|
||||
var b = p0[1] - m*p0[0];
|
||||
var y = l + p0[1];
|
||||
|
||||
return [(y - b)/m, y];
|
||||
}
|
||||
|
||||
function findright (l) {
|
||||
var m = (p1[1] - p3[1])/(p1[0] - p3[0]);
|
||||
var b = p1[1] - m*p1[0];
|
||||
var y = l + p1[1];
|
||||
|
||||
return [(y - b)/m, y];
|
||||
}
|
||||
|
||||
var x = offx, y = offy;
|
||||
var h=0, adj=0;
|
||||
|
||||
for (i=0; i<gd.length; i++) {
|
||||
this._vertices[i] = new Array();
|
||||
var v = this._vertices[i];
|
||||
var sm = this.sectionMargin;
|
||||
if (i == 0) {
|
||||
adj = 0;
|
||||
}
|
||||
if (i == 1) {
|
||||
adj = sm/3;
|
||||
}
|
||||
else if (i > 0 && i < gd.length-1) {
|
||||
adj = sm/2;
|
||||
}
|
||||
else if (i == gd.length -1) {
|
||||
adj = 2*sm/3;
|
||||
}
|
||||
v.push(findleft(h+adj));
|
||||
v.push(findright(h+adj));
|
||||
h += this._lengths[i];
|
||||
if (i == 0) {
|
||||
adj = -2*sm/3;
|
||||
}
|
||||
else if (i > 0 && i < gd.length-1) {
|
||||
adj = -sm/2;
|
||||
}
|
||||
else if (i == gd.length - 1) {
|
||||
adj = 0;
|
||||
}
|
||||
v.push(findright(h+adj));
|
||||
v.push(findleft(h+adj));
|
||||
|
||||
}
|
||||
|
||||
if (this.shadow) {
|
||||
var shadowColor = 'rgba(0,0,0,'+this.shadowAlpha+')';
|
||||
for (var i=0; i<gd.length; i++) {
|
||||
this.renderer.drawSection.call (this, ctx, this._vertices[i], shadowColor, true);
|
||||
}
|
||||
|
||||
}
|
||||
for (var i=0; i<gd.length; i++) {
|
||||
var v = this._vertices[i];
|
||||
this.renderer.drawSection.call (this, ctx, v, this.seriesColors[i]);
|
||||
|
||||
if (this.showDataLabels && gd[i][1]*100 >= this.dataLabelThreshold) {
|
||||
var fstr, label;
|
||||
|
||||
if (this.dataLabels == 'label') {
|
||||
fstr = this.dataLabelFormatString || '%s';
|
||||
label = $.jqplot.sprintf(fstr, gd[i][0]);
|
||||
}
|
||||
else if (this.dataLabels == 'value') {
|
||||
fstr = this.dataLabelFormatString || '%d';
|
||||
label = $.jqplot.sprintf(fstr, this.data[i][1]);
|
||||
}
|
||||
else if (this.dataLabels == 'percent') {
|
||||
fstr = this.dataLabelFormatString || '%d%%';
|
||||
label = $.jqplot.sprintf(fstr, gd[i][1]*100);
|
||||
}
|
||||
else if (this.dataLabels.constructor == Array) {
|
||||
fstr = this.dataLabelFormatString || '%s';
|
||||
label = $.jqplot.sprintf(fstr, this.dataLabels[this._dataIndices[i]]);
|
||||
}
|
||||
|
||||
var fact = (this._radius ) * this.dataLabelPositionFactor + this.sliceMargin + this.dataLabelNudge;
|
||||
|
||||
var x = (v[0][0] + v[1][0])/2 + this.canvas._offsets.left;
|
||||
var y = (v[1][1] + v[2][1])/2 + this.canvas._offsets.top;
|
||||
|
||||
var labelelem = $('<span class="jqplot-funnel-series jqplot-data-label" style="position:absolute;">' + label + '</span>').insertBefore(plot.eventCanvas._elem);
|
||||
x -= labelelem.width()/2;
|
||||
y -= labelelem.height()/2;
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
labelelem.css({left: x, top: y});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.jqplot.FunnelAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.FunnelAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.FunnelAxisRenderer.prototype.constructor = $.jqplot.FunnelAxisRenderer;
|
||||
|
||||
|
||||
// There are no traditional axes on a funnel chart. We just need to provide
|
||||
// dummy objects with properties so the plot will render.
|
||||
// called with scope of axis object.
|
||||
$.jqplot.FunnelAxisRenderer.prototype.init = function(options){
|
||||
//
|
||||
this.tickRenderer = $.jqplot.FunnelTickRenderer;
|
||||
$.extend(true, this, options);
|
||||
// I don't think I'm going to need _dataBounds here.
|
||||
// have to go Axis scaling in a way to fit chart onto plot area
|
||||
// and provide u2p and p2u functionality for mouse cursor, etc.
|
||||
// for convienence set _dataBounds to 0 and 100 and
|
||||
// set min/max to 0 and 100.
|
||||
this._dataBounds = {min:0, max:100};
|
||||
this.min = 0;
|
||||
this.max = 100;
|
||||
this.showTicks = false;
|
||||
this.ticks = [];
|
||||
this.showMark = false;
|
||||
this.show = false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.FunnelLegendRenderer
|
||||
* Legend Renderer specific to funnel plots. Set by default
|
||||
* when the user creates a funnel plot.
|
||||
*/
|
||||
$.jqplot.FunnelLegendRenderer = function(){
|
||||
$.jqplot.TableLegendRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.FunnelLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
|
||||
$.jqplot.FunnelLegendRenderer.prototype.constructor = $.jqplot.FunnelLegendRenderer;
|
||||
|
||||
$.jqplot.FunnelLegendRenderer.prototype.init = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: numberRows
|
||||
// Maximum number of rows in the legend. 0 or null for unlimited.
|
||||
this.numberRows = null;
|
||||
// prop: numberColumns
|
||||
// Maximum number of columns in the legend. 0 or null for unlimited.
|
||||
this.numberColumns = null;
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
// called with context of legend
|
||||
$.jqplot.FunnelLegendRenderer.prototype.draw = function() {
|
||||
var legend = this;
|
||||
if (this.show) {
|
||||
var series = this._series;
|
||||
var ss = 'position:absolute;';
|
||||
ss += (this.background) ? 'background:'+this.background+';' : '';
|
||||
ss += (this.border) ? 'border:'+this.border+';' : '';
|
||||
ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
|
||||
ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
|
||||
ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
|
||||
ss += (this.marginTop != null) ? 'margin-top:'+this.marginTop+';' : '';
|
||||
ss += (this.marginBottom != null) ? 'margin-bottom:'+this.marginBottom+';' : '';
|
||||
ss += (this.marginLeft != null) ? 'margin-left:'+this.marginLeft+';' : '';
|
||||
ss += (this.marginRight != null) ? 'margin-right:'+this.marginRight+';' : '';
|
||||
this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
|
||||
// Funnel charts legends don't go by number of series, but by number of data points
|
||||
// in the series. Refactor things here for that.
|
||||
|
||||
var pad = false,
|
||||
reverse = false,
|
||||
nr, nc;
|
||||
var s = series[0];
|
||||
var colorGenerator = new $.jqplot.ColorGenerator(s.seriesColors);
|
||||
|
||||
if (s.show) {
|
||||
var pd = s.data;
|
||||
if (this.numberRows) {
|
||||
nr = this.numberRows;
|
||||
if (!this.numberColumns){
|
||||
nc = Math.ceil(pd.length/nr);
|
||||
}
|
||||
else{
|
||||
nc = this.numberColumns;
|
||||
}
|
||||
}
|
||||
else if (this.numberColumns) {
|
||||
nc = this.numberColumns;
|
||||
nr = Math.ceil(pd.length/this.numberColumns);
|
||||
}
|
||||
else {
|
||||
nr = pd.length;
|
||||
nc = 1;
|
||||
}
|
||||
|
||||
var i, j, tr, td1, td2, lt, rs, color;
|
||||
var idx = 0;
|
||||
|
||||
for (i=0; i<nr; i++) {
|
||||
if (reverse){
|
||||
tr = $('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem);
|
||||
}
|
||||
else{
|
||||
tr = $('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem);
|
||||
}
|
||||
for (j=0; j<nc; j++) {
|
||||
if (idx < pd.length){
|
||||
lt = this.labels[idx] || pd[idx][0].toString();
|
||||
color = colorGenerator.next();
|
||||
if (!reverse){
|
||||
if (i>0){
|
||||
pad = true;
|
||||
}
|
||||
else{
|
||||
pad = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (i == nr -1){
|
||||
pad = false;
|
||||
}
|
||||
else{
|
||||
pad = true;
|
||||
}
|
||||
}
|
||||
rs = (pad) ? this.rowSpacing : '0';
|
||||
|
||||
td1 = $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
|
||||
'<div><div class="jqplot-table-legend-swatch" style="border-color:'+color+';"></div>'+
|
||||
'</div></td>');
|
||||
td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
|
||||
if (this.escapeHtml){
|
||||
td2.text(lt);
|
||||
}
|
||||
else {
|
||||
td2.html(lt);
|
||||
}
|
||||
if (reverse) {
|
||||
td2.prependTo(tr);
|
||||
td1.prependTo(tr);
|
||||
}
|
||||
else {
|
||||
td1.appendTo(tr);
|
||||
td2.appendTo(tr);
|
||||
}
|
||||
pad = true;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
// $.jqplot.FunnelLegendRenderer.prototype.pack = function(offsets) {
|
||||
// if (this.show) {
|
||||
// // fake a grid for positioning
|
||||
// var grid = {_top:offsets.top, _left:offsets.left, _right:offsets.right, _bottom:this._plotDimensions.height - offsets.bottom};
|
||||
// if (this.placement == 'insideGrid') {
|
||||
// switch (this.location) {
|
||||
// case 'nw':
|
||||
// var a = grid._left + this.xoffset;
|
||||
// var b = grid._top + this.yoffset;
|
||||
// this._elem.css('left', a);
|
||||
// this._elem.css('top', b);
|
||||
// break;
|
||||
// case 'n':
|
||||
// var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
// var b = grid._top + this.yoffset;
|
||||
// this._elem.css('left', a);
|
||||
// this._elem.css('top', b);
|
||||
// break;
|
||||
// case 'ne':
|
||||
// var a = offsets.right + this.xoffset;
|
||||
// var b = grid._top + this.yoffset;
|
||||
// this._elem.css({right:a, top:b});
|
||||
// break;
|
||||
// case 'e':
|
||||
// var a = offsets.right + this.xoffset;
|
||||
// var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
// this._elem.css({right:a, top:b});
|
||||
// break;
|
||||
// case 'se':
|
||||
// var a = offsets.right + this.xoffset;
|
||||
// var b = offsets.bottom + this.yoffset;
|
||||
// this._elem.css({right:a, bottom:b});
|
||||
// break;
|
||||
// case 's':
|
||||
// var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
// var b = offsets.bottom + this.yoffset;
|
||||
// this._elem.css({left:a, bottom:b});
|
||||
// break;
|
||||
// case 'sw':
|
||||
// var a = grid._left + this.xoffset;
|
||||
// var b = offsets.bottom + this.yoffset;
|
||||
// this._elem.css({left:a, bottom:b});
|
||||
// break;
|
||||
// case 'w':
|
||||
// var a = grid._left + this.xoffset;
|
||||
// var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
// this._elem.css({left:a, top:b});
|
||||
// break;
|
||||
// default: // same as 'se'
|
||||
// var a = grid._right - this.xoffset;
|
||||
// var b = grid._bottom + this.yoffset;
|
||||
// this._elem.css({right:a, bottom:b});
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// else {
|
||||
// switch (this.location) {
|
||||
// case 'nw':
|
||||
// var a = this._plotDimensions.width - grid._left + this.xoffset;
|
||||
// var b = grid._top + this.yoffset;
|
||||
// this._elem.css('right', a);
|
||||
// this._elem.css('top', b);
|
||||
// break;
|
||||
// case 'n':
|
||||
// var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
// var b = this._plotDimensions.height - grid._top + this.yoffset;
|
||||
// this._elem.css('left', a);
|
||||
// this._elem.css('bottom', b);
|
||||
// break;
|
||||
// case 'ne':
|
||||
// var a = this._plotDimensions.width - offsets.right + this.xoffset;
|
||||
// var b = grid._top + this.yoffset;
|
||||
// this._elem.css({left:a, top:b});
|
||||
// break;
|
||||
// case 'e':
|
||||
// var a = this._plotDimensions.width - offsets.right + this.xoffset;
|
||||
// var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
// this._elem.css({left:a, top:b});
|
||||
// break;
|
||||
// case 'se':
|
||||
// var a = this._plotDimensions.width - offsets.right + this.xoffset;
|
||||
// var b = offsets.bottom + this.yoffset;
|
||||
// this._elem.css({left:a, bottom:b});
|
||||
// break;
|
||||
// case 's':
|
||||
// var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
// var b = this._plotDimensions.height - offsets.bottom + this.yoffset;
|
||||
// this._elem.css({left:a, top:b});
|
||||
// break;
|
||||
// case 'sw':
|
||||
// var a = this._plotDimensions.width - grid._left + this.xoffset;
|
||||
// var b = offsets.bottom + this.yoffset;
|
||||
// this._elem.css({right:a, bottom:b});
|
||||
// break;
|
||||
// case 'w':
|
||||
// var a = this._plotDimensions.width - grid._left + this.xoffset;
|
||||
// var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
// this._elem.css({right:a, top:b});
|
||||
// break;
|
||||
// default: // same as 'se'
|
||||
// var a = grid._right - this.xoffset;
|
||||
// var b = grid._bottom + this.yoffset;
|
||||
// this._elem.css({right:a, bottom:b});
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// setup default renderers for axes and legend so user doesn't have to
|
||||
// called with scope of plot
|
||||
function preInit(target, data, options) {
|
||||
options = options || {};
|
||||
options.axesDefaults = options.axesDefaults || {};
|
||||
options.legend = options.legend || {};
|
||||
options.seriesDefaults = options.seriesDefaults || {};
|
||||
// only set these if there is a funnel series
|
||||
var setopts = false;
|
||||
if (options.seriesDefaults.renderer == $.jqplot.FunnelRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
else if (options.series) {
|
||||
for (var i=0; i < options.series.length; i++) {
|
||||
if (options.series[i].renderer == $.jqplot.FunnelRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setopts) {
|
||||
options.axesDefaults.renderer = $.jqplot.FunnelAxisRenderer;
|
||||
options.legend.renderer = $.jqplot.FunnelLegendRenderer;
|
||||
options.legend.preDraw = true;
|
||||
options.sortData = false;
|
||||
options.seriesDefaults.pointLabels = {show: false};
|
||||
}
|
||||
}
|
||||
|
||||
function postInit(target, data, options) {
|
||||
// if multiple series, add a reference to the previous one so that
|
||||
// funnel rings can nest.
|
||||
for (var i=0; i<this.series.length; i++) {
|
||||
if (this.series[i].renderer.constructor == $.jqplot.FunnelRenderer) {
|
||||
// don't allow mouseover and mousedown at same time.
|
||||
if (this.series[i].highlightMouseOver) {
|
||||
this.series[i].highlightMouseDown = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// called with scope of plot
|
||||
function postParseOptions(options) {
|
||||
for (var i=0; i<this.series.length; i++) {
|
||||
this.series[i].seriesColors = this.seriesColors;
|
||||
this.series[i].colorGenerator = $.jqplot.colorGenerator;
|
||||
}
|
||||
}
|
||||
|
||||
function highlight (plot, sidx, pidx) {
|
||||
var s = plot.series[sidx];
|
||||
var canvas = plot.plugins.funnelRenderer.highlightCanvas;
|
||||
canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
|
||||
s._highlightedPoint = pidx;
|
||||
plot.plugins.funnelRenderer.highlightedSeriesIndex = sidx;
|
||||
s.renderer.drawSection.call(s, canvas._ctx, s._vertices[pidx], s.highlightColors[pidx], false);
|
||||
}
|
||||
|
||||
function unhighlight (plot) {
|
||||
var canvas = plot.plugins.funnelRenderer.highlightCanvas;
|
||||
canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
|
||||
for (var i=0; i<plot.series.length; i++) {
|
||||
plot.series[i]._highlightedPoint = null;
|
||||
}
|
||||
plot.plugins.funnelRenderer.highlightedSeriesIndex = null;
|
||||
plot.target.trigger('jqplotDataUnhighlight');
|
||||
}
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var evt1 = jQuery.Event('jqplotDataMouseOver');
|
||||
evt1.pageX = ev.pageX;
|
||||
evt1.pageY = ev.pageY;
|
||||
plot.target.trigger(evt1, ins);
|
||||
if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.funnelRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, ins[0], ins[1]);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.funnelRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
|
||||
var evt = jQuery.Event('jqplotDataHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
highlight (plot, ins[0], ins[1]);
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
unhighlight (plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
|
||||
var idx = plot.plugins.funnelRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
}
|
||||
|
||||
function handleClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var evt = jQuery.Event('jqplotDataClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (neighbor) {
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
|
||||
var idx = plot.plugins.funnelRenderer.highlightedSeriesIndex;
|
||||
if (idx != null && plot.series[idx].highlightMouseDown) {
|
||||
unhighlight(plot);
|
||||
}
|
||||
var evt = jQuery.Event('jqplotDataRightClick');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
plot.target.trigger(evt, ins);
|
||||
}
|
||||
}
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
function postPlotDraw() {
|
||||
// Memory Leaks patch
|
||||
if (this.plugins.funnelRenderer && this.plugins.funnelRenderer.highlightCanvas) {
|
||||
this.plugins.funnelRenderer.highlightCanvas.resetCanvas();
|
||||
this.plugins.funnelRenderer.highlightCanvas = null;
|
||||
}
|
||||
|
||||
this.plugins.funnelRenderer = {};
|
||||
this.plugins.funnelRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
|
||||
|
||||
// do we have any data labels? if so, put highlight canvas before those
|
||||
var labels = $(this.targetId+' .jqplot-data-label');
|
||||
if (labels.length) {
|
||||
$(labels[0]).before(this.plugins.funnelRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-funnelRenderer-highlight-canvas', this._plotDimensions, this));
|
||||
}
|
||||
// else put highlight canvas before event canvas.
|
||||
else {
|
||||
this.eventCanvas._elem.before(this.plugins.funnelRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-funnelRenderer-highlight-canvas', this._plotDimensions, this));
|
||||
}
|
||||
var hctx = this.plugins.funnelRenderer.highlightCanvas.setContext();
|
||||
this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
|
||||
}
|
||||
|
||||
$.jqplot.preInitHooks.push(preInit);
|
||||
|
||||
$.jqplot.FunnelTickRenderer = function() {
|
||||
$.jqplot.AxisTickRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.FunnelTickRenderer.prototype = new $.jqplot.AxisTickRenderer();
|
||||
$.jqplot.FunnelTickRenderer.prototype.constructor = $.jqplot.FunnelTickRenderer;
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,465 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.Highlighter
|
||||
* Plugin which will highlight data points when they are moused over.
|
||||
*
|
||||
* To use this plugin, include the js
|
||||
* file in your source:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.highlighter.js"></script>
|
||||
*
|
||||
* A tooltip providing information about the data point is enabled by default.
|
||||
* To disable the tooltip, set "showTooltip" to false.
|
||||
*
|
||||
* You can control what data is displayed in the tooltip with various
|
||||
* options. The "tooltipAxes" option controls wether the x, y or both
|
||||
* data values are displayed.
|
||||
*
|
||||
* Some chart types (e.g. hi-low-close) have more than one y value per
|
||||
* data point. To display the additional values in the tooltip, set the
|
||||
* "yvalues" option to the desired number of y values present (3 for a hlc chart).
|
||||
*
|
||||
* By default, data values will be formatted with the same formatting
|
||||
* specifiers as used to format the axis ticks. A custom format code
|
||||
* can be supplied with the tooltipFormatString option. This will apply
|
||||
* to all values in the tooltip.
|
||||
*
|
||||
* For more complete control, the "formatString" option can be set. This
|
||||
* Allows conplete control over tooltip formatting. Values are passed to
|
||||
* the format string in an order determined by the "tooltipAxes" and "yvalues"
|
||||
* options. So, if you have a hi-low-close chart and you just want to display
|
||||
* the hi-low-close values in the tooltip, you could set a formatString like:
|
||||
*
|
||||
* > highlighter: {
|
||||
* > tooltipAxes: 'y',
|
||||
* > yvalues: 3,
|
||||
* > formatString:'<table class="jqplot-highlighter">
|
||||
* > <tr><td>hi:</td><td>%s</td></tr>
|
||||
* > <tr><td>low:</td><td>%s</td></tr>
|
||||
* > <tr><td>close:</td><td>%s</td></tr></table>'
|
||||
* > }
|
||||
*
|
||||
*/
|
||||
$.jqplot.Highlighter = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
//prop: show
|
||||
// true to show the highlight.
|
||||
this.show = $.jqplot.config.enablePlugins;
|
||||
// prop: markerRenderer
|
||||
// Renderer used to draw the marker of the highlighted point.
|
||||
// Renderer will assimilate attributes from the data point being highlighted,
|
||||
// so no attributes need set on the renderer directly.
|
||||
// Default is to turn off shadow drawing on the highlighted point.
|
||||
this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
|
||||
// prop: showMarker
|
||||
// true to show the marker
|
||||
this.showMarker = true;
|
||||
// prop: lineWidthAdjust
|
||||
// Pixels to add to the lineWidth of the highlight.
|
||||
this.lineWidthAdjust = 2.5;
|
||||
// prop: sizeAdjust
|
||||
// Pixels to add to the overall size of the highlight.
|
||||
this.sizeAdjust = 5;
|
||||
// prop: showTooltip
|
||||
// Show a tooltip with data point values.
|
||||
this.showTooltip = true;
|
||||
// prop: tooltipLocation
|
||||
// Where to position tooltip, 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
|
||||
this.tooltipLocation = 'nw';
|
||||
// prop: fadeTooltip
|
||||
// true = fade in/out tooltip, flase = show/hide tooltip
|
||||
this.fadeTooltip = true;
|
||||
// prop: tooltipFadeSpeed
|
||||
// 'slow', 'def', 'fast', or number of milliseconds.
|
||||
this.tooltipFadeSpeed = "fast";
|
||||
// prop: tooltipOffset
|
||||
// Pixel offset of tooltip from the highlight.
|
||||
this.tooltipOffset = 2;
|
||||
// prop: tooltipAxes
|
||||
// Which axes to display in tooltip, 'x', 'y' or 'both', 'xy' or 'yx'
|
||||
// 'both' and 'xy' are equivalent, 'yx' reverses order of labels.
|
||||
this.tooltipAxes = 'both';
|
||||
// prop; tooltipSeparator
|
||||
// String to use to separate x and y axes in tooltip.
|
||||
this.tooltipSeparator = ', ';
|
||||
// prop; tooltipContentEditor
|
||||
// Function used to edit/augment/replace the formatted tooltip contents.
|
||||
// Called as str = tooltipContentEditor(str, seriesIndex, pointIndex)
|
||||
// where str is the generated tooltip html and seriesIndex and pointIndex identify
|
||||
// the data point being highlighted. Should return the html for the tooltip contents.
|
||||
this.tooltipContentEditor = null;
|
||||
// prop: useAxesFormatters
|
||||
// Use the x and y axes formatters to format the text in the tooltip.
|
||||
this.useAxesFormatters = true;
|
||||
// prop: tooltipFormatString
|
||||
// sprintf format string for the tooltip.
|
||||
// Uses Ash Searle's javascript sprintf implementation
|
||||
// found here: http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
// See http://perldoc.perl.org/functions/sprintf.html for reference.
|
||||
// Additional "p" and "P" format specifiers added by Chris Leonello.
|
||||
this.tooltipFormatString = '%.5P';
|
||||
// prop: formatString
|
||||
// alternative to tooltipFormatString
|
||||
// will format the whole tooltip text, populating with x, y values as
|
||||
// indicated by tooltipAxes option. So, you could have a tooltip like:
|
||||
// 'Date: %s, number of cats: %d' to format the whole tooltip at one go.
|
||||
// If useAxesFormatters is true, values will be formatted according to
|
||||
// Axes formatters and you can populate your tooltip string with
|
||||
// %s placeholders.
|
||||
this.formatString = null;
|
||||
// prop: yvalues
|
||||
// Number of y values to expect in the data point array.
|
||||
// Typically this is 1. Certain plots, like OHLC, will
|
||||
// have more y values in each data point array.
|
||||
this.yvalues = 1;
|
||||
// prop: bringSeriesToFront
|
||||
// This option requires jQuery 1.4+
|
||||
// True to bring the series of the highlighted point to the front
|
||||
// of other series.
|
||||
this.bringSeriesToFront = false;
|
||||
this._tooltipElem;
|
||||
this.isHighlighting = false;
|
||||
this.currentNeighbor = null;
|
||||
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
var locations = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
|
||||
var locationIndicies = {'nw':0, 'n':1, 'ne':2, 'e':3, 'se':4, 's':5, 'sw':6, 'w':7};
|
||||
var oppositeLocations = ['se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];
|
||||
|
||||
// axis.renderer.tickrenderer.formatter
|
||||
|
||||
// called with scope of plot
|
||||
$.jqplot.Highlighter.init = function (target, data, opts){
|
||||
var options = opts || {};
|
||||
// add a highlighter attribute to the plot
|
||||
this.plugins.highlighter = new $.jqplot.Highlighter(options.highlighter);
|
||||
};
|
||||
|
||||
// called within scope of series
|
||||
$.jqplot.Highlighter.parseOptions = function (defaults, options) {
|
||||
// Add a showHighlight option to the series
|
||||
// and set it to true by default.
|
||||
this.showHighlight = true;
|
||||
};
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
$.jqplot.Highlighter.postPlotDraw = function() {
|
||||
// Memory Leaks patch
|
||||
if (this.plugins.highlighter && this.plugins.highlighter.highlightCanvas) {
|
||||
this.plugins.highlighter.highlightCanvas.resetCanvas();
|
||||
this.plugins.highlighter.highlightCanvas = null;
|
||||
}
|
||||
|
||||
if (this.plugins.highlighter && this.plugins.highlighter._tooltipElem) {
|
||||
this.plugins.highlighter._tooltipElem.emptyForce();
|
||||
this.plugins.highlighter._tooltipElem = null;
|
||||
}
|
||||
|
||||
this.plugins.highlighter.highlightCanvas = new $.jqplot.GenericCanvas();
|
||||
|
||||
this.eventCanvas._elem.before(this.plugins.highlighter.highlightCanvas.createElement(this._gridPadding, 'jqplot-highlight-canvas', this._plotDimensions, this));
|
||||
this.plugins.highlighter.highlightCanvas.setContext();
|
||||
|
||||
var elem = document.createElement('div');
|
||||
this.plugins.highlighter._tooltipElem = $(elem);
|
||||
elem = null;
|
||||
this.plugins.highlighter._tooltipElem.addClass('jqplot-highlighter-tooltip');
|
||||
this.plugins.highlighter._tooltipElem.css({position:'absolute', display:'none'});
|
||||
|
||||
this.eventCanvas._elem.before(this.plugins.highlighter._tooltipElem);
|
||||
};
|
||||
|
||||
$.jqplot.preInitHooks.push($.jqplot.Highlighter.init);
|
||||
$.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Highlighter.parseOptions);
|
||||
$.jqplot.postDrawHooks.push($.jqplot.Highlighter.postPlotDraw);
|
||||
|
||||
function draw(plot, neighbor) {
|
||||
var hl = plot.plugins.highlighter;
|
||||
var s = plot.series[neighbor.seriesIndex];
|
||||
var smr = s.markerRenderer;
|
||||
var mr = hl.markerRenderer;
|
||||
mr.style = smr.style;
|
||||
mr.lineWidth = smr.lineWidth + hl.lineWidthAdjust;
|
||||
mr.size = smr.size + hl.sizeAdjust;
|
||||
var rgba = $.jqplot.getColorComponents(smr.color);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
|
||||
mr.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
|
||||
mr.init();
|
||||
mr.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], hl.highlightCanvas._ctx);
|
||||
}
|
||||
|
||||
function showTooltip(plot, series, neighbor) {
|
||||
// neighbor looks like: {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]}
|
||||
// gridData should be x,y pixel coords on the grid.
|
||||
// add the plot._gridPadding to that to get x,y in the target.
|
||||
var hl = plot.plugins.highlighter;
|
||||
var elem = hl._tooltipElem;
|
||||
var serieshl = series.highlighter || {};
|
||||
|
||||
var opts = $.extend(true, {}, hl, serieshl);
|
||||
|
||||
if (opts.useAxesFormatters) {
|
||||
var xf = series._xaxis._ticks[0].formatter;
|
||||
var yf = series._yaxis._ticks[0].formatter;
|
||||
var xfstr = series._xaxis._ticks[0].formatString;
|
||||
var yfstr = series._yaxis._ticks[0].formatString;
|
||||
var str;
|
||||
var xstr = xf(xfstr, neighbor.data[0]);
|
||||
var ystrs = [];
|
||||
for (var i=1; i<opts.yvalues+1; i++) {
|
||||
ystrs.push(yf(yfstr, neighbor.data[i]));
|
||||
}
|
||||
if (typeof opts.formatString === 'string') {
|
||||
switch (opts.tooltipAxes) {
|
||||
case 'both':
|
||||
case 'xy':
|
||||
ystrs.unshift(xstr);
|
||||
ystrs.unshift(opts.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
case 'yx':
|
||||
ystrs.push(xstr);
|
||||
ystrs.unshift(opts.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
case 'x':
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, [opts.formatString, xstr]);
|
||||
break;
|
||||
case 'y':
|
||||
ystrs.unshift(opts.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
default: // same as xy
|
||||
ystrs.unshift(xstr);
|
||||
ystrs.unshift(opts.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (opts.tooltipAxes) {
|
||||
case 'both':
|
||||
case 'xy':
|
||||
str = xstr;
|
||||
for (var i=0; i<ystrs.length; i++) {
|
||||
str += opts.tooltipSeparator + ystrs[i];
|
||||
}
|
||||
break;
|
||||
case 'yx':
|
||||
str = '';
|
||||
for (var i=0; i<ystrs.length; i++) {
|
||||
str += ystrs[i] + opts.tooltipSeparator;
|
||||
}
|
||||
str += xstr;
|
||||
break;
|
||||
case 'x':
|
||||
str = xstr;
|
||||
break;
|
||||
case 'y':
|
||||
str = ystrs.join(opts.tooltipSeparator);
|
||||
break;
|
||||
default: // same as 'xy'
|
||||
str = xstr;
|
||||
for (var i=0; i<ystrs.length; i++) {
|
||||
str += opts.tooltipSeparator + ystrs[i];
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var str;
|
||||
if (typeof opts.formatString === 'string') {
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, [opts.formatString].concat(neighbor.data));
|
||||
}
|
||||
|
||||
else {
|
||||
if (opts.tooltipAxes == 'both' || opts.tooltipAxes == 'xy') {
|
||||
str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[0]) + opts.tooltipSeparator + $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[1]);
|
||||
}
|
||||
else if (opts.tooltipAxes == 'yx') {
|
||||
str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[1]) + opts.tooltipSeparator + $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[0]);
|
||||
}
|
||||
else if (opts.tooltipAxes == 'x') {
|
||||
str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[0]);
|
||||
}
|
||||
else if (opts.tooltipAxes == 'y') {
|
||||
str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($.isFunction(opts.tooltipContentEditor)) {
|
||||
// args str, seriesIndex, pointIndex are essential so the hook can look up
|
||||
// extra data for the point.
|
||||
str = opts.tooltipContentEditor(str, neighbor.seriesIndex, neighbor.pointIndex, plot);
|
||||
}
|
||||
elem.html(str);
|
||||
var gridpos = {x:neighbor.gridData[0], y:neighbor.gridData[1]};
|
||||
var ms = 0;
|
||||
var fact = 0.707;
|
||||
if (series.markerRenderer.show == true) {
|
||||
ms = (series.markerRenderer.size + opts.sizeAdjust)/2;
|
||||
}
|
||||
|
||||
var loc = locations;
|
||||
if (series.fillToZero && series.fill && neighbor.data[1] < 0) {
|
||||
loc = oppositeLocations;
|
||||
}
|
||||
|
||||
switch (loc[locationIndicies[opts.tooltipLocation]]) {
|
||||
case 'nw':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - fact * ms;
|
||||
break;
|
||||
case 'n':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - ms;
|
||||
break;
|
||||
case 'ne':
|
||||
var x = gridpos.x + plot._gridPadding.left + opts.tooltipOffset + fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - fact * ms;
|
||||
break;
|
||||
case 'e':
|
||||
var x = gridpos.x + plot._gridPadding.left + opts.tooltipOffset + ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
case 'se':
|
||||
var x = gridpos.x + plot._gridPadding.left + opts.tooltipOffset + fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top + opts.tooltipOffset + fact * ms;
|
||||
break;
|
||||
case 's':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
var y = gridpos.y + plot._gridPadding.top + opts.tooltipOffset + ms;
|
||||
break;
|
||||
case 'sw':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top + opts.tooltipOffset + fact * ms;
|
||||
break;
|
||||
case 'w':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
default: // same as 'nw'
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - fact * ms;
|
||||
break;
|
||||
}
|
||||
elem.css('left', x);
|
||||
elem.css('top', y);
|
||||
if (opts.fadeTooltip) {
|
||||
// Fix for stacked up animations. Thnanks Trevor!
|
||||
elem.stop(true,true).fadeIn(opts.tooltipFadeSpeed);
|
||||
}
|
||||
else {
|
||||
elem.show();
|
||||
}
|
||||
elem = null;
|
||||
|
||||
}
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
var hl = plot.plugins.highlighter;
|
||||
var c = plot.plugins.cursor;
|
||||
if (hl.show) {
|
||||
if (neighbor == null && hl.isHighlighting) {
|
||||
var evt = jQuery.Event('jqplotHighlighterUnhighlight');
|
||||
plot.target.trigger(evt);
|
||||
|
||||
var ctx = hl.highlightCanvas._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
if (hl.fadeTooltip) {
|
||||
hl._tooltipElem.fadeOut(hl.tooltipFadeSpeed);
|
||||
}
|
||||
else {
|
||||
hl._tooltipElem.hide();
|
||||
}
|
||||
if (hl.bringSeriesToFront) {
|
||||
plot.restorePreviousSeriesOrder();
|
||||
}
|
||||
hl.isHighlighting = false;
|
||||
hl.currentNeighbor = null;
|
||||
ctx = null;
|
||||
}
|
||||
else if (neighbor != null && plot.series[neighbor.seriesIndex].showHighlight && !hl.isHighlighting) {
|
||||
var evt = jQuery.Event('jqplotHighlighterHighlight');
|
||||
evt.which = ev.which;
|
||||
evt.pageX = ev.pageX;
|
||||
evt.pageY = ev.pageY;
|
||||
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data, plot];
|
||||
plot.target.trigger(evt, ins);
|
||||
|
||||
hl.isHighlighting = true;
|
||||
hl.currentNeighbor = neighbor;
|
||||
if (hl.showMarker) {
|
||||
draw(plot, neighbor);
|
||||
}
|
||||
if (hl.showTooltip && (!c || !c._zoom.started)) {
|
||||
showTooltip(plot, plot.series[neighbor.seriesIndex], neighbor);
|
||||
}
|
||||
if (hl.bringSeriesToFront) {
|
||||
plot.moveSeriesToFront(neighbor.seriesIndex);
|
||||
}
|
||||
}
|
||||
// check to see if we're highlighting the wrong point.
|
||||
else if (neighbor != null && hl.isHighlighting && hl.currentNeighbor != neighbor) {
|
||||
// highlighting the wrong point.
|
||||
|
||||
// if new series allows highlighting, highlight new point.
|
||||
if (plot.series[neighbor.seriesIndex].showHighlight) {
|
||||
var ctx = hl.highlightCanvas._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
hl.isHighlighting = true;
|
||||
hl.currentNeighbor = neighbor;
|
||||
if (hl.showMarker) {
|
||||
draw(plot, neighbor);
|
||||
}
|
||||
if (hl.showTooltip && (!c || !c._zoom.started)) {
|
||||
showTooltip(plot, plot.series[neighbor.seriesIndex], neighbor);
|
||||
}
|
||||
if (hl.bringSeriesToFront) {
|
||||
plot.moveSeriesToFront(neighbor.seriesIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -1,475 +0,0 @@
|
||||
/*
|
||||
2010-11-01 Chris Leonello
|
||||
|
||||
Slightly modified version of the original json2.js to put JSON
|
||||
functions under the $.jqplot namespace.
|
||||
|
||||
licensing and orignal comments follow:
|
||||
|
||||
http://www.JSON.org/json2.js
|
||||
2010-08-25
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
$.jqplot.JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
$.jqplot.JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = $.jqplot.JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = $.jqplot.JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = $.jqplot.JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
$.jqplot.JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = $.jqplot.JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = $.jqplot.JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
$.jqplot.JSON = window.JSON;
|
||||
|
||||
if (!window.JSON) {
|
||||
$.jqplot.JSON = {};
|
||||
}
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
|
||||
return isFinite(this.valueOf()) ?
|
||||
this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z' : null;
|
||||
};
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function (key) {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
gap,
|
||||
indent,
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
},
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ?
|
||||
'"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string' ? c :
|
||||
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' :
|
||||
'"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0 ? '[]' :
|
||||
gap ? '[\n' + gap +
|
||||
partial.join(',\n' + gap) + '\n' +
|
||||
mind + ']' :
|
||||
'[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
k = rep[i];
|
||||
if (typeof k === 'string') {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0 ? '{}' :
|
||||
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
||||
mind + '}' : '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof $.jqplot.JSON.stringify !== 'function') {
|
||||
$.jqplot.JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('$.jqplot.JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof $.jqplot.JSON.parse !== 'function') {
|
||||
$.jqplot.JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
// because they can cause invocation, and '=' because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with ']' characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function' ?
|
||||
walk({'': j}, '') : j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('$.jqplot.JSON.parse');
|
||||
};
|
||||
}
|
||||
})(jQuery);
|
57
src/html/jqplot/plugins/jqplot.json2.min.js
vendored
57
src/html/jqplot/plugins/jqplot.json2.min.js
vendored
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4r1121
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
* included jsDate library by Chris Leonello:
|
||||
*
|
||||
* Copyright (c) 2010-2011 Chris Leonello
|
||||
*
|
||||
* jsDate is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* jsDate borrows many concepts and ideas from the Date Instance
|
||||
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||||
*
|
||||
* Ken's origianl Date Instance Methods and copyright notice:
|
||||
*
|
||||
* Ken Snyder (ken d snyder at gmail dot com)
|
||||
* 2008-09-10
|
||||
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||||
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||||
*
|
||||
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||||
* Larry has generously given permission to adapt his code for inclusion
|
||||
* into jqPlot.
|
||||
*
|
||||
* Larry's original code can be found here:
|
||||
*
|
||||
* https://github.com/lsiden/export-jqplot-to-png
|
||||
*
|
||||
*
|
||||
*/
|
||||
(function($){$.jqplot.JSON=window.JSON;if(!window.JSON){$.jqplot.JSON={}}function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof $.jqplot.JSON.stringify!=="function"){$.jqplot.JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("$.jqplot.JSON.stringify")}return str("",{"":value})}}if(typeof $.jqplot.JSON.parse!=="function"){$.jqplot.JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("$.jqplot.JSON.parse")}}})(jQuery);
|
@ -1,529 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* class: $.jqplot.LogAxisRenderer
|
||||
* A plugin for a jqPlot to render a logarithmic axis.
|
||||
*
|
||||
* To use this renderer, include the plugin in your source
|
||||
* > <script type="text/javascript" language="javascript" src="plugins/jqplot.logAxisRenderer.js"></script>
|
||||
*
|
||||
* and supply the appropriate options to your plot
|
||||
*
|
||||
* > {axes:{xaxis:{renderer:$.jqplot.LogAxisRenderer}}}
|
||||
**/
|
||||
$.jqplot.LogAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
// prop: axisDefaults
|
||||
// Default properties which will be applied directly to the series.
|
||||
//
|
||||
// Group: Properties
|
||||
//
|
||||
// Properties
|
||||
//
|
||||
// base - the logarithmic base, commonly 2, 10 or Math.E
|
||||
// tickDistribution - Deprecated. "power" distribution of ticks
|
||||
// always used. Option has no effect.
|
||||
this.axisDefaults = {
|
||||
base : 10,
|
||||
tickDistribution :'power'
|
||||
};
|
||||
};
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.LogAxisRenderer.prototype.constructor = $.jqplot.LogAxisRenderer;
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype.init = function(options) {
|
||||
// prop: drawBaseline
|
||||
// True to draw the axis baseline.
|
||||
this.drawBaseline = true;
|
||||
// prop: minorTicks
|
||||
// Number of ticks to add between "major" ticks.
|
||||
// Major ticks are ticks supplied by user or auto computed.
|
||||
// Minor ticks cannot be created by user.
|
||||
this.minorTicks = 'auto';
|
||||
this._scalefact = 1.0;
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
this._autoFormatString = '%d';
|
||||
this._overrideFormatString = false;
|
||||
|
||||
for (var d in this.renderer.axisDefaults) {
|
||||
if (this[d] == null) {
|
||||
this[d] = this.renderer.axisDefaults[d];
|
||||
}
|
||||
}
|
||||
|
||||
this.resetDataBounds();
|
||||
};
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype.createTicks = function(plot) {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
var db = this._dataBounds;
|
||||
var dim = (this.name.charAt(0) === 'x') ? this._plotDimensions.width : this._plotDimensions.height;
|
||||
var interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var tt, i;
|
||||
|
||||
var threshold = 30;
|
||||
// For some reason scalefactor is screwing up ticks.
|
||||
this._scalefact = (Math.max(dim, threshold+1) - threshold)/300;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
// ticks must be in order of increasing value.
|
||||
if (userTicks.length) {
|
||||
// ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
var ut = userTicks[i];
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (ut.constructor == Array) {
|
||||
t.value = ut[0];
|
||||
t.label = ut[1];
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut[0], this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
else if ($.isPlainObject(ut)) {
|
||||
$.extend(true, t, ut);
|
||||
t.axis = this.name;
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
else {
|
||||
t.value = ut;
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
this.numberTicks = userTicks.length;
|
||||
this.min = this._ticks[0].value;
|
||||
this.max = this._ticks[this.numberTicks-1].value;
|
||||
}
|
||||
|
||||
// we don't have any ticks yet, let's make some!
|
||||
else if (this.min == null && this.max == null) {
|
||||
min = db.min * (2 - this.padMin);
|
||||
max = db.max * this.padMax;
|
||||
|
||||
// if min and max are same, space them out a bit
|
||||
if (min == max) {
|
||||
var adj = 0.05;
|
||||
min = min*(1-adj);
|
||||
max = max*(1+adj);
|
||||
}
|
||||
|
||||
// perform some checks
|
||||
if (this.min != null && this.min <= 0) {
|
||||
throw('log axis minimum must be greater than 0');
|
||||
}
|
||||
if (this.max != null && this.max <= 0) {
|
||||
throw('log axis maximum must be greater than 0');
|
||||
}
|
||||
|
||||
function findCeil (val) {
|
||||
var order = Math.pow(10, Math.floor(Math.log(val)/Math.LN10));
|
||||
return Math.ceil(val/order) * order;
|
||||
}
|
||||
|
||||
function findFloor(val) {
|
||||
var order = Math.pow(10, Math.floor(Math.log(val)/Math.LN10));
|
||||
return Math.floor(val/order) * order;
|
||||
}
|
||||
|
||||
// var range = max - min;
|
||||
var rmin, rmax;
|
||||
|
||||
// for power distribution, open up range to get a nice power of axis.renderer.base.
|
||||
// power distribution won't respect the user's min/max settings.
|
||||
rmin = Math.pow(this.base, Math.floor(Math.log(min)/Math.log(this.base)));
|
||||
rmax = Math.pow(this.base, Math.ceil(Math.log(max)/Math.log(this.base)));
|
||||
|
||||
// // if min and max are same, space them out a bit
|
||||
// if (rmin === rmax) {
|
||||
// var adj = 0.05;
|
||||
// rmin = rmin*(1-adj);
|
||||
// rmax = rmax*(1+adj);
|
||||
// }
|
||||
|
||||
var order = Math.round(Math.log(rmin)/Math.LN10);
|
||||
|
||||
if (this.tickOptions == null || !this.tickOptions.formatString) {
|
||||
this._overrideFormatString = true;
|
||||
}
|
||||
|
||||
this.min = rmin;
|
||||
this.max = rmax;
|
||||
var range = this.max - this.min;
|
||||
|
||||
var minorTicks = (this.minorTicks === 'auto') ? 0 : this.minorTicks;
|
||||
var numberTicks;
|
||||
if (this.numberTicks == null){
|
||||
if (dim > 140) {
|
||||
numberTicks = Math.round(Math.log(this.max/this.min)/Math.log(this.base) + 1);
|
||||
if (numberTicks < 2) {
|
||||
numberTicks = 2;
|
||||
}
|
||||
if (minorTicks === 0) {
|
||||
var temp = dim/(numberTicks - 1);
|
||||
if (temp < 100) {
|
||||
minorTicks = 0;
|
||||
}
|
||||
else if (temp < 190) {
|
||||
minorTicks = 1;
|
||||
}
|
||||
else if (temp < 250) {
|
||||
minorTicks = 3;
|
||||
}
|
||||
else if (temp < 600) {
|
||||
minorTicks = 4;
|
||||
}
|
||||
else {
|
||||
minorTicks = 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
numberTicks = 2;
|
||||
if (minorTicks === 0) {
|
||||
minorTicks = 1;
|
||||
}
|
||||
minorTicks = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
numberTicks = this.numberTicks;
|
||||
}
|
||||
|
||||
if (order >= 0 && minorTicks !== 3) {
|
||||
this._autoFormatString = '%d';
|
||||
}
|
||||
// Adjust format string for case with 3 ticks where we'll have like 1, 2.5, 5, 7.5, 10
|
||||
else if (order <= 0 && minorTicks === 3) {
|
||||
var temp = -(order - 1);
|
||||
this._autoFormatString = '%.'+ Math.abs(order-1) + 'f';
|
||||
}
|
||||
|
||||
// Adjust format string for values less than 1.
|
||||
else if (order < 0) {
|
||||
var temp = -order;
|
||||
this._autoFormatString = '%.'+ Math.abs(order) + 'f';
|
||||
}
|
||||
|
||||
else {
|
||||
this._autoFormatString = '%d';
|
||||
}
|
||||
|
||||
var to, t, val, tt1, spread, interval;
|
||||
for (var i=0; i<numberTicks; i++){
|
||||
tt = Math.pow(this.base, i - numberTicks + 1) * this.max;
|
||||
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
|
||||
if (this._overrideFormatString) {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
|
||||
if (minorTicks && i<numberTicks-1) {
|
||||
tt1 = Math.pow(this.base, i - numberTicks + 2) * this.max;
|
||||
spread = tt1 - tt;
|
||||
interval = tt1 / (minorTicks+1);
|
||||
for (var j=minorTicks-1; j>=0; j--) {
|
||||
val = tt1-interval*(j+1);
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(val, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// min and max are set as would be the case with zooming
|
||||
else if (this.min != null && this.max != null) {
|
||||
var opts = $.extend(true, {}, this.tickOptions, {name: this.name, value: null});
|
||||
var nt, ti;
|
||||
// don't have an interval yet, pick one that gives the most
|
||||
// "round" ticks we can get.
|
||||
if (this.numberTicks == null && this.tickInterval == null) {
|
||||
// var threshold = 30;
|
||||
var tdim = Math.max(dim, threshold+1);
|
||||
var nttarget = Math.ceil((tdim-threshold)/35 + 1);
|
||||
|
||||
var ret = $.jqplot.LinearTickGenerator.bestConstrainedInterval(this.min, this.max, nttarget);
|
||||
|
||||
this._autoFormatString = ret[3];
|
||||
nt = ret[2];
|
||||
ti = ret[4];
|
||||
|
||||
for (var i=0; i<nt; i++) {
|
||||
opts.value = this.min + i * ti;
|
||||
t = new this.tickRenderer(opts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
// for loose zoom, number ticks and interval are also set.
|
||||
else if (this.numberTicks != null && this.tickInterval != null) {
|
||||
nt = this.numberTicks;
|
||||
for (var i=0; i<nt; i++) {
|
||||
opts.value = this.min + i * this.tickInterval;
|
||||
t = new this.tickRenderer(opts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype.pack = function(pos, offsets) {
|
||||
var lb = parseInt(this.base, 10);
|
||||
var ticks = this._ticks;
|
||||
var trans = function (v) { return Math.log(v)/Math.log(lb); };
|
||||
var invtrans = function (v) { return Math.pow(Math.E, (Math.log(lb)*v)); };
|
||||
var max = trans(this.max);
|
||||
var min = trans(this.min);
|
||||
var offmax = offsets.max;
|
||||
var offmin = offsets.min;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
|
||||
for (var p in pos) {
|
||||
this._elem.css(p, pos[p]);
|
||||
}
|
||||
|
||||
this._offsets = offsets;
|
||||
// pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
|
||||
var pixellength = offmax - offmin;
|
||||
var unitlength = max - min;
|
||||
|
||||
// point to unit and unit to point conversions references to Plot DOM element top left corner.
|
||||
this.p2u = function(p){
|
||||
return invtrans((p - offmin) * unitlength / pixellength + min);
|
||||
};
|
||||
|
||||
this.u2p = function(u){
|
||||
return (trans(u) - min) * pixellength / unitlength + offmin;
|
||||
};
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis'){
|
||||
this.series_u2p = function(u){
|
||||
return (trans(u) - min) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return invtrans(p * unitlength / pixellength + min);
|
||||
};
|
||||
}
|
||||
// yaxis is max at top of canvas.
|
||||
else {
|
||||
this.series_u2p = function(u){
|
||||
return (trans(u) - max) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return invtrans(p * unitlength / pixellength + max);
|
||||
};
|
||||
}
|
||||
|
||||
if (this.show) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
for (var i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
if (t.angle < 0) {
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
// position at start
|
||||
else {
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'end':
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'start':
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'middle':
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getWidth()/2;
|
||||
}
|
||||
// var shim = t.getWidth()/2;
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('left', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
if (lshow) {
|
||||
var w = this._label._elem.outerWidth(true);
|
||||
this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
|
||||
if (this.name == 'xaxis') {
|
||||
this._label._elem.css('bottom', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('top', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
case 'end':
|
||||
if (t.angle < 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'start':
|
||||
if (t.angle > 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'middle':
|
||||
// if (t.angle > 0) {
|
||||
// shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
// }
|
||||
// else {
|
||||
// shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
// }
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight()/2;
|
||||
}
|
||||
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('top', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
if (lshow) {
|
||||
var h = this._label._elem.outerHeight(true);
|
||||
this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
|
||||
if (this.name == 'yaxis') {
|
||||
this._label._elem.css('left', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('right', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -1,611 +0,0 @@
|
||||
/**
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.4
|
||||
* Revision: 1121
|
||||
*
|
||||
* Copyright (c) 2009-2012 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||||
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||||
*
|
||||
* version 2007.04.27
|
||||
* author Ash Searle
|
||||
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
* http://hexmen.com/js/sprintf.js
|
||||
* The author (Ash Searle) has placed this code in the public domain:
|
||||
* "This code is unrestricted: you are free to use it however you like."
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
// class: $.jqplot.MekkoAxisRenderer
|
||||
// An axis renderer for a Mekko chart.
|
||||
// Should be used with a Mekko chart where the mekkoRenderer is used on the series.
|
||||
// Displays the Y axis as a range from 0 to 1 (0 to 100%) and the x axis with a tick
|
||||
// for each series scaled to the sum of all the y values.
|
||||
$.jqplot.MekkoAxisRenderer = function() {
|
||||
};
|
||||
|
||||
// called with scope of axis object.
|
||||
$.jqplot.MekkoAxisRenderer.prototype.init = function(options){
|
||||
// prop: tickMode
|
||||
// How to space the ticks on the axis.
|
||||
// 'bar' will place a tick at the width of each bar.
|
||||
// This is the default for the x axis.
|
||||
// 'even' will place ticks at even intervals. This is
|
||||
// the default for x2 axis and y axis. y axis cannot be changed.
|
||||
this.tickMode;
|
||||
// prop: barLabelRenderer
|
||||
// renderer to use to draw labels under each bar.
|
||||
this.barLabelRenderer = $.jqplot.AxisLabelRenderer;
|
||||
// prop: barLabels
|
||||
// array of labels to put under each bar.
|
||||
this.barLabels = this.barLabels || [];
|
||||
// prop: barLabelOptions
|
||||
// options object to pass to the bar label renderer.
|
||||
this.barLabelOptions = {};
|
||||
this.tickOptions = $.extend(true, {showGridline:false}, this.tickOptions);
|
||||
this._barLabels = [];
|
||||
$.extend(true, this, options);
|
||||
if (this.name == 'yaxis') {
|
||||
this.tickOptions.formatString = this.tickOptions.formatString || "%d\%";
|
||||
}
|
||||
var db = this._dataBounds;
|
||||
db.min = 0;
|
||||
// for y axes, scale always go from 0 to 1 (0 to 100%)
|
||||
if (this.name == 'yaxis' || this.name == 'y2axis') {
|
||||
db.max = 100;
|
||||
this.tickMode = 'even';
|
||||
}
|
||||
// For x axes, scale goes from 0 to sum of all y values.
|
||||
else if (this.name == 'xaxis'){
|
||||
this.tickMode = (this.tickMode == null) ? 'bar' : this.tickMode;
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
db.max += this._series[i]._sumy;
|
||||
}
|
||||
}
|
||||
else if (this.name == 'x2axis'){
|
||||
this.tickMode = (this.tickMode == null) ? 'even' : this.tickMode;
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
db.max += this._series[i]._sumy;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.draw = function(ctx, plot) {
|
||||
if (this.show) {
|
||||
// populate the axis label and value properties.
|
||||
// createTicks is a method on the renderer, but
|
||||
// call it within the scope of the axis.
|
||||
this.renderer.createTicks.call(this);
|
||||
// fill a div with axes labels in the right direction.
|
||||
// Need to pregenerate each axis to get it's bounds and
|
||||
// position it and the labels correctly on the plot.
|
||||
var dim=0;
|
||||
var temp;
|
||||
|
||||
var elem = document.createElement('div');
|
||||
this._elem = $(elem);
|
||||
this._elem.addClass('jqplot-axis jqplot-'+this.name);
|
||||
this._elem.css('position', 'absolute');
|
||||
elem = null;
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
this._elem.width(this._plotDimensions.width);
|
||||
}
|
||||
else {
|
||||
this._elem.height(this._plotDimensions.height);
|
||||
}
|
||||
|
||||
// draw the axis label
|
||||
// create a _label object.
|
||||
this.labelOptions.axis = this.name;
|
||||
this._label = new this.labelRenderer(this.labelOptions);
|
||||
if (this._label.show) {
|
||||
this._elem.append(this._label.draw(ctx));
|
||||
}
|
||||
|
||||
var t, tick, elem;
|
||||
if (this.showTicks) {
|
||||
t = this._ticks;
|
||||
for (var i=0; i<t.length; i++) {
|
||||
tick = t[i];
|
||||
if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
|
||||
this._elem.append(tick.draw(ctx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw the series labels
|
||||
for (i=0; i<this.barLabels.length; i++) {
|
||||
this.barLabelOptions.axis = this.name;
|
||||
this.barLabelOptions.label = this.barLabels[i];
|
||||
this._barLabels.push(new this.barLabelRenderer(this.barLabelOptions));
|
||||
if (this.tickMode != 'bar') {
|
||||
this._barLabels[i].show = false;
|
||||
}
|
||||
if (this._barLabels[i].show) {
|
||||
var elem = this._barLabels[i].draw(ctx, plot);
|
||||
elem.removeClass('jqplot-'+this.name+'-label');
|
||||
elem.addClass('jqplot-'+this.name+'-tick');
|
||||
elem.addClass('jqplot-mekko-barLabel');
|
||||
elem.appendTo(this._elem);
|
||||
elem = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
// called with scope of an axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.reset = function() {
|
||||
this.min = this._min;
|
||||
this.max = this._max;
|
||||
this.tickInterval = this._tickInterval;
|
||||
this.numberTicks = this._numberTicks;
|
||||
// this._ticks = this.__ticks;
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.set = function() {
|
||||
var dim = 0;
|
||||
var temp;
|
||||
var w = 0;
|
||||
var h = 0;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
if (this.show && this.showTicks) {
|
||||
var t = this._ticks;
|
||||
for (var i=0; i<t.length; i++) {
|
||||
var tick = t[i];
|
||||
if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
temp = tick._elem.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
temp = tick._elem.outerWidth(true);
|
||||
}
|
||||
if (temp > dim) {
|
||||
dim = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lshow) {
|
||||
w = this._label._elem.outerWidth(true);
|
||||
h = this._label._elem.outerHeight(true);
|
||||
}
|
||||
if (this.name == 'xaxis') {
|
||||
dim = dim + h;
|
||||
this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
|
||||
}
|
||||
else if (this.name == 'x2axis') {
|
||||
dim = dim + h;
|
||||
this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
|
||||
}
|
||||
else if (this.name == 'yaxis') {
|
||||
dim = dim + w;
|
||||
this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
|
||||
if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
|
||||
this._label._elem.css('width', w+'px');
|
||||
}
|
||||
}
|
||||
else {
|
||||
dim = dim + w;
|
||||
this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
|
||||
if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
|
||||
this._label._elem.css('width', w+'px');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.createTicks = function() {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
// databounds were set on axis initialization.
|
||||
var db = this._dataBounds;
|
||||
var dim, interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var t, tt, i, j;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
// ticks must be in order of increasing value.
|
||||
|
||||
if (userTicks.length) {
|
||||
// ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
var ut = userTicks[i];
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (ut.constructor == Array) {
|
||||
t.value = ut[0];
|
||||
t.label = ut[1];
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut[0], this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
else {
|
||||
t.value = ut;
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
this.numberTicks = userTicks.length;
|
||||
this.min = this._ticks[0].value;
|
||||
this.max = this._ticks[this.numberTicks-1].value;
|
||||
this.tickInterval = (this.max - this.min) / (this.numberTicks - 1);
|
||||
}
|
||||
|
||||
// we don't have any ticks yet, let's make some!
|
||||
else {
|
||||
if (name == 'xaxis' || name == 'x2axis') {
|
||||
dim = this._plotDimensions.width;
|
||||
}
|
||||
else {
|
||||
dim = this._plotDimensions.height;
|
||||
}
|
||||
|
||||
// if min, max and number of ticks specified, user can't specify interval.
|
||||
if (this.min != null && this.max != null && this.numberTicks != null) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
|
||||
min = (this.min != null) ? this.min : db.min;
|
||||
max = (this.max != null) ? this.max : db.max;
|
||||
|
||||
// if min and max are same, space them out a bit.+
|
||||
if (min == max) {
|
||||
var adj = 0.05;
|
||||
if (min > 0) {
|
||||
adj = Math.max(Math.log(min)/Math.LN10, 0.05);
|
||||
}
|
||||
min -= adj;
|
||||
max += adj;
|
||||
}
|
||||
|
||||
var range = max - min;
|
||||
var rmin, rmax;
|
||||
var temp, prev, curr;
|
||||
var ynumticks = [3,5,6,11,21];
|
||||
|
||||
// yaxis divide ticks in nice intervals from 0 to 1.
|
||||
if (this.name == 'yaxis' || this.name == 'y2axis') {
|
||||
this.min = 0;
|
||||
this.max = 100;
|
||||
// user didn't specify number of ticks.
|
||||
if (!this.numberTicks){
|
||||
if (this.tickInterval) {
|
||||
this.numberTicks = 3 + Math.ceil(range / this.tickInterval);
|
||||
}
|
||||
else {
|
||||
temp = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
|
||||
for (i=0; i<ynumticks.length; i++) {
|
||||
curr = temp/ynumticks[i];
|
||||
if (curr == 1) {
|
||||
this.numberTicks = ynumticks[i];
|
||||
break;
|
||||
}
|
||||
else if (curr > 1) {
|
||||
prev = curr;
|
||||
continue;
|
||||
}
|
||||
else if (curr < 1) {
|
||||
// was prev or is curr closer to one?
|
||||
if (Math.abs(prev - 1) < Math.abs(curr - 1)) {
|
||||
this.numberTicks = ynumticks[i-1];
|
||||
break;
|
||||
}
|
||||
else {
|
||||
this.numberTicks = ynumticks[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (i == ynumticks.length -1) {
|
||||
this.numberTicks = ynumticks[i];
|
||||
}
|
||||
}
|
||||
this.tickInterval = range / (this.numberTicks - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// user did specify number of ticks.
|
||||
else {
|
||||
this.tickInterval = range / (this.numberTicks - 1);
|
||||
}
|
||||
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
tt = this.min + i * this.tickInterval;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
// var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
// for x axes, have number ot ticks equal to number of series and ticks placed
|
||||
// at sum of y values for each series.
|
||||
else if (this.tickMode == 'bar') {
|
||||
this.min = 0;
|
||||
this.numberTicks = this._series.length + 1;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(0, this.name);
|
||||
this._ticks.push(t);
|
||||
|
||||
temp = 0;
|
||||
|
||||
for (i=1; i<this.numberTicks; i++){
|
||||
temp += this._series[i-1]._sumy;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(temp, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
this.max = this.max || temp;
|
||||
|
||||
// if user specified a max and it is greater than sum, add a tick
|
||||
if (this.max > temp) {
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(this.max, this.name);
|
||||
this._ticks.push(t);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.tickMode == 'even') {
|
||||
this.min = 0;
|
||||
this.max = this.max || db.max;
|
||||
// get a desired number of ticks
|
||||
var nt = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
|
||||
range = this.max - this.min;
|
||||
this.numberTicks = nt;
|
||||
this.tickInterval = range / (this.numberTicks - 1);
|
||||
|
||||
for (i=0; i<this.numberTicks; i++){
|
||||
tt = this.min + i * this.tickInterval;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
// var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.pack = function(pos, offsets) {
|
||||
var ticks = this._ticks;
|
||||
var max = this.max;
|
||||
var min = this.min;
|
||||
var offmax = offsets.max;
|
||||
var offmin = offsets.min;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
|
||||
for (var p in pos) {
|
||||
this._elem.css(p, pos[p]);
|
||||
}
|
||||
|
||||
this._offsets = offsets;
|
||||
// pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
|
||||
var pixellength = offmax - offmin;
|
||||
var unitlength = max - min;
|
||||
|
||||
// point to unit and unit to point conversions references to Plot DOM element top left corner.
|
||||
this.p2u = function(p){
|
||||
return (p - offmin) * unitlength / pixellength + min;
|
||||
};
|
||||
|
||||
this.u2p = function(u){
|
||||
return (u - min) * pixellength / unitlength + offmin;
|
||||
};
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis'){
|
||||
this.series_u2p = function(u){
|
||||
return (u - min) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + min;
|
||||
};
|
||||
}
|
||||
|
||||
else {
|
||||
this.series_u2p = function(u){
|
||||
return (u - max) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + max;
|
||||
};
|
||||
}
|
||||
|
||||
if (this.show) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
for (var i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
// will need to adjust auto positioning based on which axis this is.
|
||||
var temp = (this.name == 'xaxis') ? 1 : -1;
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
if (temp * t.angle < 0) {
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
// position at start
|
||||
else {
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'end':
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'start':
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'middle':
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getWidth()/2;
|
||||
}
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('left', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
var w;
|
||||
if (lshow) {
|
||||
w = this._label._elem.outerWidth(true);
|
||||
this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
|
||||
if (this.name == 'xaxis') {
|
||||
this._label._elem.css('bottom', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('top', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
// now show the labels under the bars.
|
||||
var b, l, r;
|
||||
for (var i=0; i<this.barLabels.length; i++) {
|
||||
b = this._barLabels[i];
|
||||
if (b.show) {
|
||||
w = b.getWidth();
|
||||
l = this._ticks[i].getLeft() + this._ticks[i].getWidth();
|
||||
r = this._ticks[i+1].getLeft();
|
||||
b._elem.css('left', (r+l-w)/2+'px');
|
||||
b._elem.css('top', this._ticks[i]._elem.css('top'));
|
||||
b.pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
// will need to adjust auto positioning based on which axis this is.
|
||||
var temp = (this.name == 'yaxis') ? 1 : -1;
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
case 'end':
|
||||
if (temp * t.angle < 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'start':
|
||||
if (t.angle > 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'middle':
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight()/2;
|
||||
}
|
||||
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('top', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
if (lshow) {
|
||||
var h = this._label._elem.outerHeight(true);
|
||||
this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
|
||||
if (this.name == 'yaxis') {
|
||||
this._label._elem.css('left', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('right', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user