/** * Constructs a new line mark with default properties. Lines are not typically * constructed directly, but by adding to a panel or an existing mark via * {@link pv.Mark#add}. * * @class Represents a series of connected line segments, or polyline, * that can be stroked with a configurable color and thickness. Each * articulation point in the line corresponds to a datum; for n points, * n-1 connected line segments are drawn. The point is positioned using * the box model. Arbitrary paths are also possible, allowing radar plots and * other custom visualizations. * *
Like areas, lines can be stroked and filled with arbitrary colors. In most * cases, lines are only stroked, but the fill style can be used to construct * arbitrary polygons. * *
See also the Line guide. * * @extends pv.Mark */ pv.Line = function() { pv.Mark.call(this); }; pv.Line.prototype = pv.extend(pv.Mark) .property("lineWidth", Number) .property("lineJoin", String) .property("strokeStyle", pv.color) .property("fillStyle", pv.color) .property("segmented", Boolean) .property("interpolate", String) .property("eccentricity", Number) .property("tension", Number); pv.Line.prototype.type = "line"; /** * The width of stroked lines, in pixels; used in conjunction with * strokeStyle to stroke the line. * * @type number * @name pv.Line.prototype.lineWidth */ /** * The style of stroked lines; used in conjunction with lineWidth to * stroke the line. The default value of this property is a categorical color. * * @type string * @name pv.Line.prototype.strokeStyle * @see pv.color */ /** * The type of corners where two lines meet. Accepted values are "bevel", * "round" and "miter". The default value is "miter". * *
For segmented lines, only "miter" joins and "linear" interpolation are * currently supported. Any other value, including null, will disable joins, * producing disjoint line segments. Note that the miter joins must be computed * manually (at least in the current SVG renderer); since this calculation may * be expensive and unnecessary for small lines, specifying null can improve * performance significantly. * *
This property is fixed. See {@link pv.Mark}. * * @type string * @name pv.Line.prototype.lineJoin */ /** * The line fill style; if non-null, the interior of the line is closed and * filled with the specified color. The default value of this property is a * null, meaning that lines are not filled by default. * *
This property is fixed. See {@link pv.Mark}. * * @type string * @name pv.Line.prototype.fillStyle * @see pv.color */ /** * Whether the line is segmented; whether variations in stroke style, line width * and the other properties are treated as fixed. Rendering segmented lines is * noticeably slower than non-segmented lines. * *
This property is fixed. See {@link pv.Mark}. * * @type boolean * @name pv.Line.prototype.segmented */ /** * How to interpolate between values. Linear interpolation ("linear") is the * default, producing a straight line between points. For piecewise constant * functions (i.e., step functions), either "step-before" or "step-after" can be * specified. To draw a clockwise circular arc between points, specify "polar"; * to draw a counterclockwise circular arc between points, specify * "polar-reverse". To draw open uniform b-splines, specify "basis". To draw * cardinal splines, specify "cardinal"; see also {@link #tension}. * *
This property is fixed. See {@link pv.Mark}. * * @type string * @name pv.Line.prototype.interpolate */ /** * The eccentricity of polar line segments; used in conjunction with * interpolate("polar"). The default value of 0 means that line segments are * drawn as circular arcs. A value of 1 draws a straight line. A value between 0 * and 1 draws an elliptical arc with the given eccentricity. * * @type number * @name pv.Line.prototype.eccentricity */ /** * The tension of cardinal splines; used in conjunction with * interpolate("cardinal"). A value between 0 and 1 draws cardinal splines with * the given tension. In some sense, the tension can be interpreted as the * "length" of the tangent; a tension of 1 will yield all zero tangents (i.e., * linear interpolation), and a tension of 0 yields a Catmull-Rom spline. The * default value is 0.7. * *
This property is fixed. See {@link pv.Mark}. * * @type number * @name pv.Line.prototype.tension */ /** * Default properties for lines. By default, there is no fill and the stroke * style is a categorical color. The default interpolation is linear. * * @type pv.Line */ pv.Line.prototype.defaults = new pv.Line() .extend(pv.Mark.prototype.defaults) .lineJoin("miter") .lineWidth(1.5) .strokeStyle(pv.Colors.category10().by(pv.parent)) .interpolate("linear") .eccentricity(0) .tension(.7); /** @private Reuse Area's implementation for segmented bind & build. */ pv.Line.prototype.bind = pv.Area.prototype.bind; pv.Line.prototype.buildInstance = pv.Area.prototype.buildInstance; /** * Constructs a new line anchor with default properties. Lines support five * different anchors:
For consistency with the other mark types, the anchor positions are * defined in terms of their opposite edge. For example, the top anchor defines * the bottom property, such that a bar added to the top anchor grows upward. * * @param {string} name the anchor name; either a string or a property function. * @returns {pv.Anchor} */ pv.Line.prototype.anchor = function(name) { return pv.Area.prototype.anchor.call(this, name) .textAlign(function(d) { switch (this.name()) { case "left": return "right"; case "bottom": case "top": case "center": return "center"; case "right": return "left"; } }) .textBaseline(function(d) { switch (this.name()) { case "right": case "left": case "center": return "middle"; case "top": return "bottom"; case "bottom": return "top"; } }); };