Alternating row color for JasperReports - colors

I want to get color to alternate for the rows in a JasperReports subreport. I have all rows with the same background color but I want it to alternate. Can this be done?

Yes you can set up a style inside the JRXML file like this:
<style name="Zebra" mode="Transparent">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 1]]></conditionExpression>
<style backcolor="#CAC5BB"/>
</conditionalStyle>
</style>
and add it to your report elements like this:
<reportElement style="Zebra" mode="Opaque" x="1" y="1" width="554" height="20"/>
You cannot add conditional styles to style template files (e.g., .jrtx files).

If you are not using "styles", you can have a static text field (with no text) or a rectangle with the background color that you need, overlapping the textfield with data and set the printWhenExpression to $V{report_COUNT}%2 == 1 OR $V{report_COUNT}%2 == 0

Related

Make a Border Appear on only the Last Row of a Tablix in Visual Studio

I have a Tablix table object that is grouped by column invoiceNumber. The number of rows in the table is not static. I want a bottom border only on the very last row of the table (so no borders between the middle rows.)
On the last cell I have a custom function in the Border property:
=IIF(ROWNUMBER("invoiceNumber") = COUNT(Fields!invoiceTotal.Value, "invoiceNumber"), "Solid", "None")
<TablixCell>
<CellContents>
<Textbox Name="Textbox41">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!invoiceTotal.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox10</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>=IIF(ROWNUMBER("invoiceNumber") = COUNT(Fields!invoiceTotal.Value, "invoiceNumber"), "Solid", "None")</Style>
</Border>
<TopBorder>
<Style>None</Style>
</TopBorder>
<BottomBorder>
<Style>None</Style>
</BottomBorder>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<rd:Selected>true</rd:Selected>
</CellContents>
</TablixCell>
</TablixCells>
But the system still puts a border under every cell. Should I place the function somewhere else?
Thank you!

SVG (1.1) : how to 'link-to' or 'centre' on a shape in a browser?

