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

@tradingview/lwc-plugin-user-price-lines

v1.0.0

Published

Lets users add price lines by clicking a + button that follows the pointer at the right edge of the pane, with an API to add, list and remove them.

Readme

User price lines

A series primitive that lets the user add price lines to a series. When the pointer comes near the right edge of the pane, a small button with a plus follows it up and down; clicking the button adds a price line at that price.

Use it for levels the user marks by hand: support and resistance, entry and exit prices, or the price an alert should fire at.

Installation

npm

Install the package. It requires lightweight-charts ^5.0.0 in your project:

npm install @tradingview/lwc-plugin-user-price-lines

Then import the plugin and attach it to a series:

import { createChart, LineSeries } from 'lightweight-charts';
import { UserPriceLines } from '@tradingview/lwc-plugin-user-price-lines';

const chart = createChart(document.getElementById('container'));
const series = chart.addSeries(LineSeries);
series.setData([
    { time: '2024-04-22', value: 101.2 },
    { time: '2024-04-23', value: 102.8 },
    { time: '2024-04-24', value: 100.9 },
]);

series.attachPrimitive(new UserPriceLines({ lineColor: '#F23645' }));

CDN

The plugin is published as ES modules. Map the library and the plugin to their CDN builds with an import map:

<script type="importmap">
{
  "imports": {
    "lightweight-charts": "https://unpkg.com/lightweight-charts@^5/dist/lightweight-charts.standalone.production.mjs",
    "@tradingview/lwc-plugin-user-price-lines": "https://unpkg.com/@tradingview/lwc-plugin-user-price-lines/dist/user-price-lines.standalone.js"
  }
}
</script>

The plugin can then be imported by name, exactly as it is under a bundler:

<script type="module">
import { createChart, LineSeries } from 'lightweight-charts';
import { UserPriceLines } from '@tradingview/lwc-plugin-user-price-lines';

const chart = createChart(document.getElementById('container'));
const series = chart.addSeries(LineSeries);
series.setData([
    { time: '2024-04-22', value: 101.2 },
    { time: '2024-04-23', value: 102.8 },
    { time: '2024-04-24', value: 100.9 },
]);

series.attachPrimitive(new UserPriceLines({ lineColor: '#F23645' }));
</script>

Usage

Attach the plugin to the series the lines belong to. The button shows near the right edge of that series' pane, wherever the series has a price, and a click on it adds a price line to the series at the price under the pointer:

const lines = new UserPriceLines({ maxLines: 3 });
series.attachPrimitive(lines);

// Lines can be added and removed from code as well.
const line = lines.addLine(102.5);
lines.lineAdded().subscribe(added => console.log('added', added.options().price));
lines.lineRemoved().subscribe(removed => console.log('removed', removed.options().price));
lines.removeLine(line);
lines.removeAll();
  • addLine(price) adds a line with the line options and returns its IPriceLine. A click on the button does the same. At maxLines, the oldest line is removed first. It throws unless the plugin is attached to a series that is on a chart.
  • removeLine(line) removes a line the plugin added and returns true; a line it did not add, or one already removed, is left alone and gives false. removeAll() removes every line the plugin added.
  • lines() lists the lines the plugin added that are still on the series, oldest first. A line removed with series.removePriceLine is left out.
  • lineAdded() and lineRemoved() fire with each line the plugin adds and removes. Lines are removed by removeLine and removeAll, to stay within maxLines, and when the plugin is detached.

Detaching the plugin, series.detachPrimitive(lines), stops it listening to the pointer, removes the lines it added and puts the crosshair mode back. Attaching it to another series while it is attached moves it there: it is detached from the first series, which removes its lines there. chart.removeSeries takes the lines away with the series, and the plugin lets go of the chart on the next pointer event.

Crosshair mode

The button follows the pointer, so the plugin sets the chart's crosshair to CrosshairMode.Normal while it is attached: in the Magnet modes the crosshair would jump between the series' values instead. The mode the chart had is put back when the plugin is detached, unless something changed it from Normal in the meantime, in which case it is left as it is. Pass setCrosshairMode: false to leave the crosshair mode alone.

Several instances

Within a pane, only the instance attached last shows its button and adds lines, so a click never adds a line to two series at once. When it is detached, the one attached before it takes over.

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | lineColor | string | '#000000' | Color of the price lines the plugin adds. | | lineWidth | LineWidth | 1 | Width of the price lines, in CSS pixels. | | lineStyle | LineStyle | LineStyle.Dashed | Style of the price lines. | | axisLabelVisible | boolean | true | Whether the price lines show their price on the price scale. | | buttonColor | string | '' | Background of the add button. An empty string uses the background of the crosshair's horizontal line label. | | hoverColor | string | '#777777' | Background of the add button while the pointer is over it. | | maxLines | number | Infinity | The most lines the plugin keeps; adding one more removes the oldest. Rounded down and at least 1; a value that is not a number means no limit. | | setCrosshairMode | boolean | true | Whether the plugin sets the crosshair to Normal mode while attached. |

Change them with lines.applyOptions({ ... }); lines.options() returns them all. The line options apply to the lines added afterwards. Lowering maxLines removes the oldest lines over the new limit.

Notes

  • The button is reported to the chart's hit test, so the cursor becomes a pointer over it and pointer events report ADD_BUTTON_ID as the hovered object (param.hoveredObjectId).
  • The button only comes up for the pointer. A crosshair placed with chart.setCrosshairPosition, as charts kept in sync do, never shows it.
  • A tap on a touch screen moves no crosshair, so no button is shown and a tap at the edge adds nothing; after a long press has brought the button up, only a tap on the button adds a line. The chart reports no click after a drag, so a drag that starts on the button adds nothing either.
  • The button always sits at the right edge of the pane, which is where the pointer leaves the pane for the right price scale. Clicking a line to remove it, placing the button by the left price scale and rounding prices to the series' price step are not part of this release.

Migrating from plugin-examples

In the plugin-examples collection the plugin was created with new UserPriceLines(chart, series, options) and taken off with remove(). Both still work and are deprecated: pass the options only and attach the plugin with series.attachPrimitive, and detach it with series.detachPrimitive. remove() now removes the lines the plugin added, as detaching does, and does not throw once the chart or the series is gone.

The options are renamed: color, the color of the lines, is lineColor, and limitToOne, which was never read, is maxLines (maxLines: 1 keeps one line). The lines can now be removed, and the plugin no longer adds lines for clicks in other panes or for two instances at once.