0.0.163 • Published 6 years ago

@pqmcgill/shape v0.0.163

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@vx/shape

npm install --save @vx/shape

Shapes are the core elements of vx. Most of what you see on the screen, like lines, bars, and areas are shapes.

<AreaClosed />

AreaClosed is a closed area under a curve.

Example

AreaClosed Example

<AreaClosed
  data={myData}
  xScale={myXScale}
  yScale={myYScale}
  x={myX}
  y={myY}
  strokeWidth={2}
  stroke={'url(#linear)'}
  fill={'url(#linear)'}
/>

Properties

NameDefaultTypeDescription
xfunctionA function that takes in a data element and returns the x value.
yfunctionA function that takes in a data element and returns the y value.
xScalefunctionA scale function for the xs.
yScalefunctionA scale function for the ys.
dataarrayAn array of x and y data.
definedd => y(d) && x(d)functionA function called by area.defined().
classNamevx-area-closedstringThe class name for the path element.
strokeDasharrayarrayThe pattern of dashes in the stroke.
strokeWidth2numberThe size of the stroke.
strokeblackstringThe color of the stroke.
fillrgba(0,0,0,0.3)stringThe color of the fill.
curvefunctionThe curve function

<AreaStack />

An <AreaStack /> is used to represent several area's stacked on top of each other.

Example

AreaStack Example

<AreaStack
  reverse
  top={margin.top}
  left={margin.left}
  keys={keys}
  data={data}
  x={(d) => xScale(x(d.data))}
  y0={(d) => yScale(d[0] / 100)}
  y1={(d) => yScale(d[1] / 100)}
  stroke={(d,i) => colorScale(i)}
  strokeWidth={1}
  fillOpacity={(d,i) => selected.includes(browserNames[i]) ? 0.8 : 0.2}
  fill={(d,i) => colorScale(i)}
  onMouseEnter={(d, i) => event => {
    updateSelected((prevState) => ([browserNames[i]]))
  }}
  onMouseLeave={(d,i) => event => {
    updateSelected(prevState => {
      if (prevState.includes(browserNames[i])) return [];
      return prevState;
    })
  }}
/>

Properties

NameDefaultTypeDescription
classNamestringThe class name for the path element.
top0numberThe margin on top.
left0numberThe margin on the left.
keysarrayKeys for the d3.stack.
dataarrayThe data for each stack.
curvefunctionThe curve function
definedfunctionA function called by area.defined().
xfunctionThe d3 x function.
x0functionThe d3 x0 function.
x1functionThe d3 x1 function.
y0functionThe d3 y0 function.
y1functionThe d3 y1 function.
glyphglyphA glyph to be added to the stack.
reversefalseboolIf true, reverses the order of stacks.

<Bar />

A simple rectangle (a <rect> element) to use in your graphs.

Example

bar example

<Bar
  width={xScale.bandwidth()}
  height={barHeight}
  x={xScale(x(d))}
  y={yMax - barHeight}
  fill="url('#lines')"
  stroke={'black'}
  strokeWidth={1}
/>

Properties

NameDefaultTypeDescription
classNamestringThe class name for the path element.
x0numberA number or function for the x coordinate.
y0numberA number or function for the y coordinate.
widthnumberThe pixel width of the bar.
heightnumberThe pixel height of the bar.
rxnumberThe pixel value of the corner radius.
rynumberThe pixel value of the corner radius.
fillsteelbluestringThe color for the fill of the rect element.
fillOpacitynumberThe opacity for the fill of the rect element
strokestringThe color for the stroke of the rect element.
strokeWidthnumberThe pixel width of the stroke.
strokeDasharrayarrayThe pattern of dashes in the stroke.
strokeLinecapstringThe svg linecap of the stroke.
strokeLinejoinstringThe svg linejoin of the stroke.
strokeMiterlimitnumberThe svg Miterlimit of the stroke.
strokeOpacitynumberThe svg opacity.

<Line />

A simple line. Good for drawing in the sand.

Example

<Line
  from={new Point({x:0, y:3})}
  to={new Point({x:0, y:10})}
/>

Properties

NameDefaultTypeDescription
fromnew Point({ x: 0 y: 0 })PointThe beginning point.
tonew Point({ x: 1 y: 1 })PointThe end point.
strokeblackstringThe color of the stroke.
strokeWidth1numberThe pixel width of the stroke.
strokeDasharrayarrayThe pattern of dashes in the stroke.
transformstringAn SVG transform.
classNamestringThe class name for the line element.

<LinePath />

A more complicated line path. A <LinePath /> is useful for making line graphs and drawing.

Example

Linepath example

<LinePath
  data={dataset[1].data}
  xScale={xScale}
  yScale={yScale}
  x={x}
  y={y}
  stroke={"black"}
  strokeWidth={2}
/>

Properties

NameDefaultTypeDescription
dataarrayThe data in x, y.
xScalefunctionA scale function for the xs.
yScalefunctionA scale function for the ys.
xfunctionA function that takes in a data element and returns the x value.
yfunctionA function that takes in a data element and returns the y value.
definedfunctionA function called by line.defined().
classNamestringThe class name for the path element.
strokesteelbluestringThe color of the stroke.
strokeWidth2numberThe pixel value for the stroke.
strokeDasharrayarrayThe pattern of dashes in the stroke.
fillnonestringThe color of the fill for the path element.
curveCurve.linearfunctionThe curve function
glyphglyphA glyph to be added to the line.

<LineRadial />

LineRadial Example

<LineRadial
  data={appleStock}
  angle={d => xScale(x(d))}
  radius={d => yScale(y(d))}
  fill="none"
  stroke={"url('#line-gradient')"}
  strokeWidth={2}
  strokeOpacity={.7}
  curve={curveBasisOpen}
  strokeLinecap="round"
/>

Properties

NameDefaultTypeDescription
classNamestringThe class for the element.
anglefunctionThe angle at each point.
radiusfunctionThe radius at each angle.
definedfunctionA function called by area.defined().
curvefunctionThe curve function
dataarrayAn array of x and y data.

Sources For Components