Is there is browser-independant way getting the browser to centre on a particular shape (by 'id' attribute) ?
I have tried using xlinks wrapped around shapes like this:
<a xlink:href="#node24"> .... </a>
I have reasonably busy (100+ shapes) directed graph diagrams (generated from dot): and when I load them up in Chrome , more often than not, the intial screen is just blank - forcing the user to use scrollbars to find the diagram at all.
I'm afraid I don't have any good news for you.
For stand-alone SVG documents, you can manipulate the part of an SVG displayed when following a link by linking to a <view> element (distinct from, but making use of, the SVG "viewBox" attribute). The view element specifies the viewBox to use and possibly some other parameters, and the graphic will be displayed with those parameters instead of the default ones.
Example code:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 100 100"
preserveAspectRatio="xMidYMin meet" >
<circle cx ="50" r="40"/>
<view id="panUp" viewBox="0 -50 100 100" />
<view id="zoomIn" viewBox="25 25 50 50" />
</svg>
If you linked to the file as a whole it would show you an image with half a circle centered at the top of the screen.
If, however, you linked to it like http://example.com/sample.svg#panUp, the circle would be the same size but centered on screen. If you linked to http://example.com/sample.svg#zoomIn, you'd only see the bottom edge of a circle that is twice as big.
(I don't have anywhere to host the file that can serve up raw SVG files, but this CodePen uses data URI to show the effects, although the data URI fragment identifiers doesn't seem to work in Firefox.)
You are supposed to be able to even specify the desired viewBox, transforms, or other attributes as part of the URL fragment (like http://example.com/sample.svg#myView(viewBox(0,0,200,200))), but I don't think that's widely implemented -- it had no effect on either Firefox or Chrome.
And even <view> fragments don't seem to work when the SVG is embedded within an HTML document. So unless your SVG is stand-alone, creating a view for each element (or one view that your dynamically change to match the clicked element), isn't going to be worth the trouble.
So what does work?
The default behaviour, when linking to a fragment (element id) that is not a <view> is to display the nearest ancestor <svg> element that contains that element ("nearest ancestor" because an SVG can contain nested <svg> tags). So if your document has a natural structure to it, you could replace some <g> elements with <svg> with a specified x,y,height and width parameter, and then linking to an element within that sub-graphic would show that view. That should work even when the SVG is embedded within a larger HTML document. But if you've got hundreds of elements moving around, it's probably not a practical solution.
Which leaves #Ian's solution of programmatically manipulating the main SVG viewBox. If you don't want to zoom in, just pan, leave the width and height as the full size of your visualization, and just change the x and y offsets. Something like:
function centerViewOnElement( el ) {
var bbox = el.getBBox()
var elCenterX = bbox.x + bbox.width/2,
elCenterY = bbox.y + bbox.height/2;
svg.setAttribute("viewBox", [(elCenterX - width/2),
(elCenterY - height/2),
width,
height
].join(" ") );
//assuming you've got the svg, width and height already saved in variables...
}
Thought I would do a simpler example, as this feels quite useful in general...with a jsfiddle here
<svg id="mySvg">
<circle id="myCirc" cx="20" cy="20" r="20"/>
<rect id="myRect" x="50" y="50" width="50" height="50"/>
</svg>
var mySvg = document.getElementById("mySvg");
function getNewViewbox( el ) {
var bbox = el.getBBox();
return newViewbox = bbox.x + " " + bbox.y + " " + bbox.width + " " + bbox.height;
}
function focusElement( ev ) {
ev.stopPropagation();
mySvg.setAttribute("viewBox", getNewViewbox( ev.target ) );
}
//click on any element, or even the svg paper
document.getElementById("mySvg").addEventListener("click", focusElement);

Trouble with conditional style

thanks to everyone ,thanks to Alex K ,I'v got the cause.this is perhaps the bug of
ireport 3.0 .
the outer style tag should not contain the color property.
I delete it ,and It works well.
================================================================================
I'm come into trouble about condition style expression in report with JasperReports.
The verison of iReport is 3.0.
I just found that the boolean expression doesn't work at all.
The conditional style:
<style
name="old"
mode="Opaque"
**forecolor="#990033"**
>
<conditionalStyle>
<conditionExpression><![CDATA[$F{age}.intValue()>60?new Boolean(true):new Boolean(false)]]></conditionExpression>
<style
name="old"
isDefault="false"
mode="Opaque"
forecolor="#990033"
>
</style>
</conditionalStyle>
</style>
The textfield expressions:
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
style="old"
x="315"
y="0"
width="78"
height="14"
key="textField-3"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{age}]]></textFieldExpression>
</textField>
the result is that all ages will be red even the ages less than 60;
thanks to everyone ,thanks to Alex K ,I'v got the cause.this is perhaps the bug of ireport 3.0 . the outer style tag should not contain the color property. I delete it ,and It works well.
that is :
the xml code generate by the ireport is
<style
name="old"
mode="Opaque"
forecolor="#990033"
>
<conditionalStyle>
<conditionExpression><![CDATA[$F{age}.intValue()>60?new Boolean(true):new Boolean(false)]]></conditionExpression>
<style
name="old"
isDefault="false"
mode="Opaque"
forecolor="#990033"
>
</style>
</conditionalStyle>
</style>
this way the style is already effective .I delete the property set in the outer style tag.
so the final xml code that works well is like below:
<style
name="old"
mode="Opaque"
>
<conditionalStyle>
<conditionExpression><![CDATA[$F{age}.intValue()>60?new Boolean(true):new Boolean(false)]]></conditionExpression>
<style
name="old"
isDefault="false"
mode="Opaque"
forecolor="#990033"
>
</style>
</conditionalStyle>
</style>

Unable to render vertically lay out addition of two numbers with MathJax and MathML

