From 3f1f6537763f94aefbda1304e0817a06a8e3a76e Mon Sep 17 00:00:00 2001 From: Vincent Pottier Date: Thu, 6 Feb 2020 22:16:55 +0100 Subject: [PATCH] Add example of fillOpacity usage in tables --- dev-playground/public/samples/tables | 62 ++++++++++++++++++++++++++- examples/pdfs/tables.pdf | Bin 49871 -> 53945 bytes examples/tables.js | 58 +++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/dev-playground/public/samples/tables b/dev-playground/public/samples/tables index ae7ff965d..a88372282 100644 --- a/dev-playground/public/samples/tables +++ b/dev-playground/public/samples/tables @@ -275,8 +275,61 @@ content: [ ] }, layout: { - fillColor: function (i, node) { - return (i % 2 === 0) ? '#CCCCCC' : null; + fillColor: function (rowIndex, node, columnIndex) { + return (rowIndex % 2 === 0) ? '#CCCCCC' : null; + } + } + }, + {text: 'handling fill color opacity...', margin: [0, 20, 0, 8]}, + {text: '... just hardcoding values in the second row', margin: [0, 20, 0, 8]}, + { + style: 'tableExample', + table: { + body: [ + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + [ + {text: 'Sample value 1',fillOpacity:0.15,fillColor:'blue'}, + {text: 'Sample value 2',fillOpacity:0.60,fillColor:'blue'}, + {text: 'Sample value 3',fillOpacity:0.85,fillColor:'blue'}, + ], + ['Sample value 1', 'Sample value 2', 'Sample value 3'] + ] + }, + }, + {text: '... using a custom styler and overriding it in the second row', margin: [0, 20, 0, 8]}, + { + style: 'tableOpacityExample', + table: { + body: [ + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + [ + {text: 'Sample value 1',fillOpacity:0.15}, + {text: 'Sample value 2',fillOpacity:0.60}, + {text: 'Sample value 3',fillOpacity:0.85}, + ], + ['Sample value 1', 'Sample value 2', 'Sample value 3'] + ] + }, + }, + {text: '... with a function (opacity at 0 means fully transparent, i.e no color)', margin: [0, 20, 0, 8]}, + { + style: 'tableExample', + table: { + body: [ + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ] + }, + layout: { + fillColor: 'blue', + fillOpacity: function (rowIndex, node, columnIndex) { + return (rowIndex/8+columnIndex/3); } } }, @@ -534,6 +587,11 @@ styles: { tableExample: { margin: [0, 5, 0, 15] }, + tableOpacityExample: { + margin: [0, 5, 0, 15], + fillColor: 'blue', + fillOpacity: 0.3 + }, tableHeader: { bold: true, fontSize: 13, diff --git a/examples/pdfs/tables.pdf b/examples/pdfs/tables.pdf index 60693d8573d3f9af6962ff7d65c39f9547ceb4da..0351e5993a6a528748f8d5b1a476cb8489d2be5c 100644 GIT binary patch delta 6484 zcmai22{csg|9?peNyuIrWv6lP+*w~+Whs$liyB+DY-0~4S3;zX$(kq`No5;5B@sfj zploF)S>6a0^1GuqiTC{f_slu-Jm2U0eD~-3J?GODvaXo6E;~w>2@|TI5^(G) zD(tot8`l$#>=1-dxdHT_L@Yww2%t$gA_PIyZMK4uB3su3Xgmf-y=ueQa3FG!BM3r7 zQN?UTwrlu$?KkkU^0H-Du(m=0=s$Esa-sMT6#(PPO5LQN7D0a~#{viyVJCrjJf5(E z9SidML-T{{+Q9o1p5LXcy zh#?Fa4xXYrSIbxm!XL&U&N2bic^^iYwgBjrXE=syEJ)~ZRK3%p+^c2bsb*(H`Bqaw zhF8>Z-Ip*H1z}JCN}pX}zb6g_LBG~`6omb?CZHhPuQd?`;eV}3D2VWD4FV{LxV!;T z5NUaXL1BUA4TQpi%Nr~T#x83IaVYGvdJvDoF6##gDD1KUAQ6RKwg4odu*)W302FrF z1PqA6E}MYCpm573U?3E3*#s607KH@vumuZ5!V{_7*LT7%ZoatEU%(eKJH2(9Ir7`C zsG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M2j|VBhUnRxlpv?qvoOe|U{aY4k-=h1ouT#U@(Vh6X{O{-Cqb5dHvKFJ)=R_&5JEP+`DS z8r)q5DL=maY3Kj2E;#(%#}i==gESsxp{Gro4}&`X8=78wiJvQ};XkL><{*K*Xbd8# zI2#dUXz;mAnkcufB(?r!${5#P+br93yEUO;k>OrVH|5(MjXy?+ILDJ(MSC-ayZb^$ zjI?`7{-MH**v*NKVg~M$MXaE36%fK;F|xqcR>d0ru~`Z3Bd;?70R*M1SksvtR!kIw z$-#i29I?0mwGf2aloKcr5FKT{T8sjTFguE-1LEf_B*+k$=B@*u(hPvl7;C@*95ob( z7qK{!g(#2=??}`^L0H*`2H}uoSvO|RHUJjDA}@dgKoAG|n*S z?xX?=!ix%cQwq9}%ozF(6>Bfn)`&0$Yc~@E$;H9@xBQz-3x1Q-qy+s`SS5#l5>6*a zq9CFuGUZPc3L=Z#)2vXskgV@ngz~0gGW|b<;y+rH@K{+U94d!pgy|?ePUMqOr~qd% zmx&f-JyTeQm#di39v*~8vTK#)6QyI2fm}Pf9!~dA6Dj1_YoH*4$nh*e7lp@)_TOw# zN8uru+NAFQ5J?D=?7>7}ROA5&kjRMASr`#Ox|)R%$Yfa9v`ZHtLs&%0%)dAs5rPey zNs0ho)_t?Bf({lW&Q3!H3=rTt@hTnw$|f^|0|0QOIST+R5ixvb9)51e0G^0PMmQ^v zAlnc#F(R2nL@*wL{;~jZg*>M)kqpeX1t5~~vk5`OjX6R{SORi@W)>!a;D1>vtB>q= zGIp+$L=tIs5rB-x&vAiF0%jKmu|zhZ7wb6&)YN3|4_i1Q4%cV&dYCa#i^!MLK`n diff --git a/examples/tables.js b/examples/tables.js index d6899238e..dd0da6f94 100644 --- a/examples/tables.js +++ b/examples/tables.js @@ -295,6 +295,59 @@ var docDefinition = { } } }, + { text: 'handling fill color opacity...', margin: [0, 20, 0, 8] }, + { text: '... just hardcoding values in the second row', margin: [0, 20, 0, 8] }, + { + style: 'tableExample', + table: { + body: [ + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + [ + {text: 'Sample value 1',fillOpacity:0.15,fillColor:'blue'}, + {text: 'Sample value 2',fillOpacity:0.60,fillColor:'blue'}, + {text: 'Sample value 3',fillOpacity:0.85,fillColor:'blue'}, + ], + ['Sample value 1', 'Sample value 2', 'Sample value 3'] + ] + }, + }, + { text: '... using a custom styler and overriding it in the second row', margin: [0, 20, 0, 8] }, + { + style: 'tableOpacityExample', + table: { + body: [ + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + [ + {text: 'Sample value 1',fillOpacity:0.15}, + {text: 'Sample value 2',fillOpacity:0.60}, + {text: 'Sample value 3',fillOpacity:0.85}, + ], + ['Sample value 1', 'Sample value 2', 'Sample value 3'] + ] + }, + }, + { text: '... with a function (opacity at 0 means fully transparent, i.e no color)', margin: [0, 20, 0, 8] }, + { + style: 'tableExample', + table: { + body: [ + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ['Sample value 1', 'Sample value 2', 'Sample value 3'], + ] + }, + layout: { + fillColor: 'blue', + fillOpacity: function (rowIndex, node, columnIndex) { + return (rowIndex/8+columnIndex/3); + } + } + }, { text: 'and can be used dash border', margin: [0, 20, 0, 8] }, { style: 'tableExample', @@ -637,6 +690,11 @@ var docDefinition = { tableExample: { margin: [0, 5, 0, 15] }, + tableOpacityExample: { + margin: [0, 5, 0, 15], + fillColor: 'blue', + fillOpacity: 0.3 + }, tableHeader: { bold: true, fontSize: 13,