Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 535... Línea 535...
535
 
535
 
536
    function draw_zero_axis_left() {
536
    function draw_zero_axis_left() {
537
      $colour = $this->parameter['zero_axis'];
537
      $colour = $this->parameter['zero_axis'];
538
      if ($colour == 'none') return;
538
      if ($colour == 'none') return;
-
 
539
      // draw zero axis on left hand side
-
 
540
      $this->calculated['zero_axis'] = (int) round(
539
      // draw zero axis on left hand side
541
        $this->calculated['boundary_box']['top'] +
-
 
542
        ($this->calculated['y_axis_left']['max'] * $this->calculated['y_axis_left']['factor'])
540
      $this->calculated['zero_axis'] = round($this->calculated['boundary_box']['top']  + ($this->calculated['y_axis_left']['max'] * $this->calculated['y_axis_left']['factor']));
543
      );
541
      ImageLine($this->image, $this->calculated['boundary_box']['left'], $this->calculated['zero_axis'], $this->calculated['boundary_box']['right'], $this->calculated['zero_axis'], $this->colour[$colour]);
544
      ImageLine($this->image, $this->calculated['boundary_box']['left'], $this->calculated['zero_axis'], $this->calculated['boundary_box']['right'], $this->calculated['zero_axis'], $this->colour[$colour]);
Línea 542... Línea 545...
542
    }
545
    }
543
 
546
 
544
    function draw_zero_axis_right() {
547
    function draw_zero_axis_right() {
545
      $colour = $this->parameter['zero_axis'];
548
      $colour = $this->parameter['zero_axis'];
-
 
549
      if ($colour == 'none') return;
-
 
550
      // draw zero axis on right hand side
546
      if ($colour == 'none') return;
551
      $this->calculated['zero_axis'] = (int) round(
-
 
552
        $this->calculated['boundary_box']['top'] +
547
      // draw zero axis on right hand side
553
        ($this->calculated['y_axis_right']['max'] * $this->calculated['y_axis_right']['factor'])
548
      $this->calculated['zero_axis'] = round($this->calculated['boundary_box']['top']  + ($this->calculated['y_axis_right']['max'] * $this->calculated['y_axis_right']['factor']));
554
      );
Línea 549... Línea 555...
549
      ImageLine($this->image, $this->calculated['boundary_box']['left'], $this->calculated['zero_axis'], $this->calculated['boundary_box']['right'], $this->calculated['zero_axis'], $this->colour[$colour]);
555
      ImageLine($this->image, $this->calculated['boundary_box']['left'], $this->calculated['zero_axis'], $this->calculated['boundary_box']['right'], $this->calculated['zero_axis'], $this->colour[$colour]);
550
    }
556
    }
Línea 689... Línea 695...
689
 
695
 