I would like to render two numbers on a web page like this:
123
+ 456
______
I've found this example:
<mstack>
<mn>496</mn>
<msrow> <mo>+</mo> <none/> <mn>28</mn> </msrow>
<msline/>
</mstack>
but MathJax doesn't support mstack, msrow and msline elements.I've attempted to use a mtable
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mtable id="test" columnalign="right">
<mtr><mtd></mtd><mtd><mn>12321</mn></mtd></mtr>
<mtr><mtd><mo>+</mo></mtd><mtd><mn>45665445</mn></mtd></mtr>
</mtable>
</math>
</body>
with this CSS:
<style type="text/css">
#test
{
border-bottom:1px solid black;
}
</style>
but the bottom border is overlapping the lower number. Is there a way to achieve this layout with MathJax/MathML?
You can see examples of this kind of layout in the MathML spec at
http://www.w3.org/Math/draft-spec/mathml.html#chapter3_presm.elemmath.examples
If, once the document has loaded, you select the button "convert and display with MathJax" then the MathML3 mstack markup will be transformed to some MathML2 that MathJax understands. The relevant javascript is all available linked from that page.
Also relevant is the discussion between myself and the MathJax developer at
https://groups.google.com/forum/#!msg/mathjax-users/wa85p5TAIe4/hgUoLEXrweoJ

fitting text into the box

on my website i allow users to create pictures with line of text they specify drawn on the picture
currently i use for that imagemagick convert - i specify svg template and let convert do the rest
here is part of code which is responsible for outputting text in the picture
<text text-anchor="middle" x="50%%" y="%s"
font-family="Times New Roman" font-size="55"
style="fill:rgb(255,255,255);">
%s
</text>
my problem is that if user provides very long strings, the text doesn't fit in the image.
i'd like text to be resized automatically to smaller font if it doesn't fit the picture. is it possible to do with svg templates? if not, what could be other solutions
You could add a script within the SVG template which called when the SVG is loaded and uses getComputedTextLength() to resize the font. It's a bit of a hacky solution, but it seems to work.
Here's a quick example that draws a box and some text inside it. The text should be resized to always fit in the box no matter how long it is (up to point at least):
To call the code when the SVG is loaded include onload="int(evt)" in the SVG tag.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="400" height="80"
onload="init(evt)">
Then the actual script:
<script type="text/ecmascript">
<![CDATA[
function init(evt)
{
if ( window.svgDocument == null )
{
svgDocument = evt.target.ownerDocument;
}
maximum_length = 300;
my_text = svgDocument.getElementById('text-to-resize');
for (var font_size=55; font_size>0; font_size--)
{
if(my_text.getComputedTextLength() < maximum_length){break;}
my_text.setAttributeNS(null, "font-size", font_size);
}
}
]]>
</script>
I just used a for loop to decrement the font-size until the text length is less than the maximum specified; I'm sure there's a better way to resize the text.
Finally the actual text and box:
<rect id="rect1" x="20" y="10" width="320" height="50" fill="white" stroke="black"/>
<text id="text-to-resize"
text-anchor="middle"
x="170" y="50"
font-family="Times New Roman" font-size="55">
whatever text
</text>
</svg>
If you change the text, the font-size should change so that it fits inside the box. You'll probably want to change the x- and y- values to correctly centre the text too.
solved by abandoning svg and doing everything with imagemagick convert and mvg template
here's the simplified script example in case anyone's pursuing something similar
script is putting an image and a title on the canvas. title is created with separate convert command, saved as temporary file and then put onto the canvas
#!/bin/sh
TEMPLATE="
push graphic-context
viewbox 0 0 600 600
affine 1 0 0 1 0.0 0.0
push graphic-context
fill 'rgb(0,0,0)'
rectangle 0,0 600,600
pop graphic-context
push graphic-context
image Over 38,38 338,338 '%s'
pop graphic-context
push graphic-context
image Over 36,400 529,55 '%s'
pop graphic-context
pop graphic-context
";
#1. creating label fitting specified proportions
#2. converting mvg template to jpeg image (and trimming it in process)
#3. removing temp file with label
convert -size 529x55 -background black -family "Times New Roman" -gravity center -fill white label:"$2" "tmp/$1title.jpg" && printf "$TEMPLATE" "images/$1.jpg" "tmp/$1title.jpg" | convert mvg:- -trim +repage -bordercolor black -border 36 "images/$1converted.jpg" && rm "tmp/$1title.jpg"
#script parameters: $1 is image id, $2 is title text

Resources