Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

563/async-example-readme #565

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@
# 4.0.3

_Fixes:_

- Fixed the warning message when the the default `resources.json` file is not found.
- Fixed the problem with the lack of the `instr` value, when the `options` is set instead.
- Corrected the `Node.js Module` example in the README.

# 4.0.2

_Hotfix_:
Expand Down
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,20 +568,24 @@ const options = {
}
};

// Initialize export settings with your chart's config
const exportSettings = exporter.setOptions(options);

// Must initialize exporting before being able to export charts
await exporter.initExport(exportSettings);
// Logic must be triggered in an asynchronous function
(async () => {
// Initialize export settings with your chart's config
const exportSettings = exporter.setOptions(options);

// Perform an export
await exporter.startExport(exportSettings, async (error, info) => {
// The export result is now in info
// It will be base64 encoded (info.data)
// Must initialize exporting before being able to export charts
await exporter.initExport(exportSettings);

// Kill the pool when we are done with it
await exporter.killPool();
});
// Perform an export
await exporter.startExport(exportSettings, async (error, info) => {
// The export result is now in info
// It will be base64 encoded (info.result)

// Kill the pool when we are done with it
await exporter.killPool();
});
})();
```

## CommonJS support
Expand Down
9 changes: 4 additions & 5 deletions lib/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export const startExport = async (settings, endCallback) => {
try {
log(4, '[chart] Attempting to export from a raw input.');

// Use whichever one is available
exportOptions.instr = exportOptions.instr || exportOptions.options;

// Perform a direct inject when forced
if (toBoolean(options.customLogic?.allowCodeExecution)) {
return doStraightInject(options, endCallback);
Expand Down Expand Up @@ -321,11 +324,7 @@ const doExport = async (options, chartJson, endCallback, svg) => {
toBoolean(options.customLogic.allowFileResources)
);
} catch (error) {
logWithStack(
2,
error,
`[chart] Unable to load the default resources.json file.`
);
log(2, `[chart] Unable to load the default resources.json file.`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/highcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function triggerExport(chartOptions, options, displayErrors) {
const userOptions = options.export.strInj
? new Function(`return ${options.export.strInj}`)()
: chartOptions;

// Trigger custom code
if (options.customLogic.customCode) {
new Function('options', options.customLogic.customCode)(userOptions);
Expand Down
Loading