690
        foreach ($this->calculated['y_axis']['tick_y'] as $set => $tickY) {
696
        foreach ($this->calculated['y_axis']['tick_y'] as $set => $tickY) {
691
          if (!$this->calculated['y_axis_left']['has_data'] && $yGrid != 'none') { // draw grid if not drawn already (above)
697
          if (!$this->calculated['y_axis_left']['has_data'] && $yGrid != 'none') { // draw grid if not drawn already (above)
692
            switch ($yGrid) {
698
            switch ($yGrid) {
693
              case 'line':
699
              case 'line':
694
                ImageLine($this->image, round($gridLeft), round($tickY), round($gridRight), round($tickY), $gridColour);
700
                ImageLine($this->image, (int) round($gridLeft), (int) round($tickY), (int) round($gridRight), (int) round($tickY), $gridColour);
695
                break;
701
                break;
696
               case 'dash':
702
               case 'dash':
697
                $this->image_dashed_line($this->image, round($gridLeft), round($tickY), round($gridRight), round($tickY), $gridColour); // Moodle
703
                $this->image_dashed_line($this->image, (int) round($gridLeft), (int) round($tickY), (int) round($gridRight), (int) round($tickY), $gridColour); // Moodle
698
                break;
704
                break;
699
            }
705
            }
Línea 700... Línea 706...
700
          }
706
          }
701
 
707
 
702
          if ($this->parameter['y_axis_text_right'] && !($set % $this->parameter['y_axis_text_right'])) { // test if tick should be displayed
708
          if ($this->parameter['y_axis_text_right'] && !($set % $this->parameter['y_axis_text_right'])) { // test if tick should be displayed
703
            // draw tick
709
            // draw tick
Línea 704... Línea 710...
704
            if ($tickColour != 'none')
710
            if ($tickColour != 'none')
705
              ImageLine($this->image, round($tickLeft), round($tickY), round($tickRight), round($tickY), $tickColour);
711
              ImageLine($this->image, (int) round($tickLeft), (int) round($tickY), (int) round($tickRight), (int) round($tickY), $tickColour);
706
 
712
 
707
            // draw axis text...
713
            // draw axis text...
Línea 765... Línea 771...
765
 
771
 
Línea 766... Línea 772...
766
          if ((string)$this->y_data[$set][$index] != 'none') {
772
          if ((string)$this->y_data[$set][$index] != 'none') {
767
 
773
 
768
            if (isset($this->y_format[$set]['y_axis']) && $this->y_format[$set]['y_axis'] == 'right') {
774
            if (isset($this->y_format[$set]['y_axis']) && $this->y_format[$set]['y_axis'] == 'right') {
769
              $this->calculated['y_plot'][$set][$index] =
775
              $this->calculated['y_plot'][$set][$index] =
770
                round(($this->y_data[$set][$index] - $this->calculated['y_axis_right']['min'])
776
                (int) round(($this->y_data[$set][$index] - $this->calculated['y_axis_right']['min'])
771
                  * $this->calculated['y_axis_right']['factor']);
777
                  * $this->calculated['y_axis_right']['factor']);
772
            } else {
778
            } else {
773
              //print "$set $index<br />";
779
              //print "$set $index<br />";
774
              $this->calculated['y_plot'][$set][$index] =
780
              $this->calculated['y_plot'][$set][$index] =
775
                round(($this->y_data[$set][$index] - $this->calculated['y_axis_left']['min'])
781
                (int) round(($this->y_data[$set][$index] - $this->calculated['y_axis_left']['min'])
Línea 776... Línea 782...
776
                  * $this->calculated['y_axis_left']['factor']);
782
                  * $this->calculated['y_axis_left']['factor']);
777
            }
783
            }
Línea 810... Línea 816...
810
      foreach ($this->calculated['x_axis']['text'] as $set => $value) {
816
      foreach ($this->calculated['x_axis']['text'] as $set => $value) {
811
        //print "index: $set<br />";
817
        //print "index: $set<br />";
812
        // x tick value
818
        // x tick value
813
        $this->calculated['x_axis']['tick_x'][$set] = $tickX;
819
        $this->calculated['x_axis']['tick_x'][$set] = $tickX;
814
        // if num ticks is auto then x plot value is same as x  tick
820
        // if num ticks is auto then x plot value is same as x  tick
815
        if ($this->parameter['x_axis_gridlines'] == 'auto') $this->calculated['x_plot'][$set] = round($tickX);
821
        if ($this->parameter['x_axis_gridlines'] == 'auto') $this->calculated['x_plot'][$set] = (int) round($tickX);
816
        //print $this->calculated['x_plot'][$set].'<br />';
822
        //print $this->calculated['x_plot'][$set].'<br />';
817
        $tickX += $xStep;
823
        $tickX += $xStep;
818
      }
824
      }
Línea 819... Línea 825...
819
 
825
 
Línea 1177... Línea 1183...
1177
      } else {
1183
      } else {
1178
        if ($max < 0) $factor = - pow(10, (floor(log10(abs($max))) + $resolution) );
1184
        if ($max < 0) $factor = - pow(10, (floor(log10(abs($max))) + $resolution) );
1179
        else $factor = pow(10, (floor(log10(abs($max))) - $resolution) );
1185
        else $factor = pow(10, (floor(log10(abs($max))) - $resolution) );
1180
      }
1186
      }
1181
      if ($factor > 0.1) { // To avoid some wierd rounding errors (Moodle)
1187
      if ($factor > 0.1) { // To avoid some wierd rounding errors (Moodle)
1182
        $factor = round($factor * 1000.0) / 1000.0; // To avoid some wierd rounding errors (Moodle)
1188
        $factor = (int) round($factor * 1000.0) / 1000.0; // To avoid some wierd rounding errors (Moodle)
1183
      } // To avoid some wierd rounding errors (Moodle)
1189
      } // To avoid some wierd rounding errors (Moodle)
Línea 1184... Línea 1190...
1184
 
1190
 
1185
      $max = $factor * @ceil($max / $factor);
1191
      $max = $factor * @ceil($max / $factor);
Línea 1581... Línea 1587...
1581
          break;
1587
          break;
1582
        case 'circle-open':
1588
        case 'circle-open':
1583
          ImageArc($this->image, $u, $v, $size, $size, 0, 360, $this->colour[$colour]);
1589
          ImageArc($this->image, $u, $v, $size, $size, 0, 360, $this->colour[$colour]);
1584
          break;
1590
          break;
1585
        case 'diamond':
1591
        case 'diamond':
1586
          if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
-
 
1587
            ImageFilledPolygon($this->image, array($u, $v - $half, $u + $half, $v, $u, $v + $half, $u - $half, $v), $this->colour[$colour]);
1592
          ImageFilledPolygon($this->image, [$u, $v - $half, $u + $half, $v, $u, $v + $half, $u - $half, $v], $this->colour[$colour]);
1588
          } else {
-
 
1589
            ImageFilledPolygon($this->image, array($u, $v - $half, $u + $half, $v, $u, $v + $half, $u - $half, $v), 4, $this->colour[$colour]);
-
 
1590
          }
-
 
1591
          break;
1593
          break;
1592
        case 'diamond-open':
1594
        case 'diamond-open':
1593
          if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
-
 
1594
            ImagePolygon($this->image, array($u, $v - $half, $u + $half, $v, $u, $v + $half, $u - $half, $v), $this->colour[$colour]);
1595
          ImagePolygon($this->image, [$u, $v - $half, $u + $half, $v, $u, $v + $half, $u - $half, $v], $this->colour[$colour]);
1595
          } else {
-
 
1596
            ImagePolygon($this->image, array($u, $v - $half, $u + $half, $v, $u, $v + $half, $u - $half, $v), 4, $this->colour[$colour]);
-
 
1597
          }
-
 
1598
          break;
1596
          break;
1599
        case 'triangle':
1597
        case 'triangle':
1600
          if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
-
 
1601
            ImageFilledPolygon($this->image, array($u, $v - $half, $u + $half, $v + $half, $u - $half, $v + $half), $this->colour[$colour]);
1598
          ImageFilledPolygon($this->image, [$u, $v - $half, $u + $half, $v + $half, $u - $half, $v + $half], $this->colour[$colour]);
1602
          } else {
-
 
1603
            ImageFilledPolygon($this->image, array($u, $v - $half, $u + $half, $v + $half, $u - $half, $v + $half), 3, $this->colour[$colour]);
-
 
1604
          }
-
 
1605
          break;
1599
          break;
1606
        case 'triangle-open':
1600
        case 'triangle-open':
1607
          if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
-
 
1608
            ImagePolygon($this->image, array($u, $v - $half, $u + $half, $v + $half, $u - $half, $v + $half), $this->colour[$colour]);
1601
          ImagePolygon($this->image, [$u, $v - $half, $u + $half, $v + $half, $u - $half, $v + $half], $this->colour[$colour]);
1609
          } else {
-
 
1610
            ImagePolygon($this->image, array($u, $v - $half, $u + $half, $v + $half, $u - $half, $v + $half), 3, $this->colour[$colour]);
-
 
1611
          }
