
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@nivo/legends
Advanced tools
@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.
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}
/>
)}
/>
);
react-chartjs-2 is a React wrapper for Chart.js, a popular JavaScript charting library. It provides a variety of chart types and customization options, including legends. Compared to @nivo/legends, react-chartjs-2 offers a more extensive set of chart types but may require more configuration for advanced customizations.
Recharts is a composable charting library built on React components. It offers a wide range of chart types and customization options, including legends. Recharts is known for its ease of use and flexibility, making it a good alternative to @nivo/legends for creating interactive and customizable charts.
Victory is a collection of composable React components for building interactive data visualizations. It provides a variety of chart types and customization options, including legends. Victory is designed to be highly flexible and modular, allowing developers to create complex visualizations with ease. It compares to @nivo/legends in terms of flexibility and ease of use.
FAQs
legend components for nivo dataviz library
The npm package @nivo/legends receives a total of 318,195 weekly downloads. As such, @nivo/legends popularity was classified as popular.
We found that @nivo/legends demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.