├── src ├── HighChartsAsset.php └── HighCharts.php ├── .php_cs ├── CONTRIBUTING.md ├── LICENSE.md ├── composer.json └── README.md /src/HighChartsAsset.php: -------------------------------------------------------------------------------- 1 | 15 | * @link http://www.ramirezcobos.com/ 16 | * @link http://www.2amigos.us/ 17 | * @package dosamigos\highcharts 18 | */ 19 | class HighChartsAsset extends AssetBundle 20 | { 21 | public $sourcePath = '@bower/highcharts-release/'; 22 | 23 | public $depends = [ 24 | 'yii\web\JqueryAsset', 25 | ]; 26 | 27 | public $js = [ 28 | 'highcharts.src.js', 29 | ]; 30 | } 31 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | in(__DIR__) 4 | ; 5 | 6 | return PhpCsFixer\Config::create() 7 | ->setRiskyAllowed(true) 8 | ->setRules(array( 9 | '@PSR2' => true, 10 | 'array_syntax' => array('syntax' => 'short'), 11 | 'combine_consecutive_unsets' => true, 12 | // 'header_comment' => array('header' => $header), 13 | 'no_extra_consecutive_blank_lines' => array( 14 | 'break', 15 | 'continue', 16 | 'extra', 17 | 'return', 18 | 'throw', 19 | 'use', 20 | 'parenthesis_brace_block', 21 | 'square_brace_block', 22 | 'curly_brace_block' 23 | ), 24 | 'no_useless_else' => true, 25 | 'no_useless_return' => true, 26 | 'ordered_class_elements' => true, 27 | 'ordered_imports' => true, 28 | 'phpdoc_add_missing_param_annotation' => true, 29 | 'psr4' => true, 30 | 'strict_comparison' => true, 31 | )) 32 | ->setFinder($finder) 33 | ; 34 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/2amigos/yii2-tinymce-widget). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ phpunit 29 | ``` 30 | 31 | 32 | **Happy coding**! -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The BSD License (BSD) 2 | 3 | Copyright (c) 2013-2015, 2amigOS! Consulting Group LLC. 4 | 5 | > Redistribution and use in source and binary forms, with or without modification, 6 | > are permitted provided that the following conditions are met: 7 | > 8 | > Redistributions of source code must retain the above copyright notice, this 9 | > list of conditions and the following disclaimer. 10 | > 11 | > Redistributions in binary form must reproduce the above copyright notice, this 12 | > list of conditions and the following disclaimer in the documentation and/or 13 | > other materials provided with the distribution. 14 | > 15 | > Neither the name of 2amigOS! Consulting Group, LLC. nor the names of its 16 | > contributors may be used to endorse or promote products derived from 17 | > this software without specific prior written permission. 18 | > 19 | >THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | >ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | >WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | >DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | >ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | >(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | >LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | >ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | >(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | >SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "2amigos/yii2-highcharts-widget", 3 | "description": "Highcharts JS widget for Yii2.", 4 | "type": "yii2-extension", 5 | "keywords": [ 6 | "2amigos", 7 | "yii", 8 | "yii2", 9 | "yii 2", 10 | "extension", 11 | "widget", 12 | "chart", 13 | "highcharts" 14 | ], 15 | "homepage": "http://yiiwheels.com/extension/highcharts-widget", 16 | "license": "BSD-3-Clause", 17 | "authors": [ 18 | { 19 | "name": "2amigOS! Consulting Group", 20 | "email": "hola@2amigos.us", 21 | "homepage": "http://2amigos.us", 22 | "role": "Developer" 23 | } 24 | ], 25 | "support": { 26 | "issues": "https://github.com/2amigos/yii2-highcharts-widget/issues", 27 | "source": "https://github.com/2amigos/yii2-highcharts-widget" 28 | }, 29 | "require": { 30 | "yiisoft/yii2": "*", 31 | "bower-asset/highcharts-release": "5.0.*" 32 | }, 33 | "require-dev": { 34 | "phpunit/phpunit": "4.*", 35 | "friendsofphp/php-cs-fixer": "^2.0", 36 | "scrutinizer/ocular": "~1.1" 37 | }, 38 | "autoload": { 39 | "psr-4": { 40 | "dosamigos\\highcharts\\": "src" 41 | } 42 | }, 43 | "extra": { 44 | "branch-alias": { 45 | "dev-master": "1.0-dev" 46 | } 47 | }, 48 | "config": { 49 | "fxp-asset": { 50 | "installer-paths": { 51 | "bower-asset-library": "vendor/bower" 52 | }, 53 | "vcs-driver-options": { 54 | "github-no-api": true 55 | }, 56 | "git-skip-update": "2 days", 57 | "pattern-skip-version": "(-build|-patch)" 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HighCharts JS Widget for Yii2 2 | ============================= 3 | 4 | [![Latest Version](https://img.shields.io/github/tag/2amigos/yii2-highcharts-widget.svg?style=flat-square&label=release)](https://github.com/2amigos/yii2-highcharts-widget/tags) 5 | [![Software License](https://img.shields.io/badge/license-BSD-brightgreen.svg?style=flat-square)](LICENSE.md) 6 | [![Build Status](https://img.shields.io/travis/2amigos/yii2-highcharts-widget/master.svg?style=flat-square)](https://travis-ci.org/2amigos/yii2-highcharts-widget) 7 | [![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/2amigos/yii2-highcharts-widget.svg?style=flat-square)](https://scrutinizer-ci.com/g/2amigos/yii2-highcharts-widget/code-structure) 8 | [![Quality Score](https://img.shields.io/scrutinizer/g/2amigos/yii2-highcharts-widget.svg?style=flat-square)](https://scrutinizer-ci.com/g/2amigos/yii2-highcharts-widget) 9 | [![Total Downloads](https://img.shields.io/packagist/dt/2amigos/yii2-highcharts-widget.svg?style=flat-square)](https://packagist.org/packages/2amigos/yii2-highcharts-widget) 10 | 11 | The amazing [HighCharts JS](http://www.highcharts.com/) widget now for Yii2. 12 | 13 | Highcharts is one of the best HTML5/Javascript charting libraries on the web. Highcharts JS is free for a non-commercial 14 | project but not if you are developing a product that you are going to make money with. 15 | 16 | Visit [HighCharts site](http://www.highcharts.com/) in order to get more information about the different options of this 17 | plugin and its [license pricing](http://shop.highsoft.com/highcharts.html). 18 | 19 | Installation 20 | ------------ 21 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 22 | 23 | Either run 24 | 25 | ``` 26 | composer require 2amigos/yii2-highcharts-widget:~1.0 27 | ``` 28 | or add 29 | 30 | ```json 31 | "2amigos/yii2-highcharts-widget" : "~1.0" 32 | ``` 33 | 34 | to the require section of your application's `composer.json` file. 35 | 36 | 37 | Usage 38 | ----- 39 | 40 | ``` 41 | // on your view 42 | 43 | [ 46 | 'chart' => [ 47 | 'type' => 'bar' 48 | ], 49 | 'title' => [ 50 | 'text' => 'Fruit Consumption' 51 | ], 52 | 'xAxis' => [ 53 | 'categories' => [ 54 | 'Apples', 55 | 'Bananas', 56 | 'Oranges' 57 | ] 58 | ], 59 | 'yAxis' => [ 60 | 'title' => [ 61 | 'text' => 'Fruit eaten' 62 | ] 63 | ], 64 | 'series' => [ 65 | ['name' => 'Jane', 'data' => [1, 0, 4]], 66 | ['name' => 'John', 'data' => [5, 7, 3]] 67 | ] 68 | ] 69 | ]); 70 | // ... 71 | ``` 72 | 73 | Further Information 74 | ------------------- 75 | Please, check the [HighCharts site](http://www.highcharts.com/) documentation for further 76 | information about its configuration options. 77 | 78 | ## Using code fixer 79 | 80 | We have added a PHP code fixer to standardize our code. It includes Symfony, PSR2 and some contributors rules. 81 | 82 | ```bash 83 | ./vendor/bin/php-cs-fixer fix ./src --config .php_cs 84 | ``` 85 | 86 | 87 | ## Contributing 88 | 89 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 90 | 91 | ## Credits 92 | 93 | - [Antonio Ramirez](https://github.com/tonydspaniard) 94 | - [All Contributors](../../contributors) 95 | 96 | ## License 97 | 98 | The BSD License (BSD). Please see [License File](LICENSE.md) for more information. 99 | 100 | > [![2amigOS!](http://www.gravatar.com/avatar/55363394d72945ff7ed312556ec041e0.png)](http://www.2amigos.us) 101 | Custom Software | Web & Mobile Software Development 102 | [www.2amigos.us](http://www.2amigos.us) 103 | -------------------------------------------------------------------------------- /src/HighCharts.php: -------------------------------------------------------------------------------- 1 | 18 | * @link http://www.ramirezcobos.com/ 19 | * @link http://www.2amigos.us/ 20 | * @package dosamigos\highcharts 21 | */ 22 | class HighCharts extends Widget 23 | { 24 | /** 25 | * @var array the HTML attributes for the links container tag. 26 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. 27 | */ 28 | public $options = []; 29 | /** 30 | * @var array the options for the HighCharts plugin. Default options have exporting enabled. 31 | * Please refer to the HighCharts plugin Web page for possible options. 32 | * @see http://api.highcharts.com/highcharts 33 | */ 34 | public $clientOptions = []; 35 | /** 36 | * @var bool Set to true to enable 3D support. 37 | */ 38 | public $enable3d = false; 39 | /** 40 | * @var bool Set to true to enable support for more chart types. 41 | */ 42 | public $enableMore = false; 43 | /** 44 | * @var array the modules to register. The modules need to point to the name of the modules available under 45 | * @vendor/2amigos/yii2-highcharts-widget/assets/vendor/modules. Only the filename (ie `drilldown.js`) that is very 46 | * important. 47 | */ 48 | public $modules = []; 49 | /** 50 | * @var bool 51 | */ 52 | private $_renderTo; 53 | 54 | /** 55 | * @inheritdoc 56 | */ 57 | public function init() 58 | { 59 | parent::init(); 60 | if (!isset($this->options['id'])) { 61 | $this->options['id'] = $this->getId(); 62 | } 63 | $this->clientOptions = ArrayHelper::merge( 64 | [ 65 | 'exporting' => [ 66 | 'enabled' => true 67 | ] 68 | ], 69 | $this->clientOptions 70 | ); 71 | 72 | if (ArrayHelper::getValue($this->clientOptions, 'exporting.enabled')) { 73 | $this->modules[] = 'exporting.js'; 74 | } 75 | 76 | $this->_renderTo = ArrayHelper::getValue($this->clientOptions, 'chart.renderTo'); 77 | } 78 | 79 | /** 80 | * @inheritdoc 81 | */ 82 | public function run() 83 | { 84 | if (empty($this->_renderTo)) { 85 | echo Html::tag('div', '', $this->options); 86 | $this->clientOptions['chart']['renderTo'] = $this->options['id']; 87 | } 88 | $this->registerClientScript(); 89 | } 90 | 91 | /** 92 | * Registers the script for the plugin 93 | */ 94 | public function registerClientScript() 95 | { 96 | $view = $this->getView(); 97 | 98 | $bundle = HighChartsAsset::register($view); 99 | $id = str_replace('-', '_', $this->options['id']); 100 | $options = $this->clientOptions; 101 | 102 | if ($this->enable3d) { 103 | $bundle->js[] = YII_DEBUG ? 'highcharts-3d.src.js' : 'highcharts-3d.js'; 104 | } 105 | 106 | if ($this->enableMore) { 107 | $bundle->js[] = YII_DEBUG ? 'highcharts-more.src.js' : 'highcharts-more.js'; 108 | } 109 | 110 | foreach ($this->modules as $module) { 111 | $bundle->js[] = "modules/{$module}"; 112 | } 113 | 114 | if ($theme = ArrayHelper::getValue($options, 'theme')) { 115 | $bundle->js[] = "themes/{$theme}.js"; 116 | } 117 | 118 | $options = Json::encode($options); 119 | 120 | $view->registerJs(";var highChart_{$id} = new Highcharts.Chart({$options});"); 121 | } 122 | } 123 | --------------------------------------------------------------------------------