Skip to content

Commit

Permalink
Prepare initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
miloschuman committed Feb 17, 2014
1 parent 44dd50e commit fed5817
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 164 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ to the require section of your `composer.json` file.
Usage
-----

To use this widget, you may insert the following code into a view file:
To use this widget, insert the following code into a view file:
```php
use miloschuman\highcharts\Highcharts;

Expand All @@ -47,7 +47,7 @@ echo Highcharts::widget([
]
]);
```
By configuring the `options` property, you may specify the options that need to be passed to the Highcharts JavaScript object. Please refer to the demo gallery and documentation on the [Highcharts website](http://www.highcharts.com/) for possible options.
By configuring the `options` property, you can specify the options that need to be passed to the Highcharts JavaScript object. Please refer to the demo gallery and documentation on the [Highcharts website](http://www.highcharts.com/) for possible options.

Alternatively, you can use a valid JSON string in place of an associative array to specify options:
```php
Expand Down Expand Up @@ -79,7 +79,7 @@ Tips
```php
...
'tooltip' => [
'formatter' => new JsExpression('function(){ return this.series.name; }')
'formatter' => new JsExpression('function(){ return this.series.name; }')
],
...
```
Expand All @@ -96,12 +96,17 @@ Tips
```php
...
'scripts' => [
'highcharts-more', // enables supplementary chart types (gauge, arearange, columnrange, etc.)
'modules/exporting', // adds Exporting button/menu to chart
'themes/grid' // applies global 'grid' theme to all charts
'highcharts-more', // enables supplementary chart types (gauge, arearange, columnrange, etc.)
'modules/exporting', // adds Exporting button/menu to chart
'themes/grid' // applies global 'grid' theme to all charts
],
...
```
Previous versions relied on auto-detection magic, but that became less reliable as Highcharts evolved. The new method
more accurately follows the native process of including/excluding additional script files and gives the user some finer-grain control.
For a list of available scripts, see the contents of `vendor/miloschuman/highcharts/assets/`.


Change Log
----------

### [v3.0.9](https://github.com/miloschuman/yii2-highcharts-widget/releases/tag/v3.0.9) (2014 February 17) ###
* Upgraded Highcharts core library to the latest release (3.0.9). See the Highcharts [changelog](http://highcharts.com/documentation/changelog "Changelog") for more information about what's new in this version.
114 changes: 0 additions & 114 deletions build/release.sh

This file was deleted.

24 changes: 11 additions & 13 deletions src/Highcharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* charting library's Chart object.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* ~~~
* use miloschuman\highcharts\Highcharts;
*
* Highcharts::widget([
Expand All @@ -41,7 +41,7 @@
* ]
* ]
* ]);
* </pre>
* ~~~
*
* By configuring the {@link $options} property, you may specify the options
* that need to be passed to the Highcharts JavaScript object. Please refer to
Expand All @@ -51,7 +51,7 @@
* Alternatively, you can use a valid JSON string in place of an associative
* array to specify options:
*
* <pre>
* ~~~
* use miloschuman\highcharts\Highcharts;
*
* Highcharts::widget([
Expand All @@ -69,7 +69,7 @@
* ]
* }'
* ]);
* </pre>
* ~~~
*
* Note: You must provide a valid JSON string (e.g. double quotes) when using
* the second option. You can quickly validate your JSON string online using
Expand All @@ -85,23 +85,21 @@ class Highcharts extends \yii\base\Widget

protected $constr = 'Chart';
protected $baseScript = 'highcharts';

public $options = [];
public $htmlOptions = [];
public $setupOptions = [];
public $scripts = [];


/**
* Renders the widget.
*/
public function run()
{
// determine the ID of the container element
if (isset($this->htmlOptions['id'])) {
$id = $this->htmlOptions['id'];
$this->id = $this->htmlOptions['id'];
} else {
$id = $this->htmlOptions['id'] = $this->getId();
$this->id = $this->htmlOptions['id'] = $this->getId();
}

// render the container element
Expand All @@ -113,15 +111,15 @@ public function run()
}

// merge options with default values
$defaultOptions = ['chart' => ['renderTo' => $id]];
$defaultOptions = ['chart' => ['renderTo' => $this->id]];
$this->options = ArrayHelper::merge($defaultOptions, $this->options);
array_unshift($this->scripts, $this->baseScript);

$this->registerAssets();

parent::run();
}

/**
* Registers required assets and the executing code block with the view
*/
Expand All @@ -134,7 +132,7 @@ protected function registerAssets()
$jsOptions = Json::encode($this->options);
$setupOptions = Json::encode($this->setupOptions);
$js = "Highcharts.setOptions($setupOptions); var chart = new Highcharts.{$this->constr}($jsOptions);";
$key = __CLASS__ . '#' . $id;
$key = __CLASS__ . '#' . $this->id;
$this->view->registerJs($js, View::POS_LOAD, $key);
}

Expand Down
49 changes: 20 additions & 29 deletions src/HighchartsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,41 @@
class HighchartsAsset extends AssetBundle
{

public $sourcePath = '@vendor/miloschuman/yii2-highcharts-widget/assets';
public $depends = [
'yii\web\JqueryAsset',
];
public $sourcePath = '@vendor/miloschuman/yii2-highcharts-widget/src/assets';
public $depends = ['yii\web\JqueryAsset'];

/**
* inheritdoc
* Registers additional JavaScript files required by the widget.
*
* @param array $scripts list of additional JavaScript files to register.
* @return $this
*/
public function init()
public function withScripts($scripts = ['highcharts'])
{
// Make sure highstock comes first. Otherwise, we get errors.
// use unminified files when in debug mode
$ext = YII_DEBUG ? 'src.js' : 'js';

// add files
foreach ($scripts as $script) {
$this->js[] = "$script.$ext";
}

// make sure that at either the highcharts or highstock base file is
// included. If both are included, make sure that highstock comes first.
$hasHighcharts = in_array("highcharts.$ext", $this->js);
$hasHighstock = in_array("highstock.$ext", $this->js);

if(!hasHighcharts && !$hasHighstock) {
if (!$hasHighcharts && !$hasHighstock) {
array_unshift($this->js, "highcharts.$ext");
} else {
if($hasHighcharts) {
if ($hasHighcharts) {
array_unshift($this->js, "highcharts.$ext");
}
if($hasHighstock) {
if ($hasHighstock) {
array_unshift($this->js, "highstock.$ext");
}
}

// if(in_array("highcharts.$ext", $this->js)) {
// array_unshift($this->js, "highcharts.$ext");
// }
parent::init();
}

/**
* Registers additional JavaScript files required by the widget.
* @param array $scripts list of additional JavaScript files to register.
*/
public function withScripts($scripts = ['highcharts'])
{
foreach ($scripts as $script) {
$js = YII_DEBUG ? "$script.src.js" : "$script.js";
if (!in_array($js, $this->js)) {
$this->js[] = $js;
}
}
return $this;
}

}

0 comments on commit fed5817

Please sign in to comment.