npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-svg-map-colorizer

v0.2.2

Published

Allows color primitives of existing SVG image with React.

Readme

What is the react-svg-map-colorizer?

This is React component which allows to use SVG maps.

SVG maps are special SVG images which consists of elements with provided id, so when loaded to DOM as <svg> element it possible to select the particular element and set it fill or stroke property to highlight this element on resulted image.

The react-svg-map-colorizer not just hide DOM manipulations on SVG element within beauty Component interface but indeed utilizes React for rendering the entire DOM subtree, so benefit from power of VDOM and batched DOM updates which the React does.

When to use this component?

  1. If you have React based app, you likely want just declare you layout and not worry about underlying DOM manipulations like loading SVG not to <img> but to <svg> which support per element changes.
  2. If you image contains a lot of elements and it expected to update a lot doing this directly per element basis could be slow. The component can do batched updates, so works good enough even when updating thousands of elements. So it might worth to include the component (and React dependencies) for such task even to non React app, so that avoid mess of manually tackling with diffs and batch updates.

What are the limitations?

  1. Currently there is support for highlighting the specified primitives with one color and filling left with another color.

  2. Implementation requires the place for mounting the React tree. So SVG image format is restricted to one, where all primitives which need updates should be included into <g id="data"> svg group. It also expected that aforementioned group will contain only supported primitives.

    1. Here is the list of supported primitives
      1. polygon
      2. rect
      3. circle
      4. ellipse
      5. line
      6. polyline
      7. path
  3. For lines colorization happen for stroke property and for shapes for fill property, path is special case as can be both, so whether alter stroke or fill decided based on initial value for fill (if visible than it would fill).

How to use the component?

Within React app

import * as React from "react";
import { Svg } from "react-svg-map-colorizer";


function MyComponentNeedSvg {
	const svgProps = {
		svgUrl: "svgUrl",
		idColorMap: {
			elementId1: "yellow",
			elementId2: "red",
			"*": "green"
		},
		onPrimitiveClick: (id) => console.log(id),
	};

	return  <Svg {...svgProps} />;
}

Within non React app

import * as ReactDom from "react-dom";
import * as React from "react";
import { Svg } from "react-svg-map-colorizer";

// The place for rendering react svg component.
const svgContainer = document.getElementById("containerId");

// To mount and update component.
function RenderColoredSvg {
	const svgProps = {
		svgUrl: "svgUrl",
		idColorMap: {
			elementId1: "yellow",
			elementId2: "red",
			"*": "green"
		},
		onPrimitiveClick: (id) => console.log(id),
	};


	// it fine to call this each time update needed.
	ReactDom.render(React.createElement(Svg, svgProps), svgContainer);
}

// When you done with svg and need remove container this 
// method should be called to properly cleanup.
function unmountSvgComponent () {
	ReactDom.unmountComponentAtNode(svgContainer);
}

Svg Props description

| Property | Description | |----------| ----------- | |svgUrl | The url to svg image. If you have file, you can create one with URL.createObjectUrl(file);, please note to keep the url same for the same image, otherwise new component would created inside which would cause performance degradation for render.| |idColorMap| Dictionary where keys are primitive ids to highlight and values are color, elements which are not listed here would be filled with initial color. The initial color can be overriden by adding special * key.| |onPrimitiveClick| The optional callback you may pass to svg. It would be called with primitive id when primitive clicked and related mouse event.| |onPrimitiveEnter| The optional callback which would be called with primitive id and mouse event when mouse enter into primitive.| |onPrimitiveLeave| The optional callback which would be called with primitive id and mouse event when mouse leaves primitive.| |onPrimitiveMove| The optional callback which would be called with primitive id and mouse event when mouse moves in primitive.| |onSvgMounted| The optional callback which called once underlying SVG mounted to the DOM. The component works outside of normal React lifecycle and just provides eventually consistent view representation so in case you need some time dependent work (e.g. use library which manipulated the DOM directly) this is the place to hook.|