createAxes method
Create an x and a y axis for polyline
.
Implementation
void createAxes(Polyline polyline) {
if (xaxisAttr == null) {
xaxisAttr = Map.from(Axis.AXIS_DEFAULT_ATTRIBUTES);
xaxisAttr[AxA.LEGENDTEXT] = "Point number";
} else {
Map<AxA, String> attr = Map.from(Axis.AXIS_DEFAULT_ATTRIBUTES);
attr.addAll(xaxisAttr); // merge with defaults
xaxisAttr = attr;
}
if (yaxisAttr == null) {
yaxisAttr = Map.from(Axis.AXIS_DEFAULT_ATTRIBUTES);
yaxisAttr[AxA.LEGENDTEXT] = "Function value";
} else {
Map<AxA, String> attr = Map.from(Axis.AXIS_DEFAULT_ATTRIBUTES);
attr.addAll(yaxisAttr); // merge with defaults
yaxisAttr = attr;
}
// physical units: use point index as defaults
double physStart = 0;
double physWidth = (polyline.array.length - 1).toDouble();
if (xaxisAttr[AxA.PHYS_X_START] != null &&
xaxisAttr[AxA.PHYS_X_START].isNotEmpty &&
xaxisAttr[AxA.PHYS_X_WIDTH] != null &&
xaxisAttr[AxA.PHYS_X_WIDTH].isNotEmpty) {
physStart = double.parse(xaxisAttr[AxA.PHYS_X_START]);
physWidth = double.parse(xaxisAttr[AxA.PHYS_X_WIDTH]);
}
// compute x axis
xaxis = Axis.coord(
polyline.array.length, // # points in the polyline's data array
polyline.xValues.first, // display the array from this index
polyline.xValues.last, // until this index
physStart,
physWidth,
true, // mode for converting point index to physical unit
null, // no extra calibration factor of axis labels
pl.dataAreaRect.width, // axis length in pixels
pl.xaxisRect.height, // height of axis area (reserves space for the labels)
pl.dataAreaRect.height, // grid line length, needed if 'grid' chosen
polyline.xphysToXscreen, // method converting physical to screen coord.
xaxisAttr,
null // no mouse or touch interaction in this example
);
// set the x axis container positions as computed by [computeLayout].
SVG.setAttr(xaxis.labelsContainer, {
SVG.X: "${pl.xaxisRect.left - xaxis.extra_space_for_edge_labels_x}",
SVG.Y: "${pl.xaxisRect.top}"
});
// set the x axis grid container positions as computed by [computeLayout].
SVG.setAttr(xaxis.xyGrid.gridContainer,
{SVG.X: "${pl.dataAreaRect.left}", SVG.Y: "${pl.dataAreaRect.top}"});
// compute y axis (intensity axis)
double firstY = polyline.yScreenToYphys(0);
double lastY = polyline.yScreenToYphys(pl.dataAreaRect.height);
if (firstY == null) firstY = polyline.ymin;
if (lastY == null) lastY = polyline.ymax;
yaxis = Axis.intens(
firstY / polyline.yscale, // axis range, account for [PyA.YSCALE]
lastY / polyline.yscale,
null, // no rescaling of y axis
null, // like above, no rescaling of y axis
null, // would only relevant for reversed axis
pl.dataAreaRect.height, // axis length in pixels
pl.yaxisRect.width, // height of axis area (reserves space for the labels)
pl.dataAreaRect.width, // grid line length, needed if 'grid' chosen
polyline.yphysToYscreen, // method converting physical to screen coord.
yaxisAttr,
null // no mouse or touch interaction in this example
);
// set the y axis container positions as computed by [computeLayout].
SVG.setAttr(yaxis.labelsContainer, {
SVG.X: "${pl.yaxisRect.left}",
SVG.Y: "${pl.yaxisRect.top - yaxis.extra_space_for_edge_labels_y}"
});
// set the y axis grid container positions as computed by [computeLayout].
SVG.setAttr(yaxis.xyGrid.gridContainer,
{SVG.X: "${pl.dataAreaRect.left}", SVG.Y: "${pl.dataAreaRect.top}"});
}