0.0.1 • Published 8 years ago

d3-container v0.0.1

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
8 years ago

d3-container

Graphic container

A D3 plugin for the margin convention. See https://bl.ocks.org/mbostock/3019563.

API Reference

# container(context)

Create container content, a g element appended to the given context, a D3 selection. Content is offset from context according to the container's left and top margin specification.

# container.contentHeight()

If content has been created, returns the content height. Otherwise, returns 0.

# container.contentWidth()

If content has been created, returns the content width. Otherwise, returns 0.

# container.height(size)

If size is specified, sets the container height to the specified value and returns the container. If size is not specified, returns the current height, which defaults to 0.

# container.margin(top,right,bottom, left)

If arguments are specified, updates container margin sizes as specified and returns the container. Margin sizes default to 0 and are specified as in CSS.

  • If only top is specified, then top, right, bottom and left margin sizes are set to top.
  • If top and right are specified, then top and bottom margins are set to top, and right and left margins are set to right.
  • If only top, right and left are specified, then top and bottom margins are set to top, right margin is set to right and left margins is set to left.

If arguments are not specified, returns the container's margin object which has getter/setter functions for top, right, bottom, and left sizes.

# container.width(size)

If size is specified, sets the container width to the specified value and returns the container. If size is not specified, returns the current width, which defaults to 0.

Sample Usage

var container = d3_container.container();

container
    .height(1000)
    .width(650)
    .margin(30, 10, 10);
    
svg.call(container);

var content = container.content();

content.append("rect")
       .attr("height", container.contentHeight())
       .attr("width", container.contentWidth())
       .attr("stroke", "green")
       .attr("stroke-width",5);