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

node-red-contrib-polygon

v0.0.5

Published

Piecewise linear interpolation with up to 20 XY pairs; robust endpoint extrapolation.

Readme

node-red-contrib-polygon

Piecewise linear interpolation Node-RED node with up to 20 (X,Y) breakpoint pairs, optional endpoint extrapolation, and strict monotonic X validation.


📌 English

What this node does

polygon computes an output value from an input (msg.payload) by linearly interpolating between user-defined breakpoints. It supports 20 (X,Y) rows, each with a Use checkbox to activate the pair. Outside the endpoint range, it can extrapolate or clamp—your choice. Settings persist correctly in the editor.

Key features

  • 20 × (Use, X, Y) rows in the edit dialog
  • Strictly increasing X enforced:
    • Editor-side validation blocks saving when used X’s are not strictly increasing.
    • Runtime guard raises alarm if a mismatched flow slips through.
  • Endpoint behavior selectable:
    • Extrapolate (default ON): linear continuation beyond first/last point.
    • Clamp: hold Y at the nearest endpoint.
  • Exact-knot handling: if IN == Xk (within a tiny epsilon), OUT = Yk.
  • One output:
    1. OUT – cloned incoming message with computed msg.payload, plus msg.trbl_al, msg.n_bp, msg.segment
  • Status text indicators for quick debugging (e.g., seg k, extrap, clamped, X order invalid, etc.)

Installation

Install from the Node-RED userDir (usually ~/.node-red, Docker: /data), then restart Node-RED and hard-refresh the editor.

cd ~/.node-red      # or: cd /data (Docker)
npm install /path/to/your/node-red-contrib-polygon
node-red-restart
# In browser: Ctrl+F5 to clear cached editor assets

Configuration & algorithm

Let the active (Use ✓) points be (X1,Y1)…(Xn,Yn), n ≥ 2, with strictly increasing X:

  • If IN is inside: find k with Xk < IN < Xk+1 and compute
    OUT = Yk + (IN − Xk) * (Yk+1 − Yk) / (Xk+1 − Xk)
  • If exactly on a knot IN == Xk (epsilon match): OUT = Yk
  • If IN < X1:
    • Extrapolate ON: use slope of (X1,Y1)–(X2,Y2)
    • Extrapolate OFF: OUT = Y1 (clamp)
  • If IN > Xn:
    • Extrapolate ON: use slope of (Xn−1,Yn−1)–(Xn,Yn)
    • Extrapolate OFF: OUT = Yn (clamp)
  • Faults (alarm true):
    • Not enough points (n < 2)
    • X order invalid (Xk ≥ Xk+1 among used rows)

Outputs

  • Output 1 (OUT): computed value in msg.payload, plus:
    • msg.trbl_al – boolean: parameter fault occurred
    • msg.n_bp – number of active pairs
    • msg.segment – used segment index (-1 if clamped/extrapolated/knot)
  • Output 2 (TRBL_AL): { payload: <boolean> } alarm

Quick test

Set two points and enable extrapolation:

  • Use1: X=0, Y=0
  • Use2: X=10, Y=100
  • Extrapolate: ON

Expected:

  • IN=-5OUT=-50 (left extrapolation)
  • IN=0OUT=0 (knot)
  • IN=5OUT=50 (interpolation)
  • IN=10OUT=100 (knot)
  • IN=15OUT=150 (right extrapolation)

Troubleshooting

  • Node doesn’t appear in the palette: install from the userDir (~/.node-red or /data), then restart Node-RED and hard-refresh the editor (Ctrl+F5).
  • Keeps clamping instead of extrapolating: ensure the Extrapolate checkbox is ON and X’s are strictly increasing.

🇭🇺 Magyar

Mit csinál ez a node?

A polygon a bemeneti msg.payload alapján számít kimenetet a töréspontok között lineáris interpolációval. A szerkesztőben 20 sor áll rendelkezésre (Use, X, Y), a szélső tartományokon pedig extrapolál vagy klampel – beállítástól függően. A beállításokat helyesen megőrzi.

Fő funkciók

  • 20 × (Use, X, Y) sor
  • Szigorúan növekvő X kikényszerítése:
    • Szerkesztő: a mentés (Done) nem engedélyezett, ha a pipált sorok X értékei nem szigorúan növekvők.
    • Futásidő: ha hibás flow kerül be, riasztást ad (TRBL_AL).
  • Végpont-kezelés választható:
    • Extrapolálás (alapból BE): lineáris folytatás az első/utolsó szakasz meredekségével.
    • Klampelés: Y az adott végpontnál marad.
  • Pontos csomópont (X-egyezés): ha IN == Xk, akkor OUT = Yk.
  • Egy kimenet:
    1. OUT – a bejövő üzenet másolata számított msg.payload-dal, plusz msg.trbl_al, msg.n_bp, msg.segment
  • Állapotjelzések a debughoz (seg k, extrap, clamped, X order invalid, stb.)

Telepítés

Telepíts a Node-RED userDir-ből (jellemzően ~/.node-red, Dockerben /data), majd indítsd újra a Node-RED-et és frissítsd a böngészőt (Ctrl+F5).

cd ~/.node-red      # vagy: cd /data (Docker)
npm install /ELERESI/UT/node-red-contrib-polygon
node-red-restart
# Böngésző: Ctrl+F5

Beállítás & algoritmus

Legyenek az aktív (Use ✓) pontok (X1,Y1)…(Xn,Yn), n ≥ 2, szigorúan növekvő X-szel:

  • Ha IN belül van: keresünk k-t, ahol Xk < IN < Xk+1, és számolunk:
    OUT = Yk + (IN − Xk) * (Yk+1 − Yk) / (Xk+1 − Xk)
  • Ha pontosan IN == Xk: OUT = Yk
  • Ha IN < X1:
    • Extrap BE: az (X1,Y1)–(X2,Y2) szakasz meredekségével
    • Extrap KI: OUT = Y1 (klampel)
  • Ha IN > Xn:
    • Extrap BE: az (Xn−1,Yn−1)–(Xn,Yn) szakasz meredekségével
    • Extrap KI: OUT = Yn (klampel)
  • Hibák (TRBL_AL = true):
    • Kevés pont (n < 2)
    • X sorrend hibás (Xk ≥ Xk+1 a használt sorokban)

Kimenetek

  • 1. kimenet (OUT): számított msg.payload, továbbá:
    • msg.trbl_al – logikai zászló hiba esetén
    • msg.n_bp – használt pontpárok száma
    • msg.segment – a használt szegmens indexe (-1 klampelés/extrapoláció/csomópont esetén)
  • 2. kimenet (TRBL_AL): { payload: <boolean> } jelző

Gyors próba

Két pont, extrapolálás BE:

  • Use1: X=0, Y=0
  • Use2: X=10, Y=100

Várt értékek:

  • IN=-5OUT=-50
  • IN=0OUT=0
  • IN=5OUT=50
  • IN=10OUT=100
  • IN=15OUT=150

Hibaelhárítás

  • Nem jelenik meg a palettán: a userDir-ből telepíts (~/.node-red vagy /data), indíts újra, és Ctrl+F5.
  • Klampel extrapolálás helyett: kapcsold BE az Extrapolálás pipát és ellenőrizd a szigorú X-sorrendet.

License

MIT