Skip to content
Merged
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
21 changes: 16 additions & 5 deletions demo/node/make_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,34 @@ let outdir = '';
if (process?.argv && process.argv[2])
outdir = process.argv[2];

function processResults(name, title, svg, pdf, png) {
function processResults(name, title, svg, svg_ref, svg_diff,
pdf, pdf_ref, pdf_diff,
png, png_ref, png_diff) {
console.log(`${title} ${name}.svg ${svg.length} ${name}.pdf ${pdf.byteLength} ${name}.png ${png.byteLength}`);

if (svg.length)
writeFileSync(`${outdir+name}.svg`, svg);
else
console.error(`Fail to create SVG for ${title}`);

if (Math.abs(svg.length - svg_ref) > svg_diff)
console.error(`${name}.svg length ${svg.length} differs too much from reference ${svg_ref}`);

if (pdf.byteLength)
writeFileSync(`${outdir+name}.pdf`, pdf);
else
console.error(`Fail to create PDF for ${title}`);

if (Math.abs(pdf.byteLength - pdf_ref) > pdf_diff)
console.error(`${name}.pdf length ${pdf.byteLength} differs too much from reference ${pdf_ref}`);

if (png.byteLength)
writeFileSync(`${outdir+name}.png`, png);
else
console.error(`Fail to create PNG for ${title}`);

if (Math.abs(png.byteLength - png_ref) > png_diff)
console.error(`${name}.png length ${png.byteLength} differs too much from reference ${png_ref}`);
}


Expand All @@ -48,26 +59,26 @@ const svg1 = await makeSVG({ object: hpxpy, option: 'col', width, height }),
pdf1buf = await makeImage({ format: 'pdf', as_buffer: true, object: hpxpy, option: 'col', width, height }),
png1buf = await makeImage({ format: 'png', as_buffer: true, object: hpxpy, option: 'col', width, height });

processResults('hist2d', 'histogram col drawing', svg1, pdf1buf, png1buf);
processResults('hist2d', 'histogram col drawing', svg1, 13179, 100, pdf1buf, 33456, 500, png1buf, 56707, 20000);

// testing 3D graphics
const svg2 = await makeSVG({ object: hpxpy, option: 'lego2', width, height }),
pdf2buf = await makeImage({ format: 'pdf', as_buffer: true, object: hpxpy, option: 'lego2', width, height }),
png2buf = await makeImage({ format: 'png', as_buffer: true, object: hpxpy, option: 'lego2', width, height });

processResults('lego', 'histogram lego drawing', svg2, pdf2buf, png2buf);
processResults('lego', 'histogram lego drawing', svg2, 57225, 20000, pdf2buf, 3086057, 1000000, png2buf, 88824, 30000);

// testing geometry
const svg3 = await makeSVG({ object: geom, option: '', width, height }),
pdf3buf = await makeImage({ format: 'pdf', as_buffer: true, object: geom, option: '', width, height }),
png3buf = await makeImage({ format: 'png', as_buffer: true, object: geom, option: '', width, height });

processResults('geom', 'geometry drawing', svg3, pdf3buf, png3buf);
processResults('geom', 'geometry drawing', svg3, 92099, 20000, pdf3buf, 68967, 20000, png3buf, 68967, 20000);

// testing latex with special symbols
const svg4 = await makeSVG({ object: latex, option: '', width, height }),
pdf4buf = await makeImage({ format: 'pdf', as_buffer: true, object: latex, option: '', width, height }),
png4buf = await makeImage({ format: 'png', as_buffer: true, object: latex, option: '', width, height });

processResults('latex', 'Canvas with latex and symbols.ttf', svg4, pdf4buf, png4buf);
processResults('latex', 'Canvas with latex and symbols.ttf', svg4, 5608, 100, pdf4buf, 9388, 500, png4buf, 41620, 15000);