Skip to content

Commit

Permalink
Merge pull request #449 from enhancement/250-scale-option
Browse files Browse the repository at this point in the history
  • Loading branch information
jszuminski authored Nov 27, 2023
2 parents 4e97c91 + 65fd84e commit 1933fd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ These are set as variables in your environment. They take precedence over option
- `EXPORT_DEFAULT_CONSTR`: The constructor to use. Can be chart, stockChart, mapChart or ganttChart.
- `EXPORT_DEFAULT_HEIGHT`: The height of the exported chart. Overrides the option in the chart settings.
- `EXPORT_DEFAULT_WIDTH`: The width of the exported chart. Overrides the option in the chart settings.
- `EXPORT_DEFAULT_SCALE`: The scale of the exported chart. Ranges between 1 and 5.
- `EXPORT_DEFAULT_SCALE`: The scale of the exported chart. Ranges between 0.1 and 5.0.

### Highcharts config
- `HIGHCHARTS_VERSION`: Highcharts version to use.
Expand Down Expand Up @@ -341,7 +341,7 @@ _Available options:_
- `--constr`: The constructor to use. Can be chart, stockChart, mapChart or ganttChart (defaults to `chart`).
- `--height`: The height of the exported chart. Overrides the option in the chart settings (defaults to `600`).
- `--width`: The width of the exported chart. Overrides the option in the chart settings (defaults to `400`).
- `--scale`: The scale of the exported chart. Ranges between 1 and 5 (defaults to `1`).
- `--scale`: The scale of the exported chart. Ranges between 0.1 and 5.0 (defaults to `1`).
- `--globalOptions`: A stringified JSON or a filename with options to be passed into the Highcharts.setOptions (defaults to `false`).
- `--themeOptions`: A stringified JSON or a filename with theme options to be passed into the Highcharts.setOptions (defaults to `false`).
- `--batch`: Starts a batch job. A string that contains input/output pairs: "in=out;in=out;.." (defaults to `false`).
Expand Down
21 changes: 10 additions & 11 deletions lib/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,18 @@ export const findChartSize = (options) => {
const globalOptions = isCorrectJSON(options.export?.globalOptions);

// Secure scale value
let scale = roundNumber(
let scale =
options.export?.scale ||
exporting?.scale ||
globalOptions?.exporting?.scale ||
options.export?.defaultScale ||
1
);
exporting?.scale ||
globalOptions?.exporting?.scale ||
options.export?.defaultScale ||
1;

if (scale > 5) {
scale = 5;
} else if (scale < 0.1) {
scale = 1;
}
// the scale cannot be lower than 0.1 and cannot be higher than 5.0
scale = Math.max(0.1, Math.min(scale, 5.0));

// we want to round the numbers like 0.23234 -> 0.23
scale = roundNumber(scale, 2);

// Find chart size and scale
return {
Expand Down

0 comments on commit 1933fd1

Please sign in to comment.