pdfmake
pdfmake copied to clipboard
z-index capability
I am taking advantage of relative positioning to put text in my canvas. However my canvas is made of solid colors so the text I am positioning on top ends up being hidden behind the canvas. Is there a way around this.
You can paste the following into the playground to see text being cutoff on the top left cell.
var chartText = [];
var chart = [{stack: chartText}, {canvas: [
{
type: 'rect',
x: 0,
y: 0,
w: 30,
h: 30,
opacity: 0.1,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 30,
y: 0,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
},
{
type: 'rect',
x: 60,
y: 0,
w: 30,
h: 30,
color: '#ad3232',
lineColor: 'black'
},
{
type: 'rect',
x: 90,
y: 0,
w: 30,
h: 30,
color: '#ad3232',
lineColor: 'black'
},
{
type: 'rect',
x: 120,
y: 0,
w: 30,
h: 30,
color: '#ad3232',
lineColor: 'black'
},
// second row
{
type: 'rect',
x: 0,
y: 30,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 30,
y: 30,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
},
{
type: 'rect',
x: 60,
y: 30,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
},
{
type: 'rect',
x: 90,
y: 30,
w: 30,
h: 30,
color: '#ad3232',
lineColor: 'black'
},
{
type: 'rect',
x: 120,
y: 30,
w: 30,
h: 30,
color: '#ad3232',
lineColor: 'black'
},
// third row
{
type: 'rect',
x: 0,
y: 60,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 30,
y: 60,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 60,
y: 60,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
},
{
type: 'rect',
x: 90,
y: 60,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
},
{
type: 'rect',
x: 120,
y: 60,
w: 30,
h: 30,
color: '#ad3232',
lineColor: 'black'
},
// fourth row
{
type: 'rect',
x: 0,
y: 90,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 30,
y: 90,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 60,
y: 90,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 90,
y: 90,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
},
{
type: 'rect',
x: 120,
y: 90,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
},
// fifth row
{
type: 'rect',
x: 0,
y: 120,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 30,
y: 120,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 60,
y: 120,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 90,
y: 120,
w: 30,
h: 30,
color: '#329932',
lineColor: 'black'
},
{
type: 'rect',
x: 120,
y: 120,
w: 30,
h: 30,
color: '#ffe34c',
lineColor: 'black'
}
]}];
buildText();
var dd = {content: [
{columns: [
{width: '50%', text: 'overlay text on grid is hidden, is there a concept of z-index'},
{width: '50%', stack: chart}
]}
]};
function buildText() {
chartText.push({text: '1234', fontSize: 8, relativePosition: {x: 10, y: -5}});
}
A workaround to achieve this is to control the order in which elements are put into the stack. Try this in the playground:
var dd = {
content: [
{ text: 'Text under the canvas', relativePosition: { y: -8 }},
{ canvas: [{ type: 'rect', x: 0, y: 0, w: 120, h: 20, color: 'red' }] },
{ text: 'Text over the canvas', relativePosition: { y: -8 }},
]
}