-
 
1612
          break;
1602
          break;
1613
        case 'dot':
1603
        case 'dot':
1614
          ImageSetPixel($this->image, $u, $v, $this->colour[$colour]);
1604
          ImageSetPixel($this->image, $u, $v, $this->colour[$colour]);
1615
          break;
1605
          break;
1616
      }
1606
      }
Línea 1669... Línea 1659...
1669
        $u_right = (int) round($x_right + $offset - 1);
1659
        $u_right = (int) round($x_right + $offset - 1);
1670
        $v       = $this->calculated['boundary_box']['bottom'] - $y + $offset;
1660
        $v       = $this->calculated['boundary_box']['bottom'] - $y + $offset;
Línea 1671... Línea 1661...
1671
 
1661
 
1672
        // Moodle addition, plus the function parameter yoffset
1662
        // Moodle addition, plus the function parameter yoffset
1673
        if ($yoffset) {                                           // Moodle
1663
        if ($yoffset) {                                           // Moodle
1674
            $yoffset = $yoffset - round(($bottom - $v) / 2.0);    // Moodle
1664
            $yoffset = $yoffset - (int) round(($bottom - $v) / 2.0);    // Moodle
1675
            $bottom -= $yoffset;                                  // Moodle
1665
            $bottom -= $yoffset;                                  // Moodle
1676
            $v      -= $yoffset;                                  // Moodle
1666
            $v      -= $yoffset;                                  // Moodle
Línea 1677... Línea 1667...
1677
        }                                                         // Moodle
1667
        }                                                         // Moodle
