示例#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;
 }
 public function articleCount()
 {
     $categories = PostCategory::all();
     $colours = RandomColor::many($categories->count(), ['hue' => 'blue']);
     return $categories->map(function ($category, $index) use($colours) {
         return ['value' => $category->posts->count(), 'color' => $colours[$index], 'highlight' => '#1D976C', 'label' => $category->name];
     })->toArray();
 }
 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;
 }
示例#5
0
 /**
  * @return string
  */
 protected function getRandomColor()
 {
     return RandomColor::one(['luminosity' => $this->backgroundLuminosity, 'hue' => $this->hues, 'format' => 'hex']);
 }
示例#6
0
文件: view.php 项目: BoBRoID/new.k-z
<?php

/** @var \common\models\Quiz $quiz */
use backend\helpers\ArrayHelper;
use dosamigos\chartjs\ChartJs;
use rmrevin\yii\fontawesome\FontAwesome;
use yii\bootstrap\Html;
$this->title = "Просмотр опроса '{$quiz->name}'";
$this->params['breadcrumbs'][] = ['url' => '/quiz', 'label' => 'Опросы'];
$this->params['breadcrumbs'][] = 'Просмотр опроса';
$colors = \Colors\RandomColor::many(sizeof($quiz->answersWithCount), ['hue' => 'blue', 'luminosity' => 'light']);
?>
<div class="panel panel-default">
    <div class="panel-heading">
        <?php 
echo Html::a(FontAwesome::i('arrow-left') . Html::tag('small', 'Назад'), ['/quiz/default/index'], ['class' => 'btn btn-app']);
?>
        <?php 
echo Html::a(FontAwesome::i('pencil') . Html::tag('small', 'Редактировать'), ['/quiz/edit/' . $quiz->id], ['class' => 'btn btn-app']);
?>
    </div>
    <div class="panel-body">
        <div class="col-xs-6">
            <?php 
echo ChartJs::widget(['type' => 'pie', 'data' => ['datasets' => [['data' => ArrayHelper::toPercents(array_values(ArrayHelper::getColumn($quiz->answersWithCount, 'count'))), 'label' => 'Результаты опроса', 'backgroundColor' => $colors]], 'labels' => array_values(ArrayHelper::getColumn($quiz->answersWithCount, 'text'))]]);
?>
        </div>
        <div class="col-xs-6">
            <?php 
