| | | | Browse by category |
Article ID: 2380
Last updated: 29 May, 2018
Question
I have activities with long names, and often, the activity name in the bar is truncated. How can I force the drawing of my activity labels so that they are displayed entirely?
Answer
You can use the IlvActivityCompositeRenderer
for that.
In the bottom part, use a IlvActivityGraphicRenderer
in which you simply draw a IlvRectangle
.
In the top part, you can use the IlvActivityLabel
, but you need to override its getBounds()
method to make sure the label is being drawn at the right place.
Implementation:
// Get the default activity renderer for the Gantt chart IlvDefaultActivityRendererFactory rendererFactory = (IlvDefaultActivityRendererFactory)_chart.getActivityRendererFactory(); // Create a composite Renderer IlvActivityCompositeRenderer compositeRenderer = new IlvActivityCompositeRenderer(); // Draw the bar: // a red rectangle... IlvRectangle rectangle = new IlvRectangle(new IlvRect(0, 0, 100, 100), true, true); rectangle.setBackground(Color.red); // Add this rectangle in a IlvActivityGraphicRenderer IlvActivityGraphicRenderer bar = new IlvActivityGraphicRenderer(rectangle); // Now add this renderer for the bar to the renderer factory compositeRenderer.addRenderer(bar); // Make sure the bar does not fill all the space // So leave the top half for the label... bar.setTopMargin(0.5f); // Now create the label IlvActivityLabel label = new IlvActivityLabel(bar) { // we need to change the getBounds of this label, public IlvRect getBounds(IlvActivityGraphic ag, IlvTransformer t) { IlvLabelInterface label = (IlvLabelInterface)getGraphic(); // make sure we've set the string to the label IlvStringProperty property = getDisplayedProperty(); if (property != null) { label.setLabel(property.getValue(ag.getActivity())); } IlvRect refBox; if (getMainRenderer() != null) { refBox = getMainRenderer().getBounds(ag, t); } else { refBox = ag.getDefinitionRect(t); } // We have computed the correct position where we want to draw the label IlvRect labelBox = label.getLabelBBox(null); labelBox.x = refBox.x + getOffset(); labelBox.y = refBox.y - labelBox.height; return labelBox; } }; // Now add this label renderer to the composite renderer compositeRenderer.addRenderer(label); // and to finish, add this composite renderer to the renderer factory rendererFactory.setLeafActivityRenderer(compositeRenderer);
This article was:
Helpful |
Not helpful
Report an issue
Article ID: 2380
Last updated: 29 May, 2018
Revision: 3
Views: 664
Posted: 15 Nov, 2010 by
Dean J.
Updated: 29 May, 2018 by
Gargani A.
Also listed in
Others in this category
Powered by KBPublisher (Knowledge base software)