0
13 | "
14 |
15 | ncf.x_filter <- function(x, df1, df2, ncp) {
16 | if (df1 == 1) {
17 | x <- x[x != 0]
18 | }
19 | return(x)
20 | }
21 |
22 | ## Moments ----
23 | ncf.mean <- function(df1, df2, ncp) {
24 | if (is.null(df2) || df2 <= 2) {
25 | value <- NULL
26 | } else {
27 | value <- (df2 * (df1 + ncp)) / (df1 * (df2 - 2))
28 | }
29 | return(value)
30 | }
31 | ncf.mean_str <- "\\frac{\\nu_2(\\nu_1 + \\lambda)}{\\nu_1(\\nu_2-2)}"
32 |
33 | ncf.variance <- function(df1, df2, ncp) {
34 | if (is.null(df2) || df2 <= 4) {
35 | value <- NULL
36 | } else {
37 | value <-
38 | (2 * df2 ** 2 * (((df1 + ncp) ** 2) + (df1 + 2 * ncp) * (df2 - 2))) /
39 | (df1 ** 2 * (df2 - 2) ** 2 * (df2 - 4))
40 | }
41 | return(value)
42 | }
43 | ncf.variance_str <- "2\\frac{(\\nu_1+\\lambda)^2+(\\nu_1+2\\lambda)(\\nu_2-2)}{(\\nu_2-2)^2(\\nu_2-4)} \\left(\\frac{\\nu_2}{\\nu_1}\\right)^2"
44 |
45 | ## Parameters ----
46 | ncf.range <- list(
47 | min = 0,
48 | max = 100,
49 | value = c(0, 20),
50 | step = 0.5
51 | )
52 | ncf.df1 <- list(
53 | name = "df1",
54 | label_name = "Degrees of freedom",
55 | label_symbol = "\\nu_1",
56 | min = 1,
57 | max = 20,
58 | value = 1
59 | )
60 | ncf.df2 <- list(
61 | name = "df2",
62 | label_name = "Degrees of freedom",
63 | label_symbol = "\\nu_2",
64 | min = 1,
65 | max = 20,
66 | value = 1
67 | )
68 | ncf.ncp <- list(
69 | name = "ncp",
70 | label_name = "Noncentrality parameter",
71 | label_symbol = "\\lambda",
72 | min = 0,
73 | max = 20,
74 | value = 0,
75 | step = 0.1
76 | )
77 |
78 | ## Instance ----
79 | ncf <- Distribution$new(
80 | dist = "ncf",
81 | name = "Noncentral F-distribution",
82 | wiki = "https://en.wikipedia.org/wiki/Noncentral_F-distribution",
83 | c_or_d = "c",
84 | func_p = ncf.func_p,
85 | func_c = ncf.func_c,
86 | formula = ncf.formula,
87 | x_filter = ncf.x_filter,
88 | mean = ncf.mean,
89 | mean_str = ncf.mean_str,
90 | variance = ncf.variance,
91 | variance_str = ncf.variance_str,
92 | range = ncf.range,
93 | ncf.df1,
94 | ncf.df2,
95 | ncf.ncp
96 | )
97 |
--------------------------------------------------------------------------------
/distributions/continuous/Noncentral_beta.R:
--------------------------------------------------------------------------------
1 | library(hypergeo)
2 | # 非心ベータ分布 ----
3 | ## functions ----
4 | ncbeta.func_p <- function(shape1, shape2, ncp) function(x) dbeta(x, shape1 = shape1, shape2 = shape2, ncp = ncp)
5 | ncbeta.func_c <- function(shape1, shape2, ncp) function(x) pbeta(x, shape1 = shape1, shape2 = shape2, ncp = ncp)
6 | ncbeta.formula <- "
7 | f(x) = \\sum_{j=0}^\\infty \\frac{1}{j!}
8 | \\left(\\frac{\\lambda}{2}\\right)^je^{-\\lambda/2}
9 | \\frac{x^{\\alpha+j-1}(1-x)^{\\beta-1}}{B(\\alpha+j,\\beta)}
10 | "
11 |
12 | ncbeta.x_filter <- function(x, shape1, shape2, ncp) {
13 | if (shape1 < 1) {
14 | x <- x[x != 0]
15 | }
16 | if (shape2 < 1) {
17 | x <- x[x != 1]
18 | }
19 | return(x)
20 | }
21 |
22 | ## Moments ----
23 | ncbeta.mean <- function(shape1, shape2, ncp) {
24 | value <- exp(-ncp / 2) *
25 | shape1 *
26 | hypergeo::genhypergeo(
27 | U = c(shape1 + 1, shape1 + shape2),
28 | L = c(shape1, 1 + shape1 + shape2),
29 | z = ncp / 2
30 | ) /
31 | (shape1 + shape2)
32 | return(value)
33 | }
34 | ncbeta.mean_str <- "
35 | e^{-\\frac{\\lambda}{2}}
36 | \\frac{\\alpha}{\\alpha+\\beta}
37 | {}_2F_2\\left(\\alpha+\\beta,\\alpha+1;\\alpha,\\alpha+\\beta+1;\\frac{\\lambda}{2}
38 | \\right)
39 | "
40 |
41 | ncbeta.variance <- function(shape1, shape2, ncp) {
42 | value.mean <- ncbeta.mean(shape1, shape2, ncp)
43 | value <- exp(-ncp / 2) *
44 | shape1 *
45 | (shape1 + 1) *
46 | hypergeo::genhypergeo(
47 | U = c(shape1 + 1, shape1 + shape2),
48 | L = c(shape1, 1 + shape1 + shape2),
49 | z = ncp / 2
50 | ) /
51 | ((shape1 + shape2) * (shape1 + shape2 + 1)) -
52 | value.mean ** 2
53 | return(value)
54 | }
55 | ncbeta.variance_str <- "
56 | e^{-\\frac{\\lambda}{2}}
57 | \\frac{\\alpha (\\alpha+1)}{(\\alpha+\\beta)(\\alpha+\\beta+1)}
58 | {}_2F_2\\left(\\alpha+\\beta,\\alpha+2;\\alpha,\\alpha+\\beta+2
59 | ;\\frac{\\lambda}{2}\\right) - \\mu^2
60 | "
61 |
62 | ## Parameters ----
63 | ncbeta.range <- list(
64 | min = 0,
65 | max = 1,
66 | value = c(0, 1),
67 | step = 0.01
68 | )
69 | ncbeta.shape1 <- list(
70 | name = "shape1",
71 | label = "形状 \\(\\alpha\\)",
72 | label_name = "Shape",
73 | label_symbol = "\\alpha",
74 | min = 0,
75 | max = 20,
76 | value = 2,
77 | step = 0.1
78 | )
79 | ncbeta.shape2 <- list(
80 | name = "shape2",
81 | label = "形状 \\(\\beta\\)",
82 | label_name = "Shape",
83 | label_symbol = "\\beta",
84 | min = 0,
85 | max = 20,
86 | value = 2,
87 | step = 0.1
88 | )
89 | ncbeta.ncp <- list(
90 | name = "ncp",
91 | label_name = "Noncentrality parameter",
92 | label_symbol = "\\lambda",
93 | min = 0,
94 | max = 20,
95 | value = 0,
96 | step = 0.1
97 | )
98 |
99 | ## Instance ----
100 | ncbeta <- Distribution$new(
101 | dist = "ncbeta",
102 | name = "Noncentral beta distribution",
103 | wiki = "https://en.wikipedia.org/wiki/Noncentral_beta_distribution",
104 | c_or_d = "c",
105 | func_p = ncbeta.func_p,
106 | func_c = ncbeta.func_c,
107 | formula = ncbeta.formula,
108 | x_filter = ncbeta.x_filter,
109 | mean = ncbeta.mean,
110 | mean_str = ncbeta.mean_str,
111 | variance = ncbeta.variance,
112 | variance_str = ncbeta.variance_str,
113 | range = ncbeta.range,
114 | ncbeta.shape1,
115 | ncbeta.shape2,
116 | ncbeta.ncp
117 | )
118 |
--------------------------------------------------------------------------------
/distributions/continuous/Noncentral_chi-squared.R:
--------------------------------------------------------------------------------
1 | # 非心カイ二乗分布
2 | ncChisq.func <- function(df, ncp, p_or_c) {
3 | if (p_or_c == "p") {
4 | func <- function(x) dchisq(x, df = df, ncp = ncp)
5 | } else {
6 | func <- function(x) pchisq(x, df = df, ncp = ncp)
7 | }
8 | return(func)
9 | }
10 | ## Functions ----
11 | ncChisq.func_p <- function(df, ncp) function(x) dchisq(x, df = df, ncp = ncp)
12 | ncChisq.func_c <- function(df, ncp) function(x) pchisq(x, df = df, ncp = ncp)
13 | ncChisq.formula <- "f_X(x; k,\\lambda) =
14 | \\sum_{i=0}^\\infty \\frac{e^{-\\lambda/2} (\\lambda/2)^i}{i!} f_{Y_{k+2i}}(x),
15 | \\ \\ \\ \\ \\mathrm{for\\ } x > 0,\\ \\ Y_q \\sim\\chi^2_q \\
16 | "
17 |
18 | ncChisq.x_filter <- function(x, df, ncp) {
19 | if (df == 1) {
20 | x <- x[x != 0]
21 | }
22 | return(x)
23 | }
24 |
25 | ## Moments ----
26 | ncChisq.mean <- function(df, ncp) df + ncp
27 | ncChisq.mean_str <- "k+\\lambda"
28 | ncChisq.variance <- function(df, ncp) 2 * (df + 2 * ncp)
29 | ncChisq.variance_str <- "2(k+2\\lambda)"
30 |
31 | ## Parameters ----
32 | ncChisq.range <- list(
33 | min = 0,
34 | max = 100,
35 | value = c(0, 20),
36 | step = 0.5
37 | )
38 | ncChisq.df <- list(
39 | name = "df",
40 | label_name = "Degrees of freedom",
41 | label_symbol = "k",
42 | min = 1,
43 | max = 20,
44 | value = 1
45 | )
46 | ncChisq.ncp <- list(
47 | name = "ncp",
48 | label_name = "Noncentrality parameter",
49 | label_symbol = "\\lambda",
50 | min = 0,
51 | max = 20,
52 | value = 0,
53 | step = 0.1
54 | )
55 |
56 | ## Instance ----
57 | ncChisq <- Distribution$new(
58 | dist = "ncChisq",
59 | name = "Noncentral chi-squared distribution",
60 | wiki = "https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution",
61 | c_or_d = "c",
62 | func_p = ncChisq.func_p,
63 | func_c = ncChisq.func_c,
64 | formula = ncChisq.formula,
65 | x_filter = ncChisq.x_filter,
66 | mean = ncChisq.mean,
67 | mean_str = ncChisq.mean_str,
68 | variance = ncChisq.variance,
69 | variance_str = ncChisq.variance_str,
70 | range = ncChisq.range,
71 | ncChisq.df,
72 | ncChisq.ncp
73 | )
74 |
--------------------------------------------------------------------------------
/distributions/continuous/Noncentral_t.R:
--------------------------------------------------------------------------------
1 | # 非心t分布
2 | ## Functions ----
3 | nct.func_p <- function(df, ncp) function(x) dt(x, df = df, ncp = ncp)
4 | nct.func_c <- function(df, ncp) function(x) pt(x, df = df, ncp = ncp)
5 | nct.formula <- "
6 | f(x) =\\frac{\\nu^{\\frac{\\nu}{2}}
7 | \\exp\\left (-\\frac{\\nu\\mu^2}{2(x^2+\\nu)} \\right )}
8 | {\\sqrt{\\pi}\\Gamma(\\frac{\\nu}{2})2^{\\frac{\\nu-1}{2}}(x^2+\\nu)^{\\frac{\\nu+1}{2}}}
9 | \\int_0^\\infty y^\\nu\\exp\\left (-\\frac{1}{2}\\left(y-\\frac{\\mu x}{\\sqrt{x^2+\\nu}}
10 | \\right)^2\\right ) dy
11 | "
12 |
13 | nct.x_filter <- NULL
14 |
15 | ## Moments ----
16 | nct.mean <- function(df, ncp) {
17 | if (is.null(df) || df <= 1) {
18 | value <- NULL
19 | } else {
20 | value <- ncp * sqrt(df / 2) * gamma((df - 1) / 2) / gamma(df / 2)
21 | }
22 | return(value)
23 | }
24 | nct.mean_str <- "\\mu\\sqrt{\\frac{\\nu}{2}}\\frac{\\Gamma((\\nu-1)/2)}{\\Gamma(\\nu/2)}"
25 | nct.variance <- function(df, ncp) {
26 | if (is.null(df) || df <= 2) {
27 | value <- NULL
28 | } else {
29 | value <- (df * (1 + ncp ** 2)) / (df - 2) -
30 | ((ncp ** 2) * df / 2) * ((gamma((df - 1) / 2) / gamma(df / 2)) ** 2)
31 | }
32 | return(value)
33 | }
34 | nct.variance_str <- "\\frac{\\nu(1+\\mu^2)}{\\nu-2}-\\frac{\\mu^2\\nu}{2}\\left(\\frac{\\Gamma((\\nu-1)/2)}{\\Gamma(\\nu/2)}\\right)^2"
35 |
36 | ## Parameters ----
37 | nct.range <- list(
38 | min = -100,
39 | max = 100,
40 | value = c(-10, 10),
41 | step = 0.5
42 | )
43 | nct.df <- list(
44 | name = "df",
45 | label_name = "Degrees of freedom",
46 | label_symbol = "\\nu",
47 | min = 1,
48 | max = 20,
49 | value = 1
50 | )
51 | nct.ncp <- list(
52 | name = "ncp",
53 | label_name = "Noncentrality parameter",
54 | label_symbol = "\\mu",
55 | min = 0,
56 | max = 20,
57 | value = 0,
58 | step = 0.1
59 | )
60 |
61 | ## Instance ----
62 | nct <- Distribution$new(
63 | dist = "nct",
64 | name = "Noncentral t-distribution",
65 | wiki = "https://en.wikipedia.org/wiki/Noncentral_t-distribution",
66 | c_or_d = "c",
67 | formula = nct.formula,
68 | func_p = nct.func_p,
69 | func_c = nct.func_c,
70 | x_filter = nct.x_filter,
71 | mean = nct.mean,
72 | mean_str = nct.mean_str,
73 | variance = nct.variance,
74 | variance_str = nct.variance_str,
75 | range = nct.range,
76 | nct.df,
77 | nct.ncp
78 | )
79 |
--------------------------------------------------------------------------------
/distributions/continuous/Normal.R:
--------------------------------------------------------------------------------
1 | # 正規分布 ----
2 | ## Functions ----
3 | norm.func_p <- function(mean, sd) function(x) dnorm(x, mean = mean, sd = sd)
4 | norm.func_c <- function(mean, sd) function(x) pnorm(x, mean = mean, sd = sd)
5 | norm.formula <- "f(x)=\\frac{1}{\\sqrt{2\\pi\\sigma^{2}}}\\exp\\!\\left(-\\frac{(x-\\mu)^2}{2\\sigma^2} \\right)"
6 |
7 | norm.x_filter <- NULL
8 |
9 | ## Moments ----
10 | norm.mean <- function(mean, sd) mean
11 | norm.mean_str <- "\\mu"
12 | norm.variance <- function(mean, sd) sd ** 2
13 | norm.variance_str <- "\\sigma^2"
14 |
15 | ## Parameters ----
16 | norm.range <- list(
17 | min = -100,
18 | max = 100,
19 | value = c(-10, 10)
20 | )
21 | norm.meanParam <- list(
22 | name = "mean",
23 | label_name = "Mean",
24 | label_symbol = "\\mu",
25 | min = -50,
26 | max = 50,
27 | value = 0
28 | )
29 | norm.sd <- list(
30 | name = "sd",
31 | label_name = "Standard deviation",
32 | label_symbol = "\\sigma",
33 | min = 0,
34 | max = 10,
35 | value = 1,
36 | step = 0.5
37 | )
38 |
39 |
40 | ## Instance ----
41 | norm <- Distribution$new(
42 | dist = "norm",
43 | name = "Normal distribution",
44 | wiki = "https://en.wikipedia.org/wiki/Normal_distribution",
45 | c_or_d = "c",
46 | func_p = norm.func_p,
47 | func_c = norm.func_c,
48 | formula = norm.formula,
49 | x_filter = norm.x_filter,
50 | mean = norm.mean,
51 | mean_str = norm.mean_str,
52 | variance = norm.variance,
53 | variance_str = norm.variance_str,
54 | range = norm.range,
55 | norm.meanParam,
56 | norm.sd
57 | )
58 |
--------------------------------------------------------------------------------
/distributions/continuous/Uniform.R:
--------------------------------------------------------------------------------
1 | # 一様分布 ----
2 | ## functions ----
3 | unif.func_p <- function(min, max) function(x) dunif(x, min = min, max = max)
4 | unif.func_c <- function(min, max) function(x) punif(x, min = min, max = max)
5 | unif.formula <- "
6 | f(x)=\\begin{cases}
7 | \\frac{1}{b - a} & \\mathrm{for}\\ a \\le x \\le b, \\\\[8pt]
8 | 0 & \\mathrm{for}\\ xb
9 | \\end{cases}
10 | "
11 |
12 | unif.x_filter <- NULL
13 |
14 | ## Moments ----
15 | unif.mean <- function(min, max) (min + max) / 2
16 | unif.mean_str <- "\\frac{1}{2}(a+b)"
17 | unif.variance <- function(min, max) ((max - min) ** 2) / 12
18 | unif.variance_str <- "\\frac{1}{12}(b-a)^2"
19 |
20 | ## Parameters ----
21 | unif.range <- list(
22 | min = -50,
23 | max = 50,
24 | value = c(0, 1),
25 | step = 0.5
26 | )
27 | unif.min <- list(
28 | name = "min",
29 | label_name = "Min",
30 | label_symbol = "a",
31 | min = -50,
32 | max = 50,
33 | value = 0,
34 | step = 0.5
35 | )
36 | unif.max <- list(
37 | name = "max",
38 | label_name = "Max",
39 | label_symbol = "b",
40 | min = -50,
41 | max = 50,
42 | value = 1,
43 | step = 0.5
44 | )
45 |
46 | ## Instance ----
47 | unif <- Distribution$new(
48 | dist = "unif",
49 | name = "Uniform distribution (continuous)",
50 | wiki = "https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)",
51 | c_or_d = "c",
52 | formula = unif.formula,
53 | func_p = unif.func_p,
54 | func_c = unif.func_c,
55 | x_filter = unif.x_filter,
56 | mean = unif.mean,
57 | mean_str = unif.mean_str,
58 | variance = unif.variance,
59 | variance_str = unif.variance_str,
60 | range = unif.range,
61 | unif.min,
62 | unif.max
63 | )
64 |
--------------------------------------------------------------------------------
/distributions/continuous/Weibull.R:
--------------------------------------------------------------------------------
1 | # ワイブル分布 ----
2 | ## Functions ----
3 | weibull.func_p <- function(shape, scale) function(x) dweibull(x, shape = shape, scale = scale)
4 | weibull.func_c <- function(shape, scale) function(x) pweibull(x, shape = shape, scale = scale)
5 | weibull.formula <- "
6 | f(t)=\\frac{m}{\\eta}\\left(\\frac{t}{\\eta}\\right)^{m-1}
7 | \\exp \\left\\{-\\left(\\frac{t}{\\eta}\\right)^m\\right\\}
8 | "
9 |
10 | weibull.x_filter <- function(x, shape, scale) {
11 | if (shape < 1) {
12 | x <- x[x != 0]
13 | }
14 | return(x)
15 | }
16 |
17 | ## Moments ----
18 | weibull.mean <- function(shape, scale) scale * gamma(1 + 1 / shape)
19 | weibull.mean_str <- "\\eta \\Gamma(1+1/m)"
20 | weibull.variance <- function(shape, scale) {
21 | (scale ** 2) * (gamma(1 + 2 / shape) - gamma(1 + 1 / shape) ** 2)
22 | }
23 | weibull.variance_str <- "\\eta^2\\left[\\Gamma\\left(1+\\frac{2}{m}\\right) - \\left(\\Gamma\\left(1+\\frac{1}{m}\\right)\\right)^2\\right]"
24 |
25 | ## Parameters ----
26 | weibull.range <- list(
27 | min = 0,
28 | max = 100,
29 | value = c(0, 20),
30 | step = 0.5
31 | )
32 | weibull.shape <- list(
33 | name = "shape",
34 | label_name = "Shape",
35 | label_symbol = "m",
36 | min = 0.1,
37 | max = 20,
38 | value = 1,
39 | step = 0.1
40 | )
41 | weibull.scale <- list(
42 | name = "scale",
43 | label_name = "Scale",
44 | label_symbol = "\\eta",
45 | min = 0.1,
46 | max = 20,
47 | value = 1,
48 | step = 0.1
49 | )
50 |
51 | ## Instance ----
52 | weibull <- Distribution$new(
53 | dist = "weibull",
54 | name = "Weibull distribution",
55 | wiki = "https://en.wikipedia.org/wiki/Weibull_distribution",
56 | c_or_d = "c",
57 | func_p = weibull.func_p,
58 | func_c = weibull.func_c,
59 | formula = weibull.formula,
60 | x_filter = weibull.x_filter,
61 | mean = weibull.mean,
62 | mean_str = weibull.mean_str,
63 | variance = weibull.variance,
64 | variance_str = weibull.variance_str,
65 | range = weibull.range,
66 | weibull.shape,
67 | weibull.scale
68 | )
69 |
--------------------------------------------------------------------------------
/distributions/continuous/t.R:
--------------------------------------------------------------------------------
1 | # t分布 ----
2 | ## Functions ----
3 | t_dist.func_p <- function(df) function(x) dt(x, df = df, ncp = 0L)
4 | t_dist.func_c <- function(df) function(x) pt(x, df = df, ncp = 0L)
5 | t_dist.formula <- "
6 | f(x) = \\frac{\\Gamma((\\nu+1)/2)}{\\sqrt{\\nu\\pi\\,}\\,
7 | \\Gamma(\\nu/2)} (1+x^2/\\nu)^{-(\\nu+1)/2}
8 | "
9 |
10 | t_dist.x_filter <- NULL
11 |
12 | ## Moments ----
13 | t_dist.mean <- function(df) 0L
14 | t_dist.mean_str <- "e^{\\mu+\\sigma^2/2}"
15 | t_dist.variance <- function(df) {
16 | if (df <= 2) {
17 | return(Inf)
18 | } else {
19 | return(df / (df - 2))
20 | }
21 | }
22 | t_dist.variance_str <- "\\frac{\\nu}{\\nu-2}"
23 |
24 | ## Parameters ----
25 | t_dist.range <- list(
26 | min = -100,
27 | max = 100,
28 | value = c(-10, 10),
29 | step = 0.5
30 | )
31 | t_dist.df <- list(
32 | name = "df",
33 | label_name = "Degrees of freedom",
34 | label_symbol = "\\nu",
35 | min = 1,
36 | max = 20,
37 | value = 1
38 | )
39 |
40 | ## Instance ----
41 | t_dist <- Distribution$new(
42 | dist = "t_dist",
43 | name = "Student's t-distribution",
44 | wiki = "https://en.wikipedia.org/wiki/Student%27s_t-distribution",
45 | c_or_d = "c",
46 | formula = t_dist.formula,
47 | func_p = t_dist.func_p,
48 | func_c = t_dist.func_c,
49 | x_filter = t_dist.x_filter,
50 | mean = t_dist.mean,
51 | mean_str = t_dist.mean_str,
52 | variance = t_dist.variance,
53 | variance_str = t_dist.variance_str,
54 | range = t_dist.range,
55 | t_dist.df
56 | )
57 |
--------------------------------------------------------------------------------
/distributions/discrete/Binomial.R:
--------------------------------------------------------------------------------
1 | # 二項分布 ----
2 | ## Functions ----
3 | binom.func_p <- function(size, prob) function(x) dbinom(x, size = size, prob = prob)
4 | binom.func_c <- function(size, prob) function(x) pbinom(x, size = size, prob = prob)
5 | binom.formula <- "
6 | P[X=k]={n\\choose k}p^k(1-p)^{n-k}\\quad\\mbox{for}\\ k=0,1,2,\\dots,n
7 | "
8 |
9 | binom.x_filter <- NULL
10 |
11 | ## Moments ----
12 | binom.mean <- function(size, prob) size * prob
13 | binom.mean_str <- "np"
14 | binom.variance <- function(size, prob) size * prob * (1 - prob)
15 | binom.variance_str <- "np(1-p)"
16 |
17 | ## Parameters ----
18 | binom.range <- list(
19 | min = 0,
20 | max = 100,
21 | value = c(0, 20),
22 | step = 1
23 | )
24 | binom.size <- list(
25 | name = "size",
26 | label_name = "Number of trials",
27 | label_symbol = "n",
28 | min = 0,
29 | max = 40,
30 | value = 10,
31 | step = 1
32 | )
33 | binom.prob <- list(
34 | name = "prob",
35 | label_name = "Probability of successful trial",
36 | label_symbol = "p",
37 | min = 0,
38 | max = 1,
39 | value = 0.5,
40 | step = 0.01
41 | )
42 |
43 | ## Instance ----
44 | binom <- Distribution$new(
45 | dist = "binom",
46 | name = "Binomial distribution",
47 | wiki = "https://en.wikipedia.org/wiki/Binomial_distribution",
48 | c_or_d = "d",
49 | formula = binom.formula,
50 | func_p = binom.func_p,
51 | func_c = binom.func_c,
52 | x_filter = binom.x_filter,
53 | mean = binom.mean,
54 | mean_str = binom.mean_str,
55 | variance = binom.variance,
56 | variance_str = binom.variance_str,
57 | range = binom.range,
58 | binom.size,
59 | binom.prob
60 | )
61 |
--------------------------------------------------------------------------------
/distributions/discrete/Discrete_uniform.R:
--------------------------------------------------------------------------------
1 | # 離散一様分布
2 | ## functions ----
3 | dunif.func_p <- function(min, max) function(x) dunif(x, min = min, max = max)
4 | dunif.func_c <- function(min, max) function(x) punif(x, min = min, max = max)
5 | dunif.formula <- "
6 | f(x)=\\begin{cases}
7 | \\frac{1}{n} & \\mathrm{for}\\ a \\le x \\le b, \\\\[8pt]
8 | 0 & \\mathrm{for}\\ x b
9 | \\end{cases}
10 | "
11 |
12 | dunif.x_filter <- NULL
13 |
14 | ## Moments ----
15 | dunif.mean <- function(min, max) (min + max) / 2
16 | dunif.mean_str <- "\\frac{a+b}{2}"
17 | dunif.variance <- function(min, max) (((max - min + 1) ** 2) - 1) / 12
18 | dunif.variance_str <- "\\frac{(b-a+1)^2 -1}{12}"
19 |
20 | ## Parameters ----
21 | dunif.range <- list(
22 | min = 0,
23 | max = 100,
24 | value = c(0, 20),
25 | step = 1
26 | )
27 | dunif.min <- list(
28 | name = "min",
29 | label_name = "Min",
30 | label_symbol = "a",
31 | min = 0,
32 | max = 100,
33 | value = 0,
34 | step = 1
35 | )
36 | dunif.max <- list(
37 | name = "max",
38 | label_name = "Max",
39 | label_symbol = "b",
40 | min = 0,
41 | max = 100,
42 | value = 20,
43 | step = 1
44 | )
45 |
46 | ## Instance ----
47 | dunif <- Distribution$new(
48 | dist = "dunif",
49 | name = "Discrete uniform distribution",
50 | wiki = "https://en.wikipedia.org/wiki/Discrete_uniform_distribution",
51 | c_or_d = "d",
52 | formula = dunif.formula,
53 | func_p = dunif.func_p,
54 | func_c = dunif.func_c,
55 | x_filter = dunif.x_filter,
56 | mean = dunif.mean,
57 | mean_str = dunif.mean_str,
58 | variance = dunif.variance,
59 | variance_str = dunif.variance_str,
60 | range = dunif.range,
61 | dunif.min,
62 | dunif.max
63 | )
64 |
--------------------------------------------------------------------------------
/distributions/discrete/Geometric.R:
--------------------------------------------------------------------------------
1 | # 幾何分布 ----
2 | ## Functions ----
3 | geom.func_p <- function(prob) function(x) dgeom(x, prob = prob)
4 | geom.func_c <- function(prob) function(x) pgeom(x, prob = prob)
5 | geom.formula <- "
6 | Pr(X = k) = p(1-p)^{k}
7 | "
8 |
9 | geom.x_filter <- NULL
10 |
11 | ## Moments ----
12 | geom.mean <- function(prob) (1 - prob) / prob
13 | geom.mean_str <- "\\frac{1-p}{p}"
14 | geom.variance <- function(prob) (1 - prob) / prob ** 2
15 | geom.variance_str <- "\\frac{1-p}{p^2}"
16 |
17 | ## Parameters ----
18 | geom.range <- list(
19 | min = 0,
20 | max = 100,
21 | value = c(0, 20),
22 | step = 1
23 | )
24 | geom.prob <- list(
25 | name = "prob",
26 | label_name = "Probability of successful trial",
27 | label_symbol = "p",
28 | min = 0,
29 | max = 1,
30 | value = 0.5,
31 | step = 0.01
32 | )
33 |
34 | ## Instance ----
35 | geom <- Distribution$new(
36 | dist = "geom",
37 | name = "Geometric distribution",
38 | wiki = "https://en.wikipedia.org/wiki/Geometric_distribution",
39 | c_or_d = "d",
40 | formula = geom.formula,
41 | func_p = geom.func_p,
42 | func_c = geom.func_c,
43 | x_filter = geom.x_filter,
44 | mean = geom.mean,
45 | mean_str = geom.mean_str,
46 | variance = geom.variance,
47 | variance_str = geom.variance_str,
48 | range = geom.range,
49 | geom.prob
50 | )
51 |
--------------------------------------------------------------------------------
/distributions/discrete/Hypergeometric.R:
--------------------------------------------------------------------------------
1 | # 超幾何分布 ----
2 | ## Functions ----
3 | hyper.func_p <- function(m, n, k) function(x) dhyper(x, m = m, n = n, k = k)
4 | hyper.func_c <- function(m, n, k) function(x) phyper(x, m = m, n = n, k = k)
5 | hyper.formula <- "
6 | \\operatorname{P}(X=x)
7 | = \\frac{\\binom{m}{x}\\binom{n}{k-x}}{\\binom{m+n}{k}}
8 | "
9 |
10 | hyper.x_filter <- NULL
11 |
12 | ## Moments ----
13 | hyper.mean <- function(m, n, k) k * m / (m + n)
14 | hyper.mean_str <- "\\frac{km}{m+n}"
15 | hyper.variance <- function(m, n, k) k * m * n * (m + n - k) / (((m + n) ** 2) * (m + n - 1))
16 | hyper.variance_str <- "\\frac{kmn(m+n-k)}{(m+n)^2 (m+n-1)}"
17 |
18 | ## Parameters ----
19 | hyper.range <- list(
20 | min = 0,
21 | max = 100,
22 | value = c(0, 50),
23 | step = 1
24 | )
25 | hyper.m <- list(
26 | name = "m",
27 | label_name = "Number of white balls in the urn",
28 | label_symbol = "m",
29 | min = 0,
30 | max = 100,
31 | value = 50,
32 | step = 1
33 | )
34 | hyper.n <- list(
35 | name = "n",
36 | label_name = "Number of black balls in the urn",
37 | label_symbol = "n",
38 | min = 0,
39 | max = 100,
40 | value = 50,
41 | step = 1
42 | )
43 | hyper.k <- list(
44 | name = "k",
45 | label_name = "Number of balls drawn from the urn",
46 | label_symbol = "k",
47 | min = 0,
48 | max = 100,
49 | value = 50,
50 | step = 1
51 | )
52 |
53 | ## Instance ----
54 | hyper <- Distribution$new(
55 | dist = "hyper",
56 | name = "Hypergeometric distribution",
57 | wiki = "https://en.wikipedia.org/wiki/Hypergeometric_distribution",
58 | c_or_d = "d",
59 | formula = hyper.formula,
60 | func_p = hyper.func_p,
61 | func_c = hyper.func_c,
62 | x_filter = hyper.x_filter,
63 | mean = hyper.mean,
64 | mean_str = hyper.mean_str,
65 | variance = hyper.variance,
66 | variance_str = hyper.variance_str,
67 | range = hyper.range,
68 | hyper.m,
69 | hyper.n,
70 | hyper.k
71 | )
72 |
--------------------------------------------------------------------------------
/distributions/discrete/Negative_binomial.R:
--------------------------------------------------------------------------------
1 | # 負の二項分布 ----
2 | ## Functions ----
3 | nbinom.func_p <- function(size, prob) function(x) dnbinom(x, size = size, prob = prob)
4 | nbinom.func_c <- function(size, prob) function(x) pnbinom(x, size = size, prob = prob)
5 | nbinom.formula <- "f(x)=P(X=x) = {x-1 \\choose r-1} p^r (1-p)^{x-r}"
6 |
7 | nbinom.x_filter <- NULL
8 |
9 | ## Moments ----
10 | nbinom.mean <- function(size, prob) {
11 | if (is.null(prob) || prob == 0) {
12 | value <- Inf
13 | } else {
14 | value <- size / prob
15 | }
16 | return(value)
17 | }
18 | nbinom.mean_str <- "\\frac{r}{p}"
19 | nbinom.variance <- function(size, prob) {
20 | if (is.null(prob) || prob == 0) {
21 | value <- Inf
22 | } else {
23 | value <- size * (1 - prob) / (prob ** 2)
24 | }
25 | return(value)
26 | }
27 | nbinom.variance_str <- "\\frac{r(1-p)}{p^2}"
28 |
29 | ## Parameters ----
30 | nbinom.range <- list(
31 | min = 0,
32 | max = 100,
33 | value = c(0, 20),
34 | step = 1
35 | )
36 | nbinom.size <- list(
37 | name = "size",
38 | label_name = "target for number of successful trials",
39 | label_symbol = "r",
40 | min = 1,
41 | max = 20,
42 | value = 1,
43 | step = 1
44 | )
45 | nbinom.prob <- list(
46 | name = "prob",
47 | label_name = "Probability of successful trial",
48 | label_symbol = "p",
49 | min = 0,
50 | max = 1,
51 | value = 0.5,
52 | step = 0.01
53 | )
54 |
55 | ## Instance ----
56 | nbinom <- Distribution$new(
57 | dist = "nbinom",
58 | name = "Negative binomial distribution",
59 | wiki = "https://en.wikipedia.org/wiki/Negative_binomial_distribution",
60 | c_or_d = "d",
61 | formula = nbinom.formula,
62 | func_p = nbinom.func_p,
63 | func_c = nbinom.func_c,
64 | x_filter = nbinom.x_filter,
65 | mean = nbinom.mean,
66 | mean_str = nbinom.mean_str,
67 | variance = nbinom.variance,
68 | variance_str = nbinom.variance_str,
69 | range = nbinom.range,
70 | nbinom.size,
71 | nbinom.prob
72 | )
73 |
--------------------------------------------------------------------------------
/distributions/discrete/Poisson.R:
--------------------------------------------------------------------------------
1 | # ポアソン分布 ----
2 | ## Functions ----
3 | pois.func_p <- function(lambda) function(x) dpois(x, lambda = lambda)
4 | pois.func_c <- function(lambda) function(x) ppois(x, lambda = lambda)
5 | pois.formula <- "
6 | P(X=k)=\\frac{\\lambda^k e^{-\\lambda}}{k!}
7 | "
8 |
9 | pois.x_filter <- NULL
10 |
11 | ## Moments ----
12 | pois.mean <- function(lambda) lambda
13 | pois.mean_str <- "\\lambda"
14 | pois.variance <- function(lambda) lambda
15 | pois.variance_str <- "\\lambda"
16 |
17 | ## Parameters ----
18 | pois.range <- list(
19 | min = 0,
20 | max = 100,
21 | value = c(0, 20),
22 | step = 1
23 | )
24 | pois.lambda <- list(
25 | name = "lambda",
26 | label_name = "",
27 | label_symbol = "\\lambda",
28 | min = 1,
29 | max = 20,
30 | value = 1,
31 | step = 0.5
32 | )
33 |
34 | ## Instance ----
35 | pois <- Distribution$new(
36 | dist = "pois",
37 | name = "Poisson distribution",
38 | wiki = "https://en.wikipedia.org/wiki/Poisson_distribution",
39 | c_or_d = "d",
40 | formula = pois.formula,
41 | func_p = pois.func_p,
42 | func_c = pois.func_c,
43 | x_filter = pois.x_filter,
44 | mean = pois.mean,
45 | mean_str = pois.mean_str,
46 | variance = pois.variance,
47 | variance_str = pois.variance_str,
48 | range = pois.range,
49 | pois.lambda
50 | )
51 |
--------------------------------------------------------------------------------
/doc/demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/doc/demo.png
--------------------------------------------------------------------------------
/doc/ja/demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/doc/ja/demo.png
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | https-portal:
2 | image: steveltn/https-portal:1
3 | ports:
4 | - '80:80'
5 | - '443:443'
6 | links:
7 | - statdist
8 | restart: always
9 | environment:
10 | DOMAINS: 'statdist.ksmzn.com -> http://statdist:3838'
11 | STAGE: 'production'
12 | # FORCE_RENEW: 'true'
13 |
14 | statdist:
15 | build: .
16 |
--------------------------------------------------------------------------------
/global.R:
--------------------------------------------------------------------------------
1 | # Any code in this file is guaranteed to be called before either
2 | # ui.R or server.R
3 |
4 | enableBookmarking(store = "url")
5 |
6 | source("utils/all.R")
7 | source("nvd3chart.R")
8 | source("i18n/main.R")
9 | source("distributions/all.R")
10 | source("components/modules.R")
--------------------------------------------------------------------------------
/i18n/config.yaml:
--------------------------------------------------------------------------------
1 | cultural_date_format: "%d/%m/%Y"
2 | cultural_bignumer_mark: " "
3 | cultural_punctuation_mark: ","
4 |
--------------------------------------------------------------------------------
/i18n/main.R:
--------------------------------------------------------------------------------
1 | library(shiny.i18n)
2 |
3 | I18N_DIR <- "./i18n"
4 |
5 | translator <- Translator$new(
6 | translation_csvs_path = I18N_DIR,
7 | translation_csv_config = file.path(I18N_DIR, "config.yaml")
8 | )
9 |
--------------------------------------------------------------------------------
/i18n/translation_ja.csv:
--------------------------------------------------------------------------------
1 | English,Japanese
2 | about.md,about_ja.md
3 | This link stores the current state of this application.,このURLはアプリの状態を保持したものです。
4 | Bookmarked application link,ブックマーク用リンク
5 | Dismiss,閉じる
6 | Press Ctrl-C to copy.,Ctrl-C を押してコピーできます。
7 | Press ⌘-C to copy.,⌘-C を押してコピーできます。
8 | mean,期待値
9 | Mean,期待値
10 | variance,分散
11 | Variance,分散
12 | Standard deviation,標準偏差
13 | Shape,形状
14 | Scale,尺度
15 | Degrees of freedom,自由度
16 | Noncentrality parameter,非中心度
17 | Location,位置
18 | Mean Log,平均log
19 | Standard deviation Log,標準偏差log
20 | Probability of successful trial,成功確率
21 | Number of trials,試行回数
22 | target for number of successful trials,成功をする前に失敗した試行回数
23 | Number of white balls in the urn,成功状態の数
24 | Number of black balls in the urn,失敗状態の数
25 | Number of balls drawn from the urn,取り出す数
26 | Min,最小値
27 | Max,最大値
28 | Undefined,定義されない
29 | Plot,プロット
30 | variance(∞ if 1 <= ν <= 2),分散 (自由度が2以下のときは∞)
31 | Probability Distributions Viewer,確率分布 Viewer
32 | Reference,参考
33 | Parameters,パラメータ
34 | Probability density function (PDF),確率密度関数
35 | Probability mass function (PMF),確率関数
36 | Cumulative distribution function (CDF),累積分布関数
37 | Range,範囲
38 | Continuous distributions,連続分布
39 | Normal distribution,正規分布
40 | https://en.wikipedia.org/wiki/Normal_distribution,https://ja.wikipedia.org/wiki/正規分布
41 | Erlang distribution,アーラン分布
42 | https://en.wikipedia.org/wiki/Erlang_distribution,https://ja.wikipedia.org/wiki/アーラン分布
43 | F-distribution,F分布
44 | https://en.wikipedia.org/wiki/F-distribution,https://ja.wikipedia.org/wiki/F分布
45 | Noncentral F-distribution,非心F分布
46 | https://en.wikipedia.org/wiki/Noncentral_F-distribution,https://en.wikipedia.org/wiki/Noncentral_F-distribution
47 | Chi-squared distribution,カイ二乗分布
48 | https://en.wikipedia.org/wiki/Chi-squared_distribution,https://ja.wikipedia.org/wiki/カイ二乗分布
49 | Noncentral chi-squared distribution,非心カイ二乗分布
50 | https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution,https://ja.wikipedia.org/wiki/非心カイ二乗分布
51 | Gamma distribution,ガンマ分布
52 | https://en.wikipedia.org/wiki/Gamma_distribution,https://ja.wikipedia.org/wiki/ガンマ分布
53 | Cauchy distribution,コーシー分布
54 | https://en.wikipedia.org/wiki/Cauchy_distribution,https://ja.wikipedia.org/wiki/コーシー分布
55 | Exponential distribution,指数分布
56 | https://en.wikipedia.org/wiki/Exponential_distribution,https://ja.wikipedia.org/wiki/指数分布
57 | Log-normal distribution,対数正規分布
58 | https://en.wikipedia.org/wiki/Log-normal_distribution,https://ja.wikipedia.org/wiki/対数正規分布
59 | Student's t-distribution,t分布
60 | https://en.wikipedia.org/wiki/Student%27s_t-distribution,https://ja.wikipedia.org/wiki/t分布
61 | Noncentral t-distribution,非心t分布
62 | https://en.wikipedia.org/wiki/Noncentral_t-distribution,https://ja.wikipedia.org/wiki/非心t分布
63 | Beta distribution,ベータ分布
64 | https://en.wikipedia.org/wiki/Beta_distribution,https://ja.wikipedia.org/wiki/ベータ分布
65 | Noncentral beta distribution,非心ベータ分布
66 | https://en.wikipedia.org/wiki/Noncentral_beta_distribution,https://en.wikipedia.org/wiki/Noncentral_beta_distribution
67 | Uniform distribution (continuous),連続一様分布
68 | https://en.wikipedia.org/wiki/Uniform_distribution_(continuous),https://ja.wikipedia.org/wiki/連続一様分布
69 | Logistic distribution,ロジスティック分布
70 | https://en.wikipedia.org/wiki/Logistic_distribution,https://ja.wikipedia.org/wiki/ロジスティック分布
71 | Weibull distribution,ワイブル分布
72 | https://en.wikipedia.org/wiki/Weibull_distribution,https://ja.wikipedia.org/wiki/ワイブル分布
73 | Discrete distributions,離散分布
74 | Geometric distribution,幾何分布
75 | https://en.wikipedia.org/wiki/Geometric_distribution,https://ja.wikipedia.org/wiki/幾何分布
76 | Hypergeometric distribution,超幾何分布
77 | https://en.wikipedia.org/wiki/Hypergeometric_distribution,https://ja.wikipedia.org/wiki/超幾何分布
78 | Binomial distribution,二項分布
79 | https://en.wikipedia.org/wiki/Binomial_distribution,https://ja.wikipedia.org/wiki/二項分布
80 | Negative binomial distribution,負の二項分布
81 | https://en.wikipedia.org/wiki/Negative_binomial_distribution,https://ja.wikipedia.org/wiki/負の二項分布
82 | Poisson distribution,ポアソン分布
83 | https://en.wikipedia.org/wiki/Poisson_distribution,https://ja.wikipedia.org/wiki/ポアソン分布
84 | Discrete uniform distribution,離散一様分布
85 | https://en.wikipedia.org/wiki/Discrete_uniform_distribution,https://ja.wikipedia.org/wiki/離散一様分布
86 |
--------------------------------------------------------------------------------
/markdown/about.md:
--------------------------------------------------------------------------------
1 | ## Shiny web app for live demonstration of probability distributions
2 |
3 | This web app enables visual inspection of various probability distributions commonly used in statistics.
4 | You can modify their parameters, and check how they influence the distributions.
5 | From the **left menu**, choose a probability distribution of interest.
6 |
7 | The web app was authored by @ksmzn using the Shiny R web app framework and the NVD3.js graphing framework. @kaz_yos translated it into English.
8 |
9 | - The original code is avaialbe at: https://github.com/ksmzn/ProbabilityDistributionsViewer
10 |
11 | ### References
12 |
13 | #### Shiny
14 |
15 | + [Shiny Official Tutorial](http://shiny.rstudio.com/tutorial/)
16 | + [Shiny - Bookmarking state](https://shiny.rstudio.com/articles/bookmarking-state.html)
17 | + [Shiny - Advanced bookmarking](https://shiny.rstudio.com/articles/advanced-bookmarking.html)
18 | + [Shiny - Modularizing Shiny app code](https://shiny.rstudio.com/articles/modules.html)
19 |
20 | #### shinydashboard
21 |
22 | + [shinydashboard](https://rstudio.github.io/shinydashboard/)
23 | + [Shiny Dashboard Behavior](https://rstudio.github.io/shinydashboard/behavior.html)
24 |
25 | #### shiny.i18n
26 |
27 | + [GitHub - Appsilon/shiny.i18n](https://github.com/Appsilon/shiny.i18n)
28 |
29 | #### JavaScript
30 |
31 | + [Simple Line Chart - NVD3.js](http://nvd3.org/examples/line.html)
32 |
33 | #### Tutorial & Example
34 |
35 | + [ボケて(bokete)のネタを全自動で流し見できるサイト作った - ほくそ笑む](http://d.hatena.ne.jp/hoxo_m/20140731/p1) (in Japanese)
36 | + [RStudio Shiny チュートリアル レッスン1 ようこそ Shiny へ - Qiita](http://qiita.com/hoxo_m/items/c8365117f3444fb51df4) (in Japanese)
37 |
38 | ### Author's blog article (in Japanese)
39 |
40 | + [Shinyで確率分布を動かして遊べるページ作った](http://ksmzn.hatenablog.com/entry/statdist-shiny)
41 |
--------------------------------------------------------------------------------
/markdown/about_ja.md:
--------------------------------------------------------------------------------
1 | ## 確率分布 Viewer
2 |
3 | 様々な確率分布のカタチを見ることができるWebアプリです。
4 | R言語でアプリを作れる [Shiny](http://shiny.rstudio.com) で作りました。
5 |
6 | パラメータを変えて、確率分布のカタチがどのように変わるのか観察しましょう。
7 | 平均値・分散の値も知ることができます。
8 |
9 | 上部のBookmarkボタンで、作成した分布の状態を保存できます。
10 | URLをコピーすれば、シェアすることも可能です。
11 |
12 | **左メニュー** からお好きな確率分布を選んでください。
13 |
14 | **【2018年2月3日 追記】**
15 |
16 | - ブックマーク機能を作成しました。
17 | 右上の「Bookmark」ボタンからどうぞ。
18 |
19 | - 言語切り替え機能を作成しました。
20 | 右上の選択ボタンからどうぞ。
21 | 現在対応しているのは日本語と英語です。
22 | その他の言語の対応は未定ですが、[PullRequest](https://github.com/ksmzn/ProbabilityDistributionsViewer/pulls) は大歓迎です。
23 | よろしくお願いします。
24 |
25 | **【2015年1月14日 追記】**
26 |
27 | NVD3.jsを使ったグラフに変更しました!
28 | また、分布名の隣に、日本版Wikipediaへのリンクを追加しました。
29 |
30 | **【2015年1月27日 追記】**
31 |
32 | なんと、
33 | このアプリを
34 | @kaz_yos
35 | さんが英語に翻訳して下さいました!!
36 |
37 | Shiny web app for live demonstration of probability distributions
38 |
39 | @kaz_yos
40 | さん、ありがとうございました。
41 |
42 | **【2015年2月25日 追記】**
43 |
44 | shinydashboard
45 | を使って
46 | デザインやUIを一新しました。
47 | shinydashboard は綺麗なデザインが簡単にできて素晴らしいですね。
48 |
49 | また、期待値や分散を追加しました。
50 | より便利になったと思います。
51 |
52 | ### 参考文献
53 |
54 | このアプリを作る際に参考にしたページは以下です。
55 | 特に、作成当時はShinyの日本語情報が少ないなか、
56 | @hoxo_m さんの記事やコードはとても参考になりました。
57 | @hoxo_m さん、ありがとうございました。
58 |
59 | #### Shiny
60 |
61 | + [Shiny Official Tutorial](http://shiny.rstudio.com/tutorial/)
62 | + [Shiny - Bookmarking state](https://shiny.rstudio.com/articles/bookmarking-state.html)
63 | + [Shiny - Advanced bookmarking](https://shiny.rstudio.com/articles/advanced-bookmarking.html)
64 | + [Shiny - Modularizing Shiny app code](https://shiny.rstudio.com/articles/modules.html)
65 |
66 | #### shinydashboard
67 |
68 | + [shinydashboard](https://rstudio.github.io/shinydashboard/)
69 | + [Shiny Dashboard Behavior](https://rstudio.github.io/shinydashboard/behavior.html)
70 |
71 | #### shiny.i18n
72 |
73 | + [GitHub - Appsilon/shiny.i18n](https://github.com/Appsilon/shiny.i18n)
74 |
75 | #### JavaScript
76 |
77 | + [Simple Line Chart - NVD3.js](http://nvd3.org/examples/line.html)
78 |
79 | #### Tutorial & Example
80 |
81 | + [ボケて(bokete)のネタを全自動で流し見できるサイト作った - ほくそ笑む](http://d.hatena.ne.jp/hoxo_m/20140731/p1)
82 | + [RStudio Shiny チュートリアル レッスン1 ようこそ Shiny へ - Qiita](http://qiita.com/hoxo_m/items/c8365117f3444fb51df4)
83 |
84 | ### 拙ブログ
85 |
86 | + [Shinyで確率分布を動かして遊べるページ作った](http://ksmzn.hatenablog.com/entry/statdist-shiny)
87 | + [Shinyで作った確率分布を動かせるページを, NVD3.jsでヌルヌルでインタラクティブなグラフにしました。そしてShinyでD3.jsを使う方法3つ。](http://ksmzn.hatenablog.com/entry/shiny-nvd3-js-nuru)
88 | + [確率分布を学ぶアプリを、shinydashboard を使って新しくしてみた & 英訳していただきました。](http://ksmzn.hatenablog.com/entry/shiny-dashboard-english)
89 | + [Dockerを使ってDigitalOceanにShinyアプリを公開する](http://ksmzn.hatenablog.com/entry/degitalocean-shiny-docker)
90 | + [shiny.i18nパッケージでshinyを多言語対応](http://ksmzn.hatenablog.com/entry/shiny-i18n)
91 | + [「ShinyModule」で中規模Shinyアプリをキレイにする](http://ksmzn.hatenablog.com/entry/shiny-module)
92 |
93 |
94 |
--------------------------------------------------------------------------------
/nvd3chart.R:
--------------------------------------------------------------------------------
1 | library(shiny)
2 |
3 | # To be called from ui.R
4 | nvd3ChartOutput <- function(inputId, type, width="100%", height="400px") {
5 | style <- sprintf(
6 | "width: %s; height: %s;",
7 | validateCssUnit(width), validateCssUnit(height)
8 | )
9 | if (type == "line") {
10 | class <- "nvd3-linechart"
11 | } else {
12 | class <- "nvd3-scatterchart"
13 | }
14 |
15 | tagList(
16 | # Include CSS/JS dependencies. Use "singleton" to make sure that even
17 | # if multiple lineChartOutputs are used in the same page, we'll still
18 | # only include these chunks once.
19 | singleton(tags$head(
20 | tags$script(src = "js/d3/d3.v3.min.js"),
21 | tags$script(src = "js/nvd3/nv.d3.min.js"),
22 | tags$link(rel = "stylesheet", type = "text/css", href = "js/nvd3/nv.d3.min.css"),
23 | tags$script(src = "js/linechart-binding.js"),
24 | tags$script(src = "js/scatterchart-binding.js")
25 | )),
26 | div(
27 | id = inputId, class = class, style = style,
28 | tag("svg", list())
29 | )
30 | )
31 | }
32 |
33 | # To be called from server.R
34 | renderNvd3Chart <- function(expr, env=parent.frame(), quoted=FALSE) {
35 | # This piece of boilerplate converts the expression `expr` into a
36 | # function called `func`. It's needed for the RStudio IDE's built-in
37 | # debugger to work properly on the expression.
38 | installExprFunction(expr, "func", env, quoted)
39 |
40 | function() {
41 | dataframe <- func()
42 | mapply(function(name) {
43 | values <- mapply(function(i, j) {
44 | list(x = i, y = j)
45 | }, dataframe$x, dataframe$y, SIMPLIFY = FALSE, USE.NAMES = FALSE)
46 | list(key = name, values = values)
47 | }, c("y"), SIMPLIFY = FALSE, USE.NAMES = FALSE)
48 | }
49 | }
50 |
51 |
52 | # Data frame or list looks like:
53 | #
54 | # {
55 | # "Series A": [1,2,3,4,5],
56 | # "Series B": [6,7,8,9,10]
57 | # }
58 | #
59 | # D3 expects:
60 | #
61 | # [
62 | # {
63 | # key: "Series A",
64 | # values: [{x:1,y:1}, {x:2,y:2}, {x:3,y:3}, {x:4,y:4}, {x:5,y:5}]
65 | # },
66 | # {
67 | # key: "Series B",
68 | # values: [{x:1,y:6}, {x:2,y:7}, {x:3,y:8}, {x:4,y:9}, {x:5,y:10}]
69 | # }
70 | # ]
--------------------------------------------------------------------------------
/rsconnect/shinyapps.io/ksmzn/statdist.dcf:
--------------------------------------------------------------------------------
1 | name: statdist
2 | account: ksmzn
3 | bundleId: 161364
4 | url: http://ksmzn.shinyapps.io/statdist
5 | server: shinyapps.io
6 |
--------------------------------------------------------------------------------
/ui.R:
--------------------------------------------------------------------------------
1 | library(shiny)
2 | library(shinydashboard)
3 | library(rmarkdown)
4 |
5 | pageTitle <- "Probability Distributions Viewer"
6 | sidebarWidth <- 300
7 |
8 | # CSS Files
9 | cssFiles <- tags$head(
10 | tags$link(rel = "stylesheet", type = "text/css", href = "css/main.css")
11 | )
12 | # JavaScript Files
13 | jsFiles <- tags$head(
14 | tags$script(src = "js/google-analytics.js")
15 | )
16 |
17 | ####################################################
18 | # UI ----
19 | ####################################################
20 | header <- dashboardHeader(
21 | title = pageTitle,
22 | titleWidth = sidebarWidth,
23 | .list = list(
24 | tags$li(
25 | class = "dropdown dummy",
26 | bookmarkButton()
27 | ),
28 | tags$li(
29 | class = "dropdown dummy",
30 | uiOutput("language_selector")
31 | )
32 | )
33 | )
34 |
35 | sidebar <- dashboardSidebar(
36 | width = sidebarWidth,
37 | sidebarMenuOutput("sidebar_menu")
38 | )
39 |
40 | board.about <- tabItem(
41 | tabName = "about",
42 | uiOutput("about")
43 | )
44 | ####################################################
45 | # Tab Items for Distributions ----
46 | ####################################################
47 | # 連続分布 ----
48 | ## Normal
49 | board.norm <- distTabUI(norm)
50 | board.erlang <- distTabUI(erlang)
51 | board.f <- distTabUI(f)
52 | board.ncf <- distTabUI(ncf, wide = T)
53 | board.chisq <- distTabUI(chisq)
54 | board.ncChisq <- distTabUI(ncChisq)
55 | board.gamma <- distTabUI(gamma)
56 | board.cauchy <- distTabUI(cauchy)
57 | board.exp_dist <- distTabUI(exp_dist)
58 | board.lnormal <- distTabUI(lnormal)
59 | board.t_dist <- distTabUI(t_dist)
60 | board.nct <- distTabUI(nct, wide = T)
61 | board.beta <- distTabUI(beta)
62 | board.ncbeta <- distTabUI(ncbeta, wide = T)
63 | board.unif <- distTabUI(unif)
64 | board.logis <- distTabUI(logis)
65 | board.weibull <- distTabUI(weibull, wide = T)
66 | # 離散分布
67 | board.geom <- distTabUI(geom)
68 | board.hyper <- distTabUI(hyper)
69 | board.binom <- distTabUI(binom)
70 | board.nbinom <- distTabUI(nbinom)
71 | board.pois <- distTabUI(pois)
72 | board.dunif <- distTabUI(dunif)
73 |
74 | body <- dashboardBody(
75 | cssFiles,
76 | jsFiles,
77 | tabItems(
78 | # Continuous
79 | board.norm,
80 | board.erlang,
81 | board.f,
82 | board.ncf,
83 | board.chisq,
84 | board.ncChisq,
85 | board.gamma,
86 | board.cauchy,
87 | board.exp_dist,
88 | board.lnormal,
89 | board.t_dist,
90 | board.nct,
91 | board.beta,
92 | board.ncbeta,
93 | board.unif,
94 | board.logis,
95 | board.weibull,
96 | # Discrete
97 | board.geom,
98 | board.hyper,
99 | board.binom,
100 | board.nbinom,
101 | board.pois,
102 | board.dunif,
103 | # About
104 | board.about
105 | )
106 | )
107 |
108 | ui <- function(req) {
109 | dashboardPage(header, sidebar, body)
110 | }
--------------------------------------------------------------------------------
/utils/all.R:
--------------------------------------------------------------------------------
1 | # Read all R files
2 | source("utils/bookmark.R")
3 |
--------------------------------------------------------------------------------
/www/css/main.css:
--------------------------------------------------------------------------------
1 | .wrapper {
2 | overflow-y: hidden;
3 | }
4 | .dummy {
5 | padding: 7px 15px 0 0;
6 | }
7 | #language_selector > .form-group {
8 | margin-bottom: 0px;
9 | }
10 | #language_selector .selectize-control {
11 | margin-bottom: 0px;
12 | }
13 |
14 | .btn-twitter {
15 | text-align: left;
16 | float: left;
17 | }
18 |
--------------------------------------------------------------------------------
/www/img/external.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/img/external.png
--------------------------------------------------------------------------------
/www/js/google-analytics.js:
--------------------------------------------------------------------------------
1 | // Initial Tracking Code
2 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
3 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
4 | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
5 | })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
6 | (function(){
7 | var uaid = '';
8 | var domain = 'statdist.ksmzn.com';
9 |
10 | if (location.host == domain){
11 | uaid = 'UA-12393166-9';
12 | }else{
13 | uaid = 'UA-12393166-8';
14 | }
15 |
16 | ga('create', uaid, 'auto');
17 | ga('send', 'pageview');
18 | })();
19 |
20 | // Event Tracking Code
21 | $(document).on('shiny:inputchanged', function(event) {
22 | if(['selected_language', 'tabs'].indexOf(event.name) >= 0 && event.value !== null){
23 | ga('send', 'event', 'input',
24 | 'updates', event.name, event.value);
25 | }
26 | })
27 |
--------------------------------------------------------------------------------
/www/js/linechart-binding.js:
--------------------------------------------------------------------------------
1 | // Put code in an Immediately Invoked Function Expression (IIFE).
2 | // This isn't strictly necessary, but it's good JavaScript hygiene.
3 | (function() {
4 |
5 | // See http://rstudio.github.io/shiny/tutorial/#building-outputs for
6 | // more information on creating output bindings.
7 |
8 | // First create a generic output binding instance, then overwrite
9 | // specific methods whose behavior we want to change.
10 | var binding = new Shiny.OutputBinding();
11 |
12 | binding.find = function(scope) {
13 | // For the given scope, return the set of elements that belong to
14 | // this binding.
15 | return $(scope).find(".nvd3-linechart");
16 | };
17 |
18 | binding.renderValue = function(el, data) {
19 | // This function will be called every time we receive new output
20 | // values for a line chart from Shiny. The "el" argument is the
21 | // div for this particular chart.
22 |
23 | var $el = $(el);
24 |
25 | // The first time we render a value for a particular element, we
26 | // need to initialize the nvd3 line chart and d3 selection. We'll
27 | // store these on $el as a data value called "state".
28 | if (!$el.data("state")) {
29 | var chart = nv.models.lineChart()
30 | .margin({left: 100})
31 | .useInteractiveGuideline(true)
32 | // .transitionDuration(350)
33 | .showLegend(false)
34 | .showYAxis(true)
35 | .showXAxis(true);
36 |
37 | chart.xAxis //Chart x-axis settings
38 | .axisLabel('X')
39 | .tickFormat(d3.format('.01f'));
40 |
41 | chart.yAxis //Chart y-axis settings
42 | .axisLabel('P')
43 | .tickFormat(d3.format('.02f'));
44 |
45 | nv.utils.windowResize(chart.update);
46 |
47 | var selection = d3.select(el).select("svg");
48 |
49 | // Store the chart object on el so we can get it next time
50 | $el.data("state", {
51 | chart: chart,
52 | selection: selection
53 | });
54 | }
55 |
56 | // Now, the code that'll run every time a value is rendered...
57 |
58 | // Retrieve the chart and selection we created earlier
59 | var state = $el.data("state");
60 |
61 | // Schedule some work with nvd3
62 | nv.addGraph(function() {
63 | // Update the chart
64 | state.selection
65 | .datum(data)
66 | .transition(500)
67 | .call(state.chart);
68 | return state.chart;
69 | });
70 | };
71 |
72 | // Tell Shiny about our new output binding
73 | Shiny.outputBindings.register(binding, "stat_dist.nvd3-linechart");
74 |
75 | })();
76 |
--------------------------------------------------------------------------------
/www/js/nvd3/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Jekyll Files #
3 | ################
4 | _site
5 |
6 |
7 | # Random Files #
8 | ################
9 | *.swp
10 | *~
11 | *.log
12 |
13 |
14 | # Private Test Data #
15 | #####################
16 | *REALDATA*
17 |
18 |
19 | # OS generated files #
20 | ######################
21 | .DS_Store*
22 | ehthumbs.db
23 | Icon?
24 | Thumbs.db
25 | # nodejs packages #
26 | ######################
27 | node_modules
28 |
--------------------------------------------------------------------------------
/www/js/nvd3/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "asi": true
3 | }
4 |
--------------------------------------------------------------------------------
/www/js/nvd3/GruntFile.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | //Project configuration.
4 | grunt.initConfig({
5 | pkg: grunt.file.readJSON('package.json'),
6 | concat: {
7 | options: {
8 | separator: ''
9 | },
10 | dist: {
11 | src: [
12 | 'src/intro.js',
13 | 'src/core.js',
14 | 'src/interactiveLayer.js',
15 | 'src/tooltip.js',
16 | 'src/utils.js',
17 | 'src/models/axis.js',
18 | 'src/models/historicalBar.js',
19 | 'src/models/bullet.js',
20 | 'src/models/bulletChart.js',
21 | 'src/models/cumulativeLineChart.js',
22 | 'src/models/discreteBar.js',
23 | 'src/models/discreteBarChart.js',
24 | 'src/models/distribution.js',
25 | 'src/models/historicalBar.js',
26 | 'src/models/historicalBarChart.js',
27 | 'src/models/indentedTree.js',
28 | 'src/models/legend.js',
29 | 'src/models/line.js',
30 | 'src/models/lineChart.js',
31 | 'src/models/linePlusBarChart.js',
32 | 'src/models/lineWithFocusChart.js',
33 | 'src/models/linePlusBarWithFocusChart.js',
34 | 'src/models/multiBar.js',
35 | 'src/models/multiBarChart.js',
36 | 'src/models/multiBarHorizontal.js',
37 | 'src/models/multiBarHorizontalChart.js',
38 | 'src/models/multiChart.js',
39 | 'src/models/ohlcBar.js',
40 | 'src/models/pie.js',
41 | 'src/models/pieChart.js',
42 | 'src/models/scatter.js',
43 | 'src/models/scatterChart.js',
44 | 'src/models/scatterPlusLineChart.js',
45 | 'src/models/sparkline.js',
46 | 'src/models/sparklinePlus.js',
47 | 'src/models/stackedArea.js',
48 | 'src/models/stackedAreaChart.js',
49 | 'src/outro.js'
50 | ],
51 | dest: 'nv.d3.js'
52 | }
53 | },
54 | uglify: {
55 | options: {
56 | banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
57 | '<%= grunt.template.today("yyyy-mm-dd") %> */'
58 | },
59 | js: {
60 | files: {
61 | 'nv.d3.min.js': ['nv.d3.js']
62 | }
63 | }
64 | },
65 | jshint: {
66 | foo: {
67 | src: "src/**/*.js"
68 | },
69 | options: {
70 | jshintrc: '.jshintrc'
71 | }
72 | },
73 | watch: {
74 | js: {
75 | files: ["src/**/*.js"],
76 | tasks: ['concat']
77 | }
78 | },
79 | copy: {
80 | css: {
81 | files: [
82 | { src: 'src/nv.d3.css', dest: 'nv.d3.css' }
83 | ]
84 | }
85 | },
86 | cssmin: {
87 | dist: {
88 | files: {
89 | 'nv.d3.min.css' : ['nv.d3.css']
90 | }
91 | }
92 | }
93 | });
94 |
95 | grunt.loadNpmTasks('grunt-contrib-watch');
96 | grunt.loadNpmTasks('grunt-contrib-concat');
97 | grunt.loadNpmTasks('grunt-contrib-jshint');
98 | grunt.loadNpmTasks('grunt-contrib-uglify');
99 | grunt.loadNpmTasks('grunt-contrib-copy');
100 | grunt.loadNpmTasks('grunt-contrib-cssmin');
101 |
102 | grunt.registerTask('default', ['concat', 'copy']);
103 | grunt.registerTask('production', ['concat', 'uglify', 'copy', 'cssmin']);
104 | grunt.registerTask('release', ['production']);
105 | grunt.registerTask('lint', ['jshint']);
106 | };
107 |
--------------------------------------------------------------------------------
/www/js/nvd3/LICENSE.md:
--------------------------------------------------------------------------------
1 |
2 | ##nvd3.js License
3 |
4 | Copyright (c) 2011, 2012 [Novus Partners, Inc.][novus]
5 |
6 | Licensed under the Apache License, Version 2.0 (the "License");
7 | you may not use this file except in compliance with the License.
8 | You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing, software
13 | distributed under the License is distributed on an "AS IS" BASIS,
14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | See the License for the specific language governing permissions and
16 | limitations under the License.
17 |
18 | [novus]: https://www.novus.com/
19 |
20 |
21 |
22 | ##d3.js License
23 |
24 | Copyright (c) 2012, Michael Bostock
25 | All rights reserved.
26 |
27 | Redistribution and use in source and binary forms, with or without
28 | modification, are permitted provided that the following conditions are met:
29 |
30 | * Redistributions of source code must retain the above copyright notice, this
31 | list of conditions and the following disclaimer.
32 |
33 | * Redistributions in binary form must reproduce the above copyright notice,
34 | this list of conditions and the following disclaimer in the documentation
35 | and/or other materials provided with the distribution.
36 |
37 | * The name Michael Bostock may not be used to endorse or promote products
38 | derived from this software without specific prior written permission.
39 |
40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 | DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
44 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
45 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
47 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
48 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 |
--------------------------------------------------------------------------------
/www/js/nvd3/Makefile:
--------------------------------------------------------------------------------
1 | JS_FILES = \
2 | src/intro.js \
3 | src/core.js \
4 | src/interactiveLayer.js \
5 | src/tooltip.js \
6 | src/utils.js \
7 | src/models/axis.js \
8 | src/models/bullet.js \
9 | src/models/bulletChart.js \
10 | src/models/cumulativeLineChart.js \
11 | src/models/discreteBar.js \
12 | src/models/discreteBarChart.js \
13 | src/models/distribution.js \
14 | src/models/historicalBar.js \
15 | src/models/historicalBarChart.js \
16 | src/models/indentedTree.js \
17 | src/models/legend.js \
18 | src/models/line.js \
19 | src/models/lineChart.js \
20 | src/models/linePlusBarChart.js \
21 | src/models/lineWithFocusChart.js \
22 | src/models/linePlusBarWithFocusChart.js \
23 | src/models/multiBar.js \
24 | src/models/multiBarChart.js \
25 | src/models/multiBarHorizontal.js \
26 | src/models/multiBarHorizontalChart.js \
27 | src/models/multiChart.js \
28 | src/models/ohlcBar.js \
29 | src/models/pie.js \
30 | src/models/pieChart.js \
31 | src/models/scatter.js \
32 | src/models/scatterChart.js \
33 | src/models/scatterPlusLineChart.js \
34 | src/models/sparkline.js \
35 | src/models/sparklinePlus.js \
36 | src/models/stackedArea.js \
37 | src/models/stackedAreaChart.js \
38 | src/outro.js
39 | CSS_FILES = \
40 | src/nv.d3.css
41 |
42 | JS_COMPILER = \
43 | uglifyjs
44 |
45 | CSS_COMPILER = \
46 | cssmin
47 |
48 | all: nv.d3.js nv.d3.min.js nv.d3.css nv.d3.min.css
49 | nv.d3.js: $(JS_FILES)
50 | nv.d3.min.js: $(JS_FILES)
51 | nv.d3.css: $(CSS_FILES)
52 | nv.d3.min.css: $(CSS_FILES)
53 |
54 | nv.d3.js: Makefile
55 | rm -f $@
56 | cat $(filter %.js,$^) >> $@
57 |
58 | nv.d3.css: Makefile
59 | rm -f $@
60 | cat $(filter %.css,$^) >> $@
61 |
62 | %.min.js:: Makefile
63 | rm -f $@
64 | $(JS_COMPILER) nv.d3.js >> $@
65 |
66 | %.min.css:: Makefile
67 | rm -f $@
68 | $(CSS_COMPILER) nv.d3.css >> $@
69 |
70 |
71 | clean:
72 | rm -rf nv.d3*.js nv.d3*.css
73 |
--------------------------------------------------------------------------------
/www/js/nvd3/README.md:
--------------------------------------------------------------------------------
1 | # NVD3 - v1.1.15-beta
2 | ## Release notes for version 1.1.15 beta
3 | * Various fixes across the board
4 |
5 | ## Overview
6 | A reusable chart library for d3.js.
7 |
8 | NVD3 may change from its current state, but will always try to follow the style of d3.js.
9 |
10 | You can also check out the [examples page](http://nvd3.org/ghpages/examples.html).
11 | **Note:** The examples on nvd3.org are outdated. For examples on how to use the latest NVD3, please checkout the **examples/** directory in the repository.
12 |
13 | ---
14 |
15 | # Current development focus
16 |
17 | - Getting documentation up.
18 | - Unifying common API functions between charts.
19 | - Bug fixes that come up.
20 |
21 | ---
22 |
23 | # Installation Instructions
24 |
25 | `d3.v3.js` is a dependency of `nv.d3.js`. Be sure to include in in your project, then:
26 | Add a script tag to include `nv.d3.js` OR `nv.d3.min.js` in your project.
27 | Also add a link to the `nv.d3.css` file.
28 |
29 | See wiki -> Documentation for more detail
30 |
31 | ---
32 |
33 | If one of [the existing models](https://github.com/novus/nvd3/tree/master/src/models) doesn't meet your needs, fork the project, implement the model and an example using it, send us a pull request, for consideration for inclusion in the project.
34 |
35 | We cannot honor all pull requests, but we will review all of them.
36 |
37 | Please do not aggregate pull requests. Aggregated pull requests are actually more difficult to review.
38 |
39 | We are currently changing our branch structure so that master will be gauranteed stable. In addition, there is now a "development" branch. This branch reflects the latest changes to NVD3 and is not necessarily stable.
40 |
41 | ---
42 |
43 | ## Minifying your fork:
44 |
45 | ### Using Make
46 | The Makefile requires [UglifyJS](https://github.com/mishoo/UglifyJS) and [CSSMin](https://github.com/jbleuzen/node-cssmin)
47 |
48 | The easiest way to install UglifyJS and CSSMin is via npm. Run `npm install -g uglify-js cssmin`. After installing verify the setup by running `uglifyjs --version` and `cssmin --help`.
49 |
50 | Once you have the `uglifyjs` and `cssmin` commands available, running `make` from your
51 | fork's root directory will rebuild both `nv.d3.js` and `nv.d3.min.js`.
52 |
53 | make # build nv.d3.js and nv.d3.css and minify
54 | make nv.d3.js # Build nv.d3.js
55 | make nv.d3.min.js # Minify nv.d3.js into nv.d3.min.js
56 | make nv.d3.css # Build nv.d3.css
57 | make nv.d3.min.css # Minify nv.d3.css into nv.d3.min.css
58 | make clean # Delete nv.d3.*js and nv.d3.*css
59 |
60 |
61 | *Without UglifyJS of CSSMin, you won't get the minified versions when running make.**
62 |
63 | ### Using Grunt
64 |
65 | You can use grunt instead of makefile to build js file. See more about [grunt](http://gruntjs.com/).
66 | ***[Nodejs](http://nodejs.org/) must be installed before you can use grunt.***
67 | Run `npm install` in root dir to install grunt and it's dependencies.
68 |
69 | Then, you can use these commands:
70 |
71 | grunt # build nv.d3.js
72 | grunt production # build nv.d3.js and nv.d3.min.js
73 | grunt watch # watch file changes in src/, and rebuild nv.d3.js, it's very helpful when delevop NVD3
74 | grunt lint # run jshint on src/**/*.js
75 |
76 | **We ask that you DO NOT minify pull requests...
77 | If you need to minify please build pull request in separate branch, and
78 | merge and minify in your master.
79 |
80 | ## Supported Browsers
81 | NVD3 runs best on WebKit based browsers.
82 |
83 | * **Google Chrome: latest version (preferred)**
84 | * **Opera 15+ (preferred)**
85 | * Safari: latest version
86 | * Firefox: latest version
87 | * Internet Explorer: 9 and 10
88 |
--------------------------------------------------------------------------------
/www/js/nvd3/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nvd3",
3 | "version": "1.1.15-beta",
4 | "homepage": "http://www.nvd3.org",
5 | "authors": [
6 | "Bob Monteverde",
7 | "Tyler Wolf",
8 | "Robin Hu",
9 | "Frank Shao"
10 | ],
11 | "description": "Re-usable charts and chart components for d3.",
12 | "main": ["nv.d3.js", "src/nv.d3.css"],
13 | "keywords": [
14 | "d3",
15 | "visualization",
16 | "svg",
17 | "charts"
18 | ],
19 | "license": "Apache License, v2.0",
20 | "dependencies": {
21 | "d3": "~3.3.13"
22 | },
23 | "ignore" : [
24 | "**/.*",
25 | "node_modules",
26 | "bower_components",
27 | "test",
28 | "tests",
29 | "src/models/*",
30 | "src/*.js",
31 | "lib",
32 | "examples",
33 | "deprecated"
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/www/js/nvd3/build.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | copy src\intro.js /B + src\core.js /B + src\tooltip.js /B temp1.js /B
3 | copy src\models\*.js /B temp2.js /B
4 | copy temp1.js /B + temp2.js /B + src\outro.js /B nv.d3.js /B
5 | del temp1.js
6 | del temp2.js
7 |
--------------------------------------------------------------------------------
/www/js/nvd3/deprecated/discreteBarChartWithEnabledTooltip.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
129 |
--------------------------------------------------------------------------------
/www/js/nvd3/deprecated/lineChart-old.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
84 |
--------------------------------------------------------------------------------
/www/js/nvd3/deprecated/lineWithFocus.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
138 |
--------------------------------------------------------------------------------
/www/js/nvd3/deprecated/lineWithLegend.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
143 |
--------------------------------------------------------------------------------
/www/js/nvd3/deprecated/monthendAxis.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
100 |
--------------------------------------------------------------------------------
/www/js/nvd3/deprecated/scatterChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
40 |
41 |
42 |
43 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
111 |
--------------------------------------------------------------------------------
/www/js/nvd3/deprecated/scatterWithLegend.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
34 |
35 |
36 |
37 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
168 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/bullet.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
98 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/bulletChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
14 |
15 |
16 | Normal Bullet Chart
17 |
18 |
19 | Bullet Chart with Custom Labels
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
117 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/crossfilter.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
168 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/discreteBarChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
118 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/historicalBar.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
159 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/historicalBarChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
107 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/images/grey-minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/js/nvd3/examples/images/grey-minus.png
--------------------------------------------------------------------------------
/www/js/nvd3/examples/images/grey-plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/js/nvd3/examples/images/grey-plus.png
--------------------------------------------------------------------------------
/www/js/nvd3/examples/images/nvd3_sampleLineChart1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/js/nvd3/examples/images/nvd3_sampleLineChart1.png
--------------------------------------------------------------------------------
/www/js/nvd3/examples/indentedtree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
128 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | NVD3 Examples List
4 |
5 |
48 | NVD3 Examples List
49 |
70 |
86 |
87 |
97 |
98 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/legend.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
77 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/line.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
97 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/lineChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
133 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/lineChartSVGResize.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
152 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/lineWithFisheyeChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
102 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/lineWithFocusChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
88 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/multiBar.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
95 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/multiBarChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
106 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/multiChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
96 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/pie.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
95 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/pieChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
21 | Test1
22 |
23 |
24 | Test2
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
123 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/scatter.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
97 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/scatterChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
40 |
41 |
42 |
43 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
119 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/scatterPlusLineChart.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
40 |
41 |
42 |
43 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
116 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/sparkline.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
21 |
22 |
23 | Sparkline:
24 |
25 |
26 |
27 |
28 |
29 |
63 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/sparklinePlus.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
17 | SparklinePlus:
18 |
19 |
20 | APPL:
21 |
22 | GOOG:
23 |
24 |
25 |
26 |
27 |
28 |
29 |
87 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/stackedArea.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
157 |
--------------------------------------------------------------------------------
/www/js/nvd3/examples/stream_layers.js:
--------------------------------------------------------------------------------
1 |
2 | /* Inspired by Lee Byron's test data generator. */
3 | function stream_layers(n, m, o) {
4 | if (arguments.length < 3) o = 0;
5 | function bump(a) {
6 | var x = 1 / (.1 + Math.random()),
7 | y = 2 * Math.random() - .5,
8 | z = 10 / (.1 + Math.random());
9 | for (var i = 0; i < m; i++) {
10 | var w = (i / m - y) * z;
11 | a[i] += x * Math.exp(-w * w);
12 | }
13 | }
14 | return d3.range(n).map(function() {
15 | var a = [], i;
16 | for (i = 0; i < m; i++) a[i] = o + o * Math.random();
17 | for (i = 0; i < 5; i++) bump(a);
18 | return a.map(stream_index);
19 | });
20 | }
21 |
22 | /* Another layer generator using gamma distributions. */
23 | function stream_waves(n, m) {
24 | return d3.range(n).map(function(i) {
25 | return d3.range(m).map(function(j) {
26 | var x = 20 * j / m - i / 3;
27 | return 2 * x * Math.exp(-.5 * x);
28 | }).map(stream_index);
29 | });
30 | }
31 |
32 | function stream_index(d, i) {
33 | return {x: i, y: Math.max(0, d)};
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/www/js/nvd3/lib/fisheye.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | d3.fisheye = {
3 | scale: function(scaleType) {
4 | return d3_fisheye_scale(scaleType(), 3, 0);
5 | },
6 | circular: function() {
7 | var radius = 200,
8 | distortion = 2,
9 | k0,
10 | k1,
11 | focus = [0, 0];
12 |
13 | function fisheye(d) {
14 | var dx = d.x - focus[0],
15 | dy = d.y - focus[1],
16 | dd = Math.sqrt(dx * dx + dy * dy);
17 | if (!dd || dd >= radius) return {x: d.x, y: d.y, z: 1};
18 | var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25;
19 | return {x: focus[0] + dx * k, y: focus[1] + dy * k, z: Math.min(k, 10)};
20 | }
21 |
22 | function rescale() {
23 | k0 = Math.exp(distortion);
24 | k0 = k0 / (k0 - 1) * radius;
25 | k1 = distortion / radius;
26 | return fisheye;
27 | }
28 |
29 | fisheye.radius = function(_) {
30 | if (!arguments.length) return radius;
31 | radius = +_;
32 | return rescale();
33 | };
34 |
35 | fisheye.distortion = function(_) {
36 | if (!arguments.length) return distortion;
37 | distortion = +_;
38 | return rescale();
39 | };
40 |
41 | fisheye.focus = function(_) {
42 | if (!arguments.length) return focus;
43 | focus = _;
44 | return fisheye;
45 | };
46 |
47 | return rescale();
48 | }
49 | };
50 |
51 | function d3_fisheye_scale(scale, d, a) {
52 |
53 | function fisheye(_) {
54 | var x = scale(_),
55 | left = x < a,
56 | v,
57 | range = d3.extent(scale.range()),
58 | min = range[0],
59 | max = range[1],
60 | m = left ? a - min : max - a;
61 | if (m == 0) m = max - min;
62 | return (left ? -1 : 1) * m * (d + 1) / (d + (m / Math.abs(x - a))) + a;
63 | }
64 |
65 | fisheye.distortion = function(_) {
66 | if (!arguments.length) return d;
67 | d = +_;
68 | return fisheye;
69 | };
70 |
71 | fisheye.focus = function(_) {
72 | if (!arguments.length) return a;
73 | a = +_;
74 | return fisheye;
75 | };
76 |
77 | fisheye.copy = function() {
78 | return d3_fisheye_scale(scale.copy(), d, a);
79 | };
80 |
81 | fisheye.nice = scale.nice;
82 | fisheye.ticks = scale.ticks;
83 | fisheye.tickFormat = scale.tickFormat;
84 | return d3.rebind(fisheye, scale, "domain", "range");
85 | }
86 | })();
87 |
--------------------------------------------------------------------------------
/www/js/nvd3/lib/hive.js:
--------------------------------------------------------------------------------
1 | d3.hive = {};
2 |
3 | d3.hive.link = function() {
4 | var source = function(d) { return d.source; },
5 | target = function(d) { return d.target; },
6 | angle = function(d) { return d.angle; },
7 | startRadius = function(d) { return d.radius; },
8 | endRadius = startRadius,
9 | arcOffset = -Math.PI / 2;
10 |
11 | function link(d, i) {
12 | var s = node(source, this, d, i),
13 | t = node(target, this, d, i),
14 | x;
15 | if (t.a < s.a) x = t, t = s, s = x;
16 | if (t.a - s.a > Math.PI) s.a += 2 * Math.PI;
17 | var a1 = s.a + (t.a - s.a) / 3,
18 | a2 = t.a - (t.a - s.a) / 3;
19 | return s.r0 - s.r1 || t.r0 - t.r1
20 | ? "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0
21 | + "L" + Math.cos(s.a) * s.r1 + "," + Math.sin(s.a) * s.r1
22 | + "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1
23 | + " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1
24 | + " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1
25 | + "L" + Math.cos(t.a) * t.r0 + "," + Math.sin(t.a) * t.r0
26 | + "C" + Math.cos(a2) * t.r0 + "," + Math.sin(a2) * t.r0
27 | + " " + Math.cos(a1) * s.r0 + "," + Math.sin(a1) * s.r0
28 | + " " + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0
29 | : "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0
30 | + "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1
31 | + " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1
32 | + " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1;
33 | }
34 |
35 | function node(method, thiz, d, i) {
36 | var node = method.call(thiz, d, i),
37 | a = +(typeof angle === "function" ? angle.call(thiz, node, i) : angle) + arcOffset,
38 | r0 = +(typeof startRadius === "function" ? startRadius.call(thiz, node, i) : startRadius),
39 | r1 = (startRadius === endRadius ? r0 : +(typeof endRadius === "function" ? endRadius.call(thiz, node, i) : endRadius));
40 | return {r0: r0, r1: r1, a: a};
41 | }
42 |
43 | link.source = function(_) {
44 | if (!arguments.length) return source;
45 | source = _;
46 | return link;
47 | };
48 |
49 | link.target = function(_) {
50 | if (!arguments.length) return target;
51 | target = _;
52 | return link;
53 | };
54 |
55 | link.angle = function(_) {
56 | if (!arguments.length) return angle;
57 | angle = _;
58 | return link;
59 | };
60 |
61 | link.radius = function(_) {
62 | if (!arguments.length) return startRadius;
63 | startRadius = endRadius = _;
64 | return link;
65 | };
66 |
67 | link.startRadius = function(_) {
68 | if (!arguments.length) return startRadius;
69 | startRadius = _;
70 | return link;
71 | };
72 |
73 | link.endRadius = function(_) {
74 | if (!arguments.length) return endRadius;
75 | endRadius = _;
76 | return link;
77 | };
78 |
79 | return link;
80 | };
81 |
--------------------------------------------------------------------------------
/www/js/nvd3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nvd3",
3 | "version": "0.0.1",
4 | "devDependencies": {
5 | "grunt": "~0.4.1",
6 | "grunt-contrib-jshint": "~0.3.0",
7 | "grunt-contrib-watch": "~0.3.1",
8 | "grunt-contrib-uglify": "~0.2.0",
9 | "grunt-contrib-concat": "~0.2.0",
10 | "grunt-contrib-copy": "~0.4.1",
11 | "grunt-contrib-cssmin": "~0.6.2"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/www/js/nvd3/src/core.js:
--------------------------------------------------------------------------------
1 |
2 | var nv = window.nv || {};
3 |
4 |
5 | nv.version = '1.1.15b';
6 | nv.dev = true //set false when in production
7 |
8 | window.nv = nv;
9 |
10 | nv.tooltip = nv.tooltip || {}; // For the tooltip system
11 | nv.utils = nv.utils || {}; // Utility subsystem
12 | nv.models = nv.models || {}; //stores all the possible models/components
13 | nv.charts = {}; //stores all the ready to use charts
14 | nv.graphs = []; //stores all the graphs currently on the page
15 | nv.logs = {}; //stores some statistics and potential error messages
16 |
17 | nv.dispatch = d3.dispatch('render_start', 'render_end');
18 |
19 | // *************************************************************************
20 | // Development render timers - disabled if dev = false
21 |
22 | if (nv.dev) {
23 | nv.dispatch.on('render_start', function(e) {
24 | nv.logs.startTime = +new Date();
25 | });
26 |
27 | nv.dispatch.on('render_end', function(e) {
28 | nv.logs.endTime = +new Date();
29 | nv.logs.totalTime = nv.logs.endTime - nv.logs.startTime;
30 | nv.log('total', nv.logs.totalTime); // used for development, to keep track of graph generation times
31 | });
32 | }
33 |
34 | // ********************************************
35 | // Public Core NV functions
36 |
37 | // Logs all arguments, and returns the last so you can test things in place
38 | // Note: in IE8 console.log is an object not a function, and if modernizr is used
39 | // then calling Function.prototype.bind with with anything other than a function
40 | // causes a TypeError to be thrown.
41 | nv.log = function() {
42 | if (nv.dev && console.log && console.log.apply)
43 | console.log.apply(console, arguments)
44 | else if (nv.dev && typeof console.log == "function" && Function.prototype.bind) {
45 | var log = Function.prototype.bind.call(console.log, console);
46 | log.apply(console, arguments);
47 | }
48 | return arguments[arguments.length - 1];
49 | };
50 |
51 |
52 | nv.render = function render(step) {
53 | step = step || 1; // number of graphs to generate in each timeout loop
54 |
55 | nv.render.active = true;
56 | nv.dispatch.render_start();
57 |
58 | setTimeout(function() {
59 | var chart, graph;
60 |
61 | for (var i = 0; i < step && (graph = nv.render.queue[i]); i++) {
62 | chart = graph.generate();
63 | if (typeof graph.callback == typeof(Function)) graph.callback(chart);
64 | nv.graphs.push(chart);
65 | }
66 |
67 | nv.render.queue.splice(0, i);
68 |
69 | if (nv.render.queue.length) setTimeout(arguments.callee, 0);
70 | else {
71 | nv.dispatch.render_end();
72 | nv.render.active = false;
73 | }
74 | }, 0);
75 | };
76 |
77 | nv.render.active = false;
78 | nv.render.queue = [];
79 |
80 | nv.addGraph = function(obj) {
81 | if (typeof arguments[0] === typeof(Function))
82 | obj = {generate: arguments[0], callback: arguments[1]};
83 |
84 | nv.render.queue.push(obj);
85 |
86 | if (!nv.render.active) nv.render();
87 | };
88 |
89 | nv.identity = function(d) { return d; };
90 |
91 | nv.strip = function(s) { return s.replace(/(\s|&)/g,''); };
92 |
93 | function daysInMonth(month,year) {
94 | return (new Date(year, month+1, 0)).getDate();
95 | }
96 |
97 | function d3_time_range(floor, step, number) {
98 | return function(t0, t1, dt) {
99 | var time = floor(t0), times = [];
100 | if (time < t0) step(time);
101 | if (dt > 1) {
102 | while (time < t1) {
103 | var date = new Date(+time);
104 | if ((number(date) % dt === 0)) times.push(date);
105 | step(time);
106 | }
107 | } else {
108 | while (time < t1) { times.push(new Date(+time)); step(time); }
109 | }
110 | return times;
111 | };
112 | }
113 |
114 | d3.time.monthEnd = function(date) {
115 | return new Date(date.getFullYear(), date.getMonth(), 0);
116 | };
117 |
118 | d3.time.monthEnds = d3_time_range(d3.time.monthEnd, function(date) {
119 | date.setUTCDate(date.getUTCDate() + 1);
120 | date.setDate(daysInMonth(date.getMonth() + 1, date.getFullYear()));
121 | }, function(date) {
122 | return date.getMonth();
123 | }
124 | );
125 |
126 |
--------------------------------------------------------------------------------
/www/js/nvd3/src/intro.js:
--------------------------------------------------------------------------------
1 | (function(){
2 |
--------------------------------------------------------------------------------
/www/js/nvd3/src/models/boilerplate.js:
--------------------------------------------------------------------------------
1 |
2 | nv.models.chartName = function() {
3 | "use strict";
4 | //============================================================
5 | // Public Variables with Default Settings
6 | //------------------------------------------------------------
7 |
8 |
9 | var margin = {top: 30, right: 10, bottom: 10, left: 10}
10 | , width = 960
11 | , height = 500
12 | , color = nv.utils.getColor(d3.scale.category20c().range())
13 | , dispatch = d3.dispatch('stateChange', 'changeState')
14 | ;
15 |
16 | //============================================================
17 |
18 |
19 | //============================================================
20 | // Private Variables
21 | //------------------------------------------------------------
22 |
23 |
24 | //============================================================
25 |
26 |
27 | function chart(selection) {
28 | selection.each(function(data) {
29 | var availableWidth = width - margin.left - margin.right,
30 | availableHeight = height - margin.top - margin.bottom,
31 | container = d3.select(this);
32 |
33 |
34 | //------------------------------------------------------------
35 | // Setup Scales
36 |
37 |
38 | //------------------------------------------------------------
39 |
40 |
41 | //------------------------------------------------------------
42 | // Setup containers and skeleton of chart
43 |
44 | var wrap = container.selectAll('g.nv-wrap.nv-chartName').data([data]);
45 | var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-chartName');
46 | var gEnter = wrapEnter.append('g');
47 | var g = wrap.select('g')
48 |
49 | gEnter.append('g').attr('class', 'nv-mainWrap');
50 |
51 | wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
52 |
53 | //------------------------------------------------------------
54 |
55 |
56 |
57 |
58 | });
59 |
60 | return chart;
61 | }
62 |
63 |
64 | //============================================================
65 | // Expose Public Variables
66 | //------------------------------------------------------------
67 |
68 |
69 | chart.dispatch = dispatch;
70 |
71 | chart.options = nv.utils.optionsFunc.bind(chart);
72 |
73 | chart.margin = function(_) {
74 | if (!arguments.length) return margin;
75 | margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
76 | margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
77 | margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
78 | margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
79 | return chart;
80 | };
81 |
82 | chart.width = function(_) {
83 | if (!arguments.length) return width;
84 | width = _;
85 | return chart;
86 | };
87 |
88 | chart.height = function(_) {
89 | if (!arguments.length) return height;
90 | height = _;
91 | return chart;
92 | };
93 |
94 | chart.color = function(_) {
95 | if (!arguments.length) return color;
96 | color = nv.utils.getColor(_)
97 | return chart;
98 | };
99 |
100 | //============================================================
101 |
102 |
103 | return chart;
104 | }
105 |
--------------------------------------------------------------------------------
/www/js/nvd3/src/outro.js:
--------------------------------------------------------------------------------
1 | })();
--------------------------------------------------------------------------------
/www/js/nvd3/test/interactiveBisectTest.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Unit tests for nv.interactiveBisect - this function is important for rendering tooltips and the guideline on charts.
9 |
15 |
16 |
17 |
18 |
19 |
20 |
159 |
--------------------------------------------------------------------------------
/www/js/nvd3/test/multiBarChartTest.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Multibar chart test cases - feel free to add more tests
8 |
11 |
12 | Normal chart, with transition delay, and bar color set.
13 |
14 |
15 |
16 | Normal chart, no transitionDuration or delay, no bar color set.
17 |
18 |
19 |
20 | Chart with single series, no group spacing.
21 |
22 |
23 |
24 | Chart with 18 series, 7 data points per series.
25 |
26 |
27 |
28 | Chart with 1 data point
29 |
30 |
31 |
32 | Chart with 2 data points
33 |
34 |
35 |
36 | Chart with 0 data points
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
149 |
--------------------------------------------------------------------------------
/www/js/nvd3/test/realTimeChartTest.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
15 | Example showing real time chart updating
16 | The chart below is a historical bar chart, which is ideal for visualizing time series data.
17 | First, you need to update the data model for the chart. In the example, we append a random number
18 | every half a second. Then, you call chart.update() .
19 |
20 |
21 |
22 | Start/Stop Stream
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/www/js/nvd3/test/testScript.js:
--------------------------------------------------------------------------------
1 | //A little snippet of D3 code that creates a button that lets you toggle whether a chart is the only one visible on a page or not.
2 | d3.selectAll(".chart button").on("click",function() {
3 | var thisId = this.parentElement.id;
4 |
5 | var chartContainer = d3.select("#" + thisId);
6 | if (chartContainer.attr("class").match("selected"))
7 | chartContainer.classed("selected",false);
8 | else
9 | chartContainer.classed("selected",true);
10 |
11 | d3.selectAll(".chart").style("display",function() {
12 | if (thisId === this.id) return "block";
13 |
14 | if (d3.select(this).style("display") === "none")
15 | return "block";
16 | else
17 | return "none";
18 | });
19 | window.onresize();
20 | });
--------------------------------------------------------------------------------
/www/js/nvd3/test/teststyle.css:
--------------------------------------------------------------------------------
1 | body {
2 | overflow-y:scroll;
3 | font-family: arial;
4 | }
5 |
6 | text {
7 | font: 12px sans-serif;
8 | }
9 |
10 | .chart {
11 | float:left;
12 | height: 500px;
13 | text-align: center;
14 | font-weight: bold;
15 | margin-bottom: 2em;
16 | }
17 | .chart.full {
18 | width: 100%;
19 | }
20 |
21 | .chart.half {
22 | width: 50%;
23 | }
24 |
25 | .chart.third {
26 | width: 33%;
27 | }
28 |
29 | .chart.selected {
30 | width: 100% !important;
31 | }
32 |
33 | .navigation a{
34 | margin-right: 1em;
35 | }
36 |
37 | .navigation {
38 | margin-bottom: 1em;
39 | }
40 |
--------------------------------------------------------------------------------
/www/js/scatterchart-binding.js:
--------------------------------------------------------------------------------
1 | // Put code in an Immediately Invoked Function Expression (IIFE).
2 | // This isn't strictly necessary, but it's good JavaScript hygiene.
3 | (function() {
4 |
5 | // See http://rstudio.github.io/shiny/tutorial/#building-outputs for
6 | // more information on creating output bindings.
7 |
8 | // First create a generic output binding instance, then overwrite
9 | // specific methods whose behavior we want to change.
10 | var binding = new Shiny.OutputBinding();
11 |
12 | binding.find = function(scope) {
13 | // For the given scope, return the set of elements that belong to
14 | // this binding.
15 | return $(scope).find(".nvd3-scatterchart");
16 | };
17 |
18 | binding.renderValue = function(el, data) {
19 | // This function will be called every time we receive new output
20 | // values for a line chart from Shiny. The "el" argument is the
21 | // div for this particular chart.
22 |
23 | var $el = $(el);
24 |
25 | // The first time we render a value for a particular element, we
26 | // need to initialize the nvd3 line chart and d3 selection. We'll
27 | // store these on $el as a data value called "state".
28 | if (!$el.data("state")) {
29 | // var chart = nv.models.lineChart()
30 | var chart = nv.models.scatterChart()
31 | .margin({left: 100})
32 | // .useInteractiveGuideline(true)
33 | // .transitionDuration(350)
34 | // .showLegend(true)
35 | .size(1)
36 | .sizeRange([50,50])
37 | .showLegend(false)
38 | .showYAxis(true)
39 | .showXAxis(true);
40 |
41 | chart.xAxis //Chart x-axis settings
42 | .axisLabel('X')
43 | .tickFormat(d3.format('d'));
44 | // .tickFormat(d3.format('.00f'));
45 | // .tickFormat(d3.format('.01f'));
46 |
47 | chart.yAxis //Chart y-axis settings
48 | .axisLabel('P')
49 | .tickFormat(d3.format('.02f'));
50 |
51 | nv.utils.windowResize(chart.update);
52 |
53 | var selection = d3.select(el).select("svg");
54 |
55 | // Store the chart object on el so we can get it next time
56 | $el.data("state", {
57 | chart: chart,
58 | selection: selection
59 | });
60 | }
61 |
62 | // Now, the code that'll run every time a value is rendered...
63 |
64 | // Retrieve the chart and selection we created earlier
65 | var state = $el.data("state");
66 |
67 | // Schedule some work with nvd3
68 | nv.addGraph(function() {
69 | // Update the chart
70 | state.selection
71 | .datum(data)
72 | .transition(500)
73 | .call(state.chart);
74 | return state.chart;
75 | });
76 | };
77 |
78 | // Tell Shiny about our new output binding
79 | Shiny.outputBindings.register(binding, "stat_dist.nvd3-scatterchart");
80 |
81 | })();
82 |
--------------------------------------------------------------------------------