prawn-table set header's row background color - ruby-on-rails

pdf.table([header, row1, row2], width: 490, cell_style: { size: 7, align: :center }) do
style(row(0), padding: [4,2], font: "#{Prawn::BASEDIR}/data/fonts/DejaVuSans-Bold.ttf")
# style(row(0).columns(2..3), width: 10 )
# style(row(0), cell_style: {background_color: "#f5f5dc"} )
style(row(1), padding: [16,10])
style(row(1).columns(-2..-1), align: :right)
style(row(2).column(0), borders: [])
style(row(2).column(-2..-1), padding: [6,10], align: :right)
end
I want row(0) to have a background color, but can't find out how (see the commented out lines - those are not working).
I use prawn-rails and prawn-table gems.
Thanks!

Ok.. I am too quick with asking questions.
Here is how you do that (use row_colors option):
pdf.table([header, row1, row2], width: 490, cell_style: { size: 7, align: :center}, row_colors: ['F0F0A3', nil, nil]) do
style(row(0), padding: [4,2], font: "#{Prawn::BASEDIR}/data/fonts/DejaVuSans-Bold.ttf")
style(row(1), padding: [16,10])
style(row(1).columns(-2..-1), align: :right)
style(row(2).column(0), borders: [])
style(row(2).column(-2..-1), padding: [6,10], align: :right)
end
I don't think, it is the best way to achieve the header's background color, but what I did is just set the colors for each row (actually color for the first row, and nil for each left).

Related

Higcharts: how to render background text over the chart, when there are plotBand with different colors?

I have this code where I have text rendered at the background of the chart and also a plotBand with a different background color.
The text in the background is rendered with:
this.renderer.text('This text is <span style="color: rgb(255,0,0)">styled</span>!!!', 50, 150)
.css({
color: 'rgb(0,0,255)',
fontSize: '40px'
}).add();
While the plotBand is configured as:
xAxis: {
plotBands: [{ // mark the weekend
color: 'rgb(0,255,0)',//'rgba(0,255,0,0.5)',
from: Date.UTC(2010, 0, 2),
to: Date.UTC(2010, 0, 4),
label: {
text: 'Plot band',
align: 'right',
x: -10
}
}],
tickInterval: 24 * 3600 * 1000, // one day
type: 'datetime'
},
In the result that I got, we can see how the plotBand goes above the background text, and this is something that I need to avoid. I need my background text to be fully visible in front of this plotBand.
As a workaround, I tied setting up the opacity the plot background color like color: 'rgba(0,255,0,0.5)', but this did not help, as the colors are interfering and it is noticeable that background text is not in front of the plotBand.
You can use the toFront method which is built in the SVGElement's.
Demo: https://jsfiddle.net/BlackLabel/vj51kogm/
function() {
let text = this.renderer.text('This text is <span style="color: rgb(255,0,0)">styled</span>!!!', 50, 150)
.css({
color: 'rgb(0,0,255)',
fontSize: '40px',
}).add();
text.toFront()
}
API: https://api.highcharts.com/class-reference/Highcharts.SVGElement#toFront

Highchart remove decimal places

I am using a highchart pie chart and displaying the data in the centre via.
function(chart1) { // on complete
var xpos = '50%';
var ypos = '50%';
var circleradius = 40;
// Render the circle
chart1.renderer.circle(xpos, ypos, circleradius).attr({
fill: '#fff',
}).add();
// Render the text
chart1.renderer.text(chart1.series[0].data[0].percentage + '%', 62, 80).css({
width: circleradius * 2,
color: '#4572A7',
fontSize: '16px',
textAlign: 'center'
}).attr({
// why doesn't zIndex get the text in front of the chart?
zIndex: 999
}).add();
});
However I would like to prevent displaying any decimal places, currently 33.33333%. I would like to display this as 33%
Is this possible, I know there is a setting allowDecimals but this did not work.
You get original percentage value from point, which it is not rounded. Use JS Math.round function:
chart1.renderer.text(Math.round(chart1.series[0].data[0].percentage) + '%', 62, 80)
.css({
width: circleradius * 2,
color: '#4572A7',
fontSize: '16px',
textAlign: 'center'
})
.attr({
zIndex: 999
})
.add();
Live demo: https://jsfiddle.net/BlackLabel/0z4hLbaw/

Highcharts Add text to label

Here is my chart : www.jsfiddle.net/bs9cLff5
I want to add the percent directly on the chart.
Example for team1 : I want to show 100% on the green.
Next, I would like to personalize the text in the label.
Team1
Good 100%
Become
Team1
'My text'
Is it possible?
Someone can help me please
Thank you everybody :D
You can use renderer to add custom elements (like text) in the chart.
chart.renderer.text('any text', 140, 140)
.css({
color: '#4572A7',
fontSize: '16px'
})
.add();
I can add to the previous answer, you can even define on click events for the label. It's very simple.
ren.label('message', 10, 10)
.attr({
fill: 'red',
stroke: 'white',
'stroke-width': 2,
padding: 5,
cursor: 'pointer',
r: 5
})
.css({
color: 'white',
width: '100px'
})
// action on click
.on('click', function () {
});

Renaming items in export menu in highcharts

Can someone please suggest if there is anyway we can rename the items in the export menu in highcharts. Currently it has entries like:
Download PNG image
Download JPEG image
...
I want to remove word "image". Moreover want to control the complete styling.
There are lots of options for this. Some can be done in Javascript, and I'm sure more can be done in CSS. Here is a JSFiddle example showing the desired text changes and some style changes.
You can read the details on this in the API under lang and navigation.
The text is changed with:
lang: {
printChart: 'Print chart',
downloadPNG: 'Download PNG',
downloadJPEG: 'Download JPEG',
downloadPDF: 'Download PDF',
downloadSVG: 'Download SVG',
contextButtonTitle: 'Context menu'
}
And the style of the button and menu with:
navigation: {
menuStyle: {
border: '1px solid #A0A0A0',
background: '#FFFFFF',
padding: '5px 0'
},
menuItemStyle: {
padding: '0 10px',
background: null,
color: '#303030',
fontSize: '11px'
},
menuItemHoverStyle: {
background: '#4572A5',
color: '#FFFFFF'
},
buttonOptions: {
symbolFill: '#E0E0E0',
symbolSize: 14,
symbolStroke: '#666',
symbolStrokeWidth: 3,
symbolX: 12.5,
symbolY: 10.5,
align: 'right',
buttonSpacing: 3,
height: 22,
// text: null,
theme: {
fill: 'white', // capture hover
stroke: 'none'
},
verticalAlign: 'top',
width: 24
}
}
You can get the default values from the source code, almost at the very top. Some of the defaults use variables that you won't have though, so you may need to change them. And as mentioned, CSS may get you the extra distance.

create label bars in titanium for the text of my labels

I want to create label bars in titanium for the text of my labels. I know am supposed to add a label property but i don't know which is it.
Below is my label.
var label = Titanium.UI.createLabel({
text: 'Register',
height: 35,
width: 200,
top: 10,
color: '#336699'
});
what i want to achieve is something like my label text which is 'register' to be on a Colored bar.
I believe backgroundColor is what you are looking for:
var label = Titanium.UI.createLabel({
text: 'Register',
height: 35,
width: 200,
top: 10,
color: '#336699',
backgroundColor: 'red'
});
You can also change the padding with backgroundPadding(Top/Left/Bottom/Right).

Resources