1 /*	$Id: extern.h,v 1.20 2015/02/12 00:19:43 kristaps Exp $ */
2 /*
3  * Copyright (c) 2014, 2015 Kristaps Dzonsons <kristaps@bsd.lv>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #ifndef EXTERN_H
18 #define EXTERN_H
19 
20 struct	kdatahist {
21 	double		 rmin; /* minimum inclusive */
22 	double		 rmax; /* maximum non-inclusive */
23 };
24 
25 struct	kdatabucket {
26 	size_t		 rmin; /* minimum inclusive */
27 	size_t		 rmax; /* maximum non-inclusive */
28 };
29 
30 struct	kdatamean {
31 	size_t		*ns; /* number of bucket modifications */
32 };
33 
34 struct	kdatastddev {
35 	size_t		*ns; /* number of bucket modifications */
36 	double		*m1s; /* incremental mean */
37 	double		*m2s; /* incremental variance parameter */
38 };
39 
40 struct	kdatavector {
41 	size_t		 stepsz; /* vector increase slush size */
42 	size_t		 pairbufsz; /* allocated buffer size */
43 };
44 
45 enum	kdatatype {
46 	KDATA_ARRAY,
47 	KDATA_BUCKET,
48 	KDATA_BUFFER,
49 	KDATA_HIST,
50 	KDATA_MEAN,
51 	KDATA_STDDEV,
52 	KDATA_VECTOR
53 };
54 
55 typedef	int (*ksetfunc)(struct kdata *, size_t, double, double);
56 
57 /*
58  * A dependant tacks on to a data source and is notified (by way of
59  * "func") whenever the value of a bucket has changed.
60  */
61 struct	kdep {
62 	struct kdata	 *dep;
63 	ksetfunc	  func;
64 };
65 
66 /*
67  * A data source can either be "real" (in the sense of being modified by
68  * the calling code) or a "dependant" (in the sense of being updated
69  * from another data source).
70  */
71 struct	kdata {
72 	struct kpair	*pairs; /* data pairs */
73 	size_t		 pairsz; /* number of pairs */
74 	size_t		 refs; /* >0 references to data */
75 	struct kdep	*deps; /* dependants */
76 	size_t		 depsz; /* number of dependants */
77 	enum kdatatype	 type;
78 	union {
79 		struct kdatahist	hist;
80 		struct kdatavector	vector;
81 		struct kdatabucket	bucket;
82 		struct kdatamean	mean;
83 		struct kdatastddev	stddev;
84 	} d;
85 };
86 
87 struct	kplotdat {
88 	struct kdata	**datas; /* referenced data */
89 	size_t		  datasz; /* number of data sets */
90 	struct kdatacfg	 *cfgs; /* plot configurations */
91 	enum kplottype	 *types; /* plot types */
92 	enum kplotstype	  stype; /* multiplot type */
93 	enum ksmthtype	  smthtype; /* smoothing type */
94 	struct ksmthcfg	  smth; /* smooth configuration */
95 	double		  sum; /* used for KSMOOTH_CDF */
96 };
97 
98 struct	kplot {
99 	struct kplotdat	*datas; /* data sets per plot */
100 	size_t		 datasz; /* number of data sets */
101 	struct kplotcfg	 cfg; /* configuration */
102 };
103 
104 struct	kplotctx {
105 	cairo_t		*cr; /* cairo context */
106 	double		 h; /* height of context */
107 	double		 w; /* width of context */
108 	struct kpair	 minv; /* minimum data point values */
109 	struct kpair	 maxv; /* maximum data point values */
110 	struct kplotcfg	 cfg;
111 
112 	/*
113 	 * When computing the plot context, we need to account for a
114 	 * margin, labels, and boundary.
115 	 * To do this, we use these "soft" offset and dimensions.
116 	 * Once we've accounted for the above, we'll use this to
117 	 * translate and resize the Cairo context for graphing.
118 	 */
119 	struct kpair	 offs;
120 	struct kpair	 dims;
121 };
122 
123 __BEGIN_DECLS
124 
125 int	 kdata_dep_add(struct kdata *, struct kdata *, ksetfunc);
126 int	 kdata_dep_run(struct kdata *, size_t);
127 int	 kdata_set(struct kdata *, size_t, double, double);
128 
129 void	 kplotctx_border_init(struct kplotctx *);
130 void	 kplotctx_grid_init(struct kplotctx *);
131 void	 kplotctx_margin_init(struct kplotctx *);
132 void	 kplotctx_tic_init(struct kplotctx *);
133 void	 kplotctx_label_init(struct kplotctx *);
134 
135 double	 kplotctx_line_fix(const struct kplotctx *, double, double);
136 
137 void	 kplotctx_font_init(struct kplotctx *, struct kplotfont *);
138 void	 kplotctx_line_init(struct kplotctx *, struct kplotline *);
139 void	 kplotctx_point_init(struct kplotctx *, struct kplotpoint *);
140 void	 kplotctx_ticln_init(struct kplotctx *, struct kplotticln *);
141 
142 void	 kplotccfg_init_palette(struct kplotccfg *, size_t);
143 
144 __END_DECLS
145 
146 #endif
147