Línea 1700... Línea 1690...
1700
        $v_start = $bottom - $y_start + $offset;
1690
        $v_start = $bottom - $y_start + $offset;
1701
        $v_end   = $bottom - $y_end + $offset;
1691
        $v_end   = $bottom - $y_end + $offset;
1702
        switch ($type) {
1692
        switch ($type) {
1703
          case 'fill':
1693
          case 'fill':
1704
            // draw it this way 'cos the FilledPolygon routine seems a bit buggy.
1694
            // draw it this way 'cos the FilledPolygon routine seems a bit buggy.
1705
            if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
-
 
1706
              ImageFilledPolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $zero, $u_start, $zero), $this->colour[$colour]);
1695
            ImageFilledPolygon($this->image, [$u_start, $v_start, $u_end, $v_end, $u_end, $zero, $u_start, $zero], $this->colour[$colour]);
1707
              ImagePolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $zero, $u_start, $zero), $this->colour[$colour]);
1696
            ImagePolygon($this->image, [$u_start, $v_start, $u_end, $v_end, $u_end, $zero, $u_start, $zero], $this->colour[$colour]);
1708
            } else {
-
 
1709
              ImageFilledPolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $zero, $u_start, $zero), 4, $this->colour[$colour]);
-
 
1710
              ImagePolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $zero, $u_start, $zero), 4, $this->colour[$colour]);
-
 
1711
            }
-
 
1712
            break;
1697
            break;
1713
          case 'open':
1698
          case 'open':
1714
            ImageLine($this->image, $u_start, $v_start, $u_end, $v_end, $this->colour[$colour]);
1699
            ImageLine($this->image, $u_start, $v_start, $u_end, $v_end, $this->colour[$colour]);
1715
            ImageLine($this->image, $u_start, $v_start, $u_start, $zero, $this->colour[$colour]);
1700
            ImageLine($this->image, $u_start, $v_start, $u_start, $zero, $this->colour[$colour]);
1716
            ImageLine($this->image, $u_end, $v_end, $u_end, $zero, $this->colour[$colour]);
1701
            ImageLine($this->image, $u_end, $v_end, $u_end, $zero, $this->colour[$colour]);
Línea 1725... Línea 1710...
1725
 
1710
 
1726
        if ($this->parameter['shadow_below_axis'] ) $bottom  += $offset;
1711
        if ($this->parameter['shadow_below_axis'] ) $bottom  += $offset;
