Draw a Histogram

@param  string $title
@param  int    $numerator
@param  int    $denominator
@param  int    $line
@param  int    $hist_id
@param  string $color
@param  string $full_color
423467
public static function histogram( $title, $numerator, $denominator, $line, $hist_id, $color = 'normal', $full_color = 'red' ) {
		$levels = array( ' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█' );
		static $hist = false;

		if( !$hist || !$hist[$hist_id] ) {
			$hist[$hist_id] = array_fill(0, Misc::cols(), $levels[0]);
		}

		$text = $title . ' - ' . self::num_display($numerator) . '/' . self::num_display($denominator) . ' ';

		#$lev = round(($numerator / $denominator) * 8);


		$lev              = intval(($numerator / $denominator) * 9);
		$lev              = min($lev, 8);
		$hist[$hist_id][] = $lev == 8 ? Style::$full_color($levels[$lev]) : Style::$color($levels[$lev]);
		array_shift($hist[$hist_id]);

		$sub_array = array_slice($hist[$hist_id], 0 - (Misc::cols() - strlen($text)) + 4);

		$str = $text . '[' . implode($sub_array, '') . ']';
		Output::line($str, $line);
	}
1139543
protected function displayTitle($title, $content_type)
    {
        // Display last word of the title in its own span so it can be styled
        // with an image.
        $title_exp = explode(' ', $title);
        $last_word = array_pop($title_exp);

        if (count($title_exp)) {
            $title = implode(' ', $title_exp) . ' ';
        } else {
            $title = '';
        }

        if ($content_type === 'text/plain') {
            echo SwatString::minimizeEntities($title);
        } else {
            echo $title;
        }

        $span_tag = new SwatHtmlTag('span');
        $span_tag->class = 'swat-table-view-orderable-column-title-last';
        $span_tag->setContent($last_word, $content_type);
        $span_tag->display();
    }
730914
public function _writeDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet_BaseDrawing $pDrawing = null, $pRelationId = -1)
	{
		if ($pRelationId >= 0) {
			// xdr:oneCellAnchor
			$objWriter->startElement('xdr:oneCellAnchor');
				// Image location
				$aCoordinates 		= PHPExcel_Cell::coordinateFromString($pDrawing->getCoordinates());
				$aCoordinates[0] 	= PHPExcel_Cell::columnIndexFromString($aCoordinates[0]);

				// xdr:from
				$objWriter->startElement('xdr:from');
					$objWriter->writeElement('xdr:col', $aCoordinates[0] - 1);
					$objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetX()));
					$objWriter->writeElement('xdr:row', $aCoordinates[1] - 1);
					$objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetY()));
				$objWriter->endElement();

				// xdr:ext
				$objWriter->startElement('xdr:ext');
					$objWriter->writeAttribute('cx', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getWidth()));
					$objWriter->writeAttribute('cy', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getHeight()));
				$objWriter->endElement();

				// xdr:pic
				$objWriter->startElement('xdr:pic');

					// xdr:nvPicPr
					$objWriter->startElement('xdr:nvPicPr');

						// xdr:cNvPr
						$objWriter->startElement('xdr:cNvPr');
						$objWriter->writeAttribute('id', $pRelationId);
						$objWriter->writeAttribute('name', $pDrawing->getName());
						$objWriter->writeAttribute('descr', $pDrawing->getDescription());
						$objWriter->endElement();

						// xdr:cNvPicPr
						$objWriter->startElement('xdr:cNvPicPr');

							// a:picLocks
							$objWriter->startElement('a:picLocks');
							$objWriter->writeAttribute('noChangeAspect', '1');
							$objWriter->endElement();

						$objWriter->endElement();

					$objWriter->endElement();

					// xdr:blipFill
					$objWriter->startElement('xdr:blipFill');

						// a:blip
						$objWriter->startElement('a:blip');
						$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
						$objWriter->writeAttribute('r:embed', 'rId' . $pRelationId);
						$objWriter->endElement();

						// a:stretch
						$objWriter->startElement('a:stretch');
							$objWriter->writeElement('a:fillRect', null);
						$objWriter->endElement();

					$objWriter->endElement();

					// xdr:spPr
					$objWriter->startElement('xdr:spPr');

						// a:xfrm
						$objWriter->startElement('a:xfrm');
						$objWriter->writeAttribute('rot', PHPExcel_Shared_Drawing::degreesToAngle($pDrawing->getRotation()));
						$objWriter->endElement();

						// a:prstGeom
						$objWriter->startElement('a:prstGeom');
						$objWriter->writeAttribute('prst', 'rect');

							// a:avLst
							$objWriter->writeElement('a:avLst', null);

						$objWriter->endElement();

