New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vx/shape

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vx/shape

vx shape

  • 0.0.168
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
129K
decreased by-15.9%
Maintainers
1
Weekly downloads
 
Created
Source

@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
xfunctionThe d3 x function.
yfunctionThe d3 y1 function.
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.
xfunctionThe d3 x function.
yfunctionThe d3 y function.
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.

<Pie />

Pie Example

<Pie
  data={browsers}
  pieValue={d => d.usage}
  outerRadius={radius - 80}
  innerRadius={radius - 120}
  fill="white"
  fillOpacity={d => 1 / (d.index + 2) }
  cornerRadius={3}
  padAngle={0}
  centroid={(centroid, arc) => {
    const [x, y] = centroid;
    const { startAngle, endAngle } = arc;
    if (endAngle - startAngle < .1) return null;
    return <Label x={x} y={y}>{arc.data.label}</Label>;
  }}
/>

Properties

NameDefaultTypeDescription
classNamestringThe class for the element.
top0numberThe distance in pixels from the top.
left0numberThe distance in pixels from the left.
dataarrayAn array of data elements.
pieValuefunctionA function that takes a data element and returns the value for the corresponding pie’s slice.
innerRadius0numberThe distance of arcs’ inner side from the center of the pie. Make it non-zero to have a “donut” chart.
outerRadiusnumberThe total radius of the pie.
cornerRadius0numberThe corner radius of pie arcs in pixels.
startAngle0numberThe angle in radians at which the pie should start.
endAnglenumberThe angle in radians at which the pie should end.
padAngle0numberThe pad (or gutter) between arcs in radians.
padRadiusnumberSet the arc padRadius
pieSortfunctionA comparator function which takes two data elements and returns -1, 0 or +1 to sort arcs.
pieSortValuesfunctionA comparator function which takes two values (as returned from pieValue) and returns -1, 0 or +1 to sort arcs.
centroidfunctionA render function which takes a centroid and an arc argument called for each arc.

Sources For Components

Keywords

FAQs

Package last updated on 22 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc