├── LICENSE
├── README.md
├── css
├── distTable.css
├── distributionDisplay.css
└── libraries
│ ├── images
│ ├── bg_fallback.png
│ ├── close.png
│ ├── icon_sprite.png
│ ├── progress_bar.gif
│ ├── slider_handles.png
│ ├── ui-icons_222222_256x240.png
│ └── ui-icons_454545_256x240.png
│ ├── jquery.aristo.css
│ ├── jquery.css
│ ├── milkbox
│ ├── close.gif
│ ├── loading.gif
│ ├── loading.old.gif
│ ├── milkbox.css
│ ├── next.gif
│ ├── play-pause.gif
│ └── prev.gif
│ └── overlay.css
├── distributionDisplay.html
├── distributionTable.html
├── docs
├── .nojekyll
├── css
│ ├── distTable.css
│ ├── distributionDisplay.css
│ └── libraries
│ │ ├── images
│ │ ├── bg_fallback.png
│ │ ├── close.png
│ │ ├── icon_sprite.png
│ │ ├── progress_bar.gif
│ │ ├── slider_handles.png
│ │ ├── ui-icons_222222_256x240.png
│ │ └── ui-icons_454545_256x240.png
│ │ ├── jquery.aristo.css
│ │ ├── jquery.css
│ │ ├── milkbox
│ │ ├── close.gif
│ │ ├── loading.gif
│ │ ├── loading.old.gif
│ │ ├── milkbox.css
│ │ ├── next.gif
│ │ ├── play-pause.gif
│ │ └── prev.gif
│ │ └── overlay.css
├── distributionDisplay.html
├── index.html
└── js
│ ├── distributionDisplay.js
│ ├── distributionList.js
│ ├── distributionObjects.js
│ └── libraries
│ ├── disableSTIX.js
│ ├── excanvas.min.js
│ ├── jquery-ui-1.8.9.min.js
│ ├── jquery.flot.crosshair.js
│ ├── jquery.flot.min.js
│ ├── jquery.tools.min.js
│ ├── jstat.js
│ ├── milkbox.js
│ └── mootools-more-1.4.0.1.js
└── js
├── distributionDisplay.js
├── distributionList.js
├── distributionObjects.js
└── libraries
├── disableSTIX.js
├── excanvas.min.js
├── jquery-ui-1.8.9.min.js
├── jquery.flot.crosshair.js
├── jquery.flot.min.js
├── jquery.tools.min.js
├── jstat.js
├── milkbox.js
└── mootools-more-1.4.0.1.js
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Richard Morey
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # stat-distributions-js
2 | Javascript library for the visualization of statistical distributions
3 |
4 | ## What the library does
5 |
6 | Allows for interactive visualizations of probability distributions. The goal of this library is to offer a simple way to define any distribution one likes, and then to immediately be able to interact with the parameters of the distribution and see how the distribution changes.
7 |
8 | [Live demo](https://richarddmorey.github.io/stat-distributions-js/)
9 |
10 | [](http://learnbayes.org/demo/stat-distributions-js/screenshots/screen-distribution.png)
11 |
12 | [](http://learnbayes.org/demo/stat-distributions-js/screenshots/screen-lightbox.png)
13 |
14 | [](http://learnbayes.org/demo/stat-distributions-js/screenshots/screen-table.png)
15 |
16 | There are two HTML files:
17 | * `distributionTable.html`: Lists all known distributions in a table, giving links for interaction with each
18 | * `distributionDisplay.html`: Gives an interface to interface with a specific distribution
19 |
20 | `distributionDisplay.html` can be used directly using URL parameters, e.g.:
21 |
22 | [https://richarddmorey.github.io/stat-distributions-js/distributionDisplay.html?dist=normal&ptzn=2&plotxrng=50,150&rangesLo=50,3&rangesHi=150,45&starts=100,15](https://richarddmorey.github.io/stat-distributions-js/?dist=normal&ptzn=2&plotxrng=50,150&rangesLo=50,3&rangesHi=150,45&starts=100,15)
23 |
24 | The setup parameters used here are:
25 | * `dist`: the distribution name
26 | * `ptzn`: the parametrization number (array index; here 2 means mean/standard deviation)
27 | * `plotxrng`: the lower and upper limit of the x axis
28 | * `rangesLo`: the lower bound for the slider for each parameter
29 | * `rangesHi`: the upper bound for the slider for each parameter
30 | * `starts`: starting values for the parameter sliders
31 |
32 |
33 | ## How it works
34 |
35 | The javascript file `distributionList.js` defines an array of `distribution` objects, each of which represents a probability distribution.
36 |
37 | ### Distibutions
38 |
39 | A distribution is defined by a distribution object, e.g.
40 |
41 | distributions["normal"] = new distribution(
42 | "normal", // label
43 | "Normal/Gaussian", // display name
44 | "continuous", // type
45 | [ normalMeanVariance, normalMeanPrecision ], // array of parametrizations
46 | null, // note
47 | { // information source about the distribution
48 | name:"Wikipedia",
49 | link:"http://en.wikipedia.org/wiki/Normal_distribution"
50 | }
51 | );
52 |
53 | New distributions can be defined analgously.
54 |
55 | ### Parametrizations
56 |
57 | Every distribution must have at least one parametrization. Most of the important information about the distribution is in the parametrization object. See the `distributionObjects.js` file for more details, and the `distributionList.js` file for examples.
58 |
59 | ## Libraries used
60 |
61 | Uses the following libraries:
62 | * For plotting: [jquery](https://jquery.com/), [jquery-ui](https://jqueryui.com/), and [flot.js](http://www.flotcharts.org/)
63 | * For the formula display: [MathJax](https://www.mathjax.org/)
64 | * For the statistical functions: [jstat](https://github.com/jstat/jstat)
65 | * For the lightbox: [mootools](http://mootools.net/) and [milkbox](http://reghellin.com/milkbox/)
66 |
67 | Old (known working) versions of these libraries are included in this repository.
68 |
--------------------------------------------------------------------------------
/css/distTable.css:
--------------------------------------------------------------------------------
1 | table.distribution {
2 | width:90%;
3 | border-top:1px solid #e5eff8;
4 | border-right:1px solid #e5eff8;
5 | margin:1em auto;
6 | border-collapse:collapse;
7 | }
8 | table.distribution caption {
9 | color: #9ba9b4;
10 | font-size:.94em;
11 | letter-spacing:.1em;
12 | margin:1em 0 0 0;
13 | padding:0;
14 | caption-side:top;
15 | text-align:center;
16 | }
17 | table.distribution tr.odd td {
18 | background:#f7fbff
19 | }
20 | table.distribution tr.odd .column1 {
21 | background:#f4f9fe;
22 | }
23 | table.distribution .column1 {
24 | background:#f9fcfe;
25 | }
26 | table.distribution td {
27 | /*color:#678197;*/
28 | color: black;
29 | border-bottom:1px solid #e5eff8;
30 | border-left:1px solid #e5eff8;
31 | padding:.3em 1em;
32 | text-align:center;
33 | }
34 | table.distribution th {
35 | font-weight: bold;
36 | color: #678197;
37 | text-align:left;
38 | border-bottom: 1px solid #e5eff8;
39 | border-left:1px solid #e5eff8;
40 | padding:.3em 1em;
41 | }
42 | table.distribution thead th {
43 | background:#f4f9fe;
44 | text-align:center;
45 | font:bold 1.2em/2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
46 | color:#66a3d3
47 | }
48 | table.distribution tfoot th {
49 | text-align:center;
50 | background:#f4f9fe;
51 | }
52 | table.distribution tfoot th strong {
53 | font:bold 1.2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
54 | margin:.5em .5em .5em 0;
55 | color:#66a3d3;
56 | }
57 | table.distribution tfoot th em {
58 | color:#f03b58;
59 | font-weight: bold;
60 | font-size: 1.1em;
61 | font-style: normal;
62 | }
63 |
--------------------------------------------------------------------------------
/css/distributionDisplay.css:
--------------------------------------------------------------------------------
1 | body{
2 | background-color: white;
3 |
4 | }
5 |
6 | .partooltip {
7 | display:none;
8 | background-color: black;
9 | font-size:16px;
10 | padding:5px;
11 | color:#fff;
12 | opacity: .8;
13 | font-family: sans-serif;
14 | }
15 |
16 | .interfacecontainer {
17 |
18 | border-style: solid;
19 | border-width: 1px;
20 | border-color: gray;
21 | padding: 10px;
22 | margin: 10px;
23 | width: 600px;
24 | height: 320px;
25 | background-color: white;
26 | }
27 |
28 | #parametercontainer {
29 | width:250px;
30 | float: left;
31 | }
32 |
33 |
34 | .paramslider {
35 | width: 150px;
36 | float: left;
37 | }
38 |
39 | .paramindicator {
40 | width: 50px;
41 | float: left;
42 | }
43 |
44 | .paramlabel {
45 | width: 20px;
46 | float: left;
47 | }
48 |
49 | .clear {
50 | clear: both;
51 | }
52 |
53 | .paramsinglecontainer {
54 | width: 250px;
55 | height: 40px;
56 | float: left;
57 | position: relative;
58 | }
59 |
60 | .controlcontainer {
61 | width: 260px;
62 | float: left;
63 | }
64 |
65 | #plottypebuttonscontainer {
66 | width: 200px;
67 | }
68 |
69 | .plotcontainer {
70 | width: 310px;
71 | float: left;
72 | }
73 |
--------------------------------------------------------------------------------
/css/libraries/images/bg_fallback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/images/bg_fallback.png
--------------------------------------------------------------------------------
/css/libraries/images/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/images/close.png
--------------------------------------------------------------------------------
/css/libraries/images/icon_sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/images/icon_sprite.png
--------------------------------------------------------------------------------
/css/libraries/images/progress_bar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/images/progress_bar.gif
--------------------------------------------------------------------------------
/css/libraries/images/slider_handles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/images/slider_handles.png
--------------------------------------------------------------------------------
/css/libraries/images/ui-icons_222222_256x240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/images/ui-icons_222222_256x240.png
--------------------------------------------------------------------------------
/css/libraries/images/ui-icons_454545_256x240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/images/ui-icons_454545_256x240.png
--------------------------------------------------------------------------------
/css/libraries/milkbox/close.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/milkbox/close.gif
--------------------------------------------------------------------------------
/css/libraries/milkbox/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/milkbox/loading.gif
--------------------------------------------------------------------------------
/css/libraries/milkbox/loading.old.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/milkbox/loading.old.gif
--------------------------------------------------------------------------------
/css/libraries/milkbox/milkbox.css:
--------------------------------------------------------------------------------
1 | /* MILKBOX CSS */
2 |
3 | #mbox-overlay{
4 | background-color: #000; /* set the Milkbox overlay color // opacity: see the js options */
5 | z-index:50000;
6 | cursor: pointer;
7 | }
8 |
9 | /* Main box */
10 | #mbox-mainbox{
11 | /* For default width and height, see the js options */
12 | top:10%;/* overwritten in the js options to properly position the main box when activated in a scrolled window */
13 | background-color: #fff;/* set the main box background color */
14 | border: 5px solid #fff;/* set the main box border */
15 | padding:5px;/* set the main box padding */
16 | }
17 |
18 | /* Where the files actually are injected */
19 | #mbox-filebox{ margin:0; padding:0; border:none; overflow:hidden; }
20 |
21 | #mbox-filebox img,
22 | #mbox-filebox iframe,
23 | #mbox-filebox swf{
24 | border:none;
25 | }
26 |
27 | /*this class is for styling the inner file box*/
28 | /*these styles will be visible after the first is loaded */
29 | .mbox-filebox-decorations{
30 | border:none;
31 | padding:0;
32 | }
33 |
34 | /* *** BOTTOM *** */
35 |
36 | /* container for controls and caption */
37 | #mbox-bottom {
38 | /* set text options */
39 | font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
40 | font-size: 12px;
41 | color: #656565;
42 | line-height: 1.4em;
43 | text-align: left;
44 | padding-top:8px;
45 | margin:0;
46 | }
47 |
48 | /* controls/navigation */
49 | /* be careful if you change buttons dimensions */
50 |
51 | #mbox-controls{
52 | /*background-color:#0f0;*/
53 | float:right;
54 | width:27px;
55 | padding-top:3px;
56 | border-left:1px solid #9c9c9c;/* set nav border */
57 | }
58 |
59 | #mbox-count{
60 | overflow:hidden;
61 | padding-top:1px;
62 | float:right;
63 | text-align:right;
64 | font-size:9px; /* count font size */
65 | }
66 |
67 | #mbox-close,
68 | #mbox-prev,
69 | #mbox-next,
70 | #mbox-playpause{
71 | float:right;
72 | height:19px;
73 | }
74 |
75 | #mbox-prev,#mbox-next{ width:15px; }
76 | #mbox-prev{ background: url(prev.gif) no-repeat; }/* IMAGE: prev */
77 | #mbox-next{ background: url(next.gif) no-repeat; }/* IMAGE: next */
78 |
79 | #mbox-playpause{ width:13px; }
80 | #mbox-playpause{ background: url(play-pause.gif) no-repeat; }/* IMAGE: prev */
81 |
82 | #mbox-close{
83 | width:17px;
84 | background:url(close.gif) no-repeat;/* IMAGE: close */
85 | }
86 |
87 | #mbox-prev:hover,
88 | #mbox-next:hover,
89 | #mbox-close:hover,
90 | #mbox-playpause:hover{
91 | background-position:0 -22px;
92 | }
93 |
94 | /* description */
95 | #mbox-caption{
96 | /*background-color:#f00;*/
97 | margin-right:27px;
98 | padding:0px 10px 0 0;
99 | font-weight: normal;
100 | text-align:justify;
101 | overflow-x: hidden; /* make sure the controls at the right remain accessible, even for small images with very large filenames: those would otherwise overlap those controls at right */
102 | }
103 |
104 | .mbox-loading{ background:url(loading.gif) no-repeat center; }/* IMAGE: loading gif */
105 | .mbox-reset{ clear:both; height:0; margin:0; padding:0; font-size:0; overflow:hidden; }
106 |
107 |
--------------------------------------------------------------------------------
/css/libraries/milkbox/next.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/milkbox/next.gif
--------------------------------------------------------------------------------
/css/libraries/milkbox/play-pause.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/milkbox/play-pause.gif
--------------------------------------------------------------------------------
/css/libraries/milkbox/prev.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/css/libraries/milkbox/prev.gif
--------------------------------------------------------------------------------
/css/libraries/overlay.css:
--------------------------------------------------------------------------------
1 | .distributionOL {
2 |
3 | /* must be initially hidden */
4 | display:none;
5 |
6 | /* place overlay on top of other elements */
7 | z-index:10000;
8 |
9 | /* styling */
10 | background-color:#333;
11 |
12 | width:675px;
13 | min-height:200px;
14 | border:1px solid #666;
15 |
16 | /* CSS3 styling for latest browsers */
17 | -moz-box-shadow:0 0 90px 5px #000;
18 | -webkit-box-shadow: 0 0 90px #000;
19 | }
20 |
21 | /* close button positioned on upper right corner */
22 | .distributionOL .close {
23 | background-image:url(images/close.png);
24 | position:absolute;
25 | right:-15px;
26 | top:-15px;
27 | cursor:pointer;
28 | height:35px;
29 | width:35px;
30 | }
31 |
32 | /* styling for elements inside overlay */
33 | .distributionOLDetails {
34 | position:absolute;
35 | top:15px;
36 | right:15px;
37 | font-size:11px;
38 | color:#fff;
39 | width:150px;
40 | }
41 |
42 | .details h3 {
43 | color:#aba;
44 | font-size:15px;
45 | margin:0 0 -10px 0;
46 | }
--------------------------------------------------------------------------------
/distributionDisplay.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Distribution display
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 | PDF
38 | CDF
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/distributionTable.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Distribution display
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Continuous
28 |
29 |
30 | Discrete
31 |
32 |
33 | Multivariate
34 |
35 |
36 | Master
37 |
38 |
39 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/docs/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/.nojekyll
--------------------------------------------------------------------------------
/docs/css/distTable.css:
--------------------------------------------------------------------------------
1 | table.distribution {
2 | width:90%;
3 | border-top:1px solid #e5eff8;
4 | border-right:1px solid #e5eff8;
5 | margin:1em auto;
6 | border-collapse:collapse;
7 | }
8 | table.distribution caption {
9 | color: #9ba9b4;
10 | font-size:.94em;
11 | letter-spacing:.1em;
12 | margin:1em 0 0 0;
13 | padding:0;
14 | caption-side:top;
15 | text-align:center;
16 | }
17 | table.distribution tr.odd td {
18 | background:#f7fbff
19 | }
20 | table.distribution tr.odd .column1 {
21 | background:#f4f9fe;
22 | }
23 | table.distribution .column1 {
24 | background:#f9fcfe;
25 | }
26 | table.distribution td {
27 | /*color:#678197;*/
28 | color: black;
29 | border-bottom:1px solid #e5eff8;
30 | border-left:1px solid #e5eff8;
31 | padding:.3em 1em;
32 | text-align:center;
33 | }
34 | table.distribution th {
35 | font-weight: bold;
36 | color: #678197;
37 | text-align:left;
38 | border-bottom: 1px solid #e5eff8;
39 | border-left:1px solid #e5eff8;
40 | padding:.3em 1em;
41 | }
42 | table.distribution thead th {
43 | background:#f4f9fe;
44 | text-align:center;
45 | font:bold 1.2em/2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
46 | color:#66a3d3
47 | }
48 | table.distribution tfoot th {
49 | text-align:center;
50 | background:#f4f9fe;
51 | }
52 | table.distribution tfoot th strong {
53 | font:bold 1.2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
54 | margin:.5em .5em .5em 0;
55 | color:#66a3d3;
56 | }
57 | table.distribution tfoot th em {
58 | color:#f03b58;
59 | font-weight: bold;
60 | font-size: 1.1em;
61 | font-style: normal;
62 | }
63 |
--------------------------------------------------------------------------------
/docs/css/distributionDisplay.css:
--------------------------------------------------------------------------------
1 | body{
2 | background-color: white;
3 |
4 | }
5 |
6 | .partooltip {
7 | display:none;
8 | background-color: black;
9 | font-size:16px;
10 | padding:5px;
11 | color:#fff;
12 | opacity: .8;
13 | font-family: sans-serif;
14 | }
15 |
16 | .interfacecontainer {
17 |
18 | border-style: solid;
19 | border-width: 1px;
20 | border-color: gray;
21 | padding: 10px;
22 | margin: 10px;
23 | width: 600px;
24 | height: 320px;
25 | background-color: white;
26 | }
27 |
28 | #parametercontainer {
29 | width:250px;
30 | float: left;
31 | }
32 |
33 |
34 | .paramslider {
35 | width: 150px;
36 | float: left;
37 | }
38 |
39 | .paramindicator {
40 | width: 50px;
41 | float: left;
42 | }
43 |
44 | .paramlabel {
45 | width: 20px;
46 | float: left;
47 | }
48 |
49 | .clear {
50 | clear: both;
51 | }
52 |
53 | .paramsinglecontainer {
54 | width: 250px;
55 | height: 40px;
56 | float: left;
57 | position: relative;
58 | }
59 |
60 | .controlcontainer {
61 | width: 260px;
62 | float: left;
63 | }
64 |
65 | #plottypebuttonscontainer {
66 | width: 200px;
67 | }
68 |
69 | .plotcontainer {
70 | width: 310px;
71 | float: left;
72 | }
73 |
--------------------------------------------------------------------------------
/docs/css/libraries/images/bg_fallback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/images/bg_fallback.png
--------------------------------------------------------------------------------
/docs/css/libraries/images/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/images/close.png
--------------------------------------------------------------------------------
/docs/css/libraries/images/icon_sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/images/icon_sprite.png
--------------------------------------------------------------------------------
/docs/css/libraries/images/progress_bar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/images/progress_bar.gif
--------------------------------------------------------------------------------
/docs/css/libraries/images/slider_handles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/images/slider_handles.png
--------------------------------------------------------------------------------
/docs/css/libraries/images/ui-icons_222222_256x240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/images/ui-icons_222222_256x240.png
--------------------------------------------------------------------------------
/docs/css/libraries/images/ui-icons_454545_256x240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/images/ui-icons_454545_256x240.png
--------------------------------------------------------------------------------
/docs/css/libraries/milkbox/close.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/milkbox/close.gif
--------------------------------------------------------------------------------
/docs/css/libraries/milkbox/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/milkbox/loading.gif
--------------------------------------------------------------------------------
/docs/css/libraries/milkbox/loading.old.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/milkbox/loading.old.gif
--------------------------------------------------------------------------------
/docs/css/libraries/milkbox/milkbox.css:
--------------------------------------------------------------------------------
1 | /* MILKBOX CSS */
2 |
3 | #mbox-overlay{
4 | background-color: #000; /* set the Milkbox overlay color // opacity: see the js options */
5 | z-index:50000;
6 | cursor: pointer;
7 | }
8 |
9 | /* Main box */
10 | #mbox-mainbox{
11 | /* For default width and height, see the js options */
12 | top:10%;/* overwritten in the js options to properly position the main box when activated in a scrolled window */
13 | background-color: #fff;/* set the main box background color */
14 | border: 5px solid #fff;/* set the main box border */
15 | padding:5px;/* set the main box padding */
16 | }
17 |
18 | /* Where the files actually are injected */
19 | #mbox-filebox{ margin:0; padding:0; border:none; overflow:hidden; }
20 |
21 | #mbox-filebox img,
22 | #mbox-filebox iframe,
23 | #mbox-filebox swf{
24 | border:none;
25 | }
26 |
27 | /*this class is for styling the inner file box*/
28 | /*these styles will be visible after the first is loaded */
29 | .mbox-filebox-decorations{
30 | border:none;
31 | padding:0;
32 | }
33 |
34 | /* *** BOTTOM *** */
35 |
36 | /* container for controls and caption */
37 | #mbox-bottom {
38 | /* set text options */
39 | font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
40 | font-size: 12px;
41 | color: #656565;
42 | line-height: 1.4em;
43 | text-align: left;
44 | padding-top:8px;
45 | margin:0;
46 | }
47 |
48 | /* controls/navigation */
49 | /* be careful if you change buttons dimensions */
50 |
51 | #mbox-controls{
52 | /*background-color:#0f0;*/
53 | float:right;
54 | width:27px;
55 | padding-top:3px;
56 | border-left:1px solid #9c9c9c;/* set nav border */
57 | }
58 |
59 | #mbox-count{
60 | overflow:hidden;
61 | padding-top:1px;
62 | float:right;
63 | text-align:right;
64 | font-size:9px; /* count font size */
65 | }
66 |
67 | #mbox-close,
68 | #mbox-prev,
69 | #mbox-next,
70 | #mbox-playpause{
71 | float:right;
72 | height:19px;
73 | }
74 |
75 | #mbox-prev,#mbox-next{ width:15px; }
76 | #mbox-prev{ background: url(prev.gif) no-repeat; }/* IMAGE: prev */
77 | #mbox-next{ background: url(next.gif) no-repeat; }/* IMAGE: next */
78 |
79 | #mbox-playpause{ width:13px; }
80 | #mbox-playpause{ background: url(play-pause.gif) no-repeat; }/* IMAGE: prev */
81 |
82 | #mbox-close{
83 | width:17px;
84 | background:url(close.gif) no-repeat;/* IMAGE: close */
85 | }
86 |
87 | #mbox-prev:hover,
88 | #mbox-next:hover,
89 | #mbox-close:hover,
90 | #mbox-playpause:hover{
91 | background-position:0 -22px;
92 | }
93 |
94 | /* description */
95 | #mbox-caption{
96 | /*background-color:#f00;*/
97 | margin-right:27px;
98 | padding:0px 10px 0 0;
99 | font-weight: normal;
100 | text-align:justify;
101 | overflow-x: hidden; /* make sure the controls at the right remain accessible, even for small images with very large filenames: those would otherwise overlap those controls at right */
102 | }
103 |
104 | .mbox-loading{ background:url(loading.gif) no-repeat center; }/* IMAGE: loading gif */
105 | .mbox-reset{ clear:both; height:0; margin:0; padding:0; font-size:0; overflow:hidden; }
106 |
107 |
--------------------------------------------------------------------------------
/docs/css/libraries/milkbox/next.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/milkbox/next.gif
--------------------------------------------------------------------------------
/docs/css/libraries/milkbox/play-pause.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/milkbox/play-pause.gif
--------------------------------------------------------------------------------
/docs/css/libraries/milkbox/prev.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richarddmorey/stat-distributions-js/189d2f40142ec6d0760f27f7fc6313482915ae0f/docs/css/libraries/milkbox/prev.gif
--------------------------------------------------------------------------------
/docs/css/libraries/overlay.css:
--------------------------------------------------------------------------------
1 | .distributionOL {
2 |
3 | /* must be initially hidden */
4 | display:none;
5 |
6 | /* place overlay on top of other elements */
7 | z-index:10000;
8 |
9 | /* styling */
10 | background-color:#333;
11 |
12 | width:675px;
13 | min-height:200px;
14 | border:1px solid #666;
15 |
16 | /* CSS3 styling for latest browsers */
17 | -moz-box-shadow:0 0 90px 5px #000;
18 | -webkit-box-shadow: 0 0 90px #000;
19 | }
20 |
21 | /* close button positioned on upper right corner */
22 | .distributionOL .close {
23 | background-image:url(images/close.png);
24 | position:absolute;
25 | right:-15px;
26 | top:-15px;
27 | cursor:pointer;
28 | height:35px;
29 | width:35px;
30 | }
31 |
32 | /* styling for elements inside overlay */
33 | .distributionOLDetails {
34 | position:absolute;
35 | top:15px;
36 | right:15px;
37 | font-size:11px;
38 | color:#fff;
39 | width:150px;
40 | }
41 |
42 | .details h3 {
43 | color:#aba;
44 | font-size:15px;
45 | margin:0 0 -10px 0;
46 | }
--------------------------------------------------------------------------------
/docs/distributionDisplay.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Distribution display
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 | PDF
38 | CDF
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Distribution display
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Continuous
28 |
29 |
30 | Discrete
31 |
32 |
33 | Multivariate
34 |
35 |
36 | Master
37 |
38 |
39 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/docs/js/distributionDisplay.js:
--------------------------------------------------------------------------------
1 | // Universal plotting options
2 | var plotPoints = 200;
3 | var plotOptions = [];
4 | var sliderPoints = 101;
5 | var roundDigits = 3;
6 | var updateTime = 100;
7 | var areaFillColor="rgba(0,200,0,.3)";
8 |
9 | plotOptions["pdf"] = {
10 | yaxis: { min:0 },
11 | colors: ["rgb(0,200,0)", "rgb(200,0,0)","rgb(150,150,150)","rgb(150,150,150)", "rgb(0,200,0)"],
12 | series: {
13 | points: { fillColor: "rgb(0,200,0)"}
14 | },
15 | grid: { hoverable: true, clickable: true },
16 | crosshair: { mode: "x" }
17 | };
18 | plotOptions["cdf"] = {
19 | yaxis: { min:0, max: 1.001},
20 | colors: ["rgb(0,0,0)", "rgb(200,0,0)", "rgb(150,150,150)","rgb(150,150,150)", "rgb(0,200,0)"],
21 | series: {
22 | points: { fillColor: "rgb(0,200,0)"}
23 | },
24 | grid: { hoverable: true, clickable: false }
25 | };
26 |
27 | var plot;
28 | var dist;
29 | var distName;
30 | var ptznNum;
31 | var starts;
32 | var rangesHi;
33 | var rangesLo;
34 | var plotxrng;
35 |
36 | var distributions = [];
37 |
38 | function getShaded(plot,pos, limits, cumdens, args){
39 | var data = plot.getData();
40 | var x1 = data[2];
41 | var x2 = data[3];
42 |
43 | if(x2.data.length!=0){
44 | x2 = x2.data[0][0];
45 | x1 = x1.data[0][0];
46 | var minx = Math.min(x1,x2);
47 | var maxx = Math.max(x1,x2);
48 | return cumdens.apply(null, [maxx].concat(args) ) -
49 | cumdens.apply(null, [minx].concat(args) );
50 | }else if(x1.data.length!=0){
51 | x1 = x1.data[0][0];
52 | return cumdens.apply(null, [x1].concat(args) );
53 | }else{
54 | return cumdens.apply(null, [pos.x].concat(args) );
55 | x2 = limits[0];
56 | x1 = pos.x;
57 | }
58 |
59 | }
60 |
61 |
62 | function showTooltip(x, y, contents) {
63 | $('
' + contents + '
').css( {
64 | position: 'absolute',
65 | display: 'none',
66 | top: y - 30,
67 | left: x + 10,
68 | border: '1px solid #fdd',
69 | padding: '2px',
70 | 'background-color': '#fee',
71 | opacity: 0.80,
72 | 'font-family': 'sans-serif'
73 | }).appendTo("body").fadeIn(0);
74 | }
75 |
76 | function makeSortedTable(type, caption){
77 |
78 | var n = distributions.length;
79 | var list = [];
80 | var i=0;
81 | for(d in distributions){
82 | if (distributions.hasOwnProperty(d))
83 | {
84 | if(distributions[d].type == type || type == "master") list.push(d);
85 | }
86 | }
87 |
88 | list.sort();
89 |
90 | document.id(type+'_distributionsdiv').grab(
91 | new Element("table",{
92 | id: type+"_distributiontable",
93 | 'class':"distribution"
94 | })
95 | );
96 |
97 | var cap = new Element('caption', {
98 | html: caption
99 | });
100 | document.id(type+'_distributiontable').grab(cap);
101 |
102 | refTableHeaderRow(type);
103 |
104 | var body = new Element("tbody",{
105 | id: type+"_distributiontablebody"
106 | });
107 | document.id(type+'_distributiontable').grab(body);
108 |
109 |
110 | if(list.length==0) return;
111 |
112 | for(;i
0;},
61 | {
62 | mean: {
63 | fun: function(mu, sig2) { return jStat.normal.mean(mu, Math.sqrt(sig2)); },
64 | display: "\\mu"
65 | },
66 | variance: {
67 | fun: function(mu, sig2) { return jStat.normal.variance(mu, Math.sqrt(sig2)); },
68 | display: "\\sigma^2"
69 | },
70 | median: {
71 | fun: function(mu, sig2) { return jStat.normal.median(mu, Math.sqrt(sig2)); },
72 | display: "\\mu"
73 | },
74 | mode: {
75 | fun: function(mu, sig2) { return jStat.normal.mode(mu, Math.sqrt(sig2)); },
76 | display: "\\mu"
77 | }
78 |
79 | },
80 | null
81 | );
82 |
83 | var normalMeanPrecision = new distributionParametrization(
84 | "mean/precision",
85 | [normalMean, normalPrecision],
86 | function(mu,tau) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
87 | function(mu,tau) { return [-5,5]; },
88 | "(-\\infty,\\infty)",
89 | function(x,mu,tau){ return jStat.normal.pdf(x,mu,Math.sqrt(1/tau)); },
90 | "\\left(\\frac{\\tau}{2\\pi}\\right)^{\\frac{1}{2}}\\exp\\left\\{-\\frac{\\tau}{2}\\left(x-\\mu\\right)^2\\right\\}",
91 | function(x,mu,tau){ return jStat.normal.cdf(x,mu,Math.sqrt(1/tau)); },
92 | "normalgamma",
93 | function(mu,tau){ return tau>0;},
94 | {
95 | mean: {
96 | fun: function(mu, tau) { return jStat.normal.mean(mu, 1/Math.sqrt(tau)); },
97 | display: "\\mu"
98 | },
99 | variance: {
100 | fun: function(mu, tau) { return jStat.normal.variance(mu, 1/Math.sqrt(tau)); },
101 | display: "\\frac{1}{\\tau}"
102 | },
103 | median: {
104 | fun: function(mu, tau) { return jStat.normal.median(mu, 1/Math.sqrt(tau)); },
105 | display: "\\mu"
106 | },
107 | mode: {
108 | fun: function(mu, tau) { return jStat.normal.mode(mu, 1/Math.sqrt(tau)); },
109 | display: "\\mu"
110 | }
111 | },
112 | null
113 |
114 | );
115 |
116 | var normalMeanStandardDeviation = new distributionParametrization(
117 | "mean/standard deviation",
118 | [normalMean, normalStandardDeviation],
119 | function(mu,sig2) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
120 | function(mu,sig2) { return [-5,5]; },
121 | "(-\\infty,\\infty)",
122 | function(x, mu, sig) { return jStat.normal.pdf(x, mu, sig); },
123 | "\\left(2\\pi\\sigma^2\\right)^{-\\frac{1}{2}}\\exp\\left\\{-\\frac{1}{2\\sigma^2}\\left(x-\\mu\\right)^2\\right\\}",
124 | function(x, mu, sig) { return jStat.normal.cdf(x, mu, sig); },
125 | null,
126 | function(mu,sig){ return sig>0;},
127 | {
128 | mean: {
129 | fun: function(mu, sig) { return jStat.normal.mean(mu, sig); },
130 | display: "\\mu"
131 | },
132 | variance: {
133 | fun: function(mu, sig) { return jStat.normal.variance(mu, sig); },
134 | display: "\\sigma"
135 | },
136 | median: {
137 | fun: function(mu, sig) { return jStat.normal.median(mu, sig); },
138 | display: "\\mu"
139 | },
140 | mode: {
141 | fun: function(mu, sig) { return jStat.normal.mode(mu, sig); },
142 | display: "\\mu"
143 | }
144 |
145 | },
146 | null
147 | );
148 |
149 |
150 | distributions["normal"] = new distribution(
151 | "normal",
152 | "Normal/Gaussian",
153 | "continuous",
154 | [ normalMeanVariance, normalMeanPrecision, normalMeanStandardDeviation],
155 | null,
156 | {
157 | name:"Wikipedia",
158 | link:"http://en.wikipedia.org/wiki/Normal_distribution"
159 | }
160 | );
161 |
162 |
163 | /*****/
164 | // Gamma distribution
165 | /*****/
166 |
167 | var gammaShape = new positiveParameter(
168 | "k",
169 | "k",
170 | function() { return [.1,10]; },
171 | true,
172 | 1,
173 | "continuous",
174 | null,
175 | "shape"
176 | );
177 |
178 | var gammaScale = new positiveParameter(
179 | "s",
180 | "s",
181 | function() { return [0.1,10]; },
182 | true,
183 | 1,
184 | "continuous",
185 | "inversegamma",
186 | "scale"
187 | );
188 |
189 | var gammaRate = new positiveParameter(
190 | "theta",
191 | "\\theta",
192 | function() { return [0.1,10]; },
193 | true,
194 | 1,
195 | "continuous",
196 | "gamma",
197 | "rate"
198 | );
199 |
200 | var gammaShapeScale = new distributionParametrization(
201 | "shape/scale",
202 | [gammaShape, gammaScale],
203 | function(k,s) { return [0,Number.POSITIVE_INFINITY]; },
204 | function(k,s) { return [.01,10]; },
205 | "(0,\\infty)",
206 | jStat.gamma.pdf,
207 | "\\frac{1}{\\Gamma(k)s^{k}} x^{k - 1} \\exp\\left\\{-\\frac{x}{s}\\right\\}",
208 | jStat.gamma.cdf,
209 | null,
210 | function(k,s){ return s>0 && k>0;},
211 | {
212 | mean: {
213 | fun: jStat.gamma.mean,
214 | display: "ks"
215 | },
216 | variance: {
217 | fun: jStat.gamma.variance,
218 | display: "ks^2"
219 | },
220 | mode: {
221 | fun: jStat.gamma.mode,
222 | display: "(k-1)s, k\\geq 1"
223 | }
224 | },
225 | null
226 |
227 | );
228 |
229 | var gammaShapeRate = new distributionParametrization(
230 | "shape/rate",
231 | [gammaShape, gammaRate],
232 | function(k,theta) { return [0,Number.POSITIVE_INFINITY]; },
233 | function(k,theta) { return [.01,10]; },
234 | "(0,\\infty)",
235 | function(x, k, theta) { return jStat.gamma.pdf(x, k, 1/theta); },
236 | "\\frac{\\theta^k}{\\Gamma(k)} x^{k - 1} \\exp\\left\\{-\\theta x\\right\\}",
237 | function(x, k, theta) { return jStat.gamma.cdf(x, k, 1/theta); },
238 | null,
239 | function(k,theta){ return theta>0 && k>0;},
240 | {
241 | mean: {
242 | fun: function(k,theta) { return jStat.gamma.mean(k, 1/theta); },
243 | display: "\\frac{k}{\\theta}"
244 | },
245 | variance: {
246 | fun: function(k,theta) { return jStat.gamma.variance(k, 1/theta); },
247 | display: "\\frac{k}{\\theta^2}"
248 | },
249 | mode: {
250 | fun: function(k,theta) { return jStat.gamma.mode(k, 1/theta); },
251 | display: "\\frac{k-1}{\\theta}, k\\geq 1"
252 | }
253 | },
254 | null
255 |
256 | );
257 | distributions["gamma"] = new distribution(
258 | "gamma",
259 | "Gamma",
260 | "continuous",
261 | [ gammaShapeScale, gammaShapeRate ],
262 | null,
263 | {
264 | name:"Wikipedia",
265 | link:"http://en.wikipedia.org/wiki/Gamma_distribution"
266 | }
267 | );
268 |
269 |
270 | /*****/
271 | // Inverse Gamma distribution
272 | /*****/
273 |
274 | var invgammaShape = new positiveParameter(
275 | "alpha",
276 | "\\alpha",
277 | function() { return [.1,10]; },
278 | true,
279 | 1,
280 | "continuous",
281 | null,
282 | "shape"
283 | );
284 |
285 | var invgammaScale = new positiveParameter(
286 | "beta",
287 | "\\beta",
288 | function() { return [0.1,10]; },
289 | true,
290 | 1,
291 | "continuous",
292 | "gamma",
293 | "scale"
294 | );
295 |
296 | var invgammaShapeScale = new distributionParametrization(
297 | "shape/scale",
298 | [invgammaShape, invgammaScale],
299 | function(alpha,beta) { return [0,Number.POSITIVE_INFINITY]; },
300 | function(alpha,beta) { return [.01,15]; },
301 | "(0,\\infty)",
302 | jStat.invgamma.pdf,
303 | "\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} x^{-\\alpha - 1} \\exp\\left\\{-\\frac{\\beta}{x}\\right\\}",
304 | jStat.invgamma.cdf,
305 | null,
306 | function(alpha,beta){ return alpha>0 && beta>0;},
307 | {
308 | mean: {
309 | fun: jStat.invgamma.mean,
310 | display: "\\frac{\\beta}{\\alpha-1}, \\alpha>1"
311 | },
312 | variance: {
313 | fun: jStat.invgamma.variance,
314 | display: "\\frac{\\beta^2}{(\\alpha-1)^2(\\alpha-2)}, \\alpha>2"
315 | },
316 | mode: {
317 | fun: jStat.invgamma.mode,
318 | display: "\\frac{\\beta}{\\alpha+1}"
319 | }
320 | },
321 | null
322 | );
323 |
324 | distributions["invgamma"] = new distribution(
325 | "invgamma",
326 | "Inverse Gamma",
327 | "continuous",
328 | [ invgammaShapeScale ],
329 | null,
330 | {
331 | name:"Wikipedia",
332 | link:"http://en.wikipedia.org/wiki/Inverse-gamma_distribution"
333 | }
334 | );
335 |
336 |
337 |
338 | /*****/
339 | // Central F distribution
340 | /*****/
341 |
342 | var Fdf1 = new positiveParameter(
343 | "nu1",
344 | "\\nu_1",
345 | function() { return [1,40]; },
346 | false,
347 | 5,
348 | "discrete",
349 | null,
350 | "numerator df"
351 | );
352 |
353 | var Fdf2 = new positiveParameter(
354 | "nu2",
355 | "\\nu_2",
356 | function() { return [1,40]; },
357 | false,
358 | 5,
359 | "discrete",
360 | null,
361 | "denominator df"
362 | );
363 |
364 | var centralFpar = new distributionParametrization(
365 | "central",
366 | [Fdf1, Fdf2],
367 | function(nu1,nu2) { return [0,Number.POSITIVE_INFINITY]; },
368 | function(nu1,nu2) { return [.01,10]; },
369 | "(0,\\infty)",
370 | jStat.centralF.pdf,
371 | "\\frac{1}{x\\mbox{Be}\\left(\\frac{\\nu_1}{2},\\frac{\\nu_2}{2}\\right)}\\sqrt{\\frac{(\\nu_1x)^{\\nu_1}\\nu_2^{\\nu_2}}{(\\nu_1x + \\nu_2)^{\\nu_1+\\nu_2}}}",
372 | jStat.centralF.cdf,
373 | null,
374 | function(nu1,nu2){ return nu1>0 && nu2>0;},
375 | {
376 | mean: {
377 | fun: jStat.centralF.mean,
378 | display: "\\frac{\\nu_2}{\\nu_2-2}, \\nu_2>2"
379 | },
380 | variance: {
381 | fun: jStat.centralF.variance,
382 | display: "\\frac{2\\nu_2^2(\\nu_1 + \\nu_2-2)}{\\nu_1(\\nu_2-2)^2(\\nu_2-4)}, \\nu_2>4"
383 | },
384 | mode: {
385 | fun: jStat.centralF.mode,
386 | display: "\\frac{\\nu_2(\\nu_1 - 2)}{\\nu_1(\\nu_2+2)}, \\nu_1<2"
387 | }
388 | },
389 | null
390 | );
391 |
392 | distributions["centralF"] = new distribution(
393 | "centralF",
394 | "central F",
395 | "continuous",
396 | [ centralFpar ],
397 | null,
398 | {
399 | name:"Wikipedia",
400 | link:"http://en.wikipedia.org/wiki/F_distribution"
401 | }
402 | );
403 |
404 |
405 |
406 | /*****/
407 | // Cauchy distribution
408 | /*****/
409 |
410 | var cauchyLocation= new unboundedParameter(
411 | "mu",
412 | "\\mu",
413 | function() { return [-8,8];},
414 | false,
415 | 0,
416 | "continuous",
417 | null,
418 | "location"
419 | );
420 |
421 | var cauchyScale = new positiveParameter(
422 | "sigma",
423 | "\\sigma",
424 | function() { return [0.1,10];},
425 | true,
426 | 1,
427 | "continuous",
428 | null,
429 | "scale"
430 | );
431 |
432 | var cauchyLocationScale = new distributionParametrization(
433 | "location/scale",
434 | [cauchyLocation, cauchyScale],
435 | function(mu,sig) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
436 | function(mu,sig) { return [-8,8]; },
437 | "(-\\infty,\\infty)",
438 | jStat.cauchy.pdf,
439 | "\\frac{1}{\\pi\\sigma\\left(1+\\left(\\frac{x-\\mu}{\\sigma}\\right)^2\\right)}",
440 | jStat.cauchy.cdf,
441 | null,
442 | function(mu,sig){ return sig>0;},
443 | {
444 | mean: {
445 | fun: function(mu, sig) { return undefined; },
446 | display: "undefined"
447 | },
448 | variance: {
449 | fun: function(mu, sig) { return undefined; },
450 | display: "undefined"
451 | },
452 | median: {
453 | fun: jStat.cauchy.median,
454 | display: "\\mu"
455 | },
456 | mode: {
457 | fun: jStat.cauchy.mode,
458 | display: "\\mu"
459 | }
460 | },
461 | null
462 |
463 | );
464 |
465 | distributions["cauchy"] = new distribution(
466 | "cauchy",
467 | "Cauchy",
468 | "continuous",
469 | [ cauchyLocationScale ],
470 | null,
471 | {
472 | name:"Wikipedia",
473 | link:"http://en.wikipedia.org/wiki/Cauchy_distribution"
474 | }
475 | );
476 |
477 | /*****/
478 | // t distribution
479 | /*****/
480 |
481 | var tnu = new positiveParameter(
482 | "nu",
483 | "\\nu",
484 | function() { return [1,50]; },
485 | false,
486 | 5,
487 | "discrete",
488 | null,
489 | "degrees of freedom"
490 | );
491 |
492 |
493 | var tLocation= new unboundedParameter(
494 | "mu",
495 | "\\mu",
496 | function() { return [-8,8];},
497 | false,
498 | 0,
499 | "continuous",
500 | null,
501 | "location"
502 | );
503 |
504 | var tScale = new positiveParameter(
505 | "sigma",
506 | "\\sigma",
507 | function() { return [0.1,10];},
508 | true,
509 | 1,
510 | "continuous",
511 | null,
512 | "scale"
513 | );
514 |
515 | var studenttLocationScale = new distributionParametrization(
516 | "location/scale",
517 | [tnu, tLocation, tScale],
518 | function(nu,mu,sig) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
519 | function(nu,mu,sig) { return [-10,10]; },
520 | "(-\\infty,\\infty)",
521 | function(x,nu,mu,sig){ return jStat.studentt.pdf( (x - mu)/sig, nu)/sig; },
522 | "\\frac{\\Gamma\\left(\\frac{\\nu+1}{2}\\right)}{\\sqrt{\\pi\\nu\\sigma^2}\\Gamma\\left(\\frac{\\nu}{2}\\right)}\\left(1+\\frac{(x-\\mu)^2}{\\nu\\sigma^2}\\right)^{-\\frac{\\nu+1}{2}}",
523 | function(x,nu,mu,sig){ return jStat.studentt.cdf( (x - mu)/sig, nu); },
524 | null,
525 | function(nu,mu,sig){ return sig > 0 && nu > 0;},
526 | {
527 | mean: {
528 | fun: function(nu, mu, sig) { return nu>1?mu:undefined; },
529 | display: "\\mu, \\nu>1"
530 | },
531 | variance: {
532 | fun: function(nu, mu, sig) { return nu>2 ? nu/(nu-2) : undefined; },
533 | display: "\\frac{\\nu}{\\nu-2}\\sigma^2, \\nu>2"
534 | },
535 | median: {
536 | fun: function(nu, mu, sig) { return mu; },
537 | display: "\\mu"
538 | },
539 | mode: {
540 | fun: function(nu, mu, sig) { return mu; },
541 | display: "\\mu"
542 | }
543 | },
544 | null
545 |
546 | );
547 |
548 | distributions["studentt"] = new distribution(
549 | "studentt",
550 | "Student's t",
551 | "continuous",
552 | [ studenttLocationScale ],
553 | null,
554 | {
555 | name:"Wikipedia",
556 | link:"http://en.wikipedia.org/wiki/Student's_t-distribution"
557 | }
558 | );
559 |
560 |
561 |
562 | /*****/
563 | // Chi-squared distribution
564 | /*****/
565 |
566 | var chisqnu = new positiveParameter(
567 | "nu",
568 | "\\nu",
569 | function() { return [1,10]; },
570 | false,
571 | 3,
572 | "discrete",
573 | null,
574 | "degrees of freedom"
575 | );
576 |
577 |
578 | var chisqScale = new positiveParameter(
579 | "sigma",
580 | "\\sigma",
581 | function() { return [0.1,10];},
582 | true,
583 | 1,
584 | "continuous",
585 | null,
586 | "scale"
587 | );
588 |
589 | var chisqScalePar = new distributionParametrization(
590 | "scaled",
591 | [chisqnu, chisqScale],
592 | function(nu,sig) { return [0,Number.POSITIVE_INFINITY]; },
593 | function(nu,sig) { return [0,40]; },
594 | "[0,\\infty)",
595 | function(x,nu,sig){ return jStat.chisquare.pdf( x/sig, nu)/sig; },
596 | "\\frac{1}{(2\\sigma)^\\frac{\\nu}{2}\\Gamma\\left(\\frac{\\nu}{2}\\right)}x^{\\frac{\\nu}{2}-1}\\exp\\left\\{-\\frac{x}{2\\sigma}\\right\\}",
597 | function(x,nu,sig){ return jStat.chisquare.cdf( x/sig, nu); },
598 | null,
599 | function(nu,sig){ return sig > 0 && nu > 0;},
600 | {
601 | mean: {
602 | fun: function(nu, sig) { return nu*sig; },
603 | display: "\\sigma\\nu"
604 | },
605 | variance: {
606 | fun: function(nu, sig) { return 2*nu*sig*sig; },
607 | display: "2\\nu\\sigma^2"
608 | }
609 | },
610 | null
611 |
612 | );
613 |
614 | distributions["chisquare"] = new distribution(
615 | "chisquare",
616 | "Chi-squared",
617 | "continuous",
618 | [ chisqScalePar ],
619 | null,
620 | {
621 | name:"Wikipedia",
622 | link:"http://en.wikipedia.org/wiki/Chi-squared_distribution"
623 | }
624 | );
625 |
626 |
627 |
628 |
629 | /*****/
630 | // Beta distribution
631 | /*****/
632 |
633 | var betaA = new positiveParameter(
634 | "a",
635 | "a",
636 | function() { return [.1,10]; },
637 | true,
638 | 1,
639 | "continuous",
640 | null,
641 | "shape"
642 | );
643 |
644 |
645 | var betaB = new positiveParameter(
646 | "b",
647 | "b",
648 | function() { return [.1,10]; },
649 | true,
650 | 1,
651 | "continuous",
652 | null,
653 | "shape"
654 | );
655 |
656 | var betaAB = new distributionParametrization(
657 | "a/b",
658 | [betaA, betaB],
659 | function(a,b) { return [0,1]; },
660 | function(a,b) { return [0,1]; },
661 | "(0,1)",
662 | jStat.beta.pdf,
663 | "\\frac{1}{\\mbox{Be}(a,b)} x^{a-1} (1-x)^{b-1}",
664 | jStat.beta.cdf,
665 | null,
666 | function(a,b){ return a>0 && b>0;},
667 | {
668 | mean: {
669 | fun: jStat.beta.mean,
670 | display: "\\frac{a}{a+b}"
671 | },
672 | variance: {
673 | fun: jStat.beta.variance,
674 | display: "\\frac{ab}{(a+b)^2(a+b+1)}"
675 | },
676 | median: {
677 | fun: jStat.beta.median,
678 | display: "no closed form"
679 | },
680 | mode: {
681 | fun: jStat.mode.median,
682 | display: "\\frac{a-1}{a+b-2}, a>1, b>1"
683 | }
684 |
685 | },
686 | null
687 |
688 | );
689 |
690 | distributions["beta"] = new distribution(
691 | "beta",
692 | "Beta",
693 | "continuous",
694 | [ betaAB ],
695 | null,
696 | {
697 | name:"Wikipedia",
698 | link:"http://en.wikipedia.org/wiki/Beta_distribution"
699 | }
700 | );
701 |
702 |
703 |
704 | /*****/
705 | // Log Normal distribution
706 | /*****/
707 |
708 | var lognormalMean = new unboundedParameter(
709 | "mu",
710 | "\\mu",
711 | function() { return [-2,2]; },
712 | false,
713 | 1,
714 | "continuous",
715 | "normal",
716 | "log-scale"
717 | );
718 |
719 | var lognormalVariance = new positiveParameter(
720 | "sigma2",
721 | "\\sigma^2",
722 | function() { return [.1,10]; },
723 | true,
724 | 1,
725 | "continuous",
726 | "inversegamma",
727 | "shape"
728 | );
729 |
730 |
731 | var lognormalMeanVariance = new distributionParametrization(
732 | "mu/sigma2",
733 | [lognormalMean, lognormalVariance],
734 | function(mu,sig2) { return [0,Number.POSITIVE_INFINITY]; },
735 | function(mu,sig2) { return [0,15]; },
736 | "(0,\\infty)",
737 | function(x, mu, sig2) { return jStat.lognormal.pdf(x, mu,Math.sqrt(sig2)); },
738 | "\\left(\\pi\\sigma^2x^2\\right)^{-\\frac{1}{2}}\\exp\\left\\{-\\frac{1}{2\\sigma^2}\\left(\\log(x)-\\mu\\right)^2\\right\\}",
739 | function(x, mu, sig2) { return jStat.lognormal.cdf(x, mu,Math.sqrt(sig2)); },
740 | "normalinversegamma",
741 | function(mu,sig2){ return sig2>0;},
742 | {
743 | mean: {
744 | fun: function(mu, sig2) { return jStat.lognormal.mean(mu, Math.sqrt(sig2)); },
745 | display: "\\exp\\left\\{\\mu + \\frac{\\sigma^2}{2}\\right\\}"
746 | },
747 | variance: {
748 | fun: function(mu, sig2) { return jStat.lognormal.variance(mu, Math.sqrt(sig2)); },
749 | display: "\\left(e^{\\sigma^2}-1\\right)\\exp\\left\\{2\\mu + \\sigma^2\\right\\}"
750 | },
751 | median: {
752 | fun: function(mu, sig2) { return jStat.lognormal.median(mu, Math.sqrt(sig2)); },
753 | display: "e^\\mu"
754 | },
755 | mode: {
756 | fun: function(mu, sig2) { return jStat.lognormal.mode(mu, Math.sqrt(sig2)); },
757 | display: "\\exp\\left\\{\\mu-\\sigma^2\\right\\}"
758 | }
759 |
760 | },
761 | null
762 | );
763 |
764 |
765 | distributions["lognormal"] = new distribution(
766 | "lognormal",
767 | "Log-normal",
768 | "continuous",
769 | [ lognormalMeanVariance ],
770 | null,
771 | {
772 | name:"Wikipedia",
773 | link:"http://en.wikipedia.org/wiki/Log-normal_distribution"
774 | }
775 | );
776 |
777 |
778 |
779 | /*****/
780 | // Weibull distribution
781 | /*****/
782 |
783 | var weibullShift = new unboundedParameter(
784 | "x0",
785 | "x_0",
786 | function() { return [-3,5]; },
787 | false,
788 | 0,
789 | "continuous",
790 | null,
791 | "shift"
792 | );
793 |
794 |
795 | var weibullShape = new positiveParameter(
796 | "k",
797 | "k",
798 | function() { return [.1,10]; },
799 | true,
800 | 1,
801 | "continuous",
802 | null,
803 | "shape"
804 | );
805 |
806 | var weibullScale = new positiveParameter(
807 | "s",
808 | "s",
809 | function() { return [0.1,10]; },
810 | true,
811 | 1,
812 | "continuous",
813 | "inversegamma",
814 | "scale"
815 | );
816 |
817 | var weibullRate = new positiveParameter(
818 | "theta",
819 | "\\theta",
820 | function() { return [0.1,10]; },
821 | true,
822 | 1,
823 | "continuous",
824 | "gamma",
825 | "rate"
826 | );
827 |
828 | var weibullShiftShapeScale = new distributionParametrization(
829 | "shift/scale/shape",
830 | [weibullShift,weibullScale, weibullShape],
831 | function(x0,s,k) { return [x0,Number.POSITIVE_INFINITY]; },
832 | function(x0,s,k) { return [x0,x0 + 10]; },
833 | "(x_0,\\infty)",
834 | function(x,x0,s,k) { return jStat.weibull.pdf(x - x0, s, k); },
835 | "\\frac{k}{s}\\left(\\frac{x-x_0}{s}\\right)^{k-1} \\exp\\left\\{-\\left(\\frac{x-x_0}{s}\\right)^k\\right\\}",
836 | function(x,x0,s,k) { return jStat.weibull.cdf(x - x0, s, k); },
837 | null,
838 | function(x0,s,k){ return s>0 && k>0;},
839 | {
840 | mean: {
841 | fun: function(x0,s,k) { return jStat.weibull.mean(s,k) + x0; },
842 | display: "x_0 + s\\Gamma\\left(1+\\frac{1}{k}\\right)"
843 | },
844 | variance: {
845 | fun: function(x0,s,k) { return jStat.weibull.variance(s,k); },
846 | display: "s^2\\Gamma\\left(1+\\frac{2}{k}\\right) - \\left(x_0 + s\\Gamma\\left(1+\\frac{1}{k}\\right)\\right)^2"
847 | },
848 | mode: {
849 | fun: function(x0,s,k) { return jStat.weibull.mode(s,k) + x0; },
850 | display: "s\\left(\\frac{k-1}{k}\\right)^{\\frac{1}{k}}, k > 1"
851 | },
852 | median: {
853 | fun: function(x0,s,k) { return jStat.weibull.median(s,k) + x0; },
854 | display: "s\\left(\\log(2)\\right)^{\\frac{1}{k}}"
855 | }
856 | },
857 | null
858 | );
859 |
860 | var weibullShiftShapeRate = new distributionParametrization(
861 | "shift/rate/shape",
862 | [weibullShift,weibullRate, weibullShape],
863 | function(x0,theta,k) { return [x0,Number.POSITIVE_INFINITY]; },
864 | function(x0,theta,k) { return [x0,x0 + 10]; },
865 | "(x_0,\\infty)",
866 | function(x,x0,theta,k) { return jStat.weibull.pdf(x - x0, 1/theta, k); },
867 | "k\\theta\\left(x\\theta\\right)^{k-1} \\exp\\left\\{-\\left(\\theta(x-x_0)\\right)^k\\right\\}",
868 | function(x,x0,theta,k) { return jStat.weibull.cdf(x - x0, 1/theta, k); },
869 | null,
870 | function(x0,theta,k){ return theta>0 && k>0;},
871 | {
872 | mean: {
873 | fun: function(x0,theta,k) { return jStat.weibull.mean(1/theta,k) + x0; },
874 | display: "x_0 + \\frac{1}{\\theta}\\Gamma\\left(1+\\frac{1}{k}\\right)"
875 | },
876 | variance: {
877 | fun: function(x0,theta,k) { return jStat.weibull.variance(1/theta,k); },
878 | display: "\\frac{1}{\\theta^2}\\Gamma\\left(1+\\frac{2}{k}\\right) - \\left(x_0 + \\frac{1}{\\theta}\\Gamma\\left(1+\\frac{1}{k}\\right)\\right)^2"
879 | },
880 | mode: {
881 | fun: function(x0,theta,k) { return jStat.weibull.mode(1/theta,k) + x0; },
882 | display: "\\frac{1}{\\theta}\\left(\\frac{k-1}{k}\\right)^{\\frac{1}{k}}, k > 1"
883 | },
884 | median: {
885 | fun: function(x0,theta,k) { return jStat.weibull.median(1/theta,k) + x0; },
886 | display: "\\frac{1}{\\theta}\\left(\\log(2)\\right)^{\\frac{1}{k}}"
887 | }
888 | },
889 | null
890 | );
891 |
892 | distributions["weibull"] = new distribution(
893 | "weibull",
894 | "three-parameter Weibull",
895 | "continuous",
896 | [ weibullShiftShapeScale, weibullShiftShapeRate ],
897 | null,
898 | {
899 | name:"Wikipedia",
900 | link:"http://en.wikipedia.org/wiki/Weibull_distribution"
901 | }
902 | );
903 |
904 |
905 |
906 |
907 |
908 | ////***************
909 | // DISCRETE
910 | ////***************
911 |
912 | /*****/
913 | // Binomial distribution
914 | /*****/
915 |
916 | var binomialN = new positiveParameter(
917 | "N",
918 | "N",
919 | function() { return [1,100]; },
920 | false,
921 | 20,
922 | "discrete",
923 | null,
924 | "sample size"
925 | );
926 |
927 | var binomialp = new distributionParameter(
928 | "p",
929 | "p",
930 | function() { return [0,1]; },
931 | function() { return [0,1]; },
932 | false,
933 | .5,
934 | "continuous",
935 | "beta",
936 | "probability of success"
937 | );
938 |
939 | var binomialNp = new distributionParametrization(
940 | "probability",
941 | [binomialN, binomialp],
942 | function(N, p) { return [0,N]; },
943 | function(N, p) { return [0,N]; },
944 | "[0,N]",
945 | jStat.binomial.pdf,
946 | "\\binom{N}{x} p^x (1-p)^{N-x}",
947 | jStat.binomial.cdf,
948 | "beta",
949 | function(N,p){ return N>0 && is_int(N) && p<1 && p>0;},
950 | {
951 | mean: {
952 | fun: jStat.binomial.mean,
953 | display: "Np"
954 | },
955 | variance: {
956 | fun: jStat.binomial.variance,
957 | display: "Np(1-p)"
958 | }
959 | },
960 | null
961 |
962 | );
963 |
964 | distributions["binomial"] = new distribution(
965 | "binomial",
966 | "Binomial",
967 | "discrete",
968 | [ binomialNp ],
969 | null,
970 | {
971 | name:"Wikipedia",
972 | link:"http://en.wikipedia.org/wiki/Binomial_distribution"
973 | }
974 | );
975 |
976 |
977 | /*****/
978 | // Poisson distribution
979 | /*****/
980 |
981 | var poissonRate = new positiveParameter(
982 | "lambda",
983 | "\\lambda",
984 | function() { return [1/10,10]; },
985 | true,
986 | 1,
987 | "continuous",
988 | null,
989 | "rate"
990 | );
991 |
992 | var poissonRate = new distributionParametrization(
993 | "rate",
994 | [ poissonRate ],
995 | function(lambda) { return [0,Number.POSITIVE_INFINITY]; },
996 | function(lambda) { return [0,25]; },
997 | "[0,\\infty)",
998 | jStat.poisson.pdf,
999 | "\\frac{\\lambda^x}{x!} \\exp\\left\\{-\\lambda\\right\\}",
1000 | jStat.poisson.cdf,
1001 | "gamma",
1002 | function(lambda){ return lambda>0;},
1003 | {
1004 | mean: {
1005 | fun: jStat.poisson.mean,
1006 | display: "\\lambda"
1007 | },
1008 | variance: {
1009 | fun: jStat.poisson.variance,
1010 | display: "\\lambda"
1011 | }
1012 | },
1013 | null
1014 | );
1015 |
1016 | distributions["poisson"] = new distribution(
1017 | "poisson",
1018 | "Poisson",
1019 | "discrete",
1020 | [ poissonRate ],
1021 | null,
1022 | {
1023 | name:"Wikipedia",
1024 | link:"http://en.wikipedia.org/wiki/Poisson_distribution"
1025 | }
1026 | );
1027 |
1028 | /*****/
1029 | // Negative Binomial distribution
1030 | /*****/
1031 |
1032 | var negbinomialr = new positiveParameter(
1033 | "r",
1034 | "r",
1035 | function() { return [1,50]; },
1036 | false,
1037 | 20,
1038 | "discrete",
1039 | null,
1040 | "number of successes required"
1041 | );
1042 |
1043 | var negbinomialp = new distributionParameter(
1044 | "p",
1045 | "p",
1046 | function() { return [0,1]; },
1047 | function() { return [0,1]; },
1048 | false,
1049 | .2,
1050 | "continuous",
1051 | "beta",
1052 | "probability of failure"
1053 | );
1054 |
1055 | var negbinomialrp = new distributionParametrization(
1056 | "probability",
1057 | [negbinomialr, negbinomialp],
1058 | function(r, p) { return [0,Number.POSITIVE_INFINITY]; },
1059 | function(r, p) { return [0,50]; },
1060 | "[0,\\infty)",
1061 | jStat.negbin.pdf,
1062 | "\\binom{x+r-1}{x} p^x (1-p)^{r}",
1063 | jStat.negbin.cdf,
1064 | "beta",
1065 | function(r,p){ return r>0 && is_int(r) && p<1 && p>0;},
1066 | {
1067 | mean: {
1068 | fun: function(r,p){ return p*r/(1-p);},
1069 | display: "\\frac{rp}{1-p}"
1070 | },
1071 | variance: {
1072 | fun: function(r,p){ return p*r/(1-p)^2;},
1073 | display: "\\frac{rp}{(1-p)^2}"
1074 | }
1075 | },
1076 | null
1077 |
1078 | );
1079 |
1080 | distributions["negativebinomial"] = new distribution(
1081 | "negativebinomial",
1082 | "Negative binomial",
1083 | "discrete",
1084 | [ negbinomialrp ],
1085 | null,
1086 | {
1087 | name:"Wikipedia",
1088 | link:"http://en.wikipedia.org/wiki/Negative_binomial_distribution"
1089 | }
1090 | );
1091 |
1092 |
--------------------------------------------------------------------------------
/docs/js/distributionObjects.js:
--------------------------------------------------------------------------------
1 | ///////////
2 | // Distribution stuff
3 | ///////////
4 |
5 |
6 | function distributionParameter(name, label, range, interactRange, interactLog, interactStart, type, conjugate, note){
7 | this.name = name;
8 | this.label = label;
9 | this.range = range;
10 | this.interactRange = interactRange;
11 | this.interactLog = interactLog;
12 | this.interactStart = interactStart;
13 | this.type = type;
14 | this.conjugate = conjugate;
15 | this.note = note;
16 | }
17 |
18 | function createElement(fstart,frangeLo,frangeHi){
19 | var limits = this.interactRange.apply(null,arguments);
20 | var start = this.interactStart;
21 |
22 | if( frangeLo != null && frangeHi !=null ){
23 | limits = [frangeLo,frangeHi];
24 | }
25 | if(fstart != null && fstart>limits[0] && fstart ', {
33 | id: "params_" + name + "_container",
34 | title: this.note
35 | }).appendTo('#parametercontainer');
36 |
37 | $("#params_" + name + "_container").addClass("paramsinglecontainer");
38 |
39 | $('
', {
40 | id: "params_label_" + name,
41 | text: " \\("+this.label+"\\) "
42 | }).appendTo('#' + "params_" + name + "_container");
43 |
44 | $("#params_label_" + name ).addClass("paramlabel");
45 |
46 | $('
', {
47 | id: "params_slider_" + name
48 | }).appendTo('#' + "params_" + name + "_container");
49 |
50 | $("#params_slider_" + name ).addClass("paramslider");
51 |
52 | $(' ', {
53 | id: "params_indicator_" + name,
54 | value: start
55 | }).appendTo('#'+"params_" + name + "_container");
56 |
57 | $("#params_indicator_" + name ).addClass("paramindicator");
58 |
59 | $(' ', {
60 | id: "params_end_" + name
61 | }).appendTo('#parametercontainer');
62 |
63 | $("#params_end_" + name ).addClass("clear");
64 |
65 | $("#params_" + name + "_container").tooltip({tipClass: "partooltip"});
66 |
67 | switch(this.type){
68 |
69 | case "discrete":
70 | var sliderMin = limits[0];
71 | var sliderMax = limits[1];
72 | var sliderStart = start;
73 | break;
74 |
75 | case "continuous":
76 | var sliderMin = 0;
77 | var sliderMax = sliderPoints-1;
78 | if(log){
79 | var sliderStart = sliderMax * (Math.log(start) - Math.log(limits[0]))/(Math.log(limits[1]) - Math.log(limits[0]));
80 | }else{
81 | var sliderStart = sliderMax * (start - limits[0])/(limits[1] - limits[0]);
82 | }
83 | break;
84 | }
85 |
86 | $( "#params_slider_" + name ).slider({ min: sliderMin, max: sliderMax, value: sliderStart });
87 | $( "#params_slider_" + name ).slider().bind('slide',function(event,ui){ slide(name,ui); } );
88 |
89 | }
90 |
91 | distributionParameter.prototype.createElement = createElement;
92 |
93 | function unboundedParameter(name, label, interactRange, interactLog, interactStart, type, conjugate, note){
94 | var range = function() { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; };
95 | distributionParameter.call(this, name, label, range, interactRange, interactLog, interactStart, type, conjugate, note);
96 | }
97 |
98 | function positiveParameter(name, label, interactRange, interactLog, interactStart, type, conjugate, note){
99 | var range = function() { return [0,Number.POSITIVE_INFINITY]; };
100 | distributionParameter.call(this, name, label, range, interactRange, interactLog, interactStart, type, conjugate, note);
101 | }
102 |
103 | positiveParameter.prototype = new distributionParameter();
104 | unboundedParameter.prototype = new distributionParameter();
105 |
106 | function distributionParametrization(ptznName, params, limits, interactLimits, displayLimits, density, densityDisplay, cdf, conjugate, check, quantities, note){
107 | this.name = ptznName;
108 | this.params = params;
109 | this.density = density;
110 | this.densityDisplay = densityDisplay;
111 | this.cdf = cdf;
112 | this.limits;
113 | this.interactLimits = interactLimits;
114 | this.checkPars = check;
115 | this.conjugate = conjugate;
116 | this.quantities = quantities;
117 | this.note = note;
118 | this.displayLimits = displayLimits;
119 | }
120 |
121 | function distribution(name,label,type,parametrizations,note,referenceurl){
122 | this.name = name;
123 | this.label = label;
124 | this.type = type;
125 | this.parametrizations = parametrizations;
126 | this.p = parametrizations[0];
127 | this.note = note;
128 | this.referenceurl = referenceurl;
129 | }
130 |
131 |
132 |
133 | function updatePlot(ptznNum,name,ui){
134 |
135 | var nptzn = this.parametrizations.length;
136 | p = (ptznNum > (nptzn - 1)) ? this.p : this.parametrizations[ptznNum];
137 |
138 |
139 |
140 | var npars = p.params.length;
141 | var i = 0;
142 | var args = [];
143 | var par, sliderMin, sliderMax, sliderFrac, parValue;
144 | var limits;
145 | var plotType;
146 |
147 | if($("#buttonPDF").attr('disabled') !== undefined){
148 | plotType="pdf";
149 | }else if($("#buttonCDF").attr('disabled') !== undefined){
150 | plotType="cdf";
151 | }else{
152 | return;
153 | }
154 |
155 |
156 | // Iterate through parameters
157 | for(;i=minx) newSeries.push(series[i]);
285 | }
286 |
287 | data[0] = {data: newSeries, lines:{show:true, fill: true, fillColor: areaFillColor} };
288 |
289 | plot.setData(data);
290 | plot.draw();
291 | }
292 |
293 | function addCDFLines(x){
294 | var data = plot.getData();
295 | var cumdens = p.cdf.apply( null, [x].concat(args) );
296 |
297 | var newSeries = [ [ limits[0], cumdens ],
298 | [ x, cumdens ],
299 | [ x, 0 ]
300 | ];
301 |
302 |
303 | data[1] = {data: newSeries, lines:{ show:true }, hoverable: false};
304 |
305 | plot.setData(data);
306 | plot.draw();
307 | }
308 |
309 |
310 | $("#"+this.plotid).unbind("plothover mouseout plotclick");
311 | $("#"+this.plotid).bind("mouseout", function(){
312 | $("#tooltip").remove();
313 | var data = plot.getData();
314 |
315 | if(data[2].data.length==0)
316 | data[0].data = [];
317 |
318 | data[1].data = [];
319 |
320 | plot.setData(data);
321 | plot.draw();
322 | });
323 |
324 |
325 | $("#"+this.plotid).bind("plotclick", function (event, pos, item) {
326 | if(plotType=="cdf" || RVtype=="discrete") return;
327 | var data = plot.getData();
328 | var x1 = data[2];
329 | var x2 = data[3];
330 | if(x1.data.length==0){
331 | data[2].data = [ [ pos.x, 0 ], [ pos.x, p.density.apply( null, [pos.x].concat(args) ) ] ];
332 | data[2].lines = { show: true };
333 | }else if(x2.data.length==0){
334 | data[3].data = [ [ pos.x, 0 ], [ pos.x, p.density.apply( null, [pos.x].concat(args) ) ] ];
335 | data[3].lines = { show: true };
336 | addFill(x1.data[0][0], x2.data[0][0]);
337 | }else{
338 | data[0].data = [];
339 | data[2].data = [];
340 | data[3].data = [];
341 | }
342 | plot.setData(data);
343 |
344 | addFill(pos);
345 |
346 | });
347 |
348 | $("#"+this.plotid).bind("plothover", function (event, pos, item) {
349 | if (item && RVtype=="discrete") {
350 | if (previousPoint != item.dataIndex) {
351 | previousPoint = item.dataIndex;
352 |
353 | $("#tooltip").remove();
354 | var x = round(item.datapoint[0], ttxDigits),
355 | y = round(item.datapoint[1], roundDigits);
356 |
357 | var funname = (plotType=="pdf") ? "p" : "F";
358 | showTooltip(item.pageX, item.pageY,
359 | funname+"(" + x + ") = " + y);
360 | if(plotType=="cdf") addCDFLines(item.datapoint[0]);
361 | }
362 | }else if(RVtype == "continuous"){
363 | $("#tooltip").remove();
364 | var dens = round(p.density.apply( null, [pos.x].concat(args) ), roundDigits);
365 | var cumdens = round(p.cdf.apply( null, [pos.x].concat(args) ), roundDigits);
366 | var x = round(pos.x, roundDigits);
367 |
368 | if(plotType=="pdf"){
369 | addFill(pos);
370 | var shaded = getShaded(plot, pos, limits, p.cdf, args);
371 | showTooltip(pos.pageX, pos.pageY,
372 | "p(" + x + ") = " + dens + " " +
373 | "Shaded: " + round(shaded, roundDigits));
374 | }else if(plotType=="cdf"){
375 | addCDFLines(pos.x);
376 | showTooltip(pos.pageX, pos.pageY,
377 | "F(" + x + ") = " + cumdens);
378 | }
379 | }
380 | else {
381 | $("#tooltip").remove();
382 | previousPoint = null;
383 | }
384 | });
385 |
386 | if(RVtype=="continuous" && plotType=="pdf") addFill();
387 |
388 | }
389 |
390 |
391 |
392 | function refTableHeaderRow(type){
393 |
394 | var head = new Element('thead');
395 | var row = new Element('tr');
396 |
397 | row.adopt(
398 | new Element('th', {
399 | html: "Name",
400 | scope: "col"
401 | }),
402 | new Element('th', {
403 | html: "Density function",
404 | scope: "col"
405 | }),
406 | new Element('th', {
407 | html: "Domain",
408 | scope: "col"
409 | }),
410 | new Element('th', {
411 | html: "Parameters",
412 | scope: "col"
413 | }),
414 | new Element('th', {
415 | html: "Conjugacy",
416 | scope: "col"
417 | }),
418 | new Element('th', {
419 | html: "Example",
420 | scope: "col"
421 | }),
422 | new Element('th', {
423 | html: "Reference",
424 | scope: "col"
425 | })
426 | );
427 |
428 | head.grab(row);
429 |
430 | head.inject(document.id(type+'_distributiontable'));
431 | }
432 |
433 | function refTableRow(odd, type){
434 |
435 | var idPre = type + "_dist_" + this.name;
436 | var rowname = idPre + "_row";
437 |
438 | var anch = new Element('a', {
439 | name: this.name+"table"
440 | });
441 |
442 | var row = new Element('tr', {
443 | id: rowname
444 | });
445 |
446 | var example = new Element('td', {
447 | id: idPre + "_example"
448 | });
449 |
450 | example.grab(
451 | new Element('a', {
452 | href: "distributionDisplay.html?dist="+this.name,
453 | id: idPre + "_interactlink",
454 | html: "Interact",
455 | title: "The "+this.label+" distribution",
456 | 'data-milkbox-size': "width:650,height:370",
457 | 'data-milkbox': "dist"
458 | })
459 | );
460 |
461 | var reference = new Element('td', {
462 | id: idPre + "_reference"
463 | });
464 |
465 | reference.grab(
466 | new Element('a', {
467 | href: this.referenceurl.link,
468 | html: this.referenceurl.name,
469 | target: "_blank"
470 | })
471 | );
472 |
473 | row.adopt(
474 | new Element('th', {
475 | id: idPre + "_name",
476 | 'class': 'column1',
477 | html: this.label,
478 | scope: "row"
479 | }),
480 | new Element('td', {
481 | id: idPre + "_density",
482 | html: "\\["+this.p.densityDisplay+"\\]"
483 | }),
484 | new Element('td', {
485 | id: idPre + "_domain",
486 | html: "\\("+this.p.displayLimits+"\\)"
487 | }),
488 | new Element('td', {
489 | id: idPre + "_parameters",
490 | html: "\\("+""+"\\)"
491 | }),
492 | new Element('td', {
493 | id: idPre + "_conjugate",
494 | html: ""
495 | }),
496 | example,
497 | reference
498 | );
499 |
500 |
501 | if(odd) row.set('class','odd');
502 |
503 | row.inject(document.id(type+'_distributiontablebody'));
504 | anch.inject(document.id(idPre+"_name"));
505 |
506 | //MathJax.Hub.Queue(["Typeset",MathJax.Hub,document.getElementById(rowname)]);
507 | }
508 |
509 | function createInterfaceElements(ptznNum){
510 |
511 | var nptzn = this.parametrizations.length;
512 | p = (ptznNum > (nptzn - 1)) ? this.p : this.parametrizations[ptznNum];
513 |
514 |
515 | var npars = p.params.length;
516 | var text="";
517 | var i = 0;
518 | var s, rl, rh;
519 | for(;i 534) {browser.STIXfontBug = true}
11 | }
12 | });
13 | if (MathJax.Hub.Browser.STIXfontBug) {
14 | HTMLCSS.FONTDATA.FONTS["STIXGeneral"].family = "STIXGeneral-Regular";
15 | HTMLCSS.FONTDATA.FONTS["STIXGeneral-italic"].family = "STIXGeneral-Italic";
16 | delete HTMLCSS.FONTDATA.FONTS["STIXGeneral-italic"].style;
17 | }
18 | });
--------------------------------------------------------------------------------
/docs/js/libraries/excanvas.min.js:
--------------------------------------------------------------------------------
1 | if(!document.createElement("canvas").getContext){(function(){var ab=Math;var n=ab.round;var l=ab.sin;var A=ab.cos;var H=ab.abs;var N=ab.sqrt;var d=10;var f=d/2;var z=+navigator.userAgent.match(/MSIE ([\d.]+)?/)[1];function y(){return this.context_||(this.context_=new D(this))}var t=Array.prototype.slice;function g(j,m,p){var i=t.call(arguments,2);return function(){return j.apply(m,i.concat(t.call(arguments)))}}function af(i){return String(i).replace(/&/g,"&").replace(/"/g,""")}function Y(m,j,i){if(!m.namespaces[j]){m.namespaces.add(j,i,"#default#VML")}}function R(j){Y(j,"g_vml_","urn:schemas-microsoft-com:vml");Y(j,"g_o_","urn:schemas-microsoft-com:office:office");if(!j.styleSheets.ex_canvas_){var i=j.createStyleSheet();i.owningElement.id="ex_canvas_";i.cssText="canvas{display:inline-block;overflow:hidden;text-align:left;width:300px;height:150px}"}}R(document);var e={init:function(i){var j=i||document;j.createElement("canvas");j.attachEvent("onreadystatechange",g(this.init_,this,j))},init_:function(p){var m=p.getElementsByTagName("canvas");for(var j=0;j1){m--}if(6*m<1){return j+(i-j)*6*m}else{if(2*m<1){return i}else{if(3*m<2){return j+(i-j)*(2/3-m)*6}else{return j}}}}var C={};function F(j){if(j in C){return C[j]}var ag,Z=1;j=String(j);if(j.charAt(0)=="#"){ag=j}else{if(/^rgb/.test(j)){var p=M(j);var ag="#",ah;for(var m=0;m<3;m++){if(p[m].indexOf("%")!=-1){ah=Math.floor(c(p[m])*255)}else{ah=+p[m]}ag+=k[r(ah,0,255)]}Z=+p[3]}else{if(/^hsl/.test(j)){var p=M(j);ag=I(p);Z=p[3]}else{ag=b[j]||j}}}return C[j]={color:ag,alpha:Z}}var o={style:"normal",variant:"normal",weight:"normal",size:10,family:"sans-serif"};var L={};function E(i){if(L[i]){return L[i]}var p=document.createElement("div");var m=p.style;try{m.font=i}catch(j){}return L[i]={style:m.fontStyle||o.style,variant:m.fontVariant||o.variant,weight:m.fontWeight||o.weight,size:m.fontSize||o.size,family:m.fontFamily||o.family}}function u(m,j){var i={};for(var ah in m){i[ah]=m[ah]}var ag=parseFloat(j.currentStyle.fontSize),Z=parseFloat(m.size);if(typeof m.size=="number"){i.size=m.size}else{if(m.size.indexOf("px")!=-1){i.size=Z}else{if(m.size.indexOf("em")!=-1){i.size=ag*Z}else{if(m.size.indexOf("%")!=-1){i.size=(ag/100)*Z}else{if(m.size.indexOf("pt")!=-1){i.size=Z/0.75}else{i.size=ag}}}}}i.size*=0.981;return i}function ac(i){return i.style+" "+i.variant+" "+i.weight+" "+i.size+"px "+i.family}var s={butt:"flat",round:"round"};function S(i){return s[i]||"square"}function D(i){this.m_=B();this.mStack_=[];this.aStack_=[];this.currentPath_=[];this.strokeStyle="#000";this.fillStyle="#000";this.lineWidth=1;this.lineJoin="miter";this.lineCap="butt";this.miterLimit=d*1;this.globalAlpha=1;this.font="10px sans-serif";this.textAlign="left";this.textBaseline="alphabetic";this.canvas=i;var m="width:"+i.clientWidth+"px;height:"+i.clientHeight+"px;overflow:hidden;position:absolute";var j=i.ownerDocument.createElement("div");j.style.cssText=m;i.appendChild(j);var p=j.cloneNode(false);p.style.backgroundColor="red";p.style.filter="alpha(opacity=0)";i.appendChild(p);this.element_=j;this.arcScaleX_=1;this.arcScaleY_=1;this.lineScale_=1}var q=D.prototype;q.clearRect=function(){if(this.textMeasureEl_){this.textMeasureEl_.removeNode(true);this.textMeasureEl_=null}this.element_.innerHTML=""};q.beginPath=function(){this.currentPath_=[]};q.moveTo=function(j,i){var m=V(this,j,i);this.currentPath_.push({type:"moveTo",x:m.x,y:m.y});this.currentX_=m.x;this.currentY_=m.y};q.lineTo=function(j,i){var m=V(this,j,i);this.currentPath_.push({type:"lineTo",x:m.x,y:m.y});this.currentX_=m.x;this.currentY_=m.y};q.bezierCurveTo=function(m,j,ak,aj,ai,ag){var i=V(this,ai,ag);var ah=V(this,m,j);var Z=V(this,ak,aj);K(this,ah,Z,i)};function K(i,Z,m,j){i.currentPath_.push({type:"bezierCurveTo",cp1x:Z.x,cp1y:Z.y,cp2x:m.x,cp2y:m.y,x:j.x,y:j.y});i.currentX_=j.x;i.currentY_=j.y}q.quadraticCurveTo=function(ai,m,j,i){var ah=V(this,ai,m);var ag=V(this,j,i);var aj={x:this.currentX_+2/3*(ah.x-this.currentX_),y:this.currentY_+2/3*(ah.y-this.currentY_)};var Z={x:aj.x+(ag.x-this.currentX_)/3,y:aj.y+(ag.y-this.currentY_)/3};K(this,aj,Z,ag)};q.arc=function(al,aj,ak,ag,j,m){ak*=d;var ap=m?"at":"wa";var am=al+A(ag)*ak-f;var ao=aj+l(ag)*ak-f;var i=al+A(j)*ak-f;var an=aj+l(j)*ak-f;if(am==i&&!m){am+=0.125}var Z=V(this,al,aj);var ai=V(this,am,ao);var ah=V(this,i,an);this.currentPath_.push({type:ap,x:Z.x,y:Z.y,radius:ak,xStart:ai.x,yStart:ai.y,xEnd:ah.x,yEnd:ah.y})};q.rect=function(m,j,i,p){this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath()};q.strokeRect=function(m,j,i,p){var Z=this.currentPath_;this.beginPath();this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath();this.stroke();this.currentPath_=Z};q.fillRect=function(m,j,i,p){var Z=this.currentPath_;this.beginPath();this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath();this.fill();this.currentPath_=Z};q.createLinearGradient=function(j,p,i,m){var Z=new U("gradient");Z.x0_=j;Z.y0_=p;Z.x1_=i;Z.y1_=m;return Z};q.createRadialGradient=function(p,ag,m,j,Z,i){var ah=new U("gradientradial");ah.x0_=p;ah.y0_=ag;ah.r0_=m;ah.x1_=j;ah.y1_=Z;ah.r1_=i;return ah};q.drawImage=function(aq,m){var aj,ah,al,ay,ao,am,at,aA;var ak=aq.runtimeStyle.width;var ap=aq.runtimeStyle.height;aq.runtimeStyle.width="auto";aq.runtimeStyle.height="auto";var ai=aq.width;var aw=aq.height;aq.runtimeStyle.width=ak;aq.runtimeStyle.height=ap;if(arguments.length==3){aj=arguments[1];ah=arguments[2];ao=am=0;at=al=ai;aA=ay=aw}else{if(arguments.length==5){aj=arguments[1];ah=arguments[2];al=arguments[3];ay=arguments[4];ao=am=0;at=ai;aA=aw}else{if(arguments.length==9){ao=arguments[1];am=arguments[2];at=arguments[3];aA=arguments[4];aj=arguments[5];ah=arguments[6];al=arguments[7];ay=arguments[8]}else{throw Error("Invalid number of arguments")}}}var az=V(this,aj,ah);var p=at/2;var j=aA/2;var ax=[];var i=10;var ag=10;ax.push(" ',' "," ");this.element_.insertAdjacentHTML("BeforeEnd",ax.join(""))};q.stroke=function(ao){var Z=10;var ap=10;var ag=5000;var ai={x:null,y:null};var an={x:null,y:null};for(var aj=0;ajan.x){an.x=m.x}if(ai.y==null||m.yan.y){an.y=m.y}}}am.push(' ">');if(!ao){w(this,am)}else{G(this,am,ai,an)}am.push("");this.element_.insertAdjacentHTML("beforeEnd",am.join(""))}};function w(m,ag){var j=F(m.strokeStyle);var p=j.color;var Z=j.alpha*m.globalAlpha;var i=m.lineScale_*m.lineWidth;if(i<1){Z*=i}ag.push(" ')}function G(aq,ai,aK,ar){var aj=aq.fillStyle;var aB=aq.arcScaleX_;var aA=aq.arcScaleY_;var j=ar.x-aK.x;var p=ar.y-aK.y;if(aj instanceof U){var an=0;var aF={x:0,y:0};var ax=0;var am=1;if(aj.type_=="gradient"){var al=aj.x0_/aB;var m=aj.y0_/aA;var ak=aj.x1_/aB;var aM=aj.y1_/aA;var aJ=V(aq,al,m);var aI=V(aq,ak,aM);var ag=aI.x-aJ.x;var Z=aI.y-aJ.y;an=Math.atan2(ag,Z)*180/Math.PI;if(an<0){an+=360}if(an<0.000001){an=0}}else{var aJ=V(aq,aj.x0_,aj.y0_);aF={x:(aJ.x-aK.x)/j,y:(aJ.y-aK.y)/p};j/=aB*d;p/=aA*d;var aD=ab.max(j,p);ax=2*aj.r0_/aD;am=2*aj.r1_/aD-ax}var av=aj.colors_;av.sort(function(aN,i){return aN.offset-i.offset});var ap=av.length;var au=av[0].color;var at=av[ap-1].color;var az=av[0].alpha*aq.globalAlpha;var ay=av[ap-1].alpha*aq.globalAlpha;var aE=[];for(var aH=0;aH ')}else{if(aj instanceof T){if(j&&p){var ah=-aK.x;var aC=-aK.y;ai.push(" ')}}else{var aL=F(aq.fillStyle);var aw=aL.color;var aG=aL.alpha*aq.globalAlpha;ai.push(' ')}}}q.fill=function(){this.stroke(true)};q.closePath=function(){this.currentPath_.push({type:"close"})};function V(j,Z,p){var i=j.m_;return{x:d*(Z*i[0][0]+p*i[1][0]+i[2][0])-f,y:d*(Z*i[0][1]+p*i[1][1]+i[2][1])-f}}q.save=function(){var i={};v(this,i);this.aStack_.push(i);this.mStack_.push(this.m_);this.m_=J(B(),this.m_)};q.restore=function(){if(this.aStack_.length){v(this.aStack_.pop(),this);this.m_=this.mStack_.pop()}};function h(i){return isFinite(i[0][0])&&isFinite(i[0][1])&&isFinite(i[1][0])&&isFinite(i[1][1])&&isFinite(i[2][0])&&isFinite(i[2][1])}function aa(j,i,p){if(!h(i)){return}j.m_=i;if(p){var Z=i[0][0]*i[1][1]-i[0][1]*i[1][0];j.lineScale_=N(H(Z))}}q.translate=function(m,j){var i=[[1,0,0],[0,1,0],[m,j,1]];aa(this,J(i,this.m_),false)};q.rotate=function(j){var p=A(j);var m=l(j);var i=[[p,m,0],[-m,p,0],[0,0,1]];aa(this,J(i,this.m_),false)};q.scale=function(m,j){this.arcScaleX_*=m;this.arcScaleY_*=j;var i=[[m,0,0],[0,j,0],[0,0,1]];aa(this,J(i,this.m_),true)};q.transform=function(Z,p,ah,ag,j,i){var m=[[Z,p,0],[ah,ag,0],[j,i,1]];aa(this,J(m,this.m_),true)};q.setTransform=function(ag,Z,ai,ah,p,j){var i=[[ag,Z,0],[ai,ah,0],[p,j,1]];aa(this,i,true)};q.drawText_=function(am,ak,aj,ap,ai){var ao=this.m_,at=1000,j=0,ar=at,ah={x:0,y:0},ag=[];var i=u(E(this.font),this.element_);var p=ac(i);var au=this.element_.currentStyle;var Z=this.textAlign.toLowerCase();switch(Z){case"left":case"center":case"right":break;case"end":Z=au.direction=="ltr"?"right":"left";break;case"start":Z=au.direction=="rtl"?"right":"left";break;default:Z="left"}switch(this.textBaseline){case"hanging":case"top":ah.y=i.size/1.75;break;case"middle":break;default:case null:case"alphabetic":case"ideographic":case"bottom":ah.y=-i.size/2.25;break}switch(Z){case"right":j=at;ar=0.05;break;case"center":j=ar=at/2;break}var aq=V(this,ak+ah.x,aj+ah.y);ag.push('');if(ai){w(this,ag)}else{G(this,ag,{x:-j,y:0},{x:ar,y:i.size})}var an=ao[0][0].toFixed(3)+","+ao[1][0].toFixed(3)+","+ao[0][1].toFixed(3)+","+ao[1][1].toFixed(3)+",0,0";var al=n(aq.x/d)+","+n(aq.y/d);ag.push(' ',' ',' ');this.element_.insertAdjacentHTML("beforeEnd",ag.join(""))};q.fillText=function(m,i,p,j){this.drawText_(m,i,p,j,false)};q.strokeText=function(m,i,p,j){this.drawText_(m,i,p,j,true)};q.measureText=function(m){if(!this.textMeasureEl_){var i=' ';this.element_.insertAdjacentHTML("beforeEnd",i);this.textMeasureEl_=this.element_.lastChild}var j=this.element_.ownerDocument;this.textMeasureEl_.innerHTML="";this.textMeasureEl_.style.font=this.font;this.textMeasureEl_.appendChild(j.createTextNode(m));return{width:this.textMeasureEl_.offsetWidth}};q.clip=function(){};q.arcTo=function(){};q.createPattern=function(j,i){return new T(j,i)};function U(i){this.type_=i;this.x0_=0;this.y0_=0;this.r0_=0;this.x1_=0;this.y1_=0;this.r1_=0;this.colors_=[]}U.prototype.addColorStop=function(j,i){i=F(i);this.colors_.push({offset:j,color:i.color,alpha:i.alpha})};function T(j,i){Q(j);switch(i){case"repeat":case null:case"":this.repetition_="repeat";break;case"repeat-x":case"repeat-y":case"no-repeat":this.repetition_=i;break;default:O("SYNTAX_ERR")}this.src_=j.src;this.width_=j.width;this.height_=j.height}function O(i){throw new P(i)}function Q(i){if(!i||i.nodeType!=1||i.tagName!="IMG"){O("TYPE_MISMATCH_ERR")}if(i.readyState!="complete"){O("INVALID_STATE_ERR")}}function P(i){this.code=this[i];this.message=i+": DOM Exception "+this.code}var X=P.prototype=new Error;X.INDEX_SIZE_ERR=1;X.DOMSTRING_SIZE_ERR=2;X.HIERARCHY_REQUEST_ERR=3;X.WRONG_DOCUMENT_ERR=4;X.INVALID_CHARACTER_ERR=5;X.NO_DATA_ALLOWED_ERR=6;X.NO_MODIFICATION_ALLOWED_ERR=7;X.NOT_FOUND_ERR=8;X.NOT_SUPPORTED_ERR=9;X.INUSE_ATTRIBUTE_ERR=10;X.INVALID_STATE_ERR=11;X.SYNTAX_ERR=12;X.INVALID_MODIFICATION_ERR=13;X.NAMESPACE_ERR=14;X.INVALID_ACCESS_ERR=15;X.VALIDATION_ERR=16;X.TYPE_MISMATCH_ERR=17;G_vmlCanvasManager=e;CanvasRenderingContext2D=D;CanvasGradient=U;CanvasPattern=T;DOMException=P})()};
--------------------------------------------------------------------------------
/docs/js/libraries/jquery.flot.crosshair.js:
--------------------------------------------------------------------------------
1 | /*
2 | Flot plugin for showing crosshairs, thin lines, when the mouse hovers
3 | over the plot.
4 |
5 | crosshair: {
6 | mode: null or "x" or "y" or "xy"
7 | color: color
8 | lineWidth: number
9 | }
10 |
11 | Set the mode to one of "x", "y" or "xy". The "x" mode enables a
12 | vertical crosshair that lets you trace the values on the x axis, "y"
13 | enables a horizontal crosshair and "xy" enables them both. "color" is
14 | the color of the crosshair (default is "rgba(170, 0, 0, 0.80)"),
15 | "lineWidth" is the width of the drawn lines (default is 1).
16 |
17 | The plugin also adds four public methods:
18 |
19 | - setCrosshair(pos)
20 |
21 | Set the position of the crosshair. Note that this is cleared if
22 | the user moves the mouse. "pos" is in coordinates of the plot and
23 | should be on the form { x: xpos, y: ypos } (you can use x2/x3/...
24 | if you're using multiple axes), which is coincidentally the same
25 | format as what you get from a "plothover" event. If "pos" is null,
26 | the crosshair is cleared.
27 |
28 | - clearCrosshair()
29 |
30 | Clear the crosshair.
31 |
32 | - lockCrosshair(pos)
33 |
34 | Cause the crosshair to lock to the current location, no longer
35 | updating if the user moves the mouse. Optionally supply a position
36 | (passed on to setCrosshair()) to move it to.
37 |
38 | Example usage:
39 | var myFlot = $.plot( $("#graph"), ..., { crosshair: { mode: "x" } } };
40 | $("#graph").bind("plothover", function (evt, position, item) {
41 | if (item) {
42 | // Lock the crosshair to the data point being hovered
43 | myFlot.lockCrosshair({ x: item.datapoint[0], y: item.datapoint[1] });
44 | }
45 | else {
46 | // Return normal crosshair operation
47 | myFlot.unlockCrosshair();
48 | }
49 | });
50 |
51 | - unlockCrosshair()
52 |
53 | Free the crosshair to move again after locking it.
54 | */
55 |
56 | (function ($) {
57 | var options = {
58 | crosshair: {
59 | mode: null, // one of null, "x", "y" or "xy",
60 | color: "rgba(170, 0, 0, 0.80)",
61 | lineWidth: 1
62 | }
63 | };
64 |
65 | function init(plot) {
66 | // position of crosshair in pixels
67 | var crosshair = { x: -1, y: -1, locked: false };
68 |
69 | plot.setCrosshair = function setCrosshair(pos) {
70 | if (!pos)
71 | crosshair.x = -1;
72 | else {
73 | var o = plot.p2c(pos);
74 | crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
75 | crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
76 | }
77 |
78 | plot.triggerRedrawOverlay();
79 | };
80 |
81 | plot.clearCrosshair = plot.setCrosshair; // passes null for pos
82 |
83 | plot.lockCrosshair = function lockCrosshair(pos) {
84 | if (pos)
85 | plot.setCrosshair(pos);
86 | crosshair.locked = true;
87 | }
88 |
89 | plot.unlockCrosshair = function unlockCrosshair() {
90 | crosshair.locked = false;
91 | }
92 |
93 | function onMouseOut(e) {
94 | if (crosshair.locked)
95 | return;
96 |
97 | if (crosshair.x != -1) {
98 | crosshair.x = -1;
99 | plot.triggerRedrawOverlay();
100 | }
101 | }
102 |
103 | function onMouseMove(e) {
104 | if (crosshair.locked)
105 | return;
106 |
107 | if (plot.getSelection && plot.getSelection()) {
108 | crosshair.x = -1; // hide the crosshair while selecting
109 | return;
110 | }
111 |
112 | var offset = plot.offset();
113 | crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
114 | crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
115 | plot.triggerRedrawOverlay();
116 | }
117 |
118 | plot.hooks.bindEvents.push(function (plot, eventHolder) {
119 | if (!plot.getOptions().crosshair.mode)
120 | return;
121 |
122 | eventHolder.mouseout(onMouseOut);
123 | eventHolder.mousemove(onMouseMove);
124 | });
125 |
126 | plot.hooks.drawOverlay.push(function (plot, ctx) {
127 | var c = plot.getOptions().crosshair;
128 | if (!c.mode)
129 | return;
130 |
131 | var plotOffset = plot.getPlotOffset();
132 |
133 | ctx.save();
134 | ctx.translate(plotOffset.left, plotOffset.top);
135 |
136 | if (crosshair.x != -1) {
137 | ctx.strokeStyle = c.color;
138 | ctx.lineWidth = c.lineWidth;
139 | ctx.lineJoin = "round";
140 |
141 | ctx.beginPath();
142 | if (c.mode.indexOf("x") != -1) {
143 | ctx.moveTo(crosshair.x, 0);
144 | ctx.lineTo(crosshair.x, plot.height());
145 | }
146 | if (c.mode.indexOf("y") != -1) {
147 | ctx.moveTo(0, crosshair.y);
148 | ctx.lineTo(plot.width(), crosshair.y);
149 | }
150 | ctx.stroke();
151 | }
152 | ctx.restore();
153 | });
154 |
155 | plot.hooks.shutdown.push(function (plot, eventHolder) {
156 | eventHolder.unbind("mouseout", onMouseOut);
157 | eventHolder.unbind("mousemove", onMouseMove);
158 | });
159 | }
160 |
161 | $.plot.plugins.push({
162 | init: init,
163 | options: options,
164 | name: 'crosshair',
165 | version: '1.0'
166 | });
167 | })(jQuery);
168 |
--------------------------------------------------------------------------------
/js/distributionDisplay.js:
--------------------------------------------------------------------------------
1 | // Universal plotting options
2 | var plotPoints = 200;
3 | var plotOptions = [];
4 | var sliderPoints = 101;
5 | var roundDigits = 3;
6 | var updateTime = 100;
7 | var areaFillColor="rgba(0,200,0,.3)";
8 |
9 | plotOptions["pdf"] = {
10 | yaxis: { min:0 },
11 | colors: ["rgb(0,200,0)", "rgb(200,0,0)","rgb(150,150,150)","rgb(150,150,150)", "rgb(0,200,0)"],
12 | series: {
13 | points: { fillColor: "rgb(0,200,0)"}
14 | },
15 | grid: { hoverable: true, clickable: true },
16 | crosshair: { mode: "x" }
17 | };
18 | plotOptions["cdf"] = {
19 | yaxis: { min:0, max: 1.001},
20 | colors: ["rgb(0,0,0)", "rgb(200,0,0)", "rgb(150,150,150)","rgb(150,150,150)", "rgb(0,200,0)"],
21 | series: {
22 | points: { fillColor: "rgb(0,200,0)"}
23 | },
24 | grid: { hoverable: true, clickable: false }
25 | };
26 |
27 | var plot;
28 | var dist;
29 | var distName;
30 | var ptznNum;
31 | var starts;
32 | var rangesHi;
33 | var rangesLo;
34 | var plotxrng;
35 |
36 | var distributions = [];
37 |
38 | function getShaded(plot,pos, limits, cumdens, args){
39 | var data = plot.getData();
40 | var x1 = data[2];
41 | var x2 = data[3];
42 |
43 | if(x2.data.length!=0){
44 | x2 = x2.data[0][0];
45 | x1 = x1.data[0][0];
46 | var minx = Math.min(x1,x2);
47 | var maxx = Math.max(x1,x2);
48 | return cumdens.apply(null, [maxx].concat(args) ) -
49 | cumdens.apply(null, [minx].concat(args) );
50 | }else if(x1.data.length!=0){
51 | x1 = x1.data[0][0];
52 | return cumdens.apply(null, [x1].concat(args) );
53 | }else{
54 | return cumdens.apply(null, [pos.x].concat(args) );
55 | x2 = limits[0];
56 | x1 = pos.x;
57 | }
58 |
59 | }
60 |
61 |
62 | function showTooltip(x, y, contents) {
63 | $('' + contents + '
').css( {
64 | position: 'absolute',
65 | display: 'none',
66 | top: y - 30,
67 | left: x + 10,
68 | border: '1px solid #fdd',
69 | padding: '2px',
70 | 'background-color': '#fee',
71 | opacity: 0.80,
72 | 'font-family': 'sans-serif'
73 | }).appendTo("body").fadeIn(0);
74 | }
75 |
76 | function makeSortedTable(type, caption){
77 |
78 | var n = distributions.length;
79 | var list = [];
80 | var i=0;
81 | for(d in distributions){
82 | if (distributions.hasOwnProperty(d))
83 | {
84 | if(distributions[d].type == type || type == "master") list.push(d);
85 | }
86 | }
87 |
88 | list.sort();
89 |
90 | document.id(type+'_distributionsdiv').grab(
91 | new Element("table",{
92 | id: type+"_distributiontable",
93 | 'class':"distribution"
94 | })
95 | );
96 |
97 | var cap = new Element('caption', {
98 | html: caption
99 | });
100 | document.id(type+'_distributiontable').grab(cap);
101 |
102 | refTableHeaderRow(type);
103 |
104 | var body = new Element("tbody",{
105 | id: type+"_distributiontablebody"
106 | });
107 | document.id(type+'_distributiontable').grab(body);
108 |
109 |
110 | if(list.length==0) return;
111 |
112 | for(;i0;},
61 | {
62 | mean: {
63 | fun: function(mu, sig2) { return jStat.normal.mean(mu, Math.sqrt(sig2)); },
64 | display: "\\mu"
65 | },
66 | variance: {
67 | fun: function(mu, sig2) { return jStat.normal.variance(mu, Math.sqrt(sig2)); },
68 | display: "\\sigma^2"
69 | },
70 | median: {
71 | fun: function(mu, sig2) { return jStat.normal.median(mu, Math.sqrt(sig2)); },
72 | display: "\\mu"
73 | },
74 | mode: {
75 | fun: function(mu, sig2) { return jStat.normal.mode(mu, Math.sqrt(sig2)); },
76 | display: "\\mu"
77 | }
78 |
79 | },
80 | null
81 | );
82 |
83 | var normalMeanPrecision = new distributionParametrization(
84 | "mean/precision",
85 | [normalMean, normalPrecision],
86 | function(mu,tau) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
87 | function(mu,tau) { return [-5,5]; },
88 | "(-\\infty,\\infty)",
89 | function(x,mu,tau){ return jStat.normal.pdf(x,mu,Math.sqrt(1/tau)); },
90 | "\\left(\\frac{\\tau}{2\\pi}\\right)^{\\frac{1}{2}}\\exp\\left\\{-\\frac{\\tau}{2}\\left(x-\\mu\\right)^2\\right\\}",
91 | function(x,mu,tau){ return jStat.normal.cdf(x,mu,Math.sqrt(1/tau)); },
92 | "normalgamma",
93 | function(mu,tau){ return tau>0;},
94 | {
95 | mean: {
96 | fun: function(mu, tau) { return jStat.normal.mean(mu, 1/Math.sqrt(tau)); },
97 | display: "\\mu"
98 | },
99 | variance: {
100 | fun: function(mu, tau) { return jStat.normal.variance(mu, 1/Math.sqrt(tau)); },
101 | display: "\\frac{1}{\\tau}"
102 | },
103 | median: {
104 | fun: function(mu, tau) { return jStat.normal.median(mu, 1/Math.sqrt(tau)); },
105 | display: "\\mu"
106 | },
107 | mode: {
108 | fun: function(mu, tau) { return jStat.normal.mode(mu, 1/Math.sqrt(tau)); },
109 | display: "\\mu"
110 | }
111 | },
112 | null
113 |
114 | );
115 |
116 | var normalMeanStandardDeviation = new distributionParametrization(
117 | "mean/standard deviation",
118 | [normalMean, normalStandardDeviation],
119 | function(mu,sig2) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
120 | function(mu,sig2) { return [-5,5]; },
121 | "(-\\infty,\\infty)",
122 | function(x, mu, sig) { return jStat.normal.pdf(x, mu, sig); },
123 | "\\left(2\\pi\\sigma^2\\right)^{-\\frac{1}{2}}\\exp\\left\\{-\\frac{1}{2\\sigma^2}\\left(x-\\mu\\right)^2\\right\\}",
124 | function(x, mu, sig) { return jStat.normal.cdf(x, mu, sig); },
125 | null,
126 | function(mu,sig){ return sig>0;},
127 | {
128 | mean: {
129 | fun: function(mu, sig) { return jStat.normal.mean(mu, sig); },
130 | display: "\\mu"
131 | },
132 | variance: {
133 | fun: function(mu, sig) { return jStat.normal.variance(mu, sig); },
134 | display: "\\sigma"
135 | },
136 | median: {
137 | fun: function(mu, sig) { return jStat.normal.median(mu, sig); },
138 | display: "\\mu"
139 | },
140 | mode: {
141 | fun: function(mu, sig) { return jStat.normal.mode(mu, sig); },
142 | display: "\\mu"
143 | }
144 |
145 | },
146 | null
147 | );
148 |
149 |
150 | distributions["normal"] = new distribution(
151 | "normal",
152 | "Normal/Gaussian",
153 | "continuous",
154 | [ normalMeanVariance, normalMeanPrecision, normalMeanStandardDeviation],
155 | null,
156 | {
157 | name:"Wikipedia",
158 | link:"http://en.wikipedia.org/wiki/Normal_distribution"
159 | }
160 | );
161 |
162 |
163 | /*****/
164 | // Gamma distribution
165 | /*****/
166 |
167 | var gammaShape = new positiveParameter(
168 | "k",
169 | "k",
170 | function() { return [.1,10]; },
171 | true,
172 | 1,
173 | "continuous",
174 | null,
175 | "shape"
176 | );
177 |
178 | var gammaScale = new positiveParameter(
179 | "s",
180 | "s",
181 | function() { return [0.1,10]; },
182 | true,
183 | 1,
184 | "continuous",
185 | "inversegamma",
186 | "scale"
187 | );
188 |
189 | var gammaRate = new positiveParameter(
190 | "theta",
191 | "\\theta",
192 | function() { return [0.1,10]; },
193 | true,
194 | 1,
195 | "continuous",
196 | "gamma",
197 | "rate"
198 | );
199 |
200 | var gammaShapeScale = new distributionParametrization(
201 | "shape/scale",
202 | [gammaShape, gammaScale],
203 | function(k,s) { return [0,Number.POSITIVE_INFINITY]; },
204 | function(k,s) { return [.01,10]; },
205 | "(0,\\infty)",
206 | jStat.gamma.pdf,
207 | "\\frac{1}{\\Gamma(k)s^{k}} x^{k - 1} \\exp\\left\\{-\\frac{x}{s}\\right\\}",
208 | jStat.gamma.cdf,
209 | null,
210 | function(k,s){ return s>0 && k>0;},
211 | {
212 | mean: {
213 | fun: jStat.gamma.mean,
214 | display: "ks"
215 | },
216 | variance: {
217 | fun: jStat.gamma.variance,
218 | display: "ks^2"
219 | },
220 | mode: {
221 | fun: jStat.gamma.mode,
222 | display: "(k-1)s, k\\geq 1"
223 | }
224 | },
225 | null
226 |
227 | );
228 |
229 | var gammaShapeRate = new distributionParametrization(
230 | "shape/rate",
231 | [gammaShape, gammaRate],
232 | function(k,theta) { return [0,Number.POSITIVE_INFINITY]; },
233 | function(k,theta) { return [.01,10]; },
234 | "(0,\\infty)",
235 | function(x, k, theta) { return jStat.gamma.pdf(x, k, 1/theta); },
236 | "\\frac{\\theta^k}{\\Gamma(k)} x^{k - 1} \\exp\\left\\{-\\theta x\\right\\}",
237 | function(x, k, theta) { return jStat.gamma.cdf(x, k, 1/theta); },
238 | null,
239 | function(k,theta){ return theta>0 && k>0;},
240 | {
241 | mean: {
242 | fun: function(k,theta) { return jStat.gamma.mean(k, 1/theta); },
243 | display: "\\frac{k}{\\theta}"
244 | },
245 | variance: {
246 | fun: function(k,theta) { return jStat.gamma.variance(k, 1/theta); },
247 | display: "\\frac{k}{\\theta^2}"
248 | },
249 | mode: {
250 | fun: function(k,theta) { return jStat.gamma.mode(k, 1/theta); },
251 | display: "\\frac{k-1}{\\theta}, k\\geq 1"
252 | }
253 | },
254 | null
255 |
256 | );
257 | distributions["gamma"] = new distribution(
258 | "gamma",
259 | "Gamma",
260 | "continuous",
261 | [ gammaShapeScale, gammaShapeRate ],
262 | null,
263 | {
264 | name:"Wikipedia",
265 | link:"http://en.wikipedia.org/wiki/Gamma_distribution"
266 | }
267 | );
268 |
269 |
270 | /*****/
271 | // Inverse Gamma distribution
272 | /*****/
273 |
274 | var invgammaShape = new positiveParameter(
275 | "alpha",
276 | "\\alpha",
277 | function() { return [.1,10]; },
278 | true,
279 | 1,
280 | "continuous",
281 | null,
282 | "shape"
283 | );
284 |
285 | var invgammaScale = new positiveParameter(
286 | "beta",
287 | "\\beta",
288 | function() { return [0.1,10]; },
289 | true,
290 | 1,
291 | "continuous",
292 | "gamma",
293 | "scale"
294 | );
295 |
296 | var invgammaShapeScale = new distributionParametrization(
297 | "shape/scale",
298 | [invgammaShape, invgammaScale],
299 | function(alpha,beta) { return [0,Number.POSITIVE_INFINITY]; },
300 | function(alpha,beta) { return [.01,15]; },
301 | "(0,\\infty)",
302 | jStat.invgamma.pdf,
303 | "\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} x^{-\\alpha - 1} \\exp\\left\\{-\\frac{\\beta}{x}\\right\\}",
304 | jStat.invgamma.cdf,
305 | null,
306 | function(alpha,beta){ return alpha>0 && beta>0;},
307 | {
308 | mean: {
309 | fun: jStat.invgamma.mean,
310 | display: "\\frac{\\beta}{\\alpha-1}, \\alpha>1"
311 | },
312 | variance: {
313 | fun: jStat.invgamma.variance,
314 | display: "\\frac{\\beta^2}{(\\alpha-1)^2(\\alpha-2)}, \\alpha>2"
315 | },
316 | mode: {
317 | fun: jStat.invgamma.mode,
318 | display: "\\frac{\\beta}{\\alpha+1}"
319 | }
320 | },
321 | null
322 | );
323 |
324 | distributions["invgamma"] = new distribution(
325 | "invgamma",
326 | "Inverse Gamma",
327 | "continuous",
328 | [ invgammaShapeScale ],
329 | null,
330 | {
331 | name:"Wikipedia",
332 | link:"http://en.wikipedia.org/wiki/Inverse-gamma_distribution"
333 | }
334 | );
335 |
336 |
337 |
338 | /*****/
339 | // Central F distribution
340 | /*****/
341 |
342 | var Fdf1 = new positiveParameter(
343 | "nu1",
344 | "\\nu_1",
345 | function() { return [1,40]; },
346 | false,
347 | 5,
348 | "discrete",
349 | null,
350 | "numerator df"
351 | );
352 |
353 | var Fdf2 = new positiveParameter(
354 | "nu2",
355 | "\\nu_2",
356 | function() { return [1,40]; },
357 | false,
358 | 5,
359 | "discrete",
360 | null,
361 | "denominator df"
362 | );
363 |
364 | var centralFpar = new distributionParametrization(
365 | "central",
366 | [Fdf1, Fdf2],
367 | function(nu1,nu2) { return [0,Number.POSITIVE_INFINITY]; },
368 | function(nu1,nu2) { return [.01,10]; },
369 | "(0,\\infty)",
370 | jStat.centralF.pdf,
371 | "\\frac{1}{x\\mbox{Be}\\left(\\frac{\\nu_1}{2},\\frac{\\nu_2}{2}\\right)}\\sqrt{\\frac{(\\nu_1x)^{\\nu_1}\\nu_2^{\\nu_2}}{(\\nu_1x + \\nu_2)^{\\nu_1+\\nu_2}}}",
372 | jStat.centralF.cdf,
373 | null,
374 | function(nu1,nu2){ return nu1>0 && nu2>0;},
375 | {
376 | mean: {
377 | fun: jStat.centralF.mean,
378 | display: "\\frac{\\nu_2}{\\nu_2-2}, \\nu_2>2"
379 | },
380 | variance: {
381 | fun: jStat.centralF.variance,
382 | display: "\\frac{2\\nu_2^2(\\nu_1 + \\nu_2-2)}{\\nu_1(\\nu_2-2)^2(\\nu_2-4)}, \\nu_2>4"
383 | },
384 | mode: {
385 | fun: jStat.centralF.mode,
386 | display: "\\frac{\\nu_2(\\nu_1 - 2)}{\\nu_1(\\nu_2+2)}, \\nu_1<2"
387 | }
388 | },
389 | null
390 | );
391 |
392 | distributions["centralF"] = new distribution(
393 | "centralF",
394 | "central F",
395 | "continuous",
396 | [ centralFpar ],
397 | null,
398 | {
399 | name:"Wikipedia",
400 | link:"http://en.wikipedia.org/wiki/F_distribution"
401 | }
402 | );
403 |
404 |
405 |
406 | /*****/
407 | // Cauchy distribution
408 | /*****/
409 |
410 | var cauchyLocation= new unboundedParameter(
411 | "mu",
412 | "\\mu",
413 | function() { return [-8,8];},
414 | false,
415 | 0,
416 | "continuous",
417 | null,
418 | "location"
419 | );
420 |
421 | var cauchyScale = new positiveParameter(
422 | "sigma",
423 | "\\sigma",
424 | function() { return [0.1,10];},
425 | true,
426 | 1,
427 | "continuous",
428 | null,
429 | "scale"
430 | );
431 |
432 | var cauchyLocationScale = new distributionParametrization(
433 | "location/scale",
434 | [cauchyLocation, cauchyScale],
435 | function(mu,sig) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
436 | function(mu,sig) { return [-8,8]; },
437 | "(-\\infty,\\infty)",
438 | jStat.cauchy.pdf,
439 | "\\frac{1}{\\pi\\sigma\\left(1+\\left(\\frac{x-\\mu}{\\sigma}\\right)^2\\right)}",
440 | jStat.cauchy.cdf,
441 | null,
442 | function(mu,sig){ return sig>0;},
443 | {
444 | mean: {
445 | fun: function(mu, sig) { return undefined; },
446 | display: "undefined"
447 | },
448 | variance: {
449 | fun: function(mu, sig) { return undefined; },
450 | display: "undefined"
451 | },
452 | median: {
453 | fun: jStat.cauchy.median,
454 | display: "\\mu"
455 | },
456 | mode: {
457 | fun: jStat.cauchy.mode,
458 | display: "\\mu"
459 | }
460 | },
461 | null
462 |
463 | );
464 |
465 | distributions["cauchy"] = new distribution(
466 | "cauchy",
467 | "Cauchy",
468 | "continuous",
469 | [ cauchyLocationScale ],
470 | null,
471 | {
472 | name:"Wikipedia",
473 | link:"http://en.wikipedia.org/wiki/Cauchy_distribution"
474 | }
475 | );
476 |
477 | /*****/
478 | // t distribution
479 | /*****/
480 |
481 | var tnu = new positiveParameter(
482 | "nu",
483 | "\\nu",
484 | function() { return [1,50]; },
485 | false,
486 | 5,
487 | "discrete",
488 | null,
489 | "degrees of freedom"
490 | );
491 |
492 |
493 | var tLocation= new unboundedParameter(
494 | "mu",
495 | "\\mu",
496 | function() { return [-8,8];},
497 | false,
498 | 0,
499 | "continuous",
500 | null,
501 | "location"
502 | );
503 |
504 | var tScale = new positiveParameter(
505 | "sigma",
506 | "\\sigma",
507 | function() { return [0.1,10];},
508 | true,
509 | 1,
510 | "continuous",
511 | null,
512 | "scale"
513 | );
514 |
515 | var studenttLocationScale = new distributionParametrization(
516 | "location/scale",
517 | [tnu, tLocation, tScale],
518 | function(nu,mu,sig) { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; },
519 | function(nu,mu,sig) { return [-10,10]; },
520 | "(-\\infty,\\infty)",
521 | function(x,nu,mu,sig){ return jStat.studentt.pdf( (x - mu)/sig, nu)/sig; },
522 | "\\frac{\\Gamma\\left(\\frac{\\nu+1}{2}\\right)}{\\sqrt{\\pi\\nu\\sigma^2}\\Gamma\\left(\\frac{\\nu}{2}\\right)}\\left(1+\\frac{(x-\\mu)^2}{\\nu\\sigma^2}\\right)^{-\\frac{\\nu+1}{2}}",
523 | function(x,nu,mu,sig){ return jStat.studentt.cdf( (x - mu)/sig, nu); },
524 | null,
525 | function(nu,mu,sig){ return sig > 0 && nu > 0;},
526 | {
527 | mean: {
528 | fun: function(nu, mu, sig) { return nu>1?mu:undefined; },
529 | display: "\\mu, \\nu>1"
530 | },
531 | variance: {
532 | fun: function(nu, mu, sig) { return nu>2 ? nu/(nu-2) : undefined; },
533 | display: "\\frac{\\nu}{\\nu-2}\\sigma^2, \\nu>2"
534 | },
535 | median: {
536 | fun: function(nu, mu, sig) { return mu; },
537 | display: "\\mu"
538 | },
539 | mode: {
540 | fun: function(nu, mu, sig) { return mu; },
541 | display: "\\mu"
542 | }
543 | },
544 | null
545 |
546 | );
547 |
548 | distributions["studentt"] = new distribution(
549 | "studentt",
550 | "Student's t",
551 | "continuous",
552 | [ studenttLocationScale ],
553 | null,
554 | {
555 | name:"Wikipedia",
556 | link:"http://en.wikipedia.org/wiki/Student's_t-distribution"
557 | }
558 | );
559 |
560 |
561 |
562 | /*****/
563 | // Chi-squared distribution
564 | /*****/
565 |
566 | var chisqnu = new positiveParameter(
567 | "nu",
568 | "\\nu",
569 | function() { return [1,10]; },
570 | false,
571 | 3,
572 | "discrete",
573 | null,
574 | "degrees of freedom"
575 | );
576 |
577 |
578 | var chisqScale = new positiveParameter(
579 | "sigma",
580 | "\\sigma",
581 | function() { return [0.1,10];},
582 | true,
583 | 1,
584 | "continuous",
585 | null,
586 | "scale"
587 | );
588 |
589 | var chisqScalePar = new distributionParametrization(
590 | "scaled",
591 | [chisqnu, chisqScale],
592 | function(nu,sig) { return [0,Number.POSITIVE_INFINITY]; },
593 | function(nu,sig) { return [0,40]; },
594 | "[0,\\infty)",
595 | function(x,nu,sig){ return jStat.chisquare.pdf( x/sig, nu)/sig; },
596 | "\\frac{1}{(2\\sigma)^\\frac{\\nu}{2}\\Gamma\\left(\\frac{\\nu}{2}\\right)}x^{\\frac{\\nu}{2}-1}\\exp\\left\\{-\\frac{x}{2\\sigma}\\right\\}",
597 | function(x,nu,sig){ return jStat.chisquare.cdf( x/sig, nu); },
598 | null,
599 | function(nu,sig){ return sig > 0 && nu > 0;},
600 | {
601 | mean: {
602 | fun: function(nu, sig) { return nu*sig; },
603 | display: "\\sigma\\nu"
604 | },
605 | variance: {
606 | fun: function(nu, sig) { return 2*nu*sig*sig; },
607 | display: "2\\nu\\sigma^2"
608 | }
609 | },
610 | null
611 |
612 | );
613 |
614 | distributions["chisquare"] = new distribution(
615 | "chisquare",
616 | "Chi-squared",
617 | "continuous",
618 | [ chisqScalePar ],
619 | null,
620 | {
621 | name:"Wikipedia",
622 | link:"http://en.wikipedia.org/wiki/Chi-squared_distribution"
623 | }
624 | );
625 |
626 |
627 |
628 |
629 | /*****/
630 | // Beta distribution
631 | /*****/
632 |
633 | var betaA = new positiveParameter(
634 | "a",
635 | "a",
636 | function() { return [.1,10]; },
637 | true,
638 | 1,
639 | "continuous",
640 | null,
641 | "shape"
642 | );
643 |
644 |
645 | var betaB = new positiveParameter(
646 | "b",
647 | "b",
648 | function() { return [.1,10]; },
649 | true,
650 | 1,
651 | "continuous",
652 | null,
653 | "shape"
654 | );
655 |
656 | var betaAB = new distributionParametrization(
657 | "a/b",
658 | [betaA, betaB],
659 | function(a,b) { return [0,1]; },
660 | function(a,b) { return [0,1]; },
661 | "(0,1)",
662 | jStat.beta.pdf,
663 | "\\frac{1}{\\mbox{Be}(a,b)} x^{a-1} (1-x)^{b-1}",
664 | jStat.beta.cdf,
665 | null,
666 | function(a,b){ return a>0 && b>0;},
667 | {
668 | mean: {
669 | fun: jStat.beta.mean,
670 | display: "\\frac{a}{a+b}"
671 | },
672 | variance: {
673 | fun: jStat.beta.variance,
674 | display: "\\frac{ab}{(a+b)^2(a+b+1)}"
675 | },
676 | median: {
677 | fun: jStat.beta.median,
678 | display: "no closed form"
679 | },
680 | mode: {
681 | fun: jStat.mode.median,
682 | display: "\\frac{a-1}{a+b-2}, a>1, b>1"
683 | }
684 |
685 | },
686 | null
687 |
688 | );
689 |
690 | distributions["beta"] = new distribution(
691 | "beta",
692 | "Beta",
693 | "continuous",
694 | [ betaAB ],
695 | null,
696 | {
697 | name:"Wikipedia",
698 | link:"http://en.wikipedia.org/wiki/Beta_distribution"
699 | }
700 | );
701 |
702 |
703 |
704 | /*****/
705 | // Log Normal distribution
706 | /*****/
707 |
708 | var lognormalMean = new unboundedParameter(
709 | "mu",
710 | "\\mu",
711 | function() { return [-2,2]; },
712 | false,
713 | 1,
714 | "continuous",
715 | "normal",
716 | "log-scale"
717 | );
718 |
719 | var lognormalVariance = new positiveParameter(
720 | "sigma2",
721 | "\\sigma^2",
722 | function() { return [.1,10]; },
723 | true,
724 | 1,
725 | "continuous",
726 | "inversegamma",
727 | "shape"
728 | );
729 |
730 |
731 | var lognormalMeanVariance = new distributionParametrization(
732 | "mu/sigma2",
733 | [lognormalMean, lognormalVariance],
734 | function(mu,sig2) { return [0,Number.POSITIVE_INFINITY]; },
735 | function(mu,sig2) { return [0,15]; },
736 | "(0,\\infty)",
737 | function(x, mu, sig2) { return jStat.lognormal.pdf(x, mu,Math.sqrt(sig2)); },
738 | "\\left(\\pi\\sigma^2x^2\\right)^{-\\frac{1}{2}}\\exp\\left\\{-\\frac{1}{2\\sigma^2}\\left(\\log(x)-\\mu\\right)^2\\right\\}",
739 | function(x, mu, sig2) { return jStat.lognormal.cdf(x, mu,Math.sqrt(sig2)); },
740 | "normalinversegamma",
741 | function(mu,sig2){ return sig2>0;},
742 | {
743 | mean: {
744 | fun: function(mu, sig2) { return jStat.lognormal.mean(mu, Math.sqrt(sig2)); },
745 | display: "\\exp\\left\\{\\mu + \\frac{\\sigma^2}{2}\\right\\}"
746 | },
747 | variance: {
748 | fun: function(mu, sig2) { return jStat.lognormal.variance(mu, Math.sqrt(sig2)); },
749 | display: "\\left(e^{\\sigma^2}-1\\right)\\exp\\left\\{2\\mu + \\sigma^2\\right\\}"
750 | },
751 | median: {
752 | fun: function(mu, sig2) { return jStat.lognormal.median(mu, Math.sqrt(sig2)); },
753 | display: "e^\\mu"
754 | },
755 | mode: {
756 | fun: function(mu, sig2) { return jStat.lognormal.mode(mu, Math.sqrt(sig2)); },
757 | display: "\\exp\\left\\{\\mu-\\sigma^2\\right\\}"
758 | }
759 |
760 | },
761 | null
762 | );
763 |
764 |
765 | distributions["lognormal"] = new distribution(
766 | "lognormal",
767 | "Log-normal",
768 | "continuous",
769 | [ lognormalMeanVariance ],
770 | null,
771 | {
772 | name:"Wikipedia",
773 | link:"http://en.wikipedia.org/wiki/Log-normal_distribution"
774 | }
775 | );
776 |
777 |
778 |
779 | /*****/
780 | // Weibull distribution
781 | /*****/
782 |
783 | var weibullShift = new unboundedParameter(
784 | "x0",
785 | "x_0",
786 | function() { return [-3,5]; },
787 | false,
788 | 0,
789 | "continuous",
790 | null,
791 | "shift"
792 | );
793 |
794 |
795 | var weibullShape = new positiveParameter(
796 | "k",
797 | "k",
798 | function() { return [.1,10]; },
799 | true,
800 | 1,
801 | "continuous",
802 | null,
803 | "shape"
804 | );
805 |
806 | var weibullScale = new positiveParameter(
807 | "s",
808 | "s",
809 | function() { return [0.1,10]; },
810 | true,
811 | 1,
812 | "continuous",
813 | "inversegamma",
814 | "scale"
815 | );
816 |
817 | var weibullRate = new positiveParameter(
818 | "theta",
819 | "\\theta",
820 | function() { return [0.1,10]; },
821 | true,
822 | 1,
823 | "continuous",
824 | "gamma",
825 | "rate"
826 | );
827 |
828 | var weibullShiftShapeScale = new distributionParametrization(
829 | "shift/scale/shape",
830 | [weibullShift,weibullScale, weibullShape],
831 | function(x0,s,k) { return [x0,Number.POSITIVE_INFINITY]; },
832 | function(x0,s,k) { return [x0,x0 + 10]; },
833 | "(x_0,\\infty)",
834 | function(x,x0,s,k) { return jStat.weibull.pdf(x - x0, s, k); },
835 | "\\frac{k}{s}\\left(\\frac{x-x_0}{s}\\right)^{k-1} \\exp\\left\\{-\\left(\\frac{x-x_0}{s}\\right)^k\\right\\}",
836 | function(x,x0,s,k) { return jStat.weibull.cdf(x - x0, s, k); },
837 | null,
838 | function(x0,s,k){ return s>0 && k>0;},
839 | {
840 | mean: {
841 | fun: function(x0,s,k) { return jStat.weibull.mean(s,k) + x0; },
842 | display: "x_0 + s\\Gamma\\left(1+\\frac{1}{k}\\right)"
843 | },
844 | variance: {
845 | fun: function(x0,s,k) { return jStat.weibull.variance(s,k); },
846 | display: "s^2\\Gamma\\left(1+\\frac{2}{k}\\right) - \\left(x_0 + s\\Gamma\\left(1+\\frac{1}{k}\\right)\\right)^2"
847 | },
848 | mode: {
849 | fun: function(x0,s,k) { return jStat.weibull.mode(s,k) + x0; },
850 | display: "s\\left(\\frac{k-1}{k}\\right)^{\\frac{1}{k}}, k > 1"
851 | },
852 | median: {
853 | fun: function(x0,s,k) { return jStat.weibull.median(s,k) + x0; },
854 | display: "s\\left(\\log(2)\\right)^{\\frac{1}{k}}"
855 | }
856 | },
857 | null
858 | );
859 |
860 | var weibullShiftShapeRate = new distributionParametrization(
861 | "shift/rate/shape",
862 | [weibullShift,weibullRate, weibullShape],
863 | function(x0,theta,k) { return [x0,Number.POSITIVE_INFINITY]; },
864 | function(x0,theta,k) { return [x0,x0 + 10]; },
865 | "(x_0,\\infty)",
866 | function(x,x0,theta,k) { return jStat.weibull.pdf(x - x0, 1/theta, k); },
867 | "k\\theta\\left(x\\theta\\right)^{k-1} \\exp\\left\\{-\\left(\\theta(x-x_0)\\right)^k\\right\\}",
868 | function(x,x0,theta,k) { return jStat.weibull.cdf(x - x0, 1/theta, k); },
869 | null,
870 | function(x0,theta,k){ return theta>0 && k>0;},
871 | {
872 | mean: {
873 | fun: function(x0,theta,k) { return jStat.weibull.mean(1/theta,k) + x0; },
874 | display: "x_0 + \\frac{1}{\\theta}\\Gamma\\left(1+\\frac{1}{k}\\right)"
875 | },
876 | variance: {
877 | fun: function(x0,theta,k) { return jStat.weibull.variance(1/theta,k); },
878 | display: "\\frac{1}{\\theta^2}\\Gamma\\left(1+\\frac{2}{k}\\right) - \\left(x_0 + \\frac{1}{\\theta}\\Gamma\\left(1+\\frac{1}{k}\\right)\\right)^2"
879 | },
880 | mode: {
881 | fun: function(x0,theta,k) { return jStat.weibull.mode(1/theta,k) + x0; },
882 | display: "\\frac{1}{\\theta}\\left(\\frac{k-1}{k}\\right)^{\\frac{1}{k}}, k > 1"
883 | },
884 | median: {
885 | fun: function(x0,theta,k) { return jStat.weibull.median(1/theta,k) + x0; },
886 | display: "\\frac{1}{\\theta}\\left(\\log(2)\\right)^{\\frac{1}{k}}"
887 | }
888 | },
889 | null
890 | );
891 |
892 | distributions["weibull"] = new distribution(
893 | "weibull",
894 | "three-parameter Weibull",
895 | "continuous",
896 | [ weibullShiftShapeScale, weibullShiftShapeRate ],
897 | null,
898 | {
899 | name:"Wikipedia",
900 | link:"http://en.wikipedia.org/wiki/Weibull_distribution"
901 | }
902 | );
903 |
904 |
905 |
906 |
907 |
908 | ////***************
909 | // DISCRETE
910 | ////***************
911 |
912 | /*****/
913 | // Binomial distribution
914 | /*****/
915 |
916 | var binomialN = new positiveParameter(
917 | "N",
918 | "N",
919 | function() { return [1,100]; },
920 | false,
921 | 20,
922 | "discrete",
923 | null,
924 | "sample size"
925 | );
926 |
927 | var binomialp = new distributionParameter(
928 | "p",
929 | "p",
930 | function() { return [0,1]; },
931 | function() { return [0,1]; },
932 | false,
933 | .5,
934 | "continuous",
935 | "beta",
936 | "probability of success"
937 | );
938 |
939 | var binomialNp = new distributionParametrization(
940 | "probability",
941 | [binomialN, binomialp],
942 | function(N, p) { return [0,N]; },
943 | function(N, p) { return [0,N]; },
944 | "[0,N]",
945 | jStat.binomial.pdf,
946 | "\\binom{N}{x} p^x (1-p)^{N-x}",
947 | jStat.binomial.cdf,
948 | "beta",
949 | function(N,p){ return N>0 && is_int(N) && p<1 && p>0;},
950 | {
951 | mean: {
952 | fun: jStat.binomial.mean,
953 | display: "Np"
954 | },
955 | variance: {
956 | fun: jStat.binomial.variance,
957 | display: "Np(1-p)"
958 | }
959 | },
960 | null
961 |
962 | );
963 |
964 | distributions["binomial"] = new distribution(
965 | "binomial",
966 | "Binomial",
967 | "discrete",
968 | [ binomialNp ],
969 | null,
970 | {
971 | name:"Wikipedia",
972 | link:"http://en.wikipedia.org/wiki/Binomial_distribution"
973 | }
974 | );
975 |
976 |
977 | /*****/
978 | // Poisson distribution
979 | /*****/
980 |
981 | var poissonRate = new positiveParameter(
982 | "lambda",
983 | "\\lambda",
984 | function() { return [1/10,10]; },
985 | true,
986 | 1,
987 | "continuous",
988 | null,
989 | "rate"
990 | );
991 |
992 | var poissonRate = new distributionParametrization(
993 | "rate",
994 | [ poissonRate ],
995 | function(lambda) { return [0,Number.POSITIVE_INFINITY]; },
996 | function(lambda) { return [0,25]; },
997 | "[0,\\infty)",
998 | jStat.poisson.pdf,
999 | "\\frac{\\lambda^x}{x!} \\exp\\left\\{-\\lambda\\right\\}",
1000 | jStat.poisson.cdf,
1001 | "gamma",
1002 | function(lambda){ return lambda>0;},
1003 | {
1004 | mean: {
1005 | fun: jStat.poisson.mean,
1006 | display: "\\lambda"
1007 | },
1008 | variance: {
1009 | fun: jStat.poisson.variance,
1010 | display: "\\lambda"
1011 | }
1012 | },
1013 | null
1014 | );
1015 |
1016 | distributions["poisson"] = new distribution(
1017 | "poisson",
1018 | "Poisson",
1019 | "discrete",
1020 | [ poissonRate ],
1021 | null,
1022 | {
1023 | name:"Wikipedia",
1024 | link:"http://en.wikipedia.org/wiki/Poisson_distribution"
1025 | }
1026 | );
1027 |
1028 | /*****/
1029 | // Negative Binomial distribution
1030 | /*****/
1031 |
1032 | var negbinomialr = new positiveParameter(
1033 | "r",
1034 | "r",
1035 | function() { return [1,50]; },
1036 | false,
1037 | 20,
1038 | "discrete",
1039 | null,
1040 | "number of successes required"
1041 | );
1042 |
1043 | var negbinomialp = new distributionParameter(
1044 | "p",
1045 | "p",
1046 | function() { return [0,1]; },
1047 | function() { return [0,1]; },
1048 | false,
1049 | .2,
1050 | "continuous",
1051 | "beta",
1052 | "probability of failure"
1053 | );
1054 |
1055 | var negbinomialrp = new distributionParametrization(
1056 | "probability",
1057 | [negbinomialr, negbinomialp],
1058 | function(r, p) { return [0,Number.POSITIVE_INFINITY]; },
1059 | function(r, p) { return [0,50]; },
1060 | "[0,\\infty)",
1061 | jStat.negbin.pdf,
1062 | "\\binom{x+r-1}{x} p^x (1-p)^{r}",
1063 | jStat.negbin.cdf,
1064 | "beta",
1065 | function(r,p){ return r>0 && is_int(r) && p<1 && p>0;},
1066 | {
1067 | mean: {
1068 | fun: function(r,p){ return p*r/(1-p);},
1069 | display: "\\frac{rp}{1-p}"
1070 | },
1071 | variance: {
1072 | fun: function(r,p){ return p*r/(1-p)^2;},
1073 | display: "\\frac{rp}{(1-p)^2}"
1074 | }
1075 | },
1076 | null
1077 |
1078 | );
1079 |
1080 | distributions["negativebinomial"] = new distribution(
1081 | "negativebinomial",
1082 | "Negative binomial",
1083 | "discrete",
1084 | [ negbinomialrp ],
1085 | null,
1086 | {
1087 | name:"Wikipedia",
1088 | link:"http://en.wikipedia.org/wiki/Negative_binomial_distribution"
1089 | }
1090 | );
1091 |
1092 |
--------------------------------------------------------------------------------
/js/distributionObjects.js:
--------------------------------------------------------------------------------
1 | ///////////
2 | // Distribution stuff
3 | ///////////
4 |
5 |
6 | function distributionParameter(name, label, range, interactRange, interactLog, interactStart, type, conjugate, note){
7 | this.name = name;
8 | this.label = label;
9 | this.range = range;
10 | this.interactRange = interactRange;
11 | this.interactLog = interactLog;
12 | this.interactStart = interactStart;
13 | this.type = type;
14 | this.conjugate = conjugate;
15 | this.note = note;
16 | }
17 |
18 | function createElement(fstart,frangeLo,frangeHi){
19 | var limits = this.interactRange.apply(null,arguments);
20 | var start = this.interactStart;
21 |
22 | if( frangeLo != null && frangeHi !=null ){
23 | limits = [frangeLo,frangeHi];
24 | }
25 | if(fstart != null && fstart>limits[0] && fstart ', {
33 | id: "params_" + name + "_container",
34 | title: this.note
35 | }).appendTo('#parametercontainer');
36 |
37 | $("#params_" + name + "_container").addClass("paramsinglecontainer");
38 |
39 | $('
', {
40 | id: "params_label_" + name,
41 | text: " \\("+this.label+"\\) "
42 | }).appendTo('#' + "params_" + name + "_container");
43 |
44 | $("#params_label_" + name ).addClass("paramlabel");
45 |
46 | $('
', {
47 | id: "params_slider_" + name
48 | }).appendTo('#' + "params_" + name + "_container");
49 |
50 | $("#params_slider_" + name ).addClass("paramslider");
51 |
52 | $(' ', {
53 | id: "params_indicator_" + name,
54 | value: start
55 | }).appendTo('#'+"params_" + name + "_container");
56 |
57 | $("#params_indicator_" + name ).addClass("paramindicator");
58 |
59 | $(' ', {
60 | id: "params_end_" + name
61 | }).appendTo('#parametercontainer');
62 |
63 | $("#params_end_" + name ).addClass("clear");
64 |
65 | $("#params_" + name + "_container").tooltip({tipClass: "partooltip"});
66 |
67 | switch(this.type){
68 |
69 | case "discrete":
70 | var sliderMin = limits[0];
71 | var sliderMax = limits[1];
72 | var sliderStart = start;
73 | break;
74 |
75 | case "continuous":
76 | var sliderMin = 0;
77 | var sliderMax = sliderPoints-1;
78 | if(log){
79 | var sliderStart = sliderMax * (Math.log(start) - Math.log(limits[0]))/(Math.log(limits[1]) - Math.log(limits[0]));
80 | }else{
81 | var sliderStart = sliderMax * (start - limits[0])/(limits[1] - limits[0]);
82 | }
83 | break;
84 | }
85 |
86 | $( "#params_slider_" + name ).slider({ min: sliderMin, max: sliderMax, value: sliderStart });
87 | $( "#params_slider_" + name ).slider().bind('slide',function(event,ui){ slide(name,ui); } );
88 |
89 | }
90 |
91 | distributionParameter.prototype.createElement = createElement;
92 |
93 | function unboundedParameter(name, label, interactRange, interactLog, interactStart, type, conjugate, note){
94 | var range = function() { return [Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY]; };
95 | distributionParameter.call(this, name, label, range, interactRange, interactLog, interactStart, type, conjugate, note);
96 | }
97 |
98 | function positiveParameter(name, label, interactRange, interactLog, interactStart, type, conjugate, note){
99 | var range = function() { return [0,Number.POSITIVE_INFINITY]; };
100 | distributionParameter.call(this, name, label, range, interactRange, interactLog, interactStart, type, conjugate, note);
101 | }
102 |
103 | positiveParameter.prototype = new distributionParameter();
104 | unboundedParameter.prototype = new distributionParameter();
105 |
106 | function distributionParametrization(ptznName, params, limits, interactLimits, displayLimits, density, densityDisplay, cdf, conjugate, check, quantities, note){
107 | this.name = ptznName;
108 | this.params = params;
109 | this.density = density;
110 | this.densityDisplay = densityDisplay;
111 | this.cdf = cdf;
112 | this.limits;
113 | this.interactLimits = interactLimits;
114 | this.checkPars = check;
115 | this.conjugate = conjugate;
116 | this.quantities = quantities;
117 | this.note = note;
118 | this.displayLimits = displayLimits;
119 | }
120 |
121 | function distribution(name,label,type,parametrizations,note,referenceurl){
122 | this.name = name;
123 | this.label = label;
124 | this.type = type;
125 | this.parametrizations = parametrizations;
126 | this.p = parametrizations[0];
127 | this.note = note;
128 | this.referenceurl = referenceurl;
129 | }
130 |
131 |
132 |
133 | function updatePlot(ptznNum,name,ui){
134 |
135 | var nptzn = this.parametrizations.length;
136 | p = (ptznNum > (nptzn - 1)) ? this.p : this.parametrizations[ptznNum];
137 |
138 |
139 |
140 | var npars = p.params.length;
141 | var i = 0;
142 | var args = [];
143 | var par, sliderMin, sliderMax, sliderFrac, parValue;
144 | var limits;
145 | var plotType;
146 |
147 | if($("#buttonPDF").attr('disabled') !== undefined){
148 | plotType="pdf";
149 | }else if($("#buttonCDF").attr('disabled') !== undefined){
150 | plotType="cdf";
151 | }else{
152 | return;
153 | }
154 |
155 |
156 | // Iterate through parameters
157 | for(;i=minx) newSeries.push(series[i]);
285 | }
286 |
287 | data[0] = {data: newSeries, lines:{show:true, fill: true, fillColor: areaFillColor} };
288 |
289 | plot.setData(data);
290 | plot.draw();
291 | }
292 |
293 | function addCDFLines(x){
294 | var data = plot.getData();
295 | var cumdens = p.cdf.apply( null, [x].concat(args) );
296 |
297 | var newSeries = [ [ limits[0], cumdens ],
298 | [ x, cumdens ],
299 | [ x, 0 ]
300 | ];
301 |
302 |
303 | data[1] = {data: newSeries, lines:{ show:true }, hoverable: false};
304 |
305 | plot.setData(data);
306 | plot.draw();
307 | }
308 |
309 |
310 | $("#"+this.plotid).unbind("plothover mouseout plotclick");
311 | $("#"+this.plotid).bind("mouseout", function(){
312 | $("#tooltip").remove();
313 | var data = plot.getData();
314 |
315 | if(data[2].data.length==0)
316 | data[0].data = [];
317 |
318 | data[1].data = [];
319 |
320 | plot.setData(data);
321 | plot.draw();
322 | });
323 |
324 |
325 | $("#"+this.plotid).bind("plotclick", function (event, pos, item) {
326 | if(plotType=="cdf" || RVtype=="discrete") return;
327 | var data = plot.getData();
328 | var x1 = data[2];
329 | var x2 = data[3];
330 | if(x1.data.length==0){
331 | data[2].data = [ [ pos.x, 0 ], [ pos.x, p.density.apply( null, [pos.x].concat(args) ) ] ];
332 | data[2].lines = { show: true };
333 | }else if(x2.data.length==0){
334 | data[3].data = [ [ pos.x, 0 ], [ pos.x, p.density.apply( null, [pos.x].concat(args) ) ] ];
335 | data[3].lines = { show: true };
336 | addFill(x1.data[0][0], x2.data[0][0]);
337 | }else{
338 | data[0].data = [];
339 | data[2].data = [];
340 | data[3].data = [];
341 | }
342 | plot.setData(data);
343 |
344 | addFill(pos);
345 |
346 | });
347 |
348 | $("#"+this.plotid).bind("plothover", function (event, pos, item) {
349 | if (item && RVtype=="discrete") {
350 | if (previousPoint != item.dataIndex) {
351 | previousPoint = item.dataIndex;
352 |
353 | $("#tooltip").remove();
354 | var x = round(item.datapoint[0], ttxDigits),
355 | y = round(item.datapoint[1], roundDigits);
356 |
357 | var funname = (plotType=="pdf") ? "p" : "F";
358 | showTooltip(item.pageX, item.pageY,
359 | funname+"(" + x + ") = " + y);
360 | if(plotType=="cdf") addCDFLines(item.datapoint[0]);
361 | }
362 | }else if(RVtype == "continuous"){
363 | $("#tooltip").remove();
364 | var dens = round(p.density.apply( null, [pos.x].concat(args) ), roundDigits);
365 | var cumdens = round(p.cdf.apply( null, [pos.x].concat(args) ), roundDigits);
366 | var x = round(pos.x, roundDigits);
367 |
368 | if(plotType=="pdf"){
369 | addFill(pos);
370 | var shaded = getShaded(plot, pos, limits, p.cdf, args);
371 | showTooltip(pos.pageX, pos.pageY,
372 | "p(" + x + ") = " + dens + " " +
373 | "Shaded: " + round(shaded, roundDigits));
374 | }else if(plotType=="cdf"){
375 | addCDFLines(pos.x);
376 | showTooltip(pos.pageX, pos.pageY,
377 | "F(" + x + ") = " + cumdens);
378 | }
379 | }
380 | else {
381 | $("#tooltip").remove();
382 | previousPoint = null;
383 | }
384 | });
385 |
386 | if(RVtype=="continuous" && plotType=="pdf") addFill();
387 |
388 | }
389 |
390 |
391 |
392 | function refTableHeaderRow(type){
393 |
394 | var head = new Element('thead');
395 | var row = new Element('tr');
396 |
397 | row.adopt(
398 | new Element('th', {
399 | html: "Name",
400 | scope: "col"
401 | }),
402 | new Element('th', {
403 | html: "Density function",
404 | scope: "col"
405 | }),
406 | new Element('th', {
407 | html: "Domain",
408 | scope: "col"
409 | }),
410 | new Element('th', {
411 | html: "Parameters",
412 | scope: "col"
413 | }),
414 | new Element('th', {
415 | html: "Conjugacy",
416 | scope: "col"
417 | }),
418 | new Element('th', {
419 | html: "Example",
420 | scope: "col"
421 | }),
422 | new Element('th', {
423 | html: "Reference",
424 | scope: "col"
425 | })
426 | );
427 |
428 | head.grab(row);
429 |
430 | head.inject(document.id(type+'_distributiontable'));
431 | }
432 |
433 | function refTableRow(odd, type){
434 |
435 | var idPre = type + "_dist_" + this.name;
436 | var rowname = idPre + "_row";
437 |
438 | var anch = new Element('a', {
439 | name: this.name+"table"
440 | });
441 |
442 | var row = new Element('tr', {
443 | id: rowname
444 | });
445 |
446 | var example = new Element('td', {
447 | id: idPre + "_example"
448 | });
449 |
450 | example.grab(
451 | new Element('a', {
452 | href: "distributionDisplay.html?dist="+this.name,
453 | id: idPre + "_interactlink",
454 | html: "Interact",
455 | title: "The "+this.label+" distribution",
456 | 'data-milkbox-size': "width:650,height:370",
457 | 'data-milkbox': "dist"
458 | })
459 | );
460 |
461 | var reference = new Element('td', {
462 | id: idPre + "_reference"
463 | });
464 |
465 | reference.grab(
466 | new Element('a', {
467 | href: this.referenceurl.link,
468 | html: this.referenceurl.name,
469 | target: "_blank"
470 | })
471 | );
472 |
473 | row.adopt(
474 | new Element('th', {
475 | id: idPre + "_name",
476 | 'class': 'column1',
477 | html: this.label,
478 | scope: "row"
479 | }),
480 | new Element('td', {
481 | id: idPre + "_density",
482 | html: "\\["+this.p.densityDisplay+"\\]"
483 | }),
484 | new Element('td', {
485 | id: idPre + "_domain",
486 | html: "\\("+this.p.displayLimits+"\\)"
487 | }),
488 | new Element('td', {
489 | id: idPre + "_parameters",
490 | html: "\\("+""+"\\)"
491 | }),
492 | new Element('td', {
493 | id: idPre + "_conjugate",
494 | html: ""
495 | }),
496 | example,
497 | reference
498 | );
499 |
500 |
501 | if(odd) row.set('class','odd');
502 |
503 | row.inject(document.id(type+'_distributiontablebody'));
504 | anch.inject(document.id(idPre+"_name"));
505 |
506 | //MathJax.Hub.Queue(["Typeset",MathJax.Hub,document.getElementById(rowname)]);
507 | }
508 |
509 | function createInterfaceElements(ptznNum){
510 |
511 | var nptzn = this.parametrizations.length;
512 | p = (ptznNum > (nptzn - 1)) ? this.p : this.parametrizations[ptznNum];
513 |
514 |
515 | var npars = p.params.length;
516 | var text="";
517 | var i = 0;
518 | var s, rl, rh;
519 | for(;i 534) {browser.STIXfontBug = true}
11 | }
12 | });
13 | if (MathJax.Hub.Browser.STIXfontBug) {
14 | HTMLCSS.FONTDATA.FONTS["STIXGeneral"].family = "STIXGeneral-Regular";
15 | HTMLCSS.FONTDATA.FONTS["STIXGeneral-italic"].family = "STIXGeneral-Italic";
16 | delete HTMLCSS.FONTDATA.FONTS["STIXGeneral-italic"].style;
17 | }
18 | });
--------------------------------------------------------------------------------
/js/libraries/excanvas.min.js:
--------------------------------------------------------------------------------
1 | if(!document.createElement("canvas").getContext){(function(){var ab=Math;var n=ab.round;var l=ab.sin;var A=ab.cos;var H=ab.abs;var N=ab.sqrt;var d=10;var f=d/2;var z=+navigator.userAgent.match(/MSIE ([\d.]+)?/)[1];function y(){return this.context_||(this.context_=new D(this))}var t=Array.prototype.slice;function g(j,m,p){var i=t.call(arguments,2);return function(){return j.apply(m,i.concat(t.call(arguments)))}}function af(i){return String(i).replace(/&/g,"&").replace(/"/g,""")}function Y(m,j,i){if(!m.namespaces[j]){m.namespaces.add(j,i,"#default#VML")}}function R(j){Y(j,"g_vml_","urn:schemas-microsoft-com:vml");Y(j,"g_o_","urn:schemas-microsoft-com:office:office");if(!j.styleSheets.ex_canvas_){var i=j.createStyleSheet();i.owningElement.id="ex_canvas_";i.cssText="canvas{display:inline-block;overflow:hidden;text-align:left;width:300px;height:150px}"}}R(document);var e={init:function(i){var j=i||document;j.createElement("canvas");j.attachEvent("onreadystatechange",g(this.init_,this,j))},init_:function(p){var m=p.getElementsByTagName("canvas");for(var j=0;j1){m--}if(6*m<1){return j+(i-j)*6*m}else{if(2*m<1){return i}else{if(3*m<2){return j+(i-j)*(2/3-m)*6}else{return j}}}}var C={};function F(j){if(j in C){return C[j]}var ag,Z=1;j=String(j);if(j.charAt(0)=="#"){ag=j}else{if(/^rgb/.test(j)){var p=M(j);var ag="#",ah;for(var m=0;m<3;m++){if(p[m].indexOf("%")!=-1){ah=Math.floor(c(p[m])*255)}else{ah=+p[m]}ag+=k[r(ah,0,255)]}Z=+p[3]}else{if(/^hsl/.test(j)){var p=M(j);ag=I(p);Z=p[3]}else{ag=b[j]||j}}}return C[j]={color:ag,alpha:Z}}var o={style:"normal",variant:"normal",weight:"normal",size:10,family:"sans-serif"};var L={};function E(i){if(L[i]){return L[i]}var p=document.createElement("div");var m=p.style;try{m.font=i}catch(j){}return L[i]={style:m.fontStyle||o.style,variant:m.fontVariant||o.variant,weight:m.fontWeight||o.weight,size:m.fontSize||o.size,family:m.fontFamily||o.family}}function u(m,j){var i={};for(var ah in m){i[ah]=m[ah]}var ag=parseFloat(j.currentStyle.fontSize),Z=parseFloat(m.size);if(typeof m.size=="number"){i.size=m.size}else{if(m.size.indexOf("px")!=-1){i.size=Z}else{if(m.size.indexOf("em")!=-1){i.size=ag*Z}else{if(m.size.indexOf("%")!=-1){i.size=(ag/100)*Z}else{if(m.size.indexOf("pt")!=-1){i.size=Z/0.75}else{i.size=ag}}}}}i.size*=0.981;return i}function ac(i){return i.style+" "+i.variant+" "+i.weight+" "+i.size+"px "+i.family}var s={butt:"flat",round:"round"};function S(i){return s[i]||"square"}function D(i){this.m_=B();this.mStack_=[];this.aStack_=[];this.currentPath_=[];this.strokeStyle="#000";this.fillStyle="#000";this.lineWidth=1;this.lineJoin="miter";this.lineCap="butt";this.miterLimit=d*1;this.globalAlpha=1;this.font="10px sans-serif";this.textAlign="left";this.textBaseline="alphabetic";this.canvas=i;var m="width:"+i.clientWidth+"px;height:"+i.clientHeight+"px;overflow:hidden;position:absolute";var j=i.ownerDocument.createElement("div");j.style.cssText=m;i.appendChild(j);var p=j.cloneNode(false);p.style.backgroundColor="red";p.style.filter="alpha(opacity=0)";i.appendChild(p);this.element_=j;this.arcScaleX_=1;this.arcScaleY_=1;this.lineScale_=1}var q=D.prototype;q.clearRect=function(){if(this.textMeasureEl_){this.textMeasureEl_.removeNode(true);this.textMeasureEl_=null}this.element_.innerHTML=""};q.beginPath=function(){this.currentPath_=[]};q.moveTo=function(j,i){var m=V(this,j,i);this.currentPath_.push({type:"moveTo",x:m.x,y:m.y});this.currentX_=m.x;this.currentY_=m.y};q.lineTo=function(j,i){var m=V(this,j,i);this.currentPath_.push({type:"lineTo",x:m.x,y:m.y});this.currentX_=m.x;this.currentY_=m.y};q.bezierCurveTo=function(m,j,ak,aj,ai,ag){var i=V(this,ai,ag);var ah=V(this,m,j);var Z=V(this,ak,aj);K(this,ah,Z,i)};function K(i,Z,m,j){i.currentPath_.push({type:"bezierCurveTo",cp1x:Z.x,cp1y:Z.y,cp2x:m.x,cp2y:m.y,x:j.x,y:j.y});i.currentX_=j.x;i.currentY_=j.y}q.quadraticCurveTo=function(ai,m,j,i){var ah=V(this,ai,m);var ag=V(this,j,i);var aj={x:this.currentX_+2/3*(ah.x-this.currentX_),y:this.currentY_+2/3*(ah.y-this.currentY_)};var Z={x:aj.x+(ag.x-this.currentX_)/3,y:aj.y+(ag.y-this.currentY_)/3};K(this,aj,Z,ag)};q.arc=function(al,aj,ak,ag,j,m){ak*=d;var ap=m?"at":"wa";var am=al+A(ag)*ak-f;var ao=aj+l(ag)*ak-f;var i=al+A(j)*ak-f;var an=aj+l(j)*ak-f;if(am==i&&!m){am+=0.125}var Z=V(this,al,aj);var ai=V(this,am,ao);var ah=V(this,i,an);this.currentPath_.push({type:ap,x:Z.x,y:Z.y,radius:ak,xStart:ai.x,yStart:ai.y,xEnd:ah.x,yEnd:ah.y})};q.rect=function(m,j,i,p){this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath()};q.strokeRect=function(m,j,i,p){var Z=this.currentPath_;this.beginPath();this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath();this.stroke();this.currentPath_=Z};q.fillRect=function(m,j,i,p){var Z=this.currentPath_;this.beginPath();this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath();this.fill();this.currentPath_=Z};q.createLinearGradient=function(j,p,i,m){var Z=new U("gradient");Z.x0_=j;Z.y0_=p;Z.x1_=i;Z.y1_=m;return Z};q.createRadialGradient=function(p,ag,m,j,Z,i){var ah=new U("gradientradial");ah.x0_=p;ah.y0_=ag;ah.r0_=m;ah.x1_=j;ah.y1_=Z;ah.r1_=i;return ah};q.drawImage=function(aq,m){var aj,ah,al,ay,ao,am,at,aA;var ak=aq.runtimeStyle.width;var ap=aq.runtimeStyle.height;aq.runtimeStyle.width="auto";aq.runtimeStyle.height="auto";var ai=aq.width;var aw=aq.height;aq.runtimeStyle.width=ak;aq.runtimeStyle.height=ap;if(arguments.length==3){aj=arguments[1];ah=arguments[2];ao=am=0;at=al=ai;aA=ay=aw}else{if(arguments.length==5){aj=arguments[1];ah=arguments[2];al=arguments[3];ay=arguments[4];ao=am=0;at=ai;aA=aw}else{if(arguments.length==9){ao=arguments[1];am=arguments[2];at=arguments[3];aA=arguments[4];aj=arguments[5];ah=arguments[6];al=arguments[7];ay=arguments[8]}else{throw Error("Invalid number of arguments")}}}var az=V(this,aj,ah);var p=at/2;var j=aA/2;var ax=[];var i=10;var ag=10;ax.push(" ',' "," ");this.element_.insertAdjacentHTML("BeforeEnd",ax.join(""))};q.stroke=function(ao){var Z=10;var ap=10;var ag=5000;var ai={x:null,y:null};var an={x:null,y:null};for(var aj=0;ajan.x){an.x=m.x}if(ai.y==null||m.yan.y){an.y=m.y}}}am.push(' ">');if(!ao){w(this,am)}else{G(this,am,ai,an)}am.push("");this.element_.insertAdjacentHTML("beforeEnd",am.join(""))}};function w(m,ag){var j=F(m.strokeStyle);var p=j.color;var Z=j.alpha*m.globalAlpha;var i=m.lineScale_*m.lineWidth;if(i<1){Z*=i}ag.push(" ')}function G(aq,ai,aK,ar){var aj=aq.fillStyle;var aB=aq.arcScaleX_;var aA=aq.arcScaleY_;var j=ar.x-aK.x;var p=ar.y-aK.y;if(aj instanceof U){var an=0;var aF={x:0,y:0};var ax=0;var am=1;if(aj.type_=="gradient"){var al=aj.x0_/aB;var m=aj.y0_/aA;var ak=aj.x1_/aB;var aM=aj.y1_/aA;var aJ=V(aq,al,m);var aI=V(aq,ak,aM);var ag=aI.x-aJ.x;var Z=aI.y-aJ.y;an=Math.atan2(ag,Z)*180/Math.PI;if(an<0){an+=360}if(an<0.000001){an=0}}else{var aJ=V(aq,aj.x0_,aj.y0_);aF={x:(aJ.x-aK.x)/j,y:(aJ.y-aK.y)/p};j/=aB*d;p/=aA*d;var aD=ab.max(j,p);ax=2*aj.r0_/aD;am=2*aj.r1_/aD-ax}var av=aj.colors_;av.sort(function(aN,i){return aN.offset-i.offset});var ap=av.length;var au=av[0].color;var at=av[ap-1].color;var az=av[0].alpha*aq.globalAlpha;var ay=av[ap-1].alpha*aq.globalAlpha;var aE=[];for(var aH=0;aH ')}else{if(aj instanceof T){if(j&&p){var ah=-aK.x;var aC=-aK.y;ai.push(" ')}}else{var aL=F(aq.fillStyle);var aw=aL.color;var aG=aL.alpha*aq.globalAlpha;ai.push(' ')}}}q.fill=function(){this.stroke(true)};q.closePath=function(){this.currentPath_.push({type:"close"})};function V(j,Z,p){var i=j.m_;return{x:d*(Z*i[0][0]+p*i[1][0]+i[2][0])-f,y:d*(Z*i[0][1]+p*i[1][1]+i[2][1])-f}}q.save=function(){var i={};v(this,i);this.aStack_.push(i);this.mStack_.push(this.m_);this.m_=J(B(),this.m_)};q.restore=function(){if(this.aStack_.length){v(this.aStack_.pop(),this);this.m_=this.mStack_.pop()}};function h(i){return isFinite(i[0][0])&&isFinite(i[0][1])&&isFinite(i[1][0])&&isFinite(i[1][1])&&isFinite(i[2][0])&&isFinite(i[2][1])}function aa(j,i,p){if(!h(i)){return}j.m_=i;if(p){var Z=i[0][0]*i[1][1]-i[0][1]*i[1][0];j.lineScale_=N(H(Z))}}q.translate=function(m,j){var i=[[1,0,0],[0,1,0],[m,j,1]];aa(this,J(i,this.m_),false)};q.rotate=function(j){var p=A(j);var m=l(j);var i=[[p,m,0],[-m,p,0],[0,0,1]];aa(this,J(i,this.m_),false)};q.scale=function(m,j){this.arcScaleX_*=m;this.arcScaleY_*=j;var i=[[m,0,0],[0,j,0],[0,0,1]];aa(this,J(i,this.m_),true)};q.transform=function(Z,p,ah,ag,j,i){var m=[[Z,p,0],[ah,ag,0],[j,i,1]];aa(this,J(m,this.m_),true)};q.setTransform=function(ag,Z,ai,ah,p,j){var i=[[ag,Z,0],[ai,ah,0],[p,j,1]];aa(this,i,true)};q.drawText_=function(am,ak,aj,ap,ai){var ao=this.m_,at=1000,j=0,ar=at,ah={x:0,y:0},ag=[];var i=u(E(this.font),this.element_);var p=ac(i);var au=this.element_.currentStyle;var Z=this.textAlign.toLowerCase();switch(Z){case"left":case"center":case"right":break;case"end":Z=au.direction=="ltr"?"right":"left";break;case"start":Z=au.direction=="rtl"?"right":"left";break;default:Z="left"}switch(this.textBaseline){case"hanging":case"top":ah.y=i.size/1.75;break;case"middle":break;default:case null:case"alphabetic":case"ideographic":case"bottom":ah.y=-i.size/2.25;break}switch(Z){case"right":j=at;ar=0.05;break;case"center":j=ar=at/2;break}var aq=V(this,ak+ah.x,aj+ah.y);ag.push('');if(ai){w(this,ag)}else{G(this,ag,{x:-j,y:0},{x:ar,y:i.size})}var an=ao[0][0].toFixed(3)+","+ao[1][0].toFixed(3)+","+ao[0][1].toFixed(3)+","+ao[1][1].toFixed(3)+",0,0";var al=n(aq.x/d)+","+n(aq.y/d);ag.push(' ',' ',' ');this.element_.insertAdjacentHTML("beforeEnd",ag.join(""))};q.fillText=function(m,i,p,j){this.drawText_(m,i,p,j,false)};q.strokeText=function(m,i,p,j){this.drawText_(m,i,p,j,true)};q.measureText=function(m){if(!this.textMeasureEl_){var i=' ';this.element_.insertAdjacentHTML("beforeEnd",i);this.textMeasureEl_=this.element_.lastChild}var j=this.element_.ownerDocument;this.textMeasureEl_.innerHTML="";this.textMeasureEl_.style.font=this.font;this.textMeasureEl_.appendChild(j.createTextNode(m));return{width:this.textMeasureEl_.offsetWidth}};q.clip=function(){};q.arcTo=function(){};q.createPattern=function(j,i){return new T(j,i)};function U(i){this.type_=i;this.x0_=0;this.y0_=0;this.r0_=0;this.x1_=0;this.y1_=0;this.r1_=0;this.colors_=[]}U.prototype.addColorStop=function(j,i){i=F(i);this.colors_.push({offset:j,color:i.color,alpha:i.alpha})};function T(j,i){Q(j);switch(i){case"repeat":case null:case"":this.repetition_="repeat";break;case"repeat-x":case"repeat-y":case"no-repeat":this.repetition_=i;break;default:O("SYNTAX_ERR")}this.src_=j.src;this.width_=j.width;this.height_=j.height}function O(i){throw new P(i)}function Q(i){if(!i||i.nodeType!=1||i.tagName!="IMG"){O("TYPE_MISMATCH_ERR")}if(i.readyState!="complete"){O("INVALID_STATE_ERR")}}function P(i){this.code=this[i];this.message=i+": DOM Exception "+this.code}var X=P.prototype=new Error;X.INDEX_SIZE_ERR=1;X.DOMSTRING_SIZE_ERR=2;X.HIERARCHY_REQUEST_ERR=3;X.WRONG_DOCUMENT_ERR=4;X.INVALID_CHARACTER_ERR=5;X.NO_DATA_ALLOWED_ERR=6;X.NO_MODIFICATION_ALLOWED_ERR=7;X.NOT_FOUND_ERR=8;X.NOT_SUPPORTED_ERR=9;X.INUSE_ATTRIBUTE_ERR=10;X.INVALID_STATE_ERR=11;X.SYNTAX_ERR=12;X.INVALID_MODIFICATION_ERR=13;X.NAMESPACE_ERR=14;X.INVALID_ACCESS_ERR=15;X.VALIDATION_ERR=16;X.TYPE_MISMATCH_ERR=17;G_vmlCanvasManager=e;CanvasRenderingContext2D=D;CanvasGradient=U;CanvasPattern=T;DOMException=P})()};
--------------------------------------------------------------------------------
/js/libraries/jquery.flot.crosshair.js:
--------------------------------------------------------------------------------
1 | /*
2 | Flot plugin for showing crosshairs, thin lines, when the mouse hovers
3 | over the plot.
4 |
5 | crosshair: {
6 | mode: null or "x" or "y" or "xy"
7 | color: color
8 | lineWidth: number
9 | }
10 |
11 | Set the mode to one of "x", "y" or "xy". The "x" mode enables a
12 | vertical crosshair that lets you trace the values on the x axis, "y"
13 | enables a horizontal crosshair and "xy" enables them both. "color" is
14 | the color of the crosshair (default is "rgba(170, 0, 0, 0.80)"),
15 | "lineWidth" is the width of the drawn lines (default is 1).
16 |
17 | The plugin also adds four public methods:
18 |
19 | - setCrosshair(pos)
20 |
21 | Set the position of the crosshair. Note that this is cleared if
22 | the user moves the mouse. "pos" is in coordinates of the plot and
23 | should be on the form { x: xpos, y: ypos } (you can use x2/x3/...
24 | if you're using multiple axes), which is coincidentally the same
25 | format as what you get from a "plothover" event. If "pos" is null,
26 | the crosshair is cleared.
27 |
28 | - clearCrosshair()
29 |
30 | Clear the crosshair.
31 |
32 | - lockCrosshair(pos)
33 |
34 | Cause the crosshair to lock to the current location, no longer
35 | updating if the user moves the mouse. Optionally supply a position
36 | (passed on to setCrosshair()) to move it to.
37 |
38 | Example usage:
39 | var myFlot = $.plot( $("#graph"), ..., { crosshair: { mode: "x" } } };
40 | $("#graph").bind("plothover", function (evt, position, item) {
41 | if (item) {
42 | // Lock the crosshair to the data point being hovered
43 | myFlot.lockCrosshair({ x: item.datapoint[0], y: item.datapoint[1] });
44 | }
45 | else {
46 | // Return normal crosshair operation
47 | myFlot.unlockCrosshair();
48 | }
49 | });
50 |
51 | - unlockCrosshair()
52 |
53 | Free the crosshair to move again after locking it.
54 | */
55 |
56 | (function ($) {
57 | var options = {
58 | crosshair: {
59 | mode: null, // one of null, "x", "y" or "xy",
60 | color: "rgba(170, 0, 0, 0.80)",
61 | lineWidth: 1
62 | }
63 | };
64 |
65 | function init(plot) {
66 | // position of crosshair in pixels
67 | var crosshair = { x: -1, y: -1, locked: false };
68 |
69 | plot.setCrosshair = function setCrosshair(pos) {
70 | if (!pos)
71 | crosshair.x = -1;
72 | else {
73 | var o = plot.p2c(pos);
74 | crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
75 | crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
76 | }
77 |
78 | plot.triggerRedrawOverlay();
79 | };
80 |
81 | plot.clearCrosshair = plot.setCrosshair; // passes null for pos
82 |
83 | plot.lockCrosshair = function lockCrosshair(pos) {
84 | if (pos)
85 | plot.setCrosshair(pos);
86 | crosshair.locked = true;
87 | }
88 |
89 | plot.unlockCrosshair = function unlockCrosshair() {
90 | crosshair.locked = false;
91 | }
92 |
93 | function onMouseOut(e) {
94 | if (crosshair.locked)
95 | return;
96 |
97 | if (crosshair.x != -1) {
98 | crosshair.x = -1;
99 | plot.triggerRedrawOverlay();
100 | }
101 | }
102 |
103 | function onMouseMove(e) {
104 | if (crosshair.locked)
105 | return;
106 |
107 | if (plot.getSelection && plot.getSelection()) {
108 | crosshair.x = -1; // hide the crosshair while selecting
109 | return;
110 | }
111 |
112 | var offset = plot.offset();
113 | crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
114 | crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
115 | plot.triggerRedrawOverlay();
116 | }
117 |
118 | plot.hooks.bindEvents.push(function (plot, eventHolder) {
119 | if (!plot.getOptions().crosshair.mode)
120 | return;
121 |
122 | eventHolder.mouseout(onMouseOut);
123 | eventHolder.mousemove(onMouseMove);
124 | });
125 |
126 | plot.hooks.drawOverlay.push(function (plot, ctx) {
127 | var c = plot.getOptions().crosshair;
128 | if (!c.mode)
129 | return;
130 |
131 | var plotOffset = plot.getPlotOffset();
132 |
133 | ctx.save();
134 | ctx.translate(plotOffset.left, plotOffset.top);
135 |
136 | if (crosshair.x != -1) {
137 | ctx.strokeStyle = c.color;
138 | ctx.lineWidth = c.lineWidth;
139 | ctx.lineJoin = "round";
140 |
141 | ctx.beginPath();
142 | if (c.mode.indexOf("x") != -1) {
143 | ctx.moveTo(crosshair.x, 0);
144 | ctx.lineTo(crosshair.x, plot.height());
145 | }
146 | if (c.mode.indexOf("y") != -1) {
147 | ctx.moveTo(0, crosshair.y);
148 | ctx.lineTo(plot.width(), crosshair.y);
149 | }
150 | ctx.stroke();
151 | }
152 | ctx.restore();
153 | });
154 |
155 | plot.hooks.shutdown.push(function (plot, eventHolder) {
156 | eventHolder.unbind("mouseout", onMouseOut);
157 | eventHolder.unbind("mousemove", onMouseMove);
158 | });
159 | }
160 |
161 | $.plot.plugins.push({
162 | init: init,
163 | options: options,
164 | name: 'crosshair',
165 | version: '1.0'
166 | });
167 | })(jQuery);
168 |
--------------------------------------------------------------------------------
/js/libraries/jquery.flot.min.js:
--------------------------------------------------------------------------------
1 | /* Javascript plotting library for jQuery, v. 0.7.
2 | *
3 | * Released under the MIT license by IOLA, December 2007.
4 | *
5 | */
6 | (function(b){b.color={};b.color.make=function(d,e,g,f){var c={};c.r=d||0;c.g=e||0;c.b=g||0;c.a=f!=null?f:1;c.add=function(h,j){for(var k=0;k=1){return"rgb("+[c.r,c.g,c.b].join(",")+")"}else{return"rgba("+[c.r,c.g,c.b,c.a].join(",")+")"}};c.normalize=function(){function h(k,j,l){return jl?l:j)}c.r=h(0,parseInt(c.r),255);c.g=h(0,parseInt(c.g),255);c.b=h(0,parseInt(c.b),255);c.a=h(0,c.a,1);return c};c.clone=function(){return b.color.make(c.r,c.b,c.g,c.a)};return c.normalize()};b.color.extract=function(d,e){var c;do{c=d.css(e).toLowerCase();if(c!=""&&c!="transparent"){break}d=d.parent()}while(!b.nodeName(d.get(0),"body"));if(c=="rgba(0, 0, 0, 0)"){c="transparent"}return b.color.parse(c)};b.color.parse=function(c){var d,f=b.color.make;if(d=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c)){return f(parseInt(d[1],10),parseInt(d[2],10),parseInt(d[3],10))}if(d=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(c)){return f(parseInt(d[1],10),parseInt(d[2],10),parseInt(d[3],10),parseFloat(d[4]))}if(d=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c)){return f(parseFloat(d[1])*2.55,parseFloat(d[2])*2.55,parseFloat(d[3])*2.55)}if(d=/rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(c)){return f(parseFloat(d[1])*2.55,parseFloat(d[2])*2.55,parseFloat(d[3])*2.55,parseFloat(d[4]))}if(d=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c)){return f(parseInt(d[1],16),parseInt(d[2],16),parseInt(d[3],16))}if(d=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c)){return f(parseInt(d[1]+d[1],16),parseInt(d[2]+d[2],16),parseInt(d[3]+d[3],16))}var e=b.trim(c).toLowerCase();if(e=="transparent"){return f(255,255,255,0)}else{d=a[e]||[0,0,0];return f(d[0],d[1],d[2])}};var a={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);(function(c){function b(av,ai,J,af){var Q=[],O={colors:["#edc240","#afd8f8","#cb4b4b","#4da74d","#9440ed"],legend:{show:true,noColumns:1,labelFormatter:null,labelBoxBorderColor:"#ccc",container:null,position:"ne",margin:5,backgroundColor:null,backgroundOpacity:0.85},xaxis:{show:null,position:"bottom",mode:null,color:null,tickColor:null,transform:null,inverseTransform:null,min:null,max:null,autoscaleMargin:null,ticks:null,tickFormatter:null,labelWidth:null,labelHeight:null,reserveSpace:null,tickLength:null,alignTicksWithAxis:null,tickDecimals:null,tickSize:null,minTickSize:null,monthNames:null,timeformat:null,twelveHourClock:false},yaxis:{autoscaleMargin:0.02,position:"left"},xaxes:[],yaxes:[],series:{points:{show:false,radius:3,lineWidth:2,fill:true,fillColor:"#ffffff",symbol:"circle"},lines:{lineWidth:2,fill:false,fillColor:null,steps:false},bars:{show:false,lineWidth:2,barWidth:1,fill:true,fillColor:null,align:"left",horizontal:false},shadowSize:3},grid:{show:true,aboveData:false,color:"#545454",backgroundColor:null,borderColor:null,tickColor:null,labelMargin:5,axisMargin:8,borderWidth:2,minBorderMargin:null,markings:null,markingsColor:"#f4f4f4",markingsLineWidth:2,clickable:false,hoverable:false,autoHighlight:true,mouseActiveRadius:10},hooks:{}},az=null,ad=null,y=null,H=null,A=null,p=[],aw=[],q={left:0,right:0,top:0,bottom:0},G=0,I=0,h=0,w=0,ak={processOptions:[],processRawData:[],processDatapoints:[],drawSeries:[],draw:[],bindEvents:[],drawOverlay:[],shutdown:[]},aq=this;aq.setData=aj;aq.setupGrid=t;aq.draw=W;aq.getPlaceholder=function(){return av};aq.getCanvas=function(){return az};aq.getPlotOffset=function(){return q};aq.width=function(){return h};aq.height=function(){return w};aq.offset=function(){var aB=y.offset();aB.left+=q.left;aB.top+=q.top;return aB};aq.getData=function(){return Q};aq.getAxes=function(){var aC={},aB;c.each(p.concat(aw),function(aD,aE){if(aE){aC[aE.direction+(aE.n!=1?aE.n:"")+"axis"]=aE}});return aC};aq.getXAxes=function(){return p};aq.getYAxes=function(){return aw};aq.c2p=C;aq.p2c=ar;aq.getOptions=function(){return O};aq.highlight=x;aq.unhighlight=T;aq.triggerRedrawOverlay=f;aq.pointOffset=function(aB){return{left:parseInt(p[aA(aB,"x")-1].p2c(+aB.x)+q.left),top:parseInt(aw[aA(aB,"y")-1].p2c(+aB.y)+q.top)}};aq.shutdown=ag;aq.resize=function(){B();g(az);g(ad)};aq.hooks=ak;F(aq);Z(J);X();aj(ai);t();W();ah();function an(aD,aB){aB=[aq].concat(aB);for(var aC=0;aC=O.colors.length){aG=0;++aF}}var aH=0,aN;for(aG=0;aGa3.datamax&&a1!=aB){a3.datamax=a1}}c.each(m(),function(a1,a2){a2.datamin=aO;a2.datamax=aI;a2.used=false});for(aU=0;aU0&&aT[aR-aP]!=null&&aT[aR-aP]!=aT[aR]&&aT[aR-aP+1]!=aT[aR+1]){for(aN=0;aNaM){aM=a0}}if(aX.y){if(a0aV){aV=a0}}}}if(aJ.bars.show){var aY=aJ.bars.align=="left"?0:-aJ.bars.barWidth/2;if(aJ.bars.horizontal){aQ+=aY;aV+=aY+aJ.bars.barWidth}else{aK+=aY;aM+=aY+aJ.bars.barWidth}}aF(aJ.xaxis,aK,aM);aF(aJ.yaxis,aQ,aV)}c.each(m(),function(a1,a2){if(a2.datamin==aO){a2.datamin=null}if(a2.datamax==aI){a2.datamax=null}})}function j(aB,aC){var aD=document.createElement("canvas");aD.className=aC;aD.width=G;aD.height=I;if(!aB){c(aD).css({position:"absolute",left:0,top:0})}c(aD).appendTo(av);if(!aD.getContext){aD=window.G_vmlCanvasManager.initElement(aD)}aD.getContext("2d").save();return aD}function B(){G=av.width();I=av.height();if(G<=0||I<=0){throw"Invalid dimensions for plot, width = "+G+", height = "+I}}function g(aC){if(aC.width!=G){aC.width=G}if(aC.height!=I){aC.height=I}var aB=aC.getContext("2d");aB.restore();aB.save()}function X(){var aC,aB=av.children("canvas.base"),aD=av.children("canvas.overlay");if(aB.length==0||aD==0){av.html("");av.css({padding:0});if(av.css("position")=="static"){av.css("position","relative")}B();az=j(true,"base");ad=j(false,"overlay");aC=false}else{az=aB.get(0);ad=aD.get(0);aC=true}H=az.getContext("2d");A=ad.getContext("2d");y=c([ad,az]);if(aC){av.data("plot").shutdown();aq.resize();A.clearRect(0,0,G,I);y.unbind();av.children().not([az,ad]).remove()}av.data("plot",aq)}function ah(){if(O.grid.hoverable){y.mousemove(aa);y.mouseleave(l)}if(O.grid.clickable){y.click(R)}an(ak.bindEvents,[y])}function ag(){if(M){clearTimeout(M)}y.unbind("mousemove",aa);y.unbind("mouseleave",l);y.unbind("click",R);an(ak.shutdown,[y])}function r(aG){function aC(aH){return aH}var aF,aB,aD=aG.options.transform||aC,aE=aG.options.inverseTransform;if(aG.direction=="x"){aF=aG.scale=h/Math.abs(aD(aG.max)-aD(aG.min));aB=Math.min(aD(aG.max),aD(aG.min))}else{aF=aG.scale=w/Math.abs(aD(aG.max)-aD(aG.min));aF=-aF;aB=Math.max(aD(aG.max),aD(aG.min))}if(aD==aC){aG.p2c=function(aH){return(aH-aB)*aF}}else{aG.p2c=function(aH){return(aD(aH)-aB)*aF}}if(!aE){aG.c2p=function(aH){return aB+aH/aF}}else{aG.c2p=function(aH){return aE(aB+aH/aF)}}}function L(aD){var aB=aD.options,aF,aJ=aD.ticks||[],aI=[],aE,aK=aB.labelWidth,aG=aB.labelHeight,aC;function aH(aM,aL){return c('").appendTo(av)}if(aD.direction=="x"){if(aK==null){aK=Math.floor(G/(aJ.length>0?aJ.length:1))}if(aG==null){aI=[];for(aF=0;aF'+aE+" ")}}if(aI.length>0){aI.push('
');aC=aH(aI,"width:10000px;");aG=aC.height();aC.remove()}}}else{if(aK==null||aG==null){for(aF=0;aF
'+aE+" ")}}if(aI.length>0){aC=aH(aI,"");if(aK==null){aK=aC.children().width()}if(aG==null){aG=aC.find("div.tickLabel").height()}aC.remove()}}}if(aK==null){aK=0}if(aG==null){aG=0}aD.labelWidth=aK;aD.labelHeight=aG}function au(aD){var aC=aD.labelWidth,aL=aD.labelHeight,aH=aD.options.position,aF=aD.options.tickLength,aG=O.grid.axisMargin,aJ=O.grid.labelMargin,aK=aD.direction=="x"?p:aw,aE;var aB=c.grep(aK,function(aN){return aN&&aN.options.position==aH&&aN.reserveSpace});if(c.inArray(aD,aB)==aB.length-1){aG=0}if(aF==null){aF="full"}var aI=c.grep(aK,function(aN){return aN&&aN.reserveSpace});var aM=c.inArray(aD,aI)==0;if(!aM&&aF=="full"){aF=5}if(!isNaN(+aF)){aJ+=+aF}if(aD.direction=="x"){aL+=aJ;if(aH=="bottom"){q.bottom+=aL+aG;aD.box={top:I-q.bottom,height:aL}}else{aD.box={top:q.top+aG,height:aL};q.top+=aL+aG}}else{aC+=aJ;if(aH=="left"){aD.box={left:q.left+aG,width:aC};q.left+=aC+aG}else{q.right+=aC+aG;aD.box={left:G-q.right,width:aC}}}aD.position=aH;aD.tickLength=aF;aD.box.padding=aJ;aD.innermost=aM}function U(aB){if(aB.direction=="x"){aB.box.left=q.left;aB.box.width=h}else{aB.box.top=q.top;aB.box.height=w}}function t(){var aC,aE=m();c.each(aE,function(aF,aG){aG.show=aG.options.show;if(aG.show==null){aG.show=aG.used}aG.reserveSpace=aG.show||aG.options.reserveSpace;n(aG)});allocatedAxes=c.grep(aE,function(aF){return aF.reserveSpace});q.left=q.right=q.top=q.bottom=0;if(O.grid.show){c.each(allocatedAxes,function(aF,aG){S(aG);P(aG);ap(aG,aG.ticks);L(aG)});for(aC=allocatedAxes.length-1;aC>=0;--aC){au(allocatedAxes[aC])}var aD=O.grid.minBorderMargin;if(aD==null){aD=0;for(aC=0;aC=0){aD=0}}if(aF.max==null){aB+=aH*aG;if(aB>0&&aE.datamax!=null&&aE.datamax<=0){aB=0}}}}aE.min=aD;aE.max=aB}function S(aG){var aM=aG.options;var aH;if(typeof aM.ticks=="number"&&aM.ticks>0){aH=aM.ticks}else{aH=0.3*Math.sqrt(aG.direction=="x"?G:I)}var aT=(aG.max-aG.min)/aH,aO,aB,aN,aR,aS,aQ,aI;if(aM.mode=="time"){var aJ={second:1000,minute:60*1000,hour:60*60*1000,day:24*60*60*1000,month:30*24*60*60*1000,year:365.2425*24*60*60*1000};var aK=[[1,"second"],[2,"second"],[5,"second"],[10,"second"],[30,"second"],[1,"minute"],[2,"minute"],[5,"minute"],[10,"minute"],[30,"minute"],[1,"hour"],[2,"hour"],[4,"hour"],[8,"hour"],[12,"hour"],[1,"day"],[2,"day"],[3,"day"],[0.25,"month"],[0.5,"month"],[1,"month"],[2,"month"],[3,"month"],[6,"month"],[1,"year"]];var aC=0;if(aM.minTickSize!=null){if(typeof aM.tickSize=="number"){aC=aM.tickSize}else{aC=aM.minTickSize[0]*aJ[aM.minTickSize[1]]}}for(var aS=0;aS=aC){break}}aO=aK[aS][0];aN=aK[aS][1];if(aN=="year"){aQ=Math.pow(10,Math.floor(Math.log(aT/aJ.year)/Math.LN10));aI=(aT/aJ.year)/aQ;if(aI<1.5){aO=1}else{if(aI<3){aO=2}else{if(aI<7.5){aO=5}else{aO=10}}}aO*=aQ}aG.tickSize=aM.tickSize||[aO,aN];aB=function(aX){var a2=[],a0=aX.tickSize[0],a3=aX.tickSize[1],a1=new Date(aX.min);var aW=a0*aJ[a3];if(a3=="second"){a1.setUTCSeconds(a(a1.getUTCSeconds(),a0))}if(a3=="minute"){a1.setUTCMinutes(a(a1.getUTCMinutes(),a0))}if(a3=="hour"){a1.setUTCHours(a(a1.getUTCHours(),a0))}if(a3=="month"){a1.setUTCMonth(a(a1.getUTCMonth(),a0))}if(a3=="year"){a1.setUTCFullYear(a(a1.getUTCFullYear(),a0))}a1.setUTCMilliseconds(0);if(aW>=aJ.minute){a1.setUTCSeconds(0)}if(aW>=aJ.hour){a1.setUTCMinutes(0)}if(aW>=aJ.day){a1.setUTCHours(0)}if(aW>=aJ.day*4){a1.setUTCDate(1)}if(aW>=aJ.year){a1.setUTCMonth(0)}var a5=0,a4=Number.NaN,aY;do{aY=a4;a4=a1.getTime();a2.push(a4);if(a3=="month"){if(a0<1){a1.setUTCDate(1);var aV=a1.getTime();a1.setUTCMonth(a1.getUTCMonth()+1);var aZ=a1.getTime();a1.setTime(a4+a5*aJ.hour+(aZ-aV)*a0);a5=a1.getUTCHours();a1.setUTCHours(0)}else{a1.setUTCMonth(a1.getUTCMonth()+a0)}}else{if(a3=="year"){a1.setUTCFullYear(a1.getUTCFullYear()+a0)}else{a1.setTime(a4+aW)}}}while(a4aU){aP=aU}aQ=Math.pow(10,-aP);aI=aT/aQ;if(aI<1.5){aO=1}else{if(aI<3){aO=2;if(aI>2.25&&(aU==null||aP+1<=aU)){aO=2.5;++aP}}else{if(aI<7.5){aO=5}else{aO=10}}}aO*=aQ;if(aM.minTickSize!=null&&aO0){if(aM.min==null){aG.min=Math.min(aG.min,aL[0])}if(aM.max==null&&aL.length>1){aG.max=Math.max(aG.max,aL[aL.length-1])}}aB=function(aX){var aY=[],aV,aW;for(aW=0;aW1&&/\..*0$/.test((aD[1]-aD[0]).toFixed(aE)))){aG.tickDecimals=aE}}}}aG.tickGenerator=aB;if(c.isFunction(aM.tickFormatter)){aG.tickFormatter=function(aV,aW){return""+aM.tickFormatter(aV,aW)}}else{aG.tickFormatter=aR}}function P(aF){var aH=aF.options.ticks,aG=[];if(aH==null||(typeof aH=="number"&&aH>0)){aG=aF.tickGenerator(aF)}else{if(aH){if(c.isFunction(aH)){aG=aH({min:aF.min,max:aF.max})}else{aG=aH}}}var aE,aB;aF.ticks=[];for(aE=0;aE1){aC=aD[1]}}else{aB=+aD}if(aC==null){aC=aF.tickFormatter(aB,aF)}if(!isNaN(aB)){aF.ticks.push({v:aB,label:aC})}}}function ap(aB,aC){if(aB.options.autoscaleMargin&&aC.length>0){if(aB.options.min==null){aB.min=Math.min(aB.min,aC[0].v)}if(aB.options.max==null&&aC.length>1){aB.max=Math.max(aB.max,aC[aC.length-1].v)}}}function W(){H.clearRect(0,0,G,I);var aC=O.grid;if(aC.show&&aC.backgroundColor){N()}if(aC.show&&!aC.aboveData){ac()}for(var aB=0;aBaG){var aC=aH;aH=aG;aG=aC}return{from:aH,to:aG,axis:aE}}function N(){H.save();H.translate(q.left,q.top);H.fillStyle=am(O.grid.backgroundColor,w,0,"rgba(255, 255, 255, 0)");H.fillRect(0,0,h,w);H.restore()}function ac(){var aF;H.save();H.translate(q.left,q.top);var aH=O.grid.markings;if(aH){if(c.isFunction(aH)){var aK=aq.getAxes();aK.xmin=aK.xaxis.min;aK.xmax=aK.xaxis.max;aK.ymin=aK.yaxis.min;aK.ymax=aK.yaxis.max;aH=aH(aK)}for(aF=0;aFaC.axis.max||aI.toaI.axis.max){continue}aC.from=Math.max(aC.from,aC.axis.min);aC.to=Math.min(aC.to,aC.axis.max);aI.from=Math.max(aI.from,aI.axis.min);aI.to=Math.min(aI.to,aI.axis.max);if(aC.from==aC.to&&aI.from==aI.to){continue}aC.from=aC.axis.p2c(aC.from);aC.to=aC.axis.p2c(aC.to);aI.from=aI.axis.p2c(aI.from);aI.to=aI.axis.p2c(aI.to);if(aC.from==aC.to||aI.from==aI.to){H.beginPath();H.strokeStyle=aD.color||O.grid.markingsColor;H.lineWidth=aD.lineWidth||O.grid.markingsLineWidth;H.moveTo(aC.from,aI.from);H.lineTo(aC.to,aI.to);H.stroke()}else{H.fillStyle=aD.color||O.grid.markingsColor;H.fillRect(aC.from,aI.to,aC.to-aC.from,aI.from-aI.to)}}}var aK=m(),aM=O.grid.borderWidth;for(var aE=0;aEaB.max||(aQ=="full"&&aM>0&&(aO==aB.min||aO==aB.max))){continue}if(aB.direction=="x"){aN=aB.p2c(aO);aJ=aQ=="full"?-w:aQ;if(aB.position=="top"){aJ=-aJ}}else{aL=aB.p2c(aO);aP=aQ=="full"?-h:aQ;if(aB.position=="left"){aP=-aP}}if(H.lineWidth==1){if(aB.direction=="x"){aN=Math.floor(aN)+0.5}else{aL=Math.floor(aL)+0.5}}H.moveTo(aN,aL);H.lineTo(aN+aP,aL+aJ)}H.stroke()}if(aM){H.lineWidth=aM;H.strokeStyle=O.grid.borderColor;H.strokeRect(-aM/2,-aM/2,h+aM,w+aM)}H.restore()}function k(){av.find(".tickLabels").remove();var aG=[''];var aJ=m();for(var aD=0;aD
');for(var aE=0;aEaC.max){continue}var aK={},aI;if(aC.direction=="x"){aI="center";aK.left=Math.round(q.left+aC.p2c(aH.v)-aC.labelWidth/2);if(aC.position=="bottom"){aK.top=aF.top+aF.padding}else{aK.bottom=I-(aF.top+aF.height-aF.padding)}}else{aK.top=Math.round(q.top+aC.p2c(aH.v)-aC.labelHeight/2);if(aC.position=="left"){aK.right=G-(aF.left+aF.width-aF.padding);aI="right"}else{aK.left=aF.left+aF.padding;aI="left"}}aK.width=aC.labelWidth;var aB=["position:absolute","text-align:"+aI];for(var aL in aK){aB.push(aL+":"+aK[aL]+"px")}aG.push(''+aH.label+"
")}aG.push(" ")}aG.push("");av.append(aG.join(""))}function d(aB){if(aB.lines.show){at(aB)}if(aB.bars.show){e(aB)}if(aB.points.show){ao(aB)}}function at(aE){function aD(aP,aQ,aI,aU,aT){var aV=aP.points,aJ=aP.pointsize,aN=null,aM=null;H.beginPath();for(var aO=aJ;aO=aR&&aS>aT.max){if(aR>aT.max){continue}aL=(aT.max-aS)/(aR-aS)*(aK-aL)+aL;aS=aT.max}else{if(aR>=aS&&aR>aT.max){if(aS>aT.max){continue}aK=(aT.max-aS)/(aR-aS)*(aK-aL)+aL;aR=aT.max}}if(aL<=aK&&aL=aK&&aL>aU.max){if(aK>aU.max){continue}aS=(aU.max-aL)/(aK-aL)*(aR-aS)+aS;aL=aU.max}else{if(aK>=aL&&aK>aU.max){if(aL>aU.max){continue}aR=(aU.max-aL)/(aK-aL)*(aR-aS)+aS;aK=aU.max}}if(aL!=aN||aS!=aM){H.moveTo(aU.p2c(aL)+aQ,aT.p2c(aS)+aI)}aN=aK;aM=aR;H.lineTo(aU.p2c(aK)+aQ,aT.p2c(aR)+aI)}H.stroke()}function aF(aI,aQ,aP){var aW=aI.points,aV=aI.pointsize,aN=Math.min(Math.max(0,aP.min),aP.max),aX=0,aU,aT=false,aM=1,aL=0,aR=0;while(true){if(aV>0&&aX>aW.length+aV){break}aX+=aV;var aZ=aW[aX-aV],aK=aW[aX-aV+aM],aY=aW[aX],aJ=aW[aX+aM];if(aT){if(aV>0&&aZ!=null&&aY==null){aR=aX;aV=-aV;aM=2;continue}if(aV<0&&aX==aL+aV){H.fill();aT=false;aV=-aV;aM=1;aX=aL=aR+aV;continue}}if(aZ==null||aY==null){continue}if(aZ<=aY&&aZ=aY&&aZ>aQ.max){if(aY>aQ.max){continue}aK=(aQ.max-aZ)/(aY-aZ)*(aJ-aK)+aK;aZ=aQ.max}else{if(aY>=aZ&&aY>aQ.max){if(aZ>aQ.max){continue}aJ=(aQ.max-aZ)/(aY-aZ)*(aJ-aK)+aK;aY=aQ.max}}if(!aT){H.beginPath();H.moveTo(aQ.p2c(aZ),aP.p2c(aN));aT=true}if(aK>=aP.max&&aJ>=aP.max){H.lineTo(aQ.p2c(aZ),aP.p2c(aP.max));H.lineTo(aQ.p2c(aY),aP.p2c(aP.max));continue}else{if(aK<=aP.min&&aJ<=aP.min){H.lineTo(aQ.p2c(aZ),aP.p2c(aP.min));H.lineTo(aQ.p2c(aY),aP.p2c(aP.min));continue}}var aO=aZ,aS=aY;if(aK<=aJ&&aK=aP.min){aZ=(aP.min-aK)/(aJ-aK)*(aY-aZ)+aZ;aK=aP.min}else{if(aJ<=aK&&aJ=aP.min){aY=(aP.min-aK)/(aJ-aK)*(aY-aZ)+aZ;aJ=aP.min}}if(aK>=aJ&&aK>aP.max&&aJ<=aP.max){aZ=(aP.max-aK)/(aJ-aK)*(aY-aZ)+aZ;aK=aP.max}else{if(aJ>=aK&&aJ>aP.max&&aK<=aP.max){aY=(aP.max-aK)/(aJ-aK)*(aY-aZ)+aZ;aJ=aP.max}}if(aZ!=aO){H.lineTo(aQ.p2c(aO),aP.p2c(aK))}H.lineTo(aQ.p2c(aZ),aP.p2c(aK));H.lineTo(aQ.p2c(aY),aP.p2c(aJ));if(aY!=aS){H.lineTo(aQ.p2c(aY),aP.p2c(aJ));H.lineTo(aQ.p2c(aS),aP.p2c(aJ))}}}H.save();H.translate(q.left,q.top);H.lineJoin="round";var aG=aE.lines.lineWidth,aB=aE.shadowSize;if(aG>0&&aB>0){H.lineWidth=aB;H.strokeStyle="rgba(0,0,0,0.1)";var aH=Math.PI/18;aD(aE.datapoints,Math.sin(aH)*(aG/2+aB/2),Math.cos(aH)*(aG/2+aB/2),aE.xaxis,aE.yaxis);H.lineWidth=aB/2;aD(aE.datapoints,Math.sin(aH)*(aG/2+aB/4),Math.cos(aH)*(aG/2+aB/4),aE.xaxis,aE.yaxis)}H.lineWidth=aG;H.strokeStyle=aE.color;var aC=ae(aE.lines,aE.color,0,w);if(aC){H.fillStyle=aC;aF(aE.datapoints,aE.xaxis,aE.yaxis)}if(aG>0){aD(aE.datapoints,0,0,aE.xaxis,aE.yaxis)}H.restore()}function ao(aE){function aH(aN,aM,aU,aK,aS,aT,aQ,aJ){var aR=aN.points,aI=aN.pointsize;for(var aL=0;aLaT.max||aOaQ.max){continue}H.beginPath();aP=aT.p2c(aP);aO=aQ.p2c(aO)+aK;if(aJ=="circle"){H.arc(aP,aO,aM,0,aS?Math.PI:Math.PI*2,false)}else{aJ(H,aP,aO,aM,aS)}H.closePath();if(aU){H.fillStyle=aU;H.fill()}H.stroke()}}H.save();H.translate(q.left,q.top);var aG=aE.points.lineWidth,aC=aE.shadowSize,aB=aE.points.radius,aF=aE.points.symbol;if(aG>0&&aC>0){var aD=aC/2;H.lineWidth=aD;H.strokeStyle="rgba(0,0,0,0.1)";aH(aE.datapoints,aB,null,aD+aD/2,true,aE.xaxis,aE.yaxis,aF);H.strokeStyle="rgba(0,0,0,0.2)";aH(aE.datapoints,aB,null,aD/2,true,aE.xaxis,aE.yaxis,aF)}H.lineWidth=aG;H.strokeStyle=aE.color;aH(aE.datapoints,aB,ae(aE.points,aE.color),0,false,aE.xaxis,aE.yaxis,aF);H.restore()}function E(aN,aM,aV,aI,aQ,aF,aD,aL,aK,aU,aR,aC){var aE,aT,aJ,aP,aG,aB,aO,aH,aS;if(aR){aH=aB=aO=true;aG=false;aE=aV;aT=aN;aP=aM+aI;aJ=aM+aQ;if(aTaL.max||aPaK.max){return}if(aEaL.max){aT=aL.max;aB=false}if(aJaK.max){aP=aK.max;aO=false}aE=aL.p2c(aE);aJ=aK.p2c(aJ);aT=aL.p2c(aT);aP=aK.p2c(aP);if(aD){aU.beginPath();aU.moveTo(aE,aJ);aU.lineTo(aE,aP);aU.lineTo(aT,aP);aU.lineTo(aT,aJ);aU.fillStyle=aD(aJ,aP);aU.fill()}if(aC>0&&(aG||aB||aO||aH)){aU.beginPath();aU.moveTo(aE,aJ+aF);if(aG){aU.lineTo(aE,aP+aF)}else{aU.moveTo(aE,aP+aF)}if(aO){aU.lineTo(aT,aP+aF)}else{aU.moveTo(aT,aP+aF)}if(aB){aU.lineTo(aT,aJ+aF)}else{aU.moveTo(aT,aJ+aF)}if(aH){aU.lineTo(aE,aJ+aF)}else{aU.moveTo(aE,aJ+aF)}aU.stroke()}}function e(aD){function aC(aJ,aI,aL,aG,aK,aN,aM){var aO=aJ.points,aF=aJ.pointsize;for(var aH=0;aH")}aH.push("");aF=true}if(aN){aJ=aN(aJ,aM)}aH.push(''+aJ+" ")}if(aF){aH.push(" ")}if(aH.length==0){return}var aL='";if(O.legend.container!=null){c(O.legend.container).html(aL)}else{var aI="",aC=O.legend.position,aD=O.legend.margin;if(aD[0]==null){aD=[aD,aD]}if(aC.charAt(0)=="n"){aI+="top:"+(aD[1]+q.top)+"px;"}else{if(aC.charAt(0)=="s"){aI+="bottom:"+(aD[1]+q.bottom)+"px;"}}if(aC.charAt(1)=="e"){aI+="right:"+(aD[0]+q.right)+"px;"}else{if(aC.charAt(1)=="w"){aI+="left:"+(aD[0]+q.left)+"px;"}}var aK=c(''+aL.replace('style="','style="position:absolute;'+aI+";")+"
").appendTo(av);if(O.legend.backgroundOpacity!=0){var aG=O.legend.backgroundColor;if(aG==null){aG=O.grid.backgroundColor;if(aG&&typeof aG=="string"){aG=c.color.parse(aG)}else{aG=c.color.extract(aK,"background-color")}aG.a=1;aG=aG.toString()}var aB=aK.children();c('
').prependTo(aK).css("opacity",O.legend.backgroundOpacity)}}}var ab=[],M=null;function K(aI,aG,aD){var aO=O.grid.mouseActiveRadius,a0=aO*aO+1,aY=null,aR=false,aW,aU;for(aW=Q.length-1;aW>=0;--aW){if(!aD(Q[aW])){continue}var aP=Q[aW],aH=aP.xaxis,aF=aP.yaxis,aV=aP.datapoints.points,aT=aP.datapoints.pointsize,aQ=aH.c2p(aI),aN=aF.c2p(aG),aC=aO/aH.scale,aB=aO/aF.scale;if(aH.options.inverseTransform){aC=Number.MAX_VALUE}if(aF.options.inverseTransform){aB=Number.MAX_VALUE}if(aP.lines.show||aP.points.show){for(aU=0;aUaC||aK-aQ<-aC||aJ-aN>aB||aJ-aN<-aB){continue}var aM=Math.abs(aH.p2c(aK)-aI),aL=Math.abs(aF.p2c(aJ)-aG),aS=aM*aM+aL*aL;if(aS=Math.min(aZ,aK)&&aN>=aJ+aE&&aN<=aJ+aX):(aQ>=aK+aE&&aQ<=aK+aX&&aN>=Math.min(aZ,aJ)&&aN<=Math.max(aZ,aJ))){aY=[aW,aU/aT]}}}}if(aY){aW=aY[0];aU=aY[1];aT=Q[aW].datapoints.pointsize;return{datapoint:Q[aW].datapoints.points.slice(aU*aT,(aU+1)*aT),dataIndex:aU,series:Q[aW],seriesIndex:aW}}return null}function aa(aB){if(O.grid.hoverable){u("plothover",aB,function(aC){return aC.hoverable!=false})}}function l(aB){if(O.grid.hoverable){u("plothover",aB,function(aC){return false})}}function R(aB){u("plotclick",aB,function(aC){return aC.clickable!=false})}function u(aC,aB,aD){var aE=y.offset(),aH=aB.pageX-aE.left-q.left,aF=aB.pageY-aE.top-q.top,aJ=C({left:aH,top:aF});aJ.pageX=aB.pageX;aJ.pageY=aB.pageY;var aK=K(aH,aF,aD);if(aK){aK.pageX=parseInt(aK.series.xaxis.p2c(aK.datapoint[0])+aE.left+q.left);aK.pageY=parseInt(aK.series.yaxis.p2c(aK.datapoint[1])+aE.top+q.top)}if(O.grid.autoHighlight){for(var aG=0;aGaH.max||aIaG.max){return}var aF=aE.points.radius+aE.points.lineWidth/2;A.lineWidth=aF;A.strokeStyle=c.color.parse(aE.color).scale("a",0.5).toString();var aB=1.5*aF,aC=aH.p2c(aC),aI=aG.p2c(aI);A.beginPath();if(aE.points.symbol=="circle"){A.arc(aC,aI,aB,0,2*Math.PI,false)}else{aE.points.symbol(A,aC,aI,aB,false)}A.closePath();A.stroke()}function v(aE,aB){A.lineWidth=aE.bars.lineWidth;A.strokeStyle=c.color.parse(aE.color).scale("a",0.5).toString();var aD=c.color.parse(aE.color).scale("a",0.5).toString();var aC=aE.bars.align=="left"?0:-aE.bars.barWidth/2;E(aB[0],aB[1],aB[2]||0,aC,aC+aE.bars.barWidth,0,function(){return aD},aE.xaxis,aE.yaxis,A,aE.bars.horizontal,aE.bars.lineWidth)}function am(aJ,aB,aH,aC){if(typeof aJ=="string"){return aJ}else{var aI=H.createLinearGradient(0,aH,0,aB);for(var aE=0,aD=aJ.colors.length;aE12){n=n-12}else{if(n==0){n=12}}}for(var g=0;g