//						// a:solidFill
//						$objWriter->startElement('a:solidFill');

//							// a:srgbClr
//							$objWriter->startElement('a:srgbClr');
//							$objWriter->writeAttribute('val', 'FFFFFF');

///* SHADE
//								// a:shade
//								$objWriter->startElement('a:shade');
//								$objWriter->writeAttribute('val', '85000');
//								$objWriter->endElement();
//*/

//							$objWriter->endElement();

//						$objWriter->endElement();
/*
						// a:ln
						$objWriter->startElement('a:ln');
						$objWriter->writeAttribute('w', '88900');
						$objWriter->writeAttribute('cap', 'sq');

							// a:solidFill
							$objWriter->startElement('a:solidFill');

								// a:srgbClr
								$objWriter->startElement('a:srgbClr');
								$objWriter->writeAttribute('val', 'FFFFFF');
								$objWriter->endElement();

							$objWriter->endElement();

							// a:miter
							$objWriter->startElement('a:miter');
							$objWriter->writeAttribute('lim', '800000');
							$objWriter->endElement();

						$objWriter->endElement();
*/

						if ($pDrawing->getShadow()->getVisible()) {
							// a:effectLst
							$objWriter->startElement('a:effectLst');

								// a:outerShdw
								$objWriter->startElement('a:outerShdw');
								$objWriter->writeAttribute('blurRad', 		PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getShadow()->getBlurRadius()));
								$objWriter->writeAttribute('dist',			PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getShadow()->getDistance()));
								$objWriter->writeAttribute('dir',			PHPExcel_Shared_Drawing::degreesToAngle($pDrawing->getShadow()->getDirection()));
								$objWriter->writeAttribute('algn',			$pDrawing->getShadow()->getAlignment());
								$objWriter->writeAttribute('rotWithShape', 	'0');

									// a:srgbClr
									$objWriter->startElement('a:srgbClr');
									$objWriter->writeAttribute('val',		$pDrawing->getShadow()->getColor()->getRGB());

										// a:alpha
										$objWriter->startElement('a:alpha');
										$objWriter->writeAttribute('val', 	$pDrawing->getShadow()->getAlpha() * 1000);
										$objWriter->endElement();

									$objWriter->endElement();

								$objWriter->endElement();

							$objWriter->endElement();
						}
/*

						// a:scene3d
						$objWriter->startElement('a:scene3d');

							// a:camera
							$objWriter->startElement('a:camera');
							$objWriter->writeAttribute('prst', 'orthographicFront');
							$objWriter->endElement();

							// a:lightRig
							$objWriter->startElement('a:lightRig');
							$objWriter->writeAttribute('rig', 'twoPt');
							$objWriter->writeAttribute('dir', 't');

								// a:rot
								$objWriter->startElement('a:rot');
								$objWriter->writeAttribute('lat', '0');
								$objWriter->writeAttribute('lon', '0');
								$objWriter->writeAttribute('rev', '0');
								$objWriter->endElement();

							$objWriter->endElement();

						$objWriter->endElement();
*/
/*
						// a:sp3d
						$objWriter->startElement('a:sp3d');

							// a:bevelT
							$objWriter->startElement('a:bevelT');
							$objWriter->writeAttribute('w', '25400');
							$objWriter->writeAttribute('h', '19050');
							$objWriter->endElement();

							// a:contourClr
							$objWriter->startElement('a:contourClr');

								// a:srgbClr
								$objWriter->startElement('a:srgbClr');
								$objWriter->writeAttribute('val', 'FFFFFF');
								$objWriter->endElement();

							$objWriter->endElement();

						$objWriter->endElement();
*/
					$objWriter->endElement();

				$objWriter->endElement();

				// xdr:clientData
				$objWriter->writeElement('xdr:clientData', null);

			$objWriter->endElement();
		} else {
			throw new PHPExcel_Writer_Exception("Invalid parameters passed.");
		}
	}
