Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / survey / graph.php
blob62e10d58ccde925216df012897c478e1f5baea20
1 <?php // $Id$
3 require_once("../../config.php");
4 require_once("$CFG->libdir/graphlib.php");
5 require_once("lib.php");
7 $id = required_param('id', PARAM_INT); // Course Module ID
8 $type = required_param('type', PARAM_FILE); // Graph Type
9 $group = optional_param('group', 0, PARAM_INT); // Group ID
10 $sid = optional_param('sid', false, PARAM_INT); // Student ID
11 $qid = optional_param('qid', 0, PARAM_INT); // Group ID
13 if (! $cm = get_coursemodule_from_id('survey', $id)) {
14 error("Course Module ID was incorrect");
17 if (! $course = get_record("course", "id", $cm->course)) {
18 error("Course is misconfigured");
21 require_login($course->id, false, $cm);
23 $groupmode = groups_get_activity_groupmode($cm); // Groups are being used
24 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
26 if (!has_capability('mod/survey:readresponses', $context)) {
27 if ($type != "student.png" or $sid != $USER->id ) {
28 error("Sorry, you aren't allowed to see this.");
29 } else if ($groupmode and !groups_is_member($group)) {
30 error("Sorry, you aren't allowed to see this.");
34 if (! $survey = get_record("survey", "id", $cm->instance)) {
35 error("Survey ID was incorrect");
38 /// Check to see if groups are being used in this survey
39 if ($group) {
40 $users = groups_get_members($group);
41 } else if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
42 $users = groups_get_grouping_members($cm->groupingid);
43 } else {
44 $users = get_course_users($course->id);
45 $group = false;
48 $stractual = get_string("actual", "survey");
49 $stractualclass = get_string("actualclass", "survey");
50 $stractualstudent = get_string("actualstudent", "survey", $course->student);
52 $strpreferred = get_string("preferred", "survey");
53 $strpreferredclass = get_string("preferredclass", "survey");
54 $strpreferredstudent = get_string("preferredstudent", "survey", $course->student);
56 $virtualscales = false; //set default value for case clauses
58 switch ($type) {
60 case "question.png":
62 $question = get_record("survey_questions", "id", $qid);
63 $question->text = get_string($question->text, "survey");
64 $question->options = get_string($question->options, "survey");
66 $options = explode(",",$question->options);
68 while (list($key,) = each($options)) {
69 $buckets1[$key] = 0;
70 $buckets2[$key] = 0;
73 if ($aaa = get_records_select("survey_answers", "survey = '$cm->instance' AND question = '$qid'")) {
74 foreach ($aaa as $aa) {
75 if (!$group or isset($users[$aa->userid])) {
76 if ($a1 = $aa->answer1) {
77 $buckets1[$a1 - 1]++;
79 if ($a2 = $aa->answer2) {
80 $buckets2[$a2 - 1]++;
87 $maxbuckets1 = max($buckets1);
88 $maxbuckets2 = max($buckets2);
89 $maxbuckets = ($maxbuckets1 > $maxbuckets2) ? $maxbuckets1 : $maxbuckets2;
91 $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
92 $graph->parameter['title'] = "$question->text";
94 $graph->x_data = $options;
96 $graph->y_data['answers1'] = $buckets1;
97 $graph->y_format['answers1'] = array('colour' => 'ltblue','bar' => 'fill','legend' =>$stractual,'bar_size' => 0.4);
98 $graph->y_data['answers2'] = $buckets2;
99 $graph->y_format['answers2'] = array('colour' =>'ltorange','bar' => 'fill','legend' =>$strpreferred,'bar_size' => 0.2);
101 $graph->parameter['legend'] = 'outside-top';
102 $graph->parameter['legend_border'] = 'black';
103 $graph->parameter['legend_offset'] = 4;
105 if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
106 $graph->y_order = array('answers1', 'answers2');
107 } else if ($maxbuckets1 > 0.0) {
108 $graph->y_order = array('answers1');
109 } else {
110 $graph->y_order = array('answers2');
113 $graph->parameter['y_axis_gridlines']= $maxbuckets + 1;
114 $graph->parameter['y_resolution_left']= 1;
115 $graph->parameter['y_decimal_left'] = 0;
116 $graph->parameter['x_axis_angle'] = 20;
117 $graph->parameter['shadow'] = 'none';
119 $graph->y_tick_labels = null;
120 $graph->offset_relation = null;
122 $graph->draw_stack();
124 break;
128 case "multiquestion.png":
130 $question = get_record("survey_questions", "id", $qid);
131 $question->text = get_string($question->text, "survey");
132 $question->options = get_string($question->options, "survey");
134 $options = explode(",",$question->options);
135 $questionorder = explode( ",", $question->multi);
137 $qqq = get_records_list("survey_questions", "id", $question->multi);
139 foreach ($questionorder as $i => $val) {
140 $names[$i] = get_string($qqq["$val"]->shorttext, "survey");
141 $buckets1[$i] = 0;
142 $buckets2[$i] = 0;
143 $count1[$i] = 0;
144 $count2[$i] = 0;
145 $indexof[$val] = $i;
146 $stdev1[$i] = 0;
147 $stdev2[$i] = 0;
150 $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
152 if ($aaa) {
153 foreach ($aaa as $a) {
154 if (!$group or isset($users[$a->userid])) {
155 $index = $indexof[$a->question];
156 if ($a->answer1) {
157 $buckets1[$index] += $a->answer1;
158 $count1[$index]++;
160 if ($a->answer2) {
161 $buckets2[$index] += $a->answer2;
162 $count2[$index]++;
168 foreach ($questionorder as $i => $val) {
169 if ($count1[$i]) {
170 $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
172 if ($count2[$i]) {
173 $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
177 if ($aaa) {
178 foreach ($aaa as $a) {
179 if (!$group or isset($users[$a->userid])) {
180 $index = $indexof[$a->question];
181 if ($a->answer1) {
182 $difference = (float) ($a->answer1 - $buckets1[$index]);
183 $stdev1[$index] += ($difference * $difference);
185 if ($a->answer2) {
186 $difference = (float) ($a->answer2 - $buckets2[$index]);
187 $stdev2[$index] += ($difference * $difference);
193 foreach ($questionorder as $i => $val) {
194 if ($count1[$i]) {
195 $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
197 if ($count2[$i]) {
198 $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
200 $buckets1[$i] = $buckets1[$i] - 1;
201 $buckets2[$i] = $buckets2[$i] - 1;
206 $maxbuckets1 = max($buckets1);
207 $maxbuckets2 = max($buckets2);
210 $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
211 $graph->parameter['title'] = "$question->text";
213 $graph->x_data = $names;
214 $graph->y_data['answers1'] = $buckets1;
215 $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line', 'point' => 'square',
216 'shadow_offset' => 4, 'legend' => $stractual);
217 $graph->y_data['answers2'] = $buckets2;
218 $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square',
219 'shadow_offset' => 4, 'legend' => $strpreferred);
220 $graph->y_data['stdev1'] = $stdev1;
221 $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill',
222 'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.3);
223 $graph->y_data['stdev2'] = $stdev2;
224 $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill',
225 'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.2);
226 $graph->offset_relation['stdev1'] = 'answers1';
227 $graph->offset_relation['stdev2'] = 'answers2';
229 $graph->parameter['bar_size'] = 0.15;
231 $graph->parameter['legend'] = 'outside-top';
232 $graph->parameter['legend_border'] = 'black';
233 $graph->parameter['legend_offset'] = 4;
235 $graph->y_tick_labels = $options;
237 if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
238 $graph->y_order = array('stdev1', 'answers1', 'stdev2', 'answers2');
239 } else if ($maxbuckets1 > 0.0) {
240 $graph->y_order = array('stdev1', 'answers1');
241 } else {
242 $graph->y_order = array('stdev2', 'answers2');
245 $graph->parameter['y_max_left']= count($options) - 1;
246 $graph->parameter['y_axis_gridlines']= count($options);
247 $graph->parameter['y_resolution_left']= 1;
248 $graph->parameter['y_decimal_left']= 1;
249 $graph->parameter['x_axis_angle'] = 20;
251 $graph->draw();
253 break;
257 case "overall.png":
259 $qqq = get_records_list("survey_questions", "id", $survey->questions);
262 foreach ($qqq as $key => $qq) {
263 if ($qq->multi) {
264 $qqq[$key]->text = get_string($qq->text, "survey");
265 $qqq[$key]->options = get_string($qq->options, "survey");
266 if ($qq->type < 0) {
267 $virtualscales = true;
271 foreach ($qqq as $qq) { // if any virtual, then use JUST virtual, else use JUST nonvirtual
272 if ($qq->multi) {
273 if ($virtualscales && $qq->type < 0) {
274 $question[] = $qq;
275 } else if (!$virtualscales && $qq->type > 0) {
276 $question[] = $qq;
280 $numquestions = count($question);
282 $options = explode(",",$question[0]->options);
283 $numoptions = count($options);
285 for ($i=0; $i<$numquestions; $i++) {
286 $names[$i] = $question[$i]->text;
287 $buckets1[$i] = 0.0;
288 $buckets2[$i] = 0.0;
289 $stdev1[$i] = 0.0;
290 $stdev2[$i] = 0.0;
291 $count1[$i] = 0;
292 $count2[$i] = 0;
293 $subquestions = $question[$i]->multi; // otherwise next line doesn't work
294 $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($subquestions)))");
296 if ($aaa) {
297 foreach ($aaa as $a) {
298 if (!$group or isset($users[$a->userid])) {
299 if ($a->answer1) {
300 $buckets1[$i] += $a->answer1;
301 $count1[$i]++;
303 if ($a->answer2) {
304 $buckets2[$i] += $a->answer2;
305 $count2[$i]++;
311 if ($count1[$i]) {
312 $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
314 if ($count2[$i]) {
315 $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
318 // Calculate the standard devaiations
319 if ($aaa) {
320 foreach ($aaa as $a) {
321 if (!$group or isset($users[$a->userid])) {
322 if ($a->answer1) {
323 $difference = (float) ($a->answer1 - $buckets1[$i]);
324 $stdev1[$i] += ($difference * $difference);
326 if ($a->answer2) {
327 $difference = (float) ($a->answer2 - $buckets2[$i]);
328 $stdev2[$i] += ($difference * $difference);
334 if ($count1[$i]) {
335 $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
337 if ($count2[$i]) {
338 $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
341 $buckets1[$i] = $buckets1[$i] - 1; // Hack because there should not be ANY 0 values in the data.
342 $buckets2[$i] = $buckets2[$i] - 1;
346 $maxbuckets1 = max($buckets1);
347 $maxbuckets2 = max($buckets2);
350 $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
351 $graph->parameter['title'] = strip_tags(format_string($survey->name,true));
353 $graph->x_data = $names;
355 $graph->y_data['answers1'] = $buckets1;
356 $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line', 'point' => 'square',
357 'shadow_offset' => 4, 'legend' => $stractual);
358 $graph->y_data['answers2'] = $buckets2;
359 $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square',
360 'shadow_offset' => 4, 'legend' => $strpreferred);
362 $graph->y_data['stdev1'] = $stdev1;
363 $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill',
364 'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.3);
365 $graph->y_data['stdev2'] = $stdev2;
366 $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill',
367 'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.2);
368 $graph->offset_relation['stdev1'] = 'answers1';
369 $graph->offset_relation['stdev2'] = 'answers2';
371 $graph->parameter['legend'] = 'outside-top';
372 $graph->parameter['legend_border'] = 'black';
373 $graph->parameter['legend_offset'] = 4;
375 $graph->y_tick_labels = $options;
377 if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
378 $graph->y_order = array('stdev1', 'answers1', 'stdev2', 'answers2');
379 } else if ($maxbuckets1 > 0.0) {
380 $graph->y_order = array('stdev1', 'answers1');
381 } else {
382 $graph->y_order = array('stdev2', 'answers2');
385 $graph->parameter['y_max_left']= $numoptions - 1;
386 $graph->parameter['y_axis_gridlines']= $numoptions;
387 $graph->parameter['y_resolution_left']= 1;
388 $graph->parameter['y_decimal_left']= 1;
389 $graph->parameter['x_axis_angle'] = 0;
390 $graph->parameter['x_inner_padding'] = 6;
392 $graph->draw();
394 break;
398 case "student.png":
400 $qqq = get_records_list("survey_questions", "id", $survey->questions);
402 foreach ($qqq as $key => $qq) {
403 if ($qq->multi) {
404 $qqq[$key]->text = get_string($qq->text, "survey");
405 $qqq[$key]->options = get_string($qq->options, "survey");
406 if ($qq->type < 0) {
407 $virtualscales = true;
411 foreach ($qqq as $qq) { // if any virtual, then use JUST virtual, else use JUST nonvirtual
412 if ($qq->multi) {
413 if ($virtualscales && $qq->type < 0) {
414 $question[] = $qq;
415 } else if (!$virtualscales && $qq->type > 0) {
416 $question[] = $qq;
420 $numquestions= count($question);
422 $options = explode(",",$question[0]->options);
423 $numoptions = count($options);
425 for ($i=0; $i<$numquestions; $i++) {
426 $names[$i] = $question[$i]->text;
427 $buckets1[$i] = 0.0;
428 $buckets2[$i] = 0.0;
429 $count1[$i] = 0;
430 $count2[$i] = 0;
431 $studbuckets1[$i] = 0.0;
432 $studbuckets2[$i] = 0.0;
433 $studcount1[$i] = 0;
434 $studcount2[$i] = 0;
435 $stdev1[$i] = 0.0;
436 $stdev2[$i] = 0.0;
438 $subquestions = $question[$i]->multi; // otherwise next line doesn't work
439 $aaa = get_records_select("survey_answers","((survey = $cm->instance) AND (question in ($subquestions)))");
441 if ($aaa) {
442 foreach ($aaa as $a) {
443 if (!$group or isset($users[$a->userid])) {
444 if ($a->userid == $sid) {
445 if ($a->answer1) {
446 $studbuckets1[$i] += $a->answer1;
447 $studcount1[$i]++;
449 if ($a->answer2) {
450 $studbuckets2[$i] += $a->answer2;
451 $studcount2[$i]++;
454 if ($a->answer1) {
455 $buckets1[$i] += $a->answer1;
456 $count1[$i]++;
458 if ($a->answer2) {
459 $buckets2[$i] += $a->answer2;
460 $count2[$i]++;
466 if ($count1[$i]) {
467 $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
469 if ($count2[$i]) {
470 $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
472 if ($studcount1[$i]) {
473 $studbuckets1[$i] = (float)$studbuckets1[$i] / (float)$studcount1[$i];
475 if ($studcount2[$i]) {
476 $studbuckets2[$i] = (float)$studbuckets2[$i] / (float)$studcount2[$i];
479 // Calculate the standard devaiations
480 foreach ($aaa as $a) {
481 if (!$group or isset($users[$a->userid])) {
482 if ($a->answer1) {
483 $difference = (float) ($a->answer1 - $buckets1[$i]);
484 $stdev1[$i] += ($difference * $difference);
486 if ($a->answer2) {
487 $difference = (float) ($a->answer2 - $buckets2[$i]);
488 $stdev2[$i] += ($difference * $difference);
493 if ($count1[$i]) {
494 $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
496 if ($count2[$i]) {
497 $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
500 $buckets1[$i] = $buckets1[$i] - 1; // Hack because there should not be ANY 0 values in the data.
501 $buckets2[$i] = $buckets2[$i] - 1;
502 $studbuckets1[$i] = $studbuckets1[$i] - 1;
503 $studbuckets2[$i] = $studbuckets2[$i] - 1;
507 $maxbuckets1 = max($buckets1);
508 $maxbuckets2 = max($buckets2);
511 $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
512 $graph->parameter['title'] = strip_tags(format_string($survey->name,true));
514 $graph->x_data = $names;
516 $graph->y_data['answers1'] = $buckets1;
517 $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line', 'point' => 'square',
518 'shadow_offset' => 0.1, 'legend' => $stractualclass);
519 $graph->y_data['answers2'] = $buckets2;
520 $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square',
521 'shadow_offset' => 0.1, 'legend' => $strpreferredclass);
522 $graph->y_data['studanswers1'] = $studbuckets1;
523 $graph->y_format['studanswers1'] = array('colour' => 'blue', 'line' => 'line', 'point' => 'square',
524 'shadow_offset' => 4, 'legend' => $stractualstudent);
525 $graph->y_data['studanswers2'] = $studbuckets2;
526 $graph->y_format['studanswers2'] = array('colour' => 'orange', 'line' => 'line', 'point' => 'square',
527 'shadow_offset' => 4, 'legend' => $strpreferredstudent);
528 $graph->y_data['stdev1'] = $stdev1;
529 $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill',
530 'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.3);
531 $graph->y_data['stdev2'] = $stdev2;
532 $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill',
533 'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.2);
534 $graph->offset_relation['stdev1'] = 'answers1';
535 $graph->offset_relation['stdev2'] = 'answers2';
537 $graph->y_tick_labels = $options;
539 $graph->parameter['bar_size'] = 0.15;
541 $graph->parameter['legend'] = 'outside-top';
542 $graph->parameter['legend_border'] = 'black';
543 $graph->parameter['legend_offset'] = 4;
545 if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
546 $graph->y_order = array('stdev1', 'stdev2', 'answers1', 'answers2', 'studanswers1', 'studanswers2');
547 } else if ($maxbuckets1 > 0.0) {
548 $graph->y_order = array('stdev1', 'answers1', 'studanswers1');
549 } else {
550 $graph->y_order = array('stdev2', 'answers2', 'studanswers2');
553 $graph->parameter['y_max_left']= $numoptions - 1;
554 $graph->parameter['y_axis_gridlines']= $numoptions;
555 $graph->parameter['y_resolution_left']= 1;
556 $graph->parameter['y_decimal_left']= 1;
557 $graph->parameter['x_axis_angle'] = 20;
559 $graph->draw();
560 break;
564 case "studentmultiquestion.png":
566 $question = get_record("survey_questions", "id", $qid);
567 $question->text = get_string($question->text, "survey");
568 $question->options = get_string($question->options, "survey");
570 $options = explode(",",$question->options);
571 $questionorder = explode( ",", $question->multi);
573 $qqq = get_records_list("survey_questions", "id", $question->multi);
575 foreach ($questionorder as $i => $val) {
576 $names[$i] = get_string($qqq[$val]->shorttext, "survey");
577 $buckets1[$i] = 0;
578 $buckets2[$i] = 0;
579 $count1[$i] = 0;
580 $count2[$i] = 0;
581 $indexof[$val] = $i;
582 $studbuckets1[$i] = 0.0;
583 $studbuckets2[$i] = 0.0;
584 $studcount1[$i] = 0;
585 $studcount2[$i] = 0;
586 $stdev1[$i] = 0.0;
587 $stdev2[$i] = 0.0;
590 $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
592 if ($aaa) {
593 foreach ($aaa as $a) {
594 if (!$group or isset($users[$a->userid])) {
595 $index = $indexof[$a->question];
596 if ($a->userid == $sid) {
597 if ($a->answer1) {
598 $studbuckets1[$index] += $a->answer1;
599 $studcount1[$index]++;
601 if ($a->answer2) {
602 $studbuckets2[$index] += $a->answer2;
603 $studcount2[$index]++;
606 if ($a->answer1) {
607 $buckets1[$index] += $a->answer1;
608 $count1[$index]++;
610 if ($a->answer2) {
611 $buckets2[$index] += $a->answer2;
612 $count2[$index]++;
618 foreach ($questionorder as $i => $val) {
619 if ($count1[$i]) {
620 $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
622 if ($count2[$i]) {
623 $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
625 if ($studcount1[$i]) {
626 $studbuckets1[$i] = (float)$studbuckets1[$i] / (float)$studcount1[$i];
628 if ($studcount2[$i]) {
629 $studbuckets2[$i] = (float)$studbuckets2[$i] / (float)$studcount2[$i];
633 foreach ($aaa as $a) {
634 if (!$group or isset($users[$a->userid])) {
635 $index = $indexof[$a->question];
636 if ($a->answer1) {
637 $difference = (float) ($a->answer1 - $buckets1[$index]);
638 $stdev1[$index] += ($difference * $difference);
640 if ($a->answer2) {
641 $difference = (float) ($a->answer2 - $buckets2[$index]);
642 $stdev2[$index] += ($difference * $difference);
647 foreach ($questionorder as $i => $val) {
648 if ($count1[$i]) {
649 $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
651 if ($count2[$i]) {
652 $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
654 $buckets1[$i] = $buckets1[$i] - 1; // Hack because there should not be ANY 0 values in the data.
655 $buckets2[$i] = $buckets2[$i] - 1;
656 $studbuckets1[$i] = $studbuckets1[$i] - 1;
657 $studbuckets2[$i] = $studbuckets2[$i] - 1;
662 $maxbuckets1 = max($buckets1);
663 $maxbuckets2 = max($buckets2);
666 $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
667 $graph->parameter['title'] = "$question->text";
669 $graph->x_data = $names;
670 $graph->y_data['answers1'] = $buckets1;
671 $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line', 'point' => 'square',
672 'shadow_offset' => 0.1, 'legend' => $stractualclass);
673 $graph->y_data['answers2'] = $buckets2;
674 $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square',
675 'shadow_offset' => 0.1, 'legend' => $strpreferredclass);
676 $graph->y_data['studanswers1'] = $studbuckets1;
677 $graph->y_format['studanswers1'] = array('colour' => 'blue', 'line' => 'line', 'point' => 'square',
678 'shadow_offset' => 4, 'legend' => $stractualstudent);
679 $graph->y_data['studanswers2'] = $studbuckets2;
680 $graph->y_format['studanswers2'] = array('colour' => 'orange', 'line' => 'line', 'point' => 'square',
681 'shadow_offset' => 4, 'legend' => $strpreferredstudent);
682 $graph->y_data['stdev1'] = $stdev1;
683 $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill',
684 'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.3);
685 $graph->y_data['stdev2'] = $stdev2;
686 $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill',
687 'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.2);
688 $graph->offset_relation['stdev1'] = 'answers1';
689 $graph->offset_relation['stdev2'] = 'answers2';
691 $graph->parameter['bar_size'] = 0.15;
693 $graph->parameter['legend'] = 'outside-top';
694 $graph->parameter['legend_border'] = 'black';
695 $graph->parameter['legend_offset'] = 4;
697 $graph->y_tick_labels = $options;
699 if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
700 $graph->y_order = array('stdev1', 'stdev2', 'answers1', 'answers2', 'studanswers1', 'studanswers2');
701 } else if ($maxbuckets1 > 0.0) {
702 $graph->y_order = array('stdev1', 'answers1', 'studanswers1');
703 } else {
704 $graph->y_order = array('stdev2', 'answers2', 'studanswers2');
707 $graph->parameter['y_max_left']= count($options)-1;
708 $graph->parameter['y_axis_gridlines']= count($options);
709 $graph->parameter['y_resolution_left']= 1;
710 $graph->parameter['y_decimal_left']= 1;
711 $graph->parameter['x_axis_angle'] = 20;
713 $graph->draw();
715 break;
717 default:
718 break;
721 exit;