1 /**
  2  * Constructs a new line mark with default properties. Lines are not typically
  3  * constructed directly, but by adding to a panel or an existing mark via
  4  * {@link pv.Mark#add}.
  5  *
  6  * @class Represents a series of connected line segments, or <i>polyline</i>,
  7  * that can be stroked with a configurable color and thickness. Each
  8  * articulation point in the line corresponds to a datum; for <i>n</i> points,
  9  * <i>n</i>-1 connected line segments are drawn. The point is positioned using
 10  * the box model. Arbitrary paths are also possible, allowing radar plots and
 11  * other custom visualizations.
 12  *
 13  * <p>Like areas, lines can be stroked and filled with arbitrary colors. In most
 14  * cases, lines are only stroked, but the fill style can be used to construct
 15  * arbitrary polygons.
 16  *
 17  * <p>See also the <a href="../../api/Line.html">Line guide</a>.
 18  *
 19  * @extends pv.Mark
 20  */
 21 pv.Line = function() {
 22   pv.Mark.call(this);
 23 };
 24 
 25 pv.Line.prototype = pv.extend(pv.Mark)
 26     .property("lineWidth")
 27     .property("strokeStyle")
 28     .property("fillStyle")
 29     .property("segmented")
 30     .property("interpolate");
 31 
 32 pv.Line.prototype.type = "line";
 33 
 34 /**
 35  * The width of stroked lines, in pixels; used in conjunction with
 36  * <tt>strokeStyle</tt> to stroke the line.
 37  *
 38  * @type number
 39  * @name pv.Line.prototype.lineWidth
 40  */
 41 
 42 /**
 43  * The style of stroked lines; used in conjunction with <tt>lineWidth</tt> to
 44  * stroke the line. The default value of this property is a categorical color.
 45  *
 46  * @type string
 47  * @name pv.Line.prototype.strokeStyle
 48  * @see pv.color
 49  */
 50 
 51 /**
 52  * The line fill style; if non-null, the interior of the line is closed and
 53  * filled with the specified color. The default value of this property is a
 54  * null, meaning that lines are not filled by default.
 55  *
 56  * @type string
 57  * @name pv.Line.prototype.fillStyle
 58  * @see pv.color
 59  */
 60 
 61 /**
 62  * Whether the line is segmented; whether variations in stroke style, line width
 63  * and the other properties are treated as fixed. Rendering segmented lines is
 64  * noticeably slower than non-segmented lines.
 65  *
 66  * <p>This property is <i>fixed</i>. See {@link pv.Mark}.
 67  *
 68  * @type boolean
 69  * @name pv.Line.prototype.segmented
 70  */
 71 
 72 /**
 73  * How to interpolate between values. Linear interpolation ("linear") is the
 74  * default, producing a straight line between points. For piecewise constant
 75  * functions (i.e., step functions), either "step-before" or "step-after" can be
 76  * specified.
 77  *
 78  * <p>Note: this property is currently supported only on non-segmented lines.
 79  *
 80  * <p>This property is <i>fixed</i>. See {@link pv.Mark}.
 81  *
 82  * @type string
 83  * @name pv.Line.prototype.interpolate
 84  */
 85 
 86 /**
 87  * Default properties for lines. By default, there is no fill and the stroke
 88  * style is a categorical color. The default interpolation is linear.
 89  *
 90  * @type pv.Line
 91  */
 92 pv.Line.prototype.defaults = new pv.Line()
 93     .extend(pv.Mark.prototype.defaults)
 94     .lineWidth(1.5)
 95     .strokeStyle(defaultStrokeStyle)
 96     .interpolate("linear");
 97 
 98 /** @private */
 99 var pv_Line_specials = {left:1, top:1, right:1, bottom:1, name:1};
100 
101 /** @private */
102 pv.Line.prototype.bind = function() {
103   pv.Mark.prototype.bind.call(this);
104   var binds = this.binds,
105       properties = binds.properties,
106       specials = binds.specials = [];
107   for (var i = 0, n = properties.length; i < n; i++) {
108     var p = properties[i];
109     if (p.name in pv_Line_specials) specials.push(p);
110   }
111 };
112 
113 /** @private */
114 pv.Line.prototype.buildInstance = function(s) {
115   if (this.index && !this.scene[0].segmented) {
116     this.buildProperties(s, this.binds.specials);
117     this.buildImplied(s);
118   } else {
119     pv.Mark.prototype.buildInstance.call(this, s);
120   }
121 };
122