initSetText method
Replaces the legend text with id
by the new text
and draws the text
marker rectangle in front of the text. stroke
defines the color of the
text marker rectangle.If stroke
is null, no rectangle will be drawn.
Implementation
void initSetText(String id, String text, String stroke) {
textElements[id] = TextElement();
textElements[id].text = text;
fontsize = int.parse(attrMap[LEGEND_ID][LegA.FONT_SIZE]);
// fontsize = int.parse(textElements[id]
// .attributes[POLYLINE_LEGEND_FONT_SIZE]); // this is used elsewhere!
textElements[id].setAttribute(SVG.FONT_SIZE, "${fontsize}");
textElements[id]
.setAttribute(SVG.FILL, attrMap[LEGEND_ID][LegA.TEXT_COLOR]);
// textAttributes[SVG.FONT_SIZE] = "${fontsize}";
// setAttr(textElements[id], textAttributes);
// add a small extra space to the font size
// int deltay = fontsize +
// int.parse(textElements[id].attributes[Aleg.POLYLINE_LEGEND_LINESEP]);
int deltay = fontsize + int.parse(attrMap[LEGEND_ID][LegA.LINESEP]);
dy = curlineNo * deltay;
int xoffs = text_marker_xoffset * 2;
if (stroke != null) {
xoffs += colored_rect_width;
}
if (topTitle != null) {
dy += 2 * deltay; // for all texts except toptitle
}
if (id == TOP_TITLE_ID) {
dy = deltay; // for toptitle only
xoffs = text_marker_xoffset * 2 - colored_rect_width ~/ 2;
// xoffs = text_marker_xoffset * 2;
// if (stroke != null) {
// xoffs -= colored_rect_width ~/ 2;
// }
}
curlineNo--;
legendContainer.append(textElements[id]);
textElements[id]
.setAttribute(SVG.X, "${xoffs}"); // x position of text begin
textElements[id]
.setAttribute(SVG.Y, "$dy"); // y position of text (baseline)
// color indicator for legend text: drawn left of the text, but not
// for the top title.
if (id != TOP_TITLE_ID && stroke != null) {
RectElement r = genTextMarkerRectangle_(id, stroke, dy - deltay);
textMarkers[id] = r;
legendContainer.append(r);
}
}