1727
        if ($this->parameter['inner_border'] != 'none') $bottom -= 1; // 1 pixel above bottom if border is to be drawn.
1712
        if ($this->parameter['inner_border'] != 'none') $bottom -= 1; // 1 pixel above bottom if border is to be drawn.
1728
        switch ($type) {
1713
        switch ($type) {
1729
          case 'fill':
-
 
1730
          if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
1714
          case 'fill':
1731
              ImageFilledPolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $bottom, $u_start, $bottom), $this->colour[$colour]);
-
 
1732
            } else {
-
 
1733
              ImageFilledPolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $bottom, $u_start, $bottom), 4, $this->colour[$colour]);
-
 
1734
            }
1715
            ImageFilledPolygon($this->image, [$u_start, $v_start, $u_end, $v_end, $u_end, $bottom, $u_start, $bottom], $this->colour[$colour]);
1735
           break;
1716
           break;
1736
            case 'open':
-
 
1737
            if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
1717
          case 'open':
1738
              ImagePolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $bottom, $u_start, $bottom), $this->colour[$colour]);
-
 
1739
            } else {
-
 
1740
              ImagePolygon($this->image, array($u_start, $v_start, $u_end, $v_end, $u_end, $bottom, $u_start, $bottom), 4, $this->colour[$colour]);
-
 
1741
            }
1718
            ImagePolygon($this->image, [$u_start, $v_start, $u_end, $v_end, $u_end, $bottom, $u_start, $bottom], $this->colour[$colour]);
1742
            break;
1719
            break;
1743
        }
1720
        }
1744
      }
1721
      }
Línea 1777... Línea 1754...
1777
        //$this->dbug("slope < 1");
1754
        //$this->dbug("slope < 1");
1778
        $m = $dy / $dx; // compute slope
1755
        $m = $dy / $dx; // compute slope
1779
        $t += $y0;
1756
        $t += $y0;
1780
        $dx = ($dx < 0) ? -1 : 1;
1757
        $dx = ($dx < 0) ? -1 : 1;
1781
        $m *= $dx;
1758
        $m *= $dx;
1782
        while (round($x0) != round($x1)) {
1759
        while ((int) round($x0) != (int) round($x1)) {
1783
          if (!$watchdog--) break;
1760
          if (!$watchdog--) break;
1784
          $x0 += $dx; // step to next x value
1761
          $x0 += $dx; // step to next x value
1785
          $t += $m;   // add slope to y value
1762
          $t += $m;   // add slope to y value
1786
          $y = round($t);
1763
          $y = (int) round($t);
1787
          //$this->dbug("x0=$x0, x1=$x1, y=$y watchdog=$watchdog");
1764
          //$this->dbug("x0=$x0, x1=$x1, y=$y watchdog=$watchdog");
1788
          $this->draw_brush($x0, $y, $size, $type, $colour);
1765
          $this->draw_brush($x0, $y, $size, $type, $colour);
Línea 1789... Línea 1766...
1789
 
1766
 
1790
        }
1767
        }
1791
      } else { // slope >= 1
1768
      } else { // slope >= 1
1792
        //$this->dbug("slope >= 1");
1769
        //$this->dbug("slope >= 1");
1793
        $m = $dx / $dy; // compute slope
1770
        $m = $dx / $dy; // compute slope
1794
        $t += $x0;
1771
        $t += $x0;
1795
        $dy = ($dy < 0) ? -1 : 1;
1772
        $dy = ($dy < 0) ? -1 : 1;
1796
        $m *= $dy;
1773
        $m *= $dy;
1797
        while (round($y0) != round($y1)) {
1774
        while ((int) round($y0) != (int) round($y1)) {
1798
          if (!$watchdog--) break;
1775
          if (!$watchdog--) break;
1799
          $y0 += $dy; // step to next y value
1776
          $y0 += $dy; // step to next y value
1800
          $t += $m;   // add slope to x value
1777
          $t += $m;   // add slope to x value
1801
          $x = round($t);
1778
          $x = (int) round($t);
1802
          //$this->dbug("x=$x, y0=$y0, y1=$y1 watchdog=$watchdog");
1779
          //$this->dbug("x=$x, y0=$y0, y1=$y1 watchdog=$watchdog");
Línea 1803... Línea 1780...
1803
          $this->draw_brush($x, $y0, $size, $type, $colour);
1780
          $this->draw_brush($x, $y0, $size, $type, $colour);
1804
 
1781
 
1805
        }
1782
        }
Línea 1806... Línea 1783...
1806
      }
