summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-11-08 23:13:07 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-11-08 23:13:48 -0500
commit6c889f406c9c581fb9ad87dd371c57d94394c59f (patch)
tree54e08f98740ced0c85309e189635bdbaf51cb1c0
parentdbdb811a58aeffdce6a2d7b2064dc588d5a055ab (diff)
use automatic scaling
-rw-r--r--asy/sched.asy31
-rw-r--r--src/st2pl.c19
-rwxr-xr-xst_draw2
3 files changed, 35 insertions, 17 deletions
diff --git a/asy/sched.asy b/asy/sched.asy
index cf932b1..4dde796 100644
--- a/asy/sched.asy
+++ b/asy/sched.asy
@@ -3,6 +3,9 @@ import palette;
3 3
4real __from = 0.0; 4real __from = 0.0;
5real __to = 0.0; 5real __to = 0.0;
6int __no_tasks = 0;
7real __scale = 1.0;
8real __time_scale = 1.0;
6 9
7void start_time(real when) 10void start_time(real when)
8{ 11{
@@ -14,6 +17,28 @@ void end_time(real when)
14 __to = when; 17 __to = when;
15} 18}
16 19
20void number_of_tasks(int n)
21{
22 __no_tasks = n;
23}
24
25void prepare_schedule(picture pic=currentpicture,
26 real t0, real t1, int no_tasks)
27{
28 real delta = t1 - t0;
29 start_time(t0);
30 end_time(t1);
31 number_of_tasks(no_tasks);
32 if (delta > 2000) {
33 __time_scale = 2000 / delta;
34 }
35 if (delta > 450) {
36 __scale = 450.0 / delta;
37 delta = 450;
38 }
39 size(pic, delta * cm, no_tasks * 1.5cm, false);
40}
41
17pen[] task_fill = { 42pen[] task_fill = {
18 rgb(1.0,0,0), 43 rgb(1.0,0,0),
19 rgb(0,0,1.0), 44 rgb(0,0,1.0),
@@ -99,7 +124,7 @@ void completed(picture pic=currentpicture, int idx=0, real when) {
99} 124}
100 125
101void draw_grid(picture pic=currentpicture, real xstep=1.0, real f=__from, 126void draw_grid(picture pic=currentpicture, real xstep=1.0, real f=__from,
102 real t=__to, int tasks=1, real xlabelstep=10.0) 127 real t=__to, int tasks=__no_tasks, real xlabelstep=10.0)
103{ 128{
104 real pos = f; 129 real pos = f;
105 int idx = 0; 130 int idx = 0;
@@ -118,8 +143,10 @@ void draw_grid(picture pic=currentpicture, real xstep=1.0, real f=__from,
118 143
119 pos = f; 144 pos = f;
120 while (pos <= t) { 145 while (pos <= t) {
121 string l = format("%f", pos); 146 Label l = scale(__time_scale) * Label(format("%f", pos));
122 label(pic, l, task_y(0, (pos, -1.2)), grid_pen); 147 label(pic, l, task_y(0, (pos, -1.2)), grid_pen);
148 path g = task_y(0, (pos, -0.8))--task_y(0, (pos - 0.5, -1.0))--task_y(0, (pos + 0.5, -1.0))--cycle;
149 fill(pic, g, grid_pen);
123 pos = pos + xlabelstep; 150 pos = pos + xlabelstep;
124 } 151 }
125 152
diff --git a/src/st2pl.c b/src/st2pl.c
index 881da66..6e86c62 100644
--- a/src/st2pl.c
+++ b/src/st2pl.c
@@ -89,7 +89,7 @@ int in_range(double from, double x, double to)
89 return from <= x && x <= to; 89 return from <= x && x <= to;
90} 90}
91 91
92static void write_asy(double from, double to, double scale) 92static void write_asy(double from, double to)
93{ 93{
94 struct task *t; 94 struct task *t;
95 struct evlink *e, *e2; 95 struct evlink *e, *e2;
@@ -97,11 +97,8 @@ static void write_asy(double from, double to, double scale)
97 u32 n = count_tasks(); 97 u32 n = count_tasks();
98 98
99 printf("import sched;\n"); 99 printf("import sched;\n");
100 100 printf("prepare_schedule(%f, %f, %d);\n", from, to, n);
101 printf("size(%fcm, %fcm, false);\n", (to - from) * scale, n * 1.5); 101 printf("draw_grid();\n");
102 printf("start_time(%f); end_time(%f);\n", from, to);
103
104 printf("draw_grid(xstep=1.0, tasks=%u);\n", n);
105 102
106 for_each_task(t) { 103 for_each_task(t) {
107 printf("task(%u, %u, %f, %f);\n", 104 printf("task(%u, %u, %f, %f);\n",
@@ -197,7 +194,7 @@ static lang_t str2mode(const char* str)
197} 194}
198 195
199 196
200#define OPTSTR "f:t:l:m:M:s:" 197#define OPTSTR "f:t:l:m:M:"
201 198
202int main(int argc, char** argv) 199int main(int argc, char** argv)
203{ 200{
@@ -206,7 +203,6 @@ int main(int argc, char** argv)
206 int opt; 203 int opt;
207 double from = 0.0; 204 double from = 0.0;
208 double to = DBL_MAX; 205 double to = DBL_MAX;
209 double scale = 1; /* cm per ms */
210 lang_t mode = PROLOG; 206 lang_t mode = PROLOG;
211 struct heap *h; 207 struct heap *h;
212 208
@@ -228,11 +224,6 @@ int main(int argc, char** argv)
228 case 't': 224 case 't':
229 to = atof(optarg); 225 to = atof(optarg);
230 break; 226 break;
231 case 's':
232 scale = atof(optarg);
233 if (scale <= 0.0)
234 usage("Scale must be > 0 cm/ms.");
235 break;
236 case 'm': 227 case 'm':
237 g_min_task = atoi(optarg); 228 g_min_task = atoi(optarg);
238 if (g_min_task > g_max_task) { 229 if (g_min_task > g_max_task) {
@@ -273,7 +264,7 @@ int main(int argc, char** argv)
273 write_prolog_kb(); 264 write_prolog_kb();
274 break; 265 break;
275 case ASYMPTOTE: 266 case ASYMPTOTE:
276 write_asy(from, to, scale); 267 write_asy(from, to);
277 break; 268 break;
278 default: 269 default:
279 usage("WTF?"); 270 usage("WTF?");
diff --git a/st_draw b/st_draw
index 5dc2153..3f79812 100755
--- a/st_draw
+++ b/st_draw
@@ -139,7 +139,7 @@ else
139fi 139fi
140 140
141info "Drawing schedule..." 141info "Drawing schedule..."
142$ST2PL -lasy -f $FROM -t $TO -s 0.4 $TRACES > $SCHED || die "$ST2PL failed." 142$ST2PL -lasy -f $FROM -t $TO $TRACES > $SCHED || die "$ST2PL failed."
143info "Generating PDF..." 143info "Generating PDF..."
144$ASY -f pdf -o $PDF $SCHED || die "$ASY failed." 144$ASY -f pdf -o $PDF $SCHED || die "$ASY failed."
145 145