Skip to content

Commit

Permalink
Upgraded Highcharts JS library to the latest release (7.1.2).
Browse files Browse the repository at this point in the history
Added support for Gantt chart type (issue #74).
  • Loading branch information
miloschuman committed Aug 7, 2019
1 parent cd248e9 commit bedfc4b
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 34 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,12 @@
Yii2 Highcharts Changelog
=========================

### [v7.1.2](https://github.com/miloschuman/yii2-highcharts/releases/tag/v7.1.2) (2019-08-07) ###
* Upgraded Highcharts JS library to the latest release (7.1.2). See the Highcharts [changelog](https://www.highcharts.com/blog/changelog/) for more information about what's new in this version.
* Added support for Gantt chart type (issue #74). See included [Gantt Chart Example](https://github.com/miloschuman/yii2-highcharts/tree/master/doc/examples/highcharts.md#gantt-chart) for usage.

### [v7.0](https://github.com/miloschuman/yii2-highcharts/releases/tag/v7.0) (2019-01-21) ###
* Upgraded Highcharts JS library to the latest release (7.0.2). See the Highcharts [changelog](https://www.highcharts.com/blog/changelog/) for more information about what's new in this version.
* Upgraded Highcharts JS library to the latest release (7.0.2).
* Fixed issue #54.

### [v6.0](https://github.com/miloschuman/yii2-highcharts/releases/tag/v6.0) (2017-10-27) ###
Expand Down
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -5,9 +5,9 @@ Yii2 Highcharts Widget
[![Total Downloads](https://poser.pugx.org/miloschuman/yii2-highcharts-widget/downloads.png)](https://packagist.org/packages/miloschuman/yii2-highcharts-widget)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/miloschuman/yii2-highcharts/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/miloschuman/yii2-highcharts/?branch=master)

Easily add [Highcharts, Highstock and Highmaps](http://www.highcharts.com/) graphs to your Yii2 application.
Easily add [Highcharts, Highstock and Highmaps](https://www.highcharts.com/) graphs to your Yii2 application.

![Screen Shot](http://www.yiiframework.com/extension/yii2-highcharts-widget/files/screenshot.png)
![Screen Shot](https://www.yiiframework.com/extension/yii2-highcharts-widget/files/screenshot.png)


About
Expand All @@ -26,7 +26,7 @@ About
Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

Either run

Expand Down Expand Up @@ -69,7 +69,7 @@ echo Highcharts::widget([
]);
```

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.
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](https://www.highcharts.com/) for possible options.

See [/doc/examples](https://github.com/miloschuman/yii2-highcharts/tree/master/doc/examples) for more usage examples.

Expand All @@ -96,7 +96,7 @@ echo Highcharts::widget([
]);
```

*Note:* You must provide a *valid* JSON string (with double quotes) when using the second option. You can quickly validate your JSON string online using [JSONLint](http://jsonlint.com/).
*Note:* You must provide a *valid* JSON string (with double quotes) when using the second option. You can quickly validate your JSON string online using [JSONLint](https://jsonlint.com/).

### Just the Assets ###

Expand All @@ -108,7 +108,7 @@ use miloschuman\highcharts\HighchartsAsset;
HighchartsAsset::register($this)->withScripts(['highstock', 'modules/exporting', 'modules/drilldown']);
```

In this scenario, you would need to write and include your own JavaScript to display the charts, just as illustrated in the [Highcharts Demo](http://www.highcharts.com/demo), [Highstock Demo](http://www.highcharts.com/stock/demo) and [Highmaps Demo](http://www.highcharts.com/maps/demo) pages.
In this scenario, you would need to write and include your own JavaScript to display the charts, just as illustrated in the [Highcharts Demo](https://www.highcharts.com/demo), [Highstock Demo](https://www.highcharts.com/stock/demo) and [Highmaps Demo](https://www.highcharts.com/maps/demo) pages.


Tips
Expand Down
50 changes: 49 additions & 1 deletion doc/examples/highcharts.md
Expand Up @@ -2,7 +2,7 @@

## Combination Chart ##

This example is ported from the Highcharts ["Column, Line and Pie" demo](http://www.highcharts.com/demo/combo/grid-light)
This example is ported from the Highcharts ["Column, Line and Pie" demo](https://www.highcharts.com/demo/combo/grid-light)
with optional exporting module and Grid Light theme enabled.

```php
Expand Down Expand Up @@ -90,3 +90,51 @@ echo Highcharts::widget([
]
]);
```

## Gantt Chart ##

This example is ported from the Highcharts ["Simple Gantt Chart" example](https://www.highcharts.com/docs/gantt/getting-started-gantt)

```php
use miloschuman\highcharts\GanttChart;
echo GanttChart::widget([
'options' => [
'title' => ['text' => 'Simple Gantt Chart'],
'series' => [
[
'name' => 'Project 1',
'data' => [
[
'id' => 's',
'name' => 'Start prototype',
'start' => new JsExpression('Date.UTC(2014, 10, 18)'),
'end' => new JsExpression('Date.UTC(2014, 10, 20)'),
],
[
'id' => 'b',
'name' => 'Develop',
'start' => new JsExpression('Date.UTC(2014, 10, 20)'),
'end' => new JsExpression('Date.UTC(2014, 10, 25)'),
'dependency' => 's',
],
[
'id' => 'a',
'name' => 'Run acceptance tests',
'start' => new JsExpression('Date.UTC(2014, 10, 23)'),
'end' => new JsExpression('Date.UTC(2014, 10, 26)'),
],
[
'name' => 'Test prototype',
'start' => new JsExpression('Date.UTC(2014, 10, 27)'),
'end' => new JsExpression('Date.UTC(2014, 10, 29)'),
'dependency' => [
'a',
'b',
],
],
],
],
],
],
]);
```
4 changes: 2 additions & 2 deletions doc/examples/highmaps.md
Expand Up @@ -2,7 +2,7 @@

## Basic Example ##

This is a basic map example using the free [Highcharts Map Collection](http://www.highcharts.com/docs/maps/map-collection)
This is a basic map example using the free [Highcharts Map Collection](https://www.highcharts.com/docs/maps/map-collection)
data. Add the following code to any view file.

```php
Expand All @@ -12,7 +12,7 @@ use yii\web\JsExpression;

// To use Highcharts Map Collection, we must register those files separately.
// The 'depends' option ensures that the main Highmaps script gets loaded first.
$this->registerJsFile('http://code.highcharts.com/mapdata/countries/de/de-all.js', [
$this->registerJsFile('https://code.highcharts.com/mapdata/countries/de/de-all.js', [
'depends' => 'miloschuman\highcharts\HighchartsAsset'
]);

Expand Down
6 changes: 3 additions & 3 deletions doc/examples/highstock.md
Expand Up @@ -2,7 +2,7 @@

## Area Spline with AJAX Data ##

This example is ported from the Highstock ["Area Spline" demo](http://www.highcharts.com/stock/demo/areaspline).
This example is ported from the Highstock ["Area Spline" demo](https://www.highcharts.com/stock/demo/areaspline).
The `'callback'` option allows you to initialize the chart after an AJAX request or
other preprocessing.

Expand Down Expand Up @@ -53,7 +53,7 @@ echo Highstock::widget([

## Compare Series with Multiple AJAX Requests ##

This example is ported from the Highstock ["Compare Multiple Series" demo](http://www.highcharts.com/stock/demo/compare).
This example is ported from the Highstock ["Compare Multiple Series" demo](https://www.highcharts.com/stock/demo/compare).
The `'callback'` option allows you to initialize the chart after an AJAX request or
other preprocessing.

Expand All @@ -69,7 +69,7 @@ $js = <<<MOO

$.each(names, function(i, name) {

$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) {
$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) {

seriesOptions[i] = {
name: name,
Expand Down
20 changes: 20 additions & 0 deletions src/GanttChart.php
@@ -0,0 +1,20 @@
<?php

/**
* GanttChart class file.
*
* @author Milo Schuman <miloschuman@gmail.com>
* @link https://github.com/miloschuman/yii2-highcharts/
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace miloschuman\highcharts;

/**
* @see Highcharts
*/
class GanttChart extends Highcharts
{
protected $constr = 'ganttChart';
protected $baseScript = 'modules/gantt';
}
12 changes: 7 additions & 5 deletions src/Highcharts.php
Expand Up @@ -5,7 +5,7 @@
*
* @author Milo Schuman <miloschuman@gmail.com>
* @link https://github.com/miloschuman/yii2-highcharts/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace miloschuman\highcharts;
Expand All @@ -17,7 +17,7 @@
use yii\web\View;

/**
* Highcharts encapsulates the {@link http://www.highcharts.com/ Highcharts}
* Highcharts encapsulates the {@link https://www.highcharts.com/ Highcharts}
* charting library's Chart object.
*
* To use this widget, you can insert the following code in a view:
Expand Down Expand Up @@ -52,13 +52,14 @@
class Highcharts extends Widget
{

protected $constr = 'Chart';
protected $constr = 'chart';
protected $baseScript = 'highcharts';
public $options = [];
public $htmlOptions = [];
public $setupOptions = [];
public $scripts = [];
public $callback = false;
public $container;

/**
* Renders the widget.
Expand All @@ -83,8 +84,9 @@ public function run()
// merge options with default values
$defaultOptions = ['chart' => ['renderTo' => $this->id]];
$this->options = ArrayHelper::merge($defaultOptions, $this->options);
array_unshift($this->scripts, $this->baseScript);
$this->container = $this->options->chart->renderTo;

array_unshift($this->scripts, $this->baseScript);
$this->registerAssets();

parent::run();
Expand All @@ -101,7 +103,7 @@ protected function registerAssets()
// prepare and register JavaScript code block
$jsOptions = Json::encode($this->options);
$setupOptions = Json::encode($this->setupOptions);
$js = "Highcharts.setOptions($setupOptions); new Highcharts.{$this->constr}($jsOptions);";
$js = "Highcharts.setOptions($setupOptions); new Highcharts.{$this->constr}('$this->container', $jsOptions);";
$key = __CLASS__ . '#' . $this->id;
if (is_string($this->callback)) {
$js = "function {$this->callback}(data) {{$js}}";
Expand Down
13 changes: 3 additions & 10 deletions src/HighchartsAsset.php
Expand Up @@ -5,7 +5,7 @@
*
* @author Milo Schuman <miloschuman@gmail.com>
* @link https://github.com/miloschuman/yii2-highcharts/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace miloschuman\highcharts;
Expand Down Expand Up @@ -33,18 +33,11 @@ public function withScripts($scripts = ['highcharts'])

// add files
foreach ($scripts as $script) {
// theme files are not packaged with a .src.js version
$this->js[] = "$script." . ((strpos($script, 'themes/') === 0) ? 'js' : $ext);
$this->js[] = "$script.$ext";
}

// make sure that either highcharts or highstock base file is included.
// make sure the highcharts base file is included first
array_unshift($this->js, "highcharts.$ext");
$hasHighstock = in_array("highstock.$ext", $this->js);
if ($hasHighstock) {
array_unshift($this->js, "highstock.$ext");
// remove highcharts if highstock is used on page
$this->js = array_diff($this->js, ["highcharts.$ext"]);
}

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Highmaps.php
Expand Up @@ -5,7 +5,7 @@
*
* @author Milo Schuman <miloschuman@gmail.com>
* @link https://github.com/miloschuman/yii2-highcharts/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace miloschuman\highcharts;
Expand All @@ -16,6 +16,6 @@
class Highmaps extends Highcharts
{

protected $constr = 'Map';
protected $constr = 'mapChart';
protected $baseScript = 'modules/map';
}
6 changes: 3 additions & 3 deletions src/Highstock.php
Expand Up @@ -5,7 +5,7 @@
*
* @author Milo Schuman <miloschuman@gmail.com>
* @link https://github.com/miloschuman/yii2-highcharts/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace miloschuman\highcharts;
Expand All @@ -16,6 +16,6 @@
class Highstock extends Highcharts
{

protected $constr = 'StockChart';
protected $baseScript = 'highstock';
protected $constr = 'stockChart';
protected $baseScript = 'modules/stock';
}
2 changes: 1 addition & 1 deletion src/SeriesDataHelper.php
Expand Up @@ -5,7 +5,7 @@
*
* @author Milo Schuman <miloschuman@gmail.com>
* @link https://github.com/miloschuman/yii2-highcharts/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace miloschuman\highcharts;
Expand Down

0 comments on commit bedfc4b

Please sign in to comment.