11/*
22 Plotly.js offline image export server with Node.js
3- Copyright (C) 2018 Dirk Stolle
3+ Copyright (C) 2018, 2021 Dirk Stolle
44
55 This program is free software: you can redistribute it and/or modify
66 it under the terms of the GNU General Public License as published by
2121var child_process = require ( 'child_process' ) ;
2222var fs = require ( 'fs' ) ;
2323const paths = require ( './paths.js' ) ;
24-
24+ const uuidv4 = require ( 'uuid/v4' ) ;
2525
2626/* Renders JSON data for a Plotly.js plot into a PNG file.
2727
@@ -38,8 +38,10 @@ const paths = require('./paths.js');
3838 rendering, may be cryptic and is not necessarily human-friendly
3939*/
4040exports . render = function ( jsonData , filename ) {
41+ const unique_id = uuidv4 ( ) ;
42+
4143 if ( ! filename ) {
42- filename = 'phantom-render-' + Date . now ( ) + '.png' ;
44+ filename = 'phantom-render-' + unique_id + '.png' ;
4345 }
4446 if ( typeof jsonData !== 'string' ) {
4547 return {
@@ -54,7 +56,7 @@ exports.render = function(jsonData, filename) {
5456 } ;
5557 }
5658
57- const plotDataFile = 'plot-data-' + Date . now ( ) + '.json' ;
59+ const plotDataFile = 'plot-data-' + unique_id + '.json' ;
5860 fs . writeFileSync ( plotDataFile , jsonData , { mode : 0o644 , flag : 'w' } ) ;
5961
6062 console . log ( "Starting PhantomJS ...\n(This might take one or two seconds.)" ) ;
0 commit comments