Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
41 / 41
ChartGenerator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
41 / 41
 generate
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
41 / 41
<?php
namespace Alxvng\QATracker\Chart;
use Alxvng\QATracker\DataProvider\Model\AbstractDataSerie;
use Goat1000\SVGGraph\LineGraph;
use Goat1000\SVGGraph\SVGGraph;
class ChartGenerator
{
    /**
     * @param        $values
     * @param string $type
     * @param array  $settings
     *
     * @return mixed
     */
    public static function generate($values, $type = LineGraph::class, array $settings = [])
    {
        $dark = 'rgb(54,54,54)';
        $darkRed = 'rgb(127,0,0)';
        $font = 'BlinkMacSystemFont,-apple-system,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",Helvetica,Arial,sans-serif';
        $settings = array_merge([
            'auto_fit' => true,
            'back_colour' => 'none',
            'pad_left' => 0,
            'pad_right' => 0,
            'pad_top' => 2,
            'pad_bottom' => 2,
            'back_stroke_width' => 0,
            'graph_title_colour' => $dark,
            'graph_title_font' => $font,
            'graph_title_font_size' => 18,
            'axis_font_size' => 12,
            'tooltip_font_size' => 16,
            'axis_colour' => $dark,
            'axis_text_colour' => $dark,
            'axis_text_space_v' => 5,
            'axis_font' => $font,
            'axis_stroke_width' => 1,
            'axis_text_space' => 5,
            'show_axis_v' => false,
            'show_axis_text_v' => false,
            'show_axis_h' => false,
            'show_data_labels' => true,
            'data_label_type' => 'circle',
            'data_label_fade_in_speed' => 40,
            'data_label_fade_out_speed' => 5,
            'data_label_click' => 'hide',
            'data_label_shadow_opacity' => 0,
            'data_label_padding' => 1,
            'marker_colour' => $darkRed,
            'marker_stroke_colour' => $darkRed,
            'line_stroke_width' => 1,
            'stroke_colour' => $dark,
            'datetime_keys' => true,
            'datetime_key_format' => AbstractDataSerie::DATE_FORMAT,
            'datetime_text_format' => 'j M',
            'minimum_grid_spacing_h' => 40,
            'show_grid_subdivisions' => true,
            'thousands' => ' ',
            'precision' => 2,
            'exception_throw' => false,
        ], $settings);
        $width = 550;
        $height = 300;
        $graph = new SVGGraph($width, $height, $settings);
        $graph->values($values);
        return $graph->fetch($type);
    }
}