482143
public static function display(\Exception $e, $title = 'Application Error')
    {
        @ob_get_clean();
        echo '
            <html>
                <head>
                    <title>' . $title . '</title>
                    <style>
                        body{margin:0;padding:30px;font:14px/1.5 Helvetica,Arial,Verdana,sans-serif;}
                        span{line-height:30px;}
                        h1{margin:0 0 30px;font-size:40px;font-weight:normal;line-height:54px;border-bottom: 2px solid #CCCCCC;}
                        h2{margin:0 0 20px;font-size:30px;font-weight:normal;line-height:50px;border-bottom: 1px solid #CCCCCC;}
                        h3,h4{margin:0 0 20px;font-size:20px;font-weight:normal;line-height:40px;border-bottom: 1px solid #CCCCCC;}
                        a{color:#428bca;text-decoration:underline;}
                        a:hover{color:#2a6496;}
                        div.file-preview{display:block;height:300px;overflow-x:auto;}
                        table{min-width:100%;line-height:30px;}
                        td.cell-left{padding-right:10px;text-align:right;border-right:1px solid #CCCCCC;}
                        td.cell-right{padding-left:10px;text-align:left;}
                        td.width50{width:50px;}
                        td.width15p{width:15%;}
                        .highlight{background:yellow;}
                        td.code-case{font-family:monospace !important;}
                    </style>
                </head>
                <body>
                    <h1>' . $title . '</h1>
                    <h2><strong>Exception: </strong><br /><code>' . get_class($e) . '</code></h2>
                    <p>
                        <strong>Line: </strong>' . $e->getLine() . '<br />
                        <strong>File: </strong>' . $e->getFile() . '<br />
                        <strong>Code: </strong>' . $e->getCode() . '
                    </p>
                    <h3>Message</h3>
                    <p>
                        <strong>' . $e->getMessage() . '</strong><br />
                    </p>
                    <h3>Additional Information:</h3>
                    <p>
                        ' . self::getMoreInformationFromException($e) . '
                    </p>
                    <h3>Trace</h3>
                    <p>
                        <pre><code>' . $e->getTraceAsString() . '</code></pre><br />
                    </p>
                    '.
                    self::getSnippetFromFile($e->getFile(), $e->getLine())
                    .'
                </body>
            </html>
        ';
        return;
    }
1169226
public function title($title = null)
    {
        if (is_null($title)) {
            return $this->title;
        }

        $this->title = $title;

        return $this;
    }
89453
protected function drawText()
    {
        /**
         * 0 Numbers
         * 1 Pure English letters
         * 2 English letters & Numbers mixed
         * 3 chinese characters
         * 4 All mixed
         */

        switch($this->randomType)
        {
            case 0:
                $this->randomNumbers();
                break;

            case 1:
                $this->randomPureLetters();
                break;

            case 3:
                $this->randomChinese();
                break;

            case 4:
                $this->randomMixed();
                break;

            case 2:
            default:
                $this->randomLetters();
                break;
        }

        if (!$this->fontFile)
        {
            $this->fontFile = __DIR__ . '../../Fonts/verdana.ttf';
        }

        if (!file_exists($this->fontFile))
        {
            throw new \InvalidArgumentException('Font file ' . $this->fontFile . ' not found.');
        }

        $textColor = imagecolorallocate($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));

        $x = ($this->width - ($this->fontSize * $this->length)) / 2;
        $y = $this->fontSize + ($this->height - $this->fontSize) / 2;
        $fontFile = (is_array($this->fontFile)) ? $this->fontFile[array_rand($this->fontFile)] : $this->fontFile;

        imagettftext($this->image, $this->fontSize , mt_rand(-8, 8), $x, $y, $textColor, $fontFile, $this->code);
    }
574219
public static void show(DMatrixD1 A , String title ) {
        JFrame frame = new JFrame(title);

        int width = 300;
        int height = 300;

        if( A.numRows > A.numCols) {
            width = width*A.numCols/A.numRows;
        } else {
            height = height*A.numRows/A.numCols;
        }

        DMatrixComponent panel = new DMatrixComponent(width,height);
        panel.setMatrix(A);

        frame.add(panel, BorderLayout.CENTER);

        frame.pack();
        frame.setVisible(true);

    }
336790
protected function drawSingleBar($im, $color) {
        $this->drawFilledRectangle($im, $this->positionX, 0, $this->positionX, $this->thickness - 1, $color);
    }
785438
public function addDescription($title, $description, $titleAttribs = [], $descAttribs = [])
    {
        $this->addTitle($title, $titleAttribs)
            ->addDesc($description, $descAttribs);

        return $this;
    }
1178881
def draw_hist(self, metric, title=""):
        
        # TODO: assert isinstance(list(values.values())[0], np.ndarray)

        rows = 1
        cols = 1
        limit = 10  # max steps to show

        # We need a 3D projection Subplot, so ignore the one provided to
        # as an create a new one.
        ax = self.figure.add_subplot(self.gs, projection="3d")
        ax.view_init(30, -80)

        # Compute histograms
        verts = []
        area_colors = []
        edge_colors = []
        for i, s in enumerate(metric.steps[-limit:]):
            hist, edges = np.histogram(metric.data[-i-1:])
            # X is bin centers
            x = np.diff(edges)/2 + edges[:-1]
            # Y is hist values
            y = hist
            x = np.concatenate([x[0:1], x, x[-1:]])
            y = np.concatenate([[0], y, [0]])

            # Ranges
            if i == 0:
                x_min = x.min()
                x_max = x.max()
                y_min = y.min()
                y_max = y.max()
            x_min = np.minimum(x_min, x.min())
            x_max = np.maximum(x_max, x.max())
            y_min = np.minimum(y_min, y.min())
            y_max = np.maximum(y_max, y.max())

            alpha = 0.8 * (i+1) / min(limit, len(metric.steps))
            verts.append(list(zip(x, y)))
            area_colors.append(np.array(self.theme["hist_color"] + [alpha]))
            edge_colors.append(np.array(self.theme["hist_outline_color"] + [alpha]))

        poly = PolyCollection(verts, facecolors=area_colors, edgecolors=edge_colors)
        ax.add_collection3d(poly, zs=list(range(min(limit, len(metric.steps)))), zdir='y')

        ax.set_xlim(x_min, x_max)
        ax.set_ylim(0, limit)
        ax.set_yticklabels(metric.formatted_steps[-limit:])
        ax.set_zlim(y_min, y_max)
        ax.set_title(metric.name)
479875
private void drawTitle(Graphics2D chartGraphics) {
    if (title != null) {
      // Strings are drawn from the baseline position of the leftmost char.
      int yTitle = (margin / 2) + titleAscent;
      int xTitle = (chartSize.width / 2) - (titleSize.width / 2);

      chartGraphics.setFont(titleFont);
      chartGraphics.setColor(titleColour);
      chartGraphics.drawString(title, xTitle, yTitle);
    }
  }
141792
public function drawCellContainer($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $valign = "T")
    {
        // Add padding
        $padding = end($this->stylestack["padding"]);
        $toppad = $padding[0];
        $bottompad = $padding[2];

        // Add border and bg color
        $fill = end($this->stylestack["isfilling"]);
        $borderwidth = end($this->stylestack["border-width"]);
        $border = end($this->stylestack["border-style"]);
        if ($border != "none") {
            $border = 1;
        } else {
            $borderwidth = "false";
        }

        // Store current position so we can jump back after cell draw
        $x = $this->document->GetX();
        $y = $this->document->GetY();
        $this->document->MultiCell($w, $this->max_line_height, "", $borderwidth, false, $fill);
        $cell_height = $this->document->GetY() - $y;

        // Jump back
        $this->setPosition($x, $y);
    }
1244901
public function title($title, $url = null)
    {
        $this->title = $title;
        $this->url = $url;

        return $this;
    }
1077519
public static function generate_html_id($title)
    {
        $t = $title;
        $t = str_replace('&amp;', '-and-', $t);
        $t = str_replace('&', '-and-', $t);
        $t = preg_replace('/[^A-Za-z0-9]+/', '-', $t);
        $t = preg_replace('/-+/', '-', $t);
        $t = trim($t, '-');
        $t = strtolower($t);

        return $t;
    }
779133
public function _htmlHeader($title)
    {

        $output = $this->_doctype();
        $output .= '<html lang="en">'."\n";
        $output .= "<head>\n\n";

        $output .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'."\n\n";
        $output .= '<meta name="generator" content="PHPDoctor '.$this->_doclet->version().' (http://peej.github.com/phpdoctor/)">'."\n";
        $output .= '<meta name="when" content="'.gmdate('r').'">'."\n\n";

        $output .= '<link rel="stylesheet" type="text/css" href="'.str_repeat('../', $this->_depth).'stylesheet.css">'."\n";
        $output .= '<link rel="start" href="'.str_repeat('../', $this->_depth).'namespaces.html">'."\n\n";

        $output .= '<title>';
        if ($title) {
            $output .= $title.' ('.$this->_doclet->windowTitle().')';
        } else {
            $output .= $this->_doclet->windowTitle();
        }
        $output .= "</title>\n\n";
        $output .= "</head>\n";

        return $output;

    }
788924
private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $title = null, string $titleFormat = null)
    {
        if (0 === $count = $this->numberOfColumns) {
            return;
        }

        $borders = $this->style->getBorderChars();
        if (!$borders[0] && !$borders[2] && !$this->style->getCrossingChar()) {
            return;
        }

        $crossings = $this->style->getCrossingChars();
        if (self::SEPARATOR_MID === $type) {
            list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[2], $crossings[8], $crossings[0], $crossings[4]];
        } elseif (self::SEPARATOR_TOP === $type) {
            list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[0], $crossings[1], $crossings[2], $crossings[3]];
        } elseif (self::SEPARATOR_TOP_BOTTOM === $type) {
            list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[0], $crossings[9], $crossings[10], $crossings[11]];
        } else {
            list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[0], $crossings[7], $crossings[6], $crossings[5]];
        }

        $markup = $leftChar;
        for ($column = 0; $column < $count; ++$column) {
            $markup .= str_repeat($horizontal, $this->effectiveColumnWidths[$column]);
            $markup .= $column === $count - 1 ? $rightChar : $midChar;
        }

        if (null !== $title) {
            $titleLength = Helper::strlenWithoutDecoration($formatter = $this->output->getFormatter(), $formattedTitle = sprintf($titleFormat, $title));
            $markupLength = Helper::strlen($markup);
            if ($titleLength > $limit = $markupLength - 4) {
                $titleLength = $limit;
                $formatLength = Helper::strlenWithoutDecoration($formatter, sprintf($titleFormat, ''));
                $formattedTitle = sprintf($titleFormat, Helper::substr($title, 0, $limit - $formatLength - 3).'...');
            }

            $titleStart = ($markupLength - $titleLength) / 2;
            if (false === mb_detect_encoding($markup, null, true)) {
                $markup = substr_replace($markup, $formattedTitle, $titleStart, $titleLength);
            } else {
                $markup = mb_substr($markup, 0, $titleStart).$formattedTitle.mb_substr($markup, $titleStart + $titleLength);
            }
        }

        $this->output->writeln(sprintf($this->style->getBorderFormat(), $markup));
    }
1067379
public static function createStandard(string $title, string $text, CardImage $cardImage = null): self
    {
        $card = new self();

        $card->title = $title;
        $card->text  = $text;
        $card->image = $cardImage;

        return $card;
    }