Exemplo n.º 1
0
    public function getDashboardHTML($width, $height, $id)
    {
        $time = GraphiteHelper::getTimeParam($this->time);
        $max = json_encode(100);
        $numerator = json_encode($this->numerator_metrics);
        $denominator = json_encode($this->denominator_metrics);
        $legend_keys = json_encode($this->legend_keys);
        if ($this->percentage_type == self::NUMBER_PERCENTAGE) {
            $interior_html = <<<EOF
                <span class="col_left">
                <span class="value_whole">--</span>
                </span><span class="col_right">
                <span
                    class="value_point">.</span><span
                    class="value_decimal">--</span><span
                    class="value_symbol">%</span>
                <span class="unit">{$this->title}</span>
                </span>
EOF;
        } else {
            $interior_html = '';
        }
        return <<<EOF
            <span id="{$id}" class="graphiteGraph {$this->percentage_type} stat"
                  style="width:{$width}px; height: {$height}px;"
                  data-time="{$time}"
                  data-title='{$this->title}'
                  data-max='{$max}'
                  data-numerator='{$numerator}'
                  data-denominator='{$denominator}'
                  data-legend-keys='{$legend_keys}'
                  >
                  {$interior_html}
            </span>
EOF;
    }
Exemplo n.º 2
0
    public function getDashboardHTML($width, $height, $add_integral = true)
    {
        $id = 'graphite-pie-' . str_replace('.', '', microtime(true));
        $legend_width = $width - 20;
        $graph_height = $height + 20;
        $show_labels = $this->show_labels ? 'true' : 'false';
        $show_legend = $this->show_legend ? 'true' : 'false';
        $sort_legend = $this->sort_legend ? 'true' : 'false';
        if ($this->is_ajax) {
            $time = GraphiteHelper::getTimeParam($this->time);
            $metrics = json_encode($this->metrics);
            $legend_keys = json_encode($this->legend_keys);
            $threshold = isset($this->threshold) ? $this->threshold : 'null';
            $formatted_colors = array();
            foreach ((array) $this->colors as $color_description) {
                $color = GraphFactory::getHexColorValue($color_description);
                $formatted_colors[] = "#{$color}";
            }
            $formatted_use_average = $this->use_average ? 'true' : 'false';
            $colors = json_encode($formatted_colors);
            return <<<EOF
            <div class='flotGraph graphite-pie'
                 data-time='{$time}'
                 data-metrics='{$metrics}'
                 data-legend-keys='{$legend_keys}'
                 data-colors='{$colors}'
                 data-show-labels='{$show_labels}'
                 data-show-legend='{$show_legend}'
                 data-sort-legend='{$sort_legend}'
                 data-threshold='{$threshold}'
                 data-use-average='{$formatted_use_average}'
            >
                <p class='html_title' style='width: {$legend_width}px;'>{$this->title}</p>
                <div class='flot-container' id='{$id}' style='height: {$graph_height}px; width: {$width}px;'></div>
            </div>
EOF;
        } else {
            $targets = array();
            foreach ($this->metrics as $metric) {
                $targets[] = $add_integral ? "integral({$metric})" : $metric;
            }
            $data = GraphiteHelper::fetchSplitRenderDataMultipleTargets($targets, $this->time);
            $json_data_values = array();
            foreach ($data as $index => $split_data) {
                if ($add_integral) {
                    $method = count($this->legend_keys) > $index ? $this->legend_keys[$index] : $this->metrics[$index];
                } else {
                    $header = $split_data[0];
                    list($method) = explode(',', $header);
                }
                if (count($split_data) > 1) {
                    $data_points = explode(',', $split_data[1]);
                    if ($add_integral) {
                        $total = GraphiteHelper::getMaxValue($data_points);
                    } else {
                        $total = GraphiteHelper::getTotal($data_points);
                    }
                    $json_data_values[] = '{label:"' . $method . '", data:' . $total . '}';
                }
            }
            $json_data = '[' . implode(',', $json_data_values) . ']';
            $threshold_setting = isset($this->threshold) ? "threshold: {$this->threshold}," : '';
            $stroke_setting = isset($this->bgColor) ? "stroke: { color: '{$this->bgColor}' }," : '';
            $formatted_colors = array();
            if ($this->colors) {
                foreach ($this->colors as $color_description) {
                    $color = GraphFactory::getHexColorValue($color_description);
                    $formatted_colors[] = "'#{$color}'";
                }
                $colors = 'colors: [' . implode(',', $formatted_colors) . '],';
            } else {
                $colors = '';
            }
            if ($this->show_legend && !$this->show_labels) {
                $label_formatter = <<<EOF
                    labelFormatter: function(label,data) {
                        return label + ' (' + (Math.round(data.percent*100)/100) + '%)';
                    },
EOF;
            } else {
                $label_formatter = "";
            }
            return <<<EOF
        <div class='flotGraph'>
            <p class='html_title' style='width: {$legend_width}px;'>{$this->title}</p>
            <div id='{$id}' style='height: {$graph_height}px; width: {$width}px;'></div>
            <script type="text/javascript">

                var data = {$json_data};
        jQuery.plot(jQuery("#{$id}"), data,
        {
                {$colors}
                series: {
                    pie: {
                        {$stroke_setting}
                        show: true,
                        label: {
                            show: {$show_labels}
                        },
                        combine: {
                            {$threshold_setting}
                            color: '#999'
                        }
                    }
                },
                legend: {
                    {$label_formatter}
                    show: {$show_legend}
                },
                grid: {
                    hoverable: true
                }
        });
        </script>
        </div>
EOF;
        }
    }
Exemplo n.º 3
0
    private function getRatioHtml()
    {
        $time = GraphiteHelper::getTimeParam($this->time);
        $numerator = json_encode($this->numerator_metrics);
        $denominator = json_encode($this->denominator_metrics);
        $ratio_suffix = $this->ratio_suffix ? " {$this->ratio_suffix}" : '';
        if ($this->numerator_metrics && $this->denominator_metrics) {
            return <<<EOF
                <span class="legend-graphite-percentage"
                      data-time="{$time}"
                      data-numerator='{$numerator}'
                      data-denominator='{$denominator}'
                      >
                    (<span class="value_whole">-</span><span class="value_point">.</span><span class="value_decimal">-</span>%{$ratio_suffix})
                </span>
EOF;
        } else {
            return '';
        }
    }