genPolyline method
Generatey the svg polyline element from the xypairs
Implementation
void genPolyline() {
if (attr[PyA.REFYMAX] == null || attr[PyA.REFYMAX] == "null") {
refYmax = null; // local y scaling
} else {
// y scaling such that ymax will become this value:
refYmax = double.parse(attr[PyA.REFYMAX]);
}
if (refYmax != null && ymax.abs() > 0.0001) {
// the result will be that this polyline gets scaled rel. to refYmax
double normFactor = 1.0;
normFactor = refYmax / ymax;
ymin = normFactor * ymin;
ymax = normFactor * ymax;
}
StringBuffer points = StringBuffer(); // xs ys pairs
xshift = int.parse(attr[PyA.XSHIFT]);
yshift1 = int.parse(attr[PyA.YSHIFT1]);
yshift2 = int.parse(attr[PyA.YSHIFT2]);
xscale = double.parse(attr[PyA.XSCALE]);
yscale = double.parse(attr[PyA.YSCALE]);
if (attr[PyA.YSCALE2] != null) {
// apply 2nd yscale factor if present
yscale *= double.parse(attr[PyA.YSCALE2]);
}
// print("3=$yscale");
// considering the inset of the polyline within the data area
effectivePolylineWidth = dataAreaWidth - 2 * insetx;
effectivePolylineHeight = dataAreaHeight - insety - insety2;
double x, y; // user coordinates
// double xscreen, yscreen; // screen coordinates relative to dataArea origin
int xs, ys; // rounded screen coordinates relative to dataArea origin
int npnts = xValues.length; //cpd.xValues.length;
ysMin = 1000 * 1000;
ysMax = 0;
for (int i = 0; i < npnts; i++) {
x = xValues[i] * xscale; //cpd.xValues[i]*xscale;
y = cpd.cArray[i];
// convert physical to screen relative to dataArea origin
xs = xphysToXscreen(x).round();
ys = yphysToYscreen(y).round();
if (!clipDataAtYBoundary) {
// This will indicate where data disappear from the viewport in y direction,
// instead of just clipping
if (ys < 0) {
ys = 2;
} else if (ys > effectivePolylineHeight) {
ys = effectivePolylineHeight - 1;
}
}
if (i == npnts - 1) {
points.write("$xs $ys");
} else {
points.write("$xs $ys,");
}
if (i == 0) {
xsFirst = xs;
}
if (i == npnts - 1) {
xsLast = xs;
}
if (ys > ysMax) {
ysMax = ys;
yysMin = y; // !
}
if (ys < ysMin) {
ysMin = ys;
yysMax = y; // !
}
} // for(int i=0; i<npnts; i++)
if (polyline != null) {
polyline.remove();
}
polyline = PolylineElement(); // to be added to a container
setSelected(isSelected);
polyline
..setAttribute(SVG.STROKE, attr[PyA.STROKE])
..setAttribute(SVG.FILL, "none")
// ..setAttribute(FONT_SIZE, attributes[PyA.STROKE]) // ??
..setAttribute("points", points.toString());
if (attr[PyA.ROTATE] != null) {
polyline.setAttribute(SVG.TRANSFORM, attr[PyA.ROTATE]);
}
polylineContainer.append(polyline);
ysLast = ys;
//(yphysToXscreen(cpd.yValues[0]) + ys)~/2); //yphysToXscreen(0.0));
if (attr[PyA.DRAW_SELECTION_ICON] == Utils.TRUE) {
addSelectionIcon(xs, ys);
}
addPointShapes();
addMarkerText(xs, ys);
// changeListeners.forEach((Function f) => f(this)); // tell registered listeners that this polyline was updated.
}