Skip to content

Commit

Permalink
add width size
Browse files Browse the repository at this point in the history
  • Loading branch information
farshidrezaei committed Oct 25, 2021
1 parent 675d90a commit c255de3
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/Services/ChartExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ public function __construct( $htmlPath )
/**
* @throws CouldNotTakeBrowsershot
*/
public function save( string $path ): string
public function save( string $path,$width=null ): string
{
Browsershot::url(
$shot=Browsershot::url(
"file://".$this->htmlPath
)
->setNodeBinary( config( 'chartio.nodePath' ) )
->setNpmBinary( config( 'chartio.npmPath' ) )
->showBackground()
->setDelay( 2500 )
->select( '#chart-wrapper' )
->save( $path );
->select( '#chart-wrapper' );
if ($width) {
$shot=$shot->width($width);
}
$shot->save( $path );
unlink( $this->htmlPath );
return $path;
}
Expand Down
13 changes: 13 additions & 0 deletions src/Services/Charts/AbstractChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ abstract class AbstractChart

protected string $yAxisField = 'y';

protected null|int|string $width=null;

protected ?string $htmlPath = null;
protected string $color = '#13b6b9';
protected ?array $colorSet = [ "#009299", "#1AD7DB", "#589DFB", "#5EDFFF", "#B7E778" ];
Expand Down Expand Up @@ -68,6 +70,17 @@ public function description( string $description = '' ): AbstractChart
return $this;
}

/**
* @param string $width
*
* @return $this
*/
public function width( null|int|string $width = null ): AbstractChart
{
$this->width = $width;
return $this;
}


/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Charts/BarChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function generate(): ChartExporter
$this->htmlPath = "$tempDir/$tempName";

file_put_contents( $this->htmlPath, $template );
return new ChartExporter( $this->htmlPath );
return new ChartExporter( $this->htmlPath ,$this->width);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Services/Charts/CloudChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function generate(): ChartExporter
$this->htmlPath = "$tempDir/$tempName";

file_put_contents( $this->htmlPath, $template );
return new ChartExporter($this->htmlPath);
return new ChartExporter($this->htmlPath,$this->width);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Services/Charts/ColumnChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function generate(): ChartExporter
$this->htmlPath = "$tempDir/$tempName";

file_put_contents( $this->htmlPath, $template );
return new ChartExporter($this->htmlPath);
return new ChartExporter($this->htmlPath,$this->width);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Services/Charts/CustomChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function generate(): ChartExporter
$this->htmlPath = "$tempDir/$tempName";

file_put_contents( $this->htmlPath, $template );
return new ChartExporter( $this->htmlPath );
return new ChartExporter( $this->htmlPath,$this->width );
}

public function chartOptions( array $chartOptions ): static
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Charts/DonutChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function generate(): ChartExporter
$this->htmlPath = "$tempDir/$tempName";

file_put_contents( $this->htmlPath, $template );
return new ChartExporter($this->htmlPath);
return new ChartExporter($this->htmlPath,$this->width);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Services/Charts/LineChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function generate(): ChartExporter
$this->htmlPath = "$tempDir/$tempName";

file_put_contents( $this->htmlPath, $template );
return new ChartExporter($this->htmlPath);
return new ChartExporter($this->htmlPath,$this->width);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Services/Charts/PieChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function generate(): ChartExporter
$this->htmlPath = "$tempDir/$tempName";

file_put_contents( $this->htmlPath, $template );
return new ChartExporter($this->htmlPath);
return new ChartExporter($this->htmlPath,$this->width);
}


Expand Down

0 comments on commit c255de3

Please sign in to comment.