Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nivo/legends

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nivo/legends

legend components for nivo dataviz library

  • 0.88.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
435K
decreased by-0.79%
Maintainers
1
Weekly downloads
 
Created

What is @nivo/legends?

@nivo/legends is a part of the Nivo library, which provides a set of components to build data visualizations in a React application. The @nivo/legends package specifically deals with creating and customizing legends for various types of charts, making it easier to interpret the data being visualized.

What are @nivo/legends's main functionalities?

Basic Legend

This code demonstrates how to create a basic legend using the LegendSvg component from @nivo/legends. The legend is positioned at the top-left corner and displays three series with different colors.

import { LegendSvg } from '@nivo/legends';

const MyLegend = () => (
  <LegendSvg
    data={[
      { id: 'A', label: 'Series A', color: 'hsl(0, 70%, 50%)' },
      { id: 'B', label: 'Series B', color: 'hsl(120, 70%, 50%)' },
      { id: 'C', label: 'Series C', color: 'hsl(240, 70%, 50%)' }
    ]}
    anchor="top-left"
    direction="column"
    justify={false}
    translateX={20}
    translateY={20}
    itemsSpacing={2}
    itemWidth={100}
    itemHeight={20}
    itemDirection="left-to-right"
    itemOpacity={0.75}
    symbolSize={12}
    symbolShape="circle"
  />
);

Interactive Legend

This code demonstrates how to create an interactive legend using the LegendSvg component from @nivo/legends. The legend items are clickable, and clicking on an item will trigger an alert displaying the label of the clicked item.

import { LegendSvg } from '@nivo/legends';

const MyInteractiveLegend = () => (
  <LegendSvg
    data={[
      { id: 'A', label: 'Series A', color: 'hsl(0, 70%, 50%)' },
      { id: 'B', label: 'Series B', color: 'hsl(120, 70%, 50%)' },
      { id: 'C', label: 'Series C', color: 'hsl(240, 70%, 50%)' }
    ]}
    anchor="top-left"
    direction="column"
    justify={false}
    translateX={20}
    translateY={20}
    itemsSpacing={2}
    itemWidth={100}
    itemHeight={20}
    itemDirection="left-to-right"
    itemOpacity={0.75}
    symbolSize={12}
    symbolShape="circle"
    onClick={(datum) => alert(`Clicked on ${datum.label}`)}
  />
);

Custom Symbol Shape

This code demonstrates how to create a legend with custom symbol shapes using the LegendSvg component from @nivo/legends. The symbols are rendered as rectangles with rounded corners instead of the default circles.

import { LegendSvg } from '@nivo/legends';

const MyCustomSymbolLegend = () => (
  <LegendSvg
    data={[
      { id: 'A', label: 'Series A', color: 'hsl(0, 70%, 50%)' },
      { id: 'B', label: 'Series B', color: 'hsl(120, 70%, 50%)' },
      { id: 'C', label: 'Series C', color: 'hsl(240, 70%, 50%)' }
    ]}
    anchor="top-left"
    direction="column"
    justify={false}
    translateX={20}
    translateY={20}
    itemsSpacing={2}
    itemWidth={100}
    itemHeight={20}
    itemDirection="left-to-right"
    itemOpacity={0.75}
    symbolSize={12}
    symbolShape={({ x, y, size, fill, borderWidth, borderColor }) => (
      <rect
        x={x}
        y={y}
        width={size}
        height={size}
        fill={fill}
        strokeWidth={borderWidth}
        stroke={borderColor}
        rx={3}
        ry={3}
      />
    )}
  />
);

Other packages similar to @nivo/legends

FAQs

Package last updated on 11 Nov 2024

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