Example #1
1
 function render()
 {
     if (count($this->results) > 0) {
         $max = max(array_map(function ($result) {
             return $result['count'];
         }, $this->results));
     } else {
         $max = 0;
     }
     // see http://bost.ocks.org/mike/bar/2/
     return h()->div->class('ui fluid card')->div->class('content')->div->class('header')->c($this->label)->end->end->div->class('content')->svg->viewBox('0 0 700 ' . count($this->results) * 30)->style('background:#fff;width:100%;')->c(array_map(function ($result) use($max) {
         $barWidth = $result['count'] / $max * 500;
         $labelAtRight = $barWidth < 40;
         $key = $result['_id'];
         $color = RandomColor::one(['luminosity' => 'bright', 'prng' => function ($min, $max) use($key) {
             # Get the color by hashing the text
             # So it stays the same when the page is refreshed
             return hexdec(UTF8::substr(md5($key), 0, 2)) / pow(16, 2) * ($max - $min) + $min;
         }]);
         if ($key === true) {
             $key = 'Yes';
             $color = '#21ba45';
         } elseif ($key === false) {
             $key = 'No';
             $color = '#db2828';
         } elseif ($key === null) {
             $key = '(None)';
             $color = '#777';
         }
         return h()->g->transform('translate(0, ' . $result['index'] * 30 . ')')->text->style('dominant-baseline:middle;text-anchor:end;')->x(140)->y(15)->c($key)->end->rect->width($barWidth)->y(5)->x(150)->height(20)->fill($color)->end->text->x(150 + $barWidth + ($labelAtRight ? 2 : -5))->y(15)->fill($labelAtRight ? 'black' : 'white')->style('dominant-baseline:middle;' . 'text-anchor:' . ($labelAtRight ? 'start;' : 'end;'))->c($result['count'])->end->end;
     }, $this->results))->end->end->end;
 }
 private function getJsonDataForCategoryExpensesChart()
 {
     $em = $this->getDoctrine()->getManager();
     $transactionRepo = $em->getRepository('AppBundle:Transaction');
     $return = array();
     foreach ($transactionRepo->getCategorySpendings() as $category) {
         $return[] = array('label' => $category['name'], 'value' => ceil($category['sum_category']), 'color' => RandomColor::one());
     }
     return $return;
 }
 public function generateGraphData()
 {
     $reportData = [];
     $workFlows = Workflow::all();
     $totalSites = Site::all()->count();
     $colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink'];
     foreach ($workFlows as $flow) {
         $taskNames = $flow->tasks->lists('name')->toArray();
         foreach ($taskNames as $taskName) {
             $res = \DB::select('SELECT DISTINCT count(jfs_tasks.name) AS count FROM jfs_site_jfs_task INNER JOIN jfs_tasks ON jfs_site_jfs_task.jfs_task_id = jfs_tasks.id WHERE jfs_tasks.name = "' . $taskName . '" AND completed = 1 GROUP BY jfs_task_id');
             if (count($res)) {
                 $reportData[$flow->name][$taskName]['count'] = number_format($res[0]->count / $totalSites, 3) * 100;
             } else {
                 $reportData[$flow->name][$taskName]['count'] = 0;
             }
             $reportData[$flow->name][$taskName]['backgroundColor'] = RandomColor::one(['hue' => $colors[array_rand($colors, 1)]]);
             $reportData[$flow->name][$taskName]['hoverBackgroundColor'] = "#00C0EF";
         }
     }
     return $reportData;
 }
Example #4
0
 /**
  * @return string
  */
 protected function getRandomColor()
 {
     return RandomColor::one(['luminosity' => $this->backgroundLuminosity, 'hue' => $this->hues, 'format' => 'hex']);
 }
Example #5
0
  <pre>RandomColor::many(36);</pre>
  <div class="output">
  <?php 
foreach (RandomColor::many(36) as $c) {
    echo '<span style="background:' . $c . ';"></span>';
}
?>
  </div>
  
  <p>
    You can also pass an options object to randomColor. This allows you to specify the hue, luminosity and the format of colors to generate.
  </p>
  
  <h3>Format</h3>
  <?php 
$c = RandomColor::one(array('format' => 'hsv', 'luminosity' => 'dark'));
?>
  <pre>
RandomColor::one(array('format'=>'hex'));
  <?php 
echo '<span style="color:' . RandomColor::hsv2hex($c) . ';">// "' . RandomColor::hsv2hex($c) . '"</span>';
?>


RandomColor::one(array('format'=>'hsv'));
  <?php 
echo '<span style="color:' . RandomColor::hsv2hex($c) . ';">// ' . preg_replace('/\\s+|,\\s+(\\))/', '$1', var_export($c, true)) . '</span>';
?>


RandomColor::one(array('format'=>'hsl'));
Example #6
0
 public function authReports()
 {
     $reportData = ['factor', 'integration', 'reason', 'result'];
     $colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink'];
     $totalLogs = DuoLog::select('id')->count();
     foreach ($reportData as $report) {
         $res = \DB::select("SELECT DISTINCT {$report}, count(*) as count FROM duo_logs GROUP BY {$report}");
         foreach ($res as $graph) {
             $graphData[$report][$graph->{$report}]['count'] = number_format($graph->count / $totalLogs, 3) * 100;
             $graphData[$report][$graph->{$report}]['backgroundColor'] = RandomColor::one(['hue' => $colors[array_rand($colors, 1)]]);
             $graphData[$report][$graph->{$report}]['hoverBackgroundColor'] = "#00C0EF";
         }
     }
     return view('duo.authlogs.reports', compact('graphData'));
 }