echo ChartJs::widget(['type' => 'bar', 'data' => ['datasets' => [['data' => array_values(ArrayHelper::getColumn($quiz->answersWithCount, 'count')), 'label' => 'Результаты опроса', 'backgroundColor' => $colors]], 'labels' => array_values(ArrayHelper::getColumn($quiz->answersWithCount, 'text'))], 'options' => []]);
?>
 /**
  * Lavanda engine initialisation method.
  *
  * @param Request $request
  * @param Router $router
  * @param ViewFactory $viewFactory
  * @param ValidationFactory $validationFactory
  * @param Filesystem $fileSystem
  * @param FormBuilder $formBuilder
  */
 public function boot(Repository $config, Request $request, Translator $translator, Router $router, ViewFactory $viewFactory, ValidationFactory $validationFactory, Filesystem $fileSystem, FormBuilder $formBuilder)
 {
     // model dependencies
     Model::setRequest($request);
     Model::setTranslator($translator);
     Model::setView($viewFactory);
     Model::setFormBuilder($formBuilder);
     Model::setBasePath($this->app->basePath());
     Model::setPublicPath($this->app->make('path.public'));
     // adding Lavanda controllers to routing
     if (!$this->app->routesAreCached()) {
         $router->get('admin', ['uses' => 'Idealogica\\Lavanda\\MainController@index', 'as' => 'admin.main.index']);
         $router->get('admin/_image', ['uses' => 'Idealogica\\Lavanda\\ImageController@index', 'as' => 'admin.image.index']);
         $router->get('admin/{model}', ['uses' => 'Idealogica\\Lavanda\\EntityController@index', 'as' => 'admin.entity.index']);
         $router->get('admin/{model}/create', ['uses' => 'Idealogica\\Lavanda\\EntityController@create', 'as' => 'admin.entity.create']);
         $router->post('admin/{model}', ['uses' => 'Idealogica\\Lavanda\\EntityController@store', 'as' => 'admin.entity.store']);
         $router->get('admin/{model}/{id}', ['uses' => 'Idealogica\\Lavanda\\EntityController@show', 'as' => 'admin.entity.show']);
         $router->get('admin/{model}/{id}/edit', ['uses' => 'Idealogica\\Lavanda\\EntityController@edit', 'as' => 'admin.entity.edit']);
         $router->put('admin/{model}/{id}', ['uses' => 'Idealogica\\Lavanda\\EntityController@update', 'as' => 'admin.entity.update']);
         $router->delete('admin/{model}/{id}', ['uses' => 'Idealogica\\Lavanda\\EntityController@destroy', 'as' => 'admin.entity.destroy']);
     }
     // custom image validation method
     $validationFactory->extend('lavanda_image', function ($attribute, $value, $parameters) use($request) {
         if ($request->hasFile($attribute)) {
             $validator = Validator::make($request->all(), [$attribute => 'min:1|max:10000|mimes:' . implode(',', $parameters)]);
             return !$validator->fails();
         }
         return true;
     });
     // view composer
     $viewFactory->composer(['lavanda::layout.common', 'lavanda::main.index'], function (View $view) use($config, $fileSystem, $request) {
         $menu = [];
         $maxCount = 0;
         $modelPath = $config->get('lavanda.model_path');
         $files = array_values($fileSystem->files($modelPath));
         mt_srand(10);
         $colors = RandomColor::many(count($files), ['luminosity' => 'light', 'hue' => 265]);
         foreach ($files as $idx => $file) {
             $model = strtolower(basename($file, ".php"));
             $modelClass = getModelClass($model);
             if (!in_array('Idealogica\\Lavanda\\Model', class_parents($modelClass))) {
                 continue;
             }
             $url = adminRoute($model, 'index');
             $count = $modelClass::count();
             $maxCount = $count > $maxCount ? $count : $maxCount;
             $menu[] = ['title' => $modelClass::getPluralName(), 'url' => $url, 'selected' => preg_match('/^' . preg_quote($url, '/') . '/', $request->url()), 'count' => $count, 'columns' => 1, 'color' => (string) (new Color($colors[$idx]))->desaturate(50)->lighten(5)];
         }
         $tiles = $menu;
         if ($maxCount) {
             $rowItems = [];
             $countRow = function ($rowItems) {
                 $rowColumns = 0;
                 foreach ($rowItems as $item) {
                     $rowColumns += $item['columns'];
                 }
                 return $rowColumns;
             };
             $stretchRow = function (array &$rowItems) use($countRow) {
                 if ($rowItems) {
                     $count = $countRow($rowItems);
                     if ($count < 12) {
                         $add = (int) ((12 - $count) / count($rowItems));
                         foreach ($rowItems as &$rowItem) {
                             $rowItem['columns'] += $add;
                         }
                         foreach ($rowItems as &$rowItem) {
                             if ($countRow($rowItems) >= 12) {
                                 break;
                             }
                             $rowItem['columns']++;
                         }
                     }
                 }
             };
             usort($tiles, function ($a, $b) {
                 if ($a['count'] == $b['count']) {
                     return 0;
                 }
                 return $a['count'] > $b['count'] ? -1 : 1;
             });
             foreach ($tiles as &$item) {
                 $columns = (int) round(12 * $item['count'] / $maxCount);
                 $item['columns'] = $columns ?: 1;
                 $rowItems[] =& $item;
                 $rowColumns = $countRow($rowItems);
                 if ($rowColumns > 12) {
                     unset($rowItems[count($rowItems) - 1]);
                     $stretchRow($rowItems);
                     $rowItems = [];
                     $rowItems[] =& $item;
                 } elseif ($rowColumns == 12) {
                     $rowItems = [];
                 }
             }
             $stretchRow($rowItems);
         }
         $view->with('menu', $menu)->with('tiles', $tiles);
     });
     // request rebinding
     $this->app->rebinding('request', function ($app, $request) {
         $app->forgetInstance('laravel-form-helper');
         $app->forgetInstance('laravel-form-builder');
         $app->bindShared('laravel-form-helper', function ($app) use($request) {
             $configuration = $app['config']->get('laravel-form-builder');
             return new FormHelper($app['view'], $request, $configuration);
         });
         $app->bindShared('laravel-form-builder', function ($app) {
             return new FormBuilder($app, $app['laravel-form-helper']);
         });
         Model::flush();
         Model::setRequest($request);
         Model::setFormBuilder($app->make('laravel-form-builder'));
     });
     // package configuration
     $packageDir = dirname(__DIR__);
     $viewsPath = $packageDir . '/views';
     $translationsPath = $packageDir . '/lang';
     $assetsPath = $packageDir . '/assets';
     $configPath = $packageDir . '/config/common.php';
     $this->loadViewsFrom($viewsPath, 'lavanda');
     $this->loadTranslationsFrom($translationsPath, 'lavanda');
     $this->mergeConfigFrom($configPath, 'lavanda');
     $this->publishes([$translationsPath => base_path('resources/lang/vendor/lavanda')], 'lang');
     $this->publishes([$viewsPath => base_path('resources/views/vendor/lavanda')], 'views');
     $this->publishes([$assetsPath => public_path('vendor/lavanda')], 'public');
     $this->publishes([$configPath => config_path('lavanda.php')], 'config');
 }
示例#8
0
  
  <h3>Dark colors</h3>
  <pre>RandomColor::many(27, array('luminosity'=>'dark'));</pre>
  <div class="output">
  <?php 
foreach (RandomColor::many(27, array('luminosity' => 'dark')) as $c) {
    echo '<span style="background:' . $c . ';"></span>';
}
?>
  </div>
  
  <h3>Truly random colors</h3>
  <pre>RandomColor::many(36, array('luminosity'=>'random', 'hue'=>'random'));</pre>
  <div class="output">
  <?php 
foreach (RandomColor::many(36, array('luminosity' => 'random', 'hue' => 'random')) as $c) {
    echo '<span style="background:' . $c . ';"></span>';
}
?>
  </div>
  
  <a class="btn btn-danger btn-lg btn-download" href="https://github.com/mistic100/RandomColor.php">
    Get this on GitHub &nbsp;&nbsp;
    <i class="glyphicon glyphicon-arrow-right"></i>
  </a>
  
  <footer class="footer">
    <p>Made by <a href="http://www.strangeplanet.fr">Damien "Mistic" Sorel</a> based on the work of <a href="http://twitter.com/davidmerfieId">David Merfield</a>. Licensed under the MIT License.</p>
  </footer>
  
</body>
示例#9
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'));
 }