1783
      }
1807
    }
1784
    }
1808
 
1785
 
1809
    function draw_brush($x, $y, $size, $type, $colour) {
1786
    function draw_brush($x, $y, $size, $type, $colour) {
1810
      $x = round($x);
1787
      $x = (int) round($x);
1811
      $y = round($y);
1788
      $y = (int) round($y);
1812
      $half = round($size / 2);
1789
      $half = (int) round($size / 2);
1813
      switch ($type) {
1790
      switch ($type) {
1814
        case 'circle':
1791
        case 'circle':
Línea 1823... Línea 1800...
1823
          break;
1800
          break;
1824
        case 'horizontal':
1801
        case 'horizontal':
1825
          ImageFilledRectangle($this->image, $x-$half, $y, $x+$half, $y+1, $this->colour[$colour]);
1802
          ImageFilledRectangle($this->image, $x-$half, $y, $x+$half, $y+1, $this->colour[$colour]);
1826
          break;
1803
          break;
1827
        case 'slash':
1804
        case 'slash':
1828
          if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
-
 
1829
            ImageFilledPolygon($this->image, array(
1805
          ImageFilledPolygon(
1830
              $x + $half, $y - $half,
-
 
1831
              $x + $half + 1, $y - $half,
-
 
1832
              $x - $half + 1, $y + $half,
-
 
1833
              $x - $half, $y + $half
-
 
1834
            ), $this->colour[$colour]);
1806
            $this->image,
1835
          } else {
1807
            [
1836
            ImageFilledPolygon($this->image, array(
-
 
1837
              $x + $half, $y - $half,
1808
              $x + $half, $y - $half,
1838
              $x + $half + 1, $y - $half,
1809
              $x + $half + 1, $y - $half,
1839
              $x - $half + 1, $y + $half,
1810
              $x - $half + 1, $y + $half,
1840
              $x - $half, $y + $half
1811
              $x - $half, $y + $half,
-
 
1812
            ],
1841
            ), 4, $this->colour[$colour]);
1813
            $this->colour[$colour]
1842
          }
1814
          );
1843
          break;
1815
          break;
1844
        case 'backslash':
1816
        case 'backslash':
1845
          if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
1817
          ImageFilledPolygon(
1846
            ImageFilledPolygon($this->image, array(
1818
            $this->image,
-
 
1819
            [
1847
              $x - $half, $y - $half,
1820
              $x - $half, $y - $half,
1848
              $x - $half + 1, $y - $half,
1821
              $x - $half + 1, $y - $half,
1849
              $x + $half + 1, $y + $half,
1822
              $x + $half + 1, $y + $half,
1850
              $x + $half, $y + $half
1823
              $x + $half, $y + $half,
1851
            ), $this->colour[$colour]);
-
 
1852
          } else {
1824
            ],
1853
            ImageFilledPolygon($this->image, array(
-
 
1854
              $x - $half, $y-$half,
-
 
1855
              $x - $half + 1, $y - $half,
-
 
1856
              $x + $half + 1, $y + $half,
-
 
1857
              $x + $half, $y + $half
-
 
1858
            ), 4, $this->colour[$colour]);
1825
            $this->colour[$colour]
1859
          }
1826
          );
1860
          break;
1827
          break;
1861
        default:
1828
        default:
1862
          @eval($type); // user can create own brush script.
1829
          @eval($type); // user can create own brush script.
1863
      }
1830
      }
1864
    }
1831
    }