Skip to content
Merged

3.1.1 #474

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 3.1.1

- Version number is now correct in splash and `/health` when running as a node module
- Fixed an issue with setting `minWorkers` and `maxWorkers` as CLI arguments
- Fixed issues with page resets between exports causing exceptions
- Fixed an issue with width settings causing bad exports if set to a percentage or a `px` suffixed width
- Fixed an issue with SVG exports in the UI

# 3.1.0

- Fixed an issue with SVG base 64 exports
Expand Down
9 changes: 8 additions & 1 deletion lib/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const findChartSize = (options) => {
scale = roundNumber(scale, 2);

// Find chart size and scale
return {
const size = {
height:
options.export?.height ||
exporting?.sourceHeight ||
Expand All @@ -222,6 +222,13 @@ export const findChartSize = (options) => {
600,
scale
};

// Get rid of potential px and %
for (var [param, value] of Object.entries(size)) {
size[param] =
typeof value === 'string' ? +value.replace(/px|%/gi, '') : value;
}
return size;
};

/**
Expand Down
28 changes: 16 additions & 12 deletions lib/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const getClipRegion = (page) =>
* @returns {string} - A string representation of a screenshot.
*/
const createImage = async (page, type, encoding, clip, rasterizationTimeout) =>
await Promise.race([
Promise.race([
page.screenshot({
type,
encoding,
Expand All @@ -67,7 +67,7 @@ const createImage = async (page, type, encoding, clip, rasterizationTimeout) =>
// the expected type format is PNG
omitBackground: type == 'png'
}),
new Promise((resolve, reject) =>
new Promise((_resolve, reject) =>
setTimeout(
() => reject(new Error('Rasterization timeout')),
rasterizationTimeout || 1500
Expand Down Expand Up @@ -425,16 +425,20 @@ export default async (page, chart, options) => {

// Destroy old charts after the export is done
await page.evaluate(() => {
// eslint-disable-next-line no-undef
const oldCharts = Highcharts.charts;

// Check in any already existing charts
if (oldCharts.length) {
// Destroy old charts
for (const oldChart of oldCharts) {
oldChart && oldChart.destroy();
// eslint-disable-next-line no-undef
Highcharts.charts.shift();
// We are not guaranteed that Highcharts is loaded, e,g, when doing SVG
// exports
if (typeof Highcharts !== 'undefined') {
// eslint-disable-next-line no-undef
const oldCharts = Highcharts.charts;

// Check in any already existing charts
if (Array.isArray(oldCharts) && oldCharts.length) {
// Destroy old charts
for (const oldChart of oldCharts) {
oldChart && oldChart.destroy();
// eslint-disable-next-line no-undef
Highcharts.charts.shift();
}
}
}
});
Expand Down
10 changes: 7 additions & 3 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const factory = {
}

// Clear page
await clearPage(workerHandle.page, false);
await clearPage(workerHandle.page, true);
return true;
},

Expand Down Expand Up @@ -161,13 +161,17 @@ export const init = async (config) => {
attachProcessExitListeners();
}

if (parseInt(poolConfig.minWorkers) > parseInt(poolConfig.maxWorkers)) {
poolConfig.minWorkers = poolConfig.maxWorkers;
}

try {
// Create a pool along with a minimal number of resources
pool = new Pool({
// Get the create/validate/destroy/log functions
...factory,
min: poolConfig.minWorkers,
max: poolConfig.maxWorkers,
min: parseInt(poolConfig.minWorkers),
max: parseInt(poolConfig.maxWorkers),
acquireTimeoutMillis: poolConfig.acquireTimeout,
createTimeoutMillis: poolConfig.createTimeout,
destroyTimeoutMillis: poolConfig.destroyTimeout,
Expand Down
11 changes: 9 additions & 2 deletions lib/server/routes/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ See LICENSE file in root for details.
import cache from '../../cache.js';
import pool from '../../pool.js';

const packageVersion = process.env.npm_package_version;
import { readFileSync } from 'fs';
import { __dirname } from './../../utils.js';
import { join as pather } from 'path';

const pkgFile = JSON.parse(
readFileSync(pather(__dirname, 'package.json'))
);

const serverStartTime = new Date();

/**
Expand All @@ -32,7 +39,7 @@ export default (app) =>
Math.floor(
(new Date().getTime() - serverStartTime.getTime()) / 1000 / 60
) + ' minutes',
version: packageVersion,
version: pkgFile.version,
highchartsVersion: cache.version(),
averageProcessingTime: pool.averageTime(),
performedExports: pool.processedWorkCount(),
Expand Down
8 changes: 4 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See LICENSE file in root for details.

import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { join as pather } from 'path';

import { defaultConfig } from '../lib/schemas/config.js';
import { log } from './logger.js';
Expand Down Expand Up @@ -280,10 +281,9 @@ export const optionsStringify = (options, allowFunctions) => {
*/
export const printLogo = (noLogo) => {
// Get package version either from env or from package.json
const packageVersion =
process.env.npm_package_version ||
JSON.parse(readFileSync(new URL('../package.json', import.meta.url)))
.version;
const packageVersion = JSON.parse(
readFileSync(pather(__dirname, 'package.json'))
).version;

// Print text only
if (noLogo) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Highsoft AS <support@highcharts.com> (http://www.highcharts.com/about)",
"license": "MIT",
"type": "module",
"version": "3.1.0",
"version": "3.1.1",
"main": "dist/index.esm.js",
"exports": {
".": {
Expand Down
3 changes: 2 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ const highexp = {};
preview.innerHTML =
'<img src="data:' + format.value + ';base64,' + data + '"/>';
} else if (format.value === 'image/svg+xml') {
preview.innerHTML = data;
preview.innerHTML =
'<img src="data:image/svg+xml;base64,' + data + '"/>';
} else if (format.value === 'application/pdf') {
preview.innerHTML = '';
try {
Expand Down