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

react-path-marker

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-path-marker

A marker for SVG paths in React

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-path-marker License: MIT npm version Demo: Simple Example

A simple, free marker for svgs with optional text The component detects the SVG and Path locations/sizes. The component also detects the display text width of the marker. Based on that information a calculation is done so that the rendering of the marker will be optimized and correctly oriented.

Note: In SVG, the rendering order is based on the document order. I.e. the first elements in the SVG document fragment getting "painted" first. Subsequent elements are painted on top of previously painted elements. To avoid issues with path elements rendered on top of markers, please place all markers below all content path elements.

Demo

Click here for live demo.

Install

In order to install, run the following command:

$ npm install react-path-marker --save

Usage

A very simple `App.tsx' example:

import React from "react"
import "./App.css"
import { PathMarker } from "react-path-marker" // import the package

function App() {

  const svgRef = React.createRef<SVGSVGElement>()
  const pathRef = React.createRef<SVGCircleElement>()

  return (
    < div className="App" >
      < div className="Main">
        <svg width="400" height="400" ref={svgRef}>
          <circle cx={50} cy={50} r={50} fill="red" ref={pathRef} />
          <PathMarker svgRef={svgRef} pathRef={pathRef} colro={"red"} borderColor={"blue"}/>
        </svg>
      </div>
    </div>
  )
}

export default App

Customization

The following parameters are passed to the marker component:

PropTypeDescription
svgRefReact.RefObjectMandatory. A React reference object to the SVG element
pathRefReact.RefObjectMandatory. A React reference object to the path element bounded to the marker
markerRefReact.RefObjectOptional. A React reference object to the marker itself. Default: new reference
borderColorstringOptional. Color for marker border. Default: "black"
colorstringOptional. Color for marker background. Default: "black"

Notes:

  • pathRef must be a valid reference to a path element. There are a number of such types such as SVGRectElement, SVGCircleElement, etc.
  • The SVG rendering should be such that all the marker elelments are at the bottom of the SVG definition, and specifically, after the path elements. Otherwise, there is a risk of paths overlaping markers.

License

MIT

Keywords

FAQs

Package last updated on 12 Aug 2020

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