/** * Constructs a new rule with default properties. Rules are not typically * constructed directly, but by adding to a panel or an existing mark via * {@link pv.Mark#add}. * * @class Represents a horizontal or vertical rule. Rules are frequently used * for axes and grid lines. For example, specifying only the bottom property * draws horizontal rules, while specifying only the left draws vertical * rules. Rules can also be used as thin bars. The visual style is controlled in * the same manner as lines. * *
Rules are positioned exclusively the standard box model properties. The * following combinations of properties are supported: * *
Properties | Orientation | * *
---|---|
left | vertical |
right | vertical |
left, bottom, top | vertical |
right, bottom, top | vertical |
top | horizontal |
bottom | horizontal |
top, left, right | horizontal |
bottom, left, right | horizontal |
left, top, height | vertical |
left, bottom, height | vertical |
right, top, height | vertical |
right, bottom, height | vertical |
left, top, width | horizontal |
left, bottom, width | horizontal |
right, top, width | horizontal |
right, bottom, width | horizontal |
Small rules can be used as tick marks; alternatively, a {@link Dot} with * the "tick" shape can be used. * *
See also the Rule guide. * * @see pv.Line * @extends pv.Mark */ pv.Rule = function() { pv.Mark.call(this); }; pv.Rule.prototype = pv.extend(pv.Mark) .property("width", Number) .property("height", Number) .property("lineWidth", Number) .property("strokeStyle", pv.color); pv.Rule.prototype.type = "rule"; /** * The width of the rule, in pixels. If the left position is specified, the rule * extends rightward from the left edge; if the right position is specified, the * rule extends leftward from the right edge. * * @type number * @name pv.Rule.prototype.width */ /** * The height of the rule, in pixels. If the bottom position is specified, the * rule extends upward from the bottom edge; if the top position is specified, * the rule extends downward from the top edge. * * @type number * @name pv.Rule.prototype.height */ /** * The width of stroked lines, in pixels; used in conjunction with * strokeStyle to stroke the rule. The default value is 1 pixel. * * @type number * @name pv.Rule.prototype.lineWidth */ /** * The style of stroked lines; used in conjunction with lineWidth to * stroke the rule. The default value of this property is black. * * @type string * @name pv.Rule.prototype.strokeStyle * @see pv.color */ /** * Default properties for rules. By default, a single-pixel black line is * stroked. * * @type pv.Rule */ pv.Rule.prototype.defaults = new pv.Rule() .extend(pv.Mark.prototype.defaults) .lineWidth(1) .strokeStyle("black") .antialias(false); /** * Constructs a new rule anchor with default properties. Rules 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.Rule.prototype.anchor = pv.Line.prototype.anchor; /** @private Sets width or height based on orientation. */ pv.Rule.prototype.buildImplied = function(s) { var l = s.left, r = s.right, t = s.top, b = s.bottom; /* Determine horizontal or vertical orientation. */ if ((s.width != null) || ((l == null) && (r == null)) || ((r != null) && (l != null))) { s.height = 0; } else { s.width = 0; } pv.Mark.prototype.buildImplied.call(this, s); };