11import { vd } from './helper/general-helper' ;
22import Automizer , { modify } from './index' ;
33
4- const outputName = 'create-presentation-file-proxy .test.pptx' ;
4+ const outputName = 'modify-chart-props .test.pptx' ;
55const automizer = new Automizer ( {
66 templateDir : `${ __dirname } /../__tests__/pptx-templates` ,
77 outputDir : `${ __dirname } /../__tests__/pptx-output` ,
8- // Streaming is only implemented for jszip
8+ // You can enable 'archiveType' and set mode: 'fs'
9+ // This will extract all templates and output to disk.
10+ // It will not improve performance, but it can help debugging:
11+ // You don't have to manually extract pptx contents, which can
12+ // be annoying if you need to look inside your files.
913 // archiveType: {
1014 // mode: 'fs',
1115 // baseDir: `${__dirname}/../__tests__/pptx-cache`,
1216 // workDir: outputName,
1317 // cleanupWorkDir: true,
1418 // },
15- rootTemplate : 'RootTemplateWithImages.pptx' ,
16- presTemplates : [
17- `RootTemplate.pptx` ,
18- `SlideWithImages.pptx` ,
19- `ChartBarsStacked.pptx` ,
20- ] ,
19+ rootTemplate : 'RootTemplate.pptx' ,
20+ presTemplates : [ `ChartBarsStacked.pptx` ] ,
2121 removeExistingSlides : true ,
2222 cleanup : true ,
23- compression : 1 ,
23+ compression : 0 ,
2424} ) ;
2525
2626const run = async ( ) => {
27- // const pres = automizer
28- // .loadRoot(`RootTemplateWithImages.pptx`)
29- // .load(`RootTemplate.pptx`, 'root')
30- // .load(`SlideWithImages.pptx`, 'images')
31- // .load(`ChartBarsStacked.pptx`, 'charts');
32-
3327 const dataSmaller = {
3428 series : [ { label : 'series s1' } , { label : 'series s2' } ] ,
3529 categories : [
@@ -38,41 +32,37 @@ const run = async () => {
3832 ] ,
3933 } ;
4034
41- const pres = await automizer
35+ const result = await automizer
4236 . addSlide ( 'ChartBarsStacked.pptx' , 1 , ( slide ) => {
43- slide . modifyElement ( 'BarsStacked' , [ modify . setChartData ( dataSmaller ) ] ) ;
44- slide . addElement ( 'ChartBarsStacked.pptx' , 1 , 'BarsStacked' , [
45- modify . setChartData ( dataSmaller ) ,
46- ] ) ;
47- } )
48- . addSlide ( 'SlideWithImages.pptx' , 1 )
49- . addSlide ( 'RootTemplate.pptx' , 1 , ( slide ) => {
50- slide . addElement ( 'ChartBarsStacked.pptx' , 1 , 'BarsStacked' , [
51- modify . setChartData ( dataSmaller ) ,
37+ slide . modifyElement ( 'BarsStacked' , [
38+ // This needs to be worked out:
39+ modify . setPlotArea ( {
40+ // Plot area width is a share of chart space.
41+ // We shrink it to 50% of available chart width.
42+ w : 0.4 ,
43+ h : 0.4 ,
44+ x : 0.0 ,
45+ y : 0.0 ,
46+ } ) ,
47+ // Label area position and dimensions. Automatically sets the label visible.
48+ modify . setLegendPosition ( {
49+ w : 0.2 ,
50+ h : 1.0 ,
51+ x : 1.0 ,
52+ y : 0.0 ,
53+ } ) ,
54+ // Hides the label by zeroing label area
55+ modify . minimizeChartLegend ( ) ,
56+ // We can as well set chart data to insert our custom values.
57+ // modify.setChartData(dataSmaller),
58+
59+ // Dump the shape:
60+ // modify.dump,
5261 ] ) ;
5362 } )
54- . addSlide ( 'ChartBarsStacked.pptx' , 1 , ( slide ) => {
55- slide . addElement ( 'SlideWithImages.pptx' , 2 , 'imageJPG' ) ;
56- slide . modifyElement ( 'BarsStacked' , [ modify . setChartData ( dataSmaller ) ] ) ;
57- } )
58- . addSlide ( 'ChartBarsStacked.pptx' , 1 , ( slide ) => {
59- slide . addElement ( 'SlideWithImages.pptx' , 2 , 'imageJPG' ) ;
60- slide . modifyElement ( 'BarsStacked' , [ modify . setChartData ( dataSmaller ) ] ) ;
61- } ) ;
62-
63- const stream = await pres . stream ( {
64- compressionOptions : {
65- level : 9 ,
66- } ,
67- } ) ;
68-
69- const jszip = await pres . getJSZip ( ) ;
70- const base64 = await jszip . generateAsync ( { type : 'base64' } ) ;
71- vd ( stream ) ;
72-
73- // stream.pipe(process.stdout);
63+ . write ( outputName ) ;
7464
75- // vd(pres.rootTemplate.content );
65+ vd ( 'It took ' + result . duration . toPrecision ( 2 ) + 's' ) ;
7666} ;
7767
7868run ( ) . catch ( ( error ) => {
0 commit comments