Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@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.
v0.47.0 (2018-08-30)
<a name="v0.46.0"></a>
FAQs
legend components for nivo dataviz library
The npm package @nivo/legends receives a total of 313,188 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.