Legend constructor
Constructs a Legend with optional legendAttributes
. If null,
LEGEND_DEFAULT_ATTRIBUTES will apply. If not null the specified attributes
will override the respective default ones.
X and Y of these attributes may be specified absolutely, e.g. 1
0, 10px, .. or relatively to the legend container 5%, 60%, ... .
The legend svg container can be accessed via the attribute legendContainer
of this class.
nlines
is 1 if only 1 legend line is to be added using setText().
If nlines
> 1, each time a legend text is added its position will be
decremented by fontsize.
The initial position of the first legend text is nlines*fontsize.
Implementation
Legend(Map<LegA, String> legendAttributes, this.nlines) {
curlineNo = nlines;
attrMap[LEGEND_ID] = new Map.from(LEGEND_DEFAULT_ATTRIBUTES);
if (legendAttributes != null && legendAttributes.isNotEmpty) {
attrMap[LEGEND_ID].addAll(legendAttributes); // merge
}
// textAttributes = attrMap[LEGEND_ID]; // contained in same map
legendContainer.setAttribute(SVG.X, attrMap[LEGEND_ID][LegA.X]);
legendContainer.setAttribute(SVG.Y, attrMap[LEGEND_ID][LegA.Y]);
colored_rect_width = int.parse(attrMap[LEGEND_ID][LegA.COLORED_RECT_WIDTH]);
// if a toptitle is specified, set it at the top of the legend.
// the position handling is done in setText()
topTitle = attrMap[LEGEND_ID][LegA.TOP_TITLE];
if (topTitle != null && topTitle.isNotEmpty) {
initSetText(TOP_TITLE_ID, topTitle, null);
}
}