553 | | if votes_total > 0: |
554 | | self._logger.debug(str(self._poll.data[choice] * 1.0 / votes_total)) |
| 556 | if self._view_answer \ |
| 557 | or not self._poll.active: |
| 558 | if votes_total > 0: |
| 559 | self._logger.debug(str(self._poll.data[choice] * 1.0 / votes_total)) |
| 560 | |
| 561 | graph_box = hippo.CanvasBox( |
| 562 | box_width = GRAPH_WIDTH, |
| 563 | orientation = hippo.ORIENTATION_HORIZONTAL) |
| 564 | answer_row.append(graph_box) |
| 565 | |
| 566 | graph_box.append(hippo.CanvasText( |
| 567 | text=justify(self._poll.data, choice), |
| 568 | xalign=hippo.ALIGNMENT_END, |
| 569 | padding_right = 2, |
| 570 | color=style.Color(DARK_GREEN).get_int(), |
| 571 | box_width = GRAPH_TEXT_WIDTH)) |
| 572 | |
| 573 | |
| 574 | graph_box.append(hippo.CanvasBox( |
| 575 | orientation=hippo.ORIENTATION_HORIZONTAL, |
| 576 | background_color=style.Color(PINK).get_int(), |
| 577 | box_width = int(float(self._poll.data[choice]) * |
| 578 | (GRAPH_WIDTH - GRAPH_TEXT_WIDTH*2) / votes_total))) |
| 579 | |
| 580 | graph_box.append(hippo.CanvasText( |
| 581 | text=str(self._poll.data[choice] * 100 / votes_total)+'%', |
| 582 | xalign=hippo.ALIGNMENT_START, |
| 583 | padding_left = 2, |
| 584 | color=style.Color(DARK_GREEN).get_int(), |
| 585 | box_width = GRAPH_TEXT_WIDTH)) |
564 | | padding_right = 2, |
565 | | color=style.Color(DARK_GREEN).get_int(), |
566 | | box_width = GRAPH_TEXT_WIDTH)) |
567 | | |
568 | | |
569 | | graph_box.append(hippo.CanvasBox( |
570 | | orientation=hippo.ORIENTATION_HORIZONTAL, |
571 | | background_color=style.Color(PINK).get_int(), |
572 | | box_width = int(float(self._poll.data[choice]) * |
573 | | (GRAPH_WIDTH - GRAPH_TEXT_WIDTH*2) / votes_total))) |
574 | | |
575 | | graph_box.append(hippo.CanvasText( |
576 | | text=str(self._poll.data[choice] * 100 / votes_total)+'%', |
| 597 | spacing=8, |
| 598 | box_height=4, |
| 599 | padding_left = GRAPH_TEXT_WIDTH, |
| 600 | padding_right = GRAPH_TEXT_WIDTH, |
| 601 | orientation=hippo.ORIENTATION_HORIZONTAL) |
| 602 | line = hippo.CanvasBox( |
| 603 | background_color=style.Color(DARK_GREEN).get_int(), |
| 604 | box_width = GRAPH_WIDTH - GRAPH_TEXT_WIDTH*2, |
| 605 | orientation=hippo.ORIENTATION_HORIZONTAL) |
| 606 | line_box.append(line) |
| 607 | answer_box.append(line_box) |
| 608 | |
| 609 | # total votes |
| 610 | totals_box = hippo.CanvasBox( |
| 611 | xalign=hippo.ALIGNMENT_END, |
| 612 | box_width = GRAPH_WIDTH, |
| 613 | spacing=8, |
| 614 | padding_left = GRAPH_TEXT_WIDTH, |
| 615 | padding_right = GRAPH_TEXT_WIDTH, |
| 616 | orientation=hippo.ORIENTATION_HORIZONTAL) |
| 617 | answer_box.append(totals_box) |
| 618 | |
| 619 | spacer = hippo.CanvasBox( |
| 620 | box_width=100, orientation=hippo.ORIENTATION_VERTICAL) |
| 621 | |
| 622 | spacer.append(hippo.CanvasText( |
| 623 | text=str(votes_total), |
| 624 | xalign=hippo.ALIGNMENT_END, |
| 625 | color=style.Color(DARK_GREEN).get_int())) |
| 626 | totals_box.append(spacer) |
| 627 | |
| 628 | totals_box.append(hippo.CanvasText( |
| 629 | text=' '+_('votes'), |
578 | | padding_left = 2, |
579 | | color=style.Color(DARK_GREEN).get_int(), |
580 | | box_width = GRAPH_TEXT_WIDTH)) |
581 | | |
582 | | answer_box.append(answer_row) |
583 | | |
584 | | if (self._poll.active and self._has_voted) or\ |
585 | | not self._poll.active: |
586 | | |
587 | | # Line above total |
588 | | line_box = hippo.CanvasBox( |
589 | | xalign=hippo.ALIGNMENT_END, |
590 | | spacing=8, |
591 | | box_height=4, |
592 | | padding_left = GRAPH_TEXT_WIDTH, |
593 | | padding_right = GRAPH_TEXT_WIDTH, |
594 | | orientation=hippo.ORIENTATION_HORIZONTAL) |
595 | | line = hippo.CanvasBox( |
596 | | background_color=style.Color(DARK_GREEN).get_int(), |
597 | | box_width = GRAPH_WIDTH - GRAPH_TEXT_WIDTH*2, |
598 | | orientation=hippo.ORIENTATION_HORIZONTAL) |
599 | | line_box.append(line) |
600 | | answer_box.append(line_box) |
601 | | |
602 | | # total votes |
603 | | totals_box = hippo.CanvasBox( |
604 | | xalign=hippo.ALIGNMENT_END, |
605 | | box_width = GRAPH_WIDTH, |
606 | | spacing=8, |
607 | | padding_left = GRAPH_TEXT_WIDTH, |
608 | | padding_right = GRAPH_TEXT_WIDTH, |
609 | | orientation=hippo.ORIENTATION_HORIZONTAL) |
610 | | answer_box.append(totals_box) |
611 | | |
612 | | spacer = hippo.CanvasBox( |
613 | | box_width=100, orientation=hippo.ORIENTATION_VERTICAL) |
614 | | |
615 | | spacer.append(hippo.CanvasText( |
616 | | text=str(votes_total), |
617 | | xalign=hippo.ALIGNMENT_END, |
618 | | color=style.Color(DARK_GREEN).get_int())) |
619 | | totals_box.append(spacer) |
620 | | |
621 | | totals_box.append(hippo.CanvasText( |
622 | | text=' '+_('votes'), |
623 | | xalign=hippo.ALIGNMENT_START, |
624 | | color=style.Color(DARK_GREEN).get_int())) |
625 | | if votes_total < self._poll.maxvoters: |
626 | | totals_box.append(hippo.CanvasText( |
627 | | text=' ('+str(self._poll.maxvoters-votes_total)+ |
628 | | ' votes left to collect)', |
629 | | color=style.Color(DARK_GREEN).get_int())) |
| 631 | color=style.Color(DARK_GREEN).get_int())) |
| 632 | if votes_total < self._poll.maxvoters: |
| 633 | totals_box.append(hippo.CanvasText( |
| 634 | text=' ('+str(self._poll.maxvoters-votes_total)+ |
| 635 | ' votes left to collect)', |
| 636 | color=style.Color(DARK_GREEN).get_int())) |