Skip to content

Commit

Permalink
Set function createExpression as static.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jan 9, 2024
1 parent ea15854 commit 11fd15d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## [Unreleased]

TBD
### [2.20.8] - 2024-01-09

Check failure on line 6 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / build

Headings should be surrounded by blank lines

CHANGELOG.md:6 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "### [2.20.8] - 2024-01-09"] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md022.md

Check failure on line 6 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / build

Headings should be surrounded by blank lines

CHANGELOG.md:6 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "### [2.20.8] - 2024-01-09"] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md022.md

- Set function `createExpression` as static.

### [2.20.7] - 2024-01-08

Expand Down Expand Up @@ -117,6 +120,7 @@ as possible. See [Security Advisory: ZF2014-01](https://framework.zend.com/secur
- Initial release

[Unreleased]: https://github.com/laurentmuller/HighchartsBundle/compare/1.7...HEAD
[2.20.8]: https://github.com/laurentmuller/HighchartsBundle/compare/2.20.7...2.20.8
[2.20.7]: https://github.com/laurentmuller/HighchartsBundle/compare/2.20.6...2.20.7
[2.20.6]: https://github.com/laurentmuller/HighchartsBundle/compare/2.20.5...2.20.6
[2.20.5]: https://github.com/laurentmuller/HighchartsBundle/compare/2.20.4...2.20.5
Expand Down
10 changes: 5 additions & 5 deletions resources/doc/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $chart->series([

## Pie chart with Drilldown

This is a simple recipe to re-create a chart similar to the drilldown pie-chart demo at [highcharts.com/demo/pie-drilldown](https://www.highcharts.com/demo/pie-drilldown)
This is a simple recipe to re-create a chart like the drilldown pie-chart demo at [highcharts.com/demo/pie-drilldown](https://www.highcharts.com/demo/pie-drilldown)

```php
$chart = new Highchart();
Expand Down Expand Up @@ -104,7 +104,7 @@ $chart->drilldown->series($drilldown);

## Multi-axes plot

This is a simple recipe for creating a plot with multiple y-axes, similar to [the highcharts demo](https://www.highcharts.com/demo/combo-multi-axes)
This is a simple recipe for creating a plot with multiple y-axes, like the [highcharts demo](https://www.highcharts.com/demo/combo-multi-axes)

```php
$series = [
Expand All @@ -125,7 +125,7 @@ $series = [
$yData = [
[
'labels' => [
'formatter' => new Expr('function () { return this.value + " degrees C" }'),
'formatter' => Highchart.createExpression('function () { return this.value + " degrees C" }'),
'style' => ['color' => '#AA4643')
],
'title' => [
Expand All @@ -136,7 +136,7 @@ $yData = [
],
[
'labels' => [
'formatter' => new Expr('function () { return this.value + " mm" }'),
'formatter' => Highchart.createExpression('function () { return this.value + " mm" }'),
'style' => ['color' => '#4572A7']
],
'gridLineWidth' => 0,
Expand All @@ -155,7 +155,7 @@ $chart->title->text('Average Monthly Weather Data for Tokyo');
$chart->xAxis->categories($categories);
$chart->yAxis($yData);
$chart->legend->enabled(false);
$formatter = new Expr('function () {
$formatter = Highchart.createExpression('function () {
var unit = {
"Rainfall": "mm",
"Temperature": "degrees C"
Expand Down
30 changes: 15 additions & 15 deletions src/Highcharts/AbstractChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,6 @@ public function __call(string $name, mixed $value): static
return $this;
}

/**
* @psalm-param ChartInterface::ENGINE_* $engine
*/
public function render(string $engine = self::ENGINE_JQUERY): string
{
$chartJS = '';
$this->renderChartStart($chartJS, $engine);
$this->renderChartCommon($chartJS);
$this->renderChartOptions($chartJS);
$this->renderChartEnd($chartJS, $engine);

return \trim($chartJS);
}

/**
* Create an expression.
*
Expand All @@ -102,7 +88,7 @@ public function render(string $engine = self::ENGINE_JQUERY): string
*
* @psalm-api
*/
protected function createExpression(string $expression, bool $trim = true): Expr
public static function createExpression(string $expression, bool $trim = true): Expr
{
if ($trim) {
$expression = (string) \preg_replace('/\s+/', ' ', \trim($expression));
Expand All @@ -111,6 +97,20 @@ protected function createExpression(string $expression, bool $trim = true): Expr
return new Expr($expression);
}

/**
* @psalm-param ChartInterface::ENGINE_* $engine
*/
public function render(string $engine = self::ENGINE_JQUERY): string
{
$chartJS = '';
$this->renderChartStart($chartJS, $engine);
$this->renderChartCommon($chartJS);
$this->renderChartOptions($chartJS);
$this->renderChartEnd($chartJS, $engine);

return \trim($chartJS);
}

/**
* Gets the chart class (type) to create.
*/
Expand Down

0 comments on commit 11fd15d

Please sign in to comment.