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-session-highlighting

v1.0.0

Published

Shades the background behind each bar from a color function of its time, for trading sessions, weekends, market hours or any other time-based highlight.

Readme

Session highlighting

A series primitive that shades the background behind each bar of a series. You give it a function from a bar's time to a color, and every bar of the attached series gets a full-height column in that color, as wide as the bar itself. The columns follow the series as the chart scrolls and zooms.

Use it to show where one trading session ends and the next begins, to tint pre-market and after-hours bars, to mark weekends or holidays, or to shade any other time-based condition behind the data.

Installation

npm

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

npm install @tradingview/lwc-plugin-session-highlighting

Then import the plugin and add it to a chart:

import { createChart, CandlestickSeries } from 'lightweight-charts';
import { SessionHighlighting } from '@tradingview/lwc-plugin-session-highlighting';

const chart = createChart(document.getElementById('container'));
const series = chart.addSeries(CandlestickSeries);
series.setData(data);

series.attachPrimitive(new SessionHighlighting(time => {
    const day = new Date(time * 1000).getUTCDay();
    return day === 0 || day === 6 ? 'rgba(255, 152, 1, 0.2)' : '';
}));

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-session-highlighting": "https://unpkg.com/@tradingview/lwc-plugin-session-highlighting/dist/session-highlighting.standalone.js"
  }
}
</script>

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

<script type="module">
import { createChart, CandlestickSeries } from 'lightweight-charts';
import { SessionHighlighting } from '@tradingview/lwc-plugin-session-highlighting';

const chart = createChart(document.getElementById('container'));
const series = chart.addSeries(CandlestickSeries);
series.setData(data);

series.attachPrimitive(new SessionHighlighting(time => {
    const day = new Date(time * 1000).getUTCDay();
    return day === 0 || day === 6 ? 'rgba(255, 152, 1, 0.2)' : '';
}));
</script>

Usage

The highlighter

The first constructor argument is the highlighter: a function which receives a bar's time and returns a CSS color. Return an empty string for a bar that should not be shaded. The time comes in whatever form your data uses, so for business-day data check for an object:

import { isBusinessDay } from 'lightweight-charts';

function toDate(time) {
    if (isBusinessDay(time)) {
        return new Date(Date.UTC(time.year, time.month - 1, time.day));
    }
    return typeof time === 'number' ? new Date(time * 1000) : new Date(time);
}

const highlighter = time => {
    const hour = toDate(time).getUTCHours();
    if (hour < 9 || hour >= 16) {
        return 'rgba(120, 123, 134, 0.15)'; // outside the main session
    }
    return '';
};

const highlighting = new SessionHighlighting(highlighter);
series.attachPrimitive(highlighting);

The highlighter is called once per bar when the series data is set, and once for the last bar when series.update() appends or replaces it, so it can do real work per call; series.pop() drops the popped bars without calling it. Keep it a function of the time alone: a historical update, which is series.update(bar, true), re-asks it for the last bar rather than for the bar it changed, and one that turns a bar into whitespace, or whitespace into a bar, re-asks it for every bar. Translucent colors let the grid and the series show through; the shading is drawn behind both by default.

To remove the shading, detach it from the series:

series.detachPrimitive(highlighting);

Changing the shading

highlighting.applyOptions({ zOrder: 'top', visible: false });
highlighting.setHighlighter(time => '#F0F3FA'); // recolors every bar
highlighting.options(); // the current options, with the defaults filled in

applyOptions merges: an option which is not passed, or is passed as undefined, is left unchanged.

Options

Options are passed as the second constructor argument, which is optional, as is every option in it. The type is SessionHighlightingOptions, and the defaults are exported as defaultOptions.

| Option | Type | Default | Description | | --- | --- | --- | --- | | visible | boolean | true | Whether the shading is drawn at all. | | zOrder | 'bottom' \| 'normal' \| 'top' | 'bottom' | Layer the shading is drawn in. 'bottom' puts it behind the grid and the series. |

Notes

  • Each column is exactly one bar wide, taken from the time scale's bar spacing, so neighboring columns abut with no seams and no overlap at any zoom level or device pixel ratio.
  • Only bars of the attached series are shaded. Whitespace items and gaps in the data get no column, even where another series has a bar at that time.
  • The shading appears only in the pane the series is drawn in, never under the price scales or the time scale. To shade a second pane, attach another SessionHighlighting to a series in that pane.
  • Only the bars on screen are drawn, so the cost of a paint is bounded by the width of the chart, not by the length of the history. An incremental series.update() or series.pop() does read the series data once to find out what changed, which is proportional to the number of bars.