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

@visx/legend

Package Overview
Dependencies
Maintainers
4
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@visx/legend

visx legend

  • 2.10.0-alpha.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
158K
increased by11.11%
Maintainers
4
Weekly downloads
 
Created

What is @visx/legend?

@visx/legend is a part of the VisX library, which provides a collection of reusable low-level visualization components for React. The @visx/legend package specifically helps in creating legends for charts and graphs, making it easier to interpret the data being visualized.

What are @visx/legend's main functionalities?

Legend

This code demonstrates how to create a simple ordinal legend using the @visx/legend package. The LegendOrdinal component is used to map domain values to colors, making it easier to understand the data represented in a chart.

import React from 'react';
import { LegendOrdinal } from '@visx/legend';
import { scaleOrdinal } from '@visx/scale';

const ordinalColorScale = scaleOrdinal({
  domain: ['Apple', 'Banana', 'Cherry'],
  range: ['#ff0000', '#ffff00', '#ff007f'],
});

const LegendExample = () => (
  <LegendOrdinal scale={ordinalColorScale} labelFormat={label => `${label}`} />
);

export default LegendExample;

Legend with Shape

This example shows how to create a legend with custom shapes using the @visx/legend package. The Circle component from @visx/shape is used to render colored circles next to each legend label.

import React from 'react';
import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend';
import { scaleOrdinal } from '@visx/scale';
import { Circle } from '@visx/shape';

const ordinalColorScale = scaleOrdinal({
  domain: ['Apple', 'Banana', 'Cherry'],
  range: ['#ff0000', '#ffff00', '#ff007f'],
});

const LegendWithShapeExample = () => (
  <LegendOrdinal scale={ordinalColorScale} labelFormat={label => `${label}`}>
    {labels =>
      labels.map((label, i) => (
        <LegendItem key={`legend-ordinal-${i}`} margin="0 5px">
          <Circle fill={label.value} size={10} />
          <LegendLabel align="left" margin="0 0 0 4px">
            {label.text}
          </LegendLabel>
        </LegendItem>
      ))
    }
  </LegendOrdinal>
);

export default LegendWithShapeExample;

Other packages similar to @visx/legend

Keywords

FAQs

Package last updated on 02 May 2022

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