JSPM

chartjs-plugin-interaction-tools

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 2
    • Score
      100M100P100Q23400F
    • License MIT

    Two Chart.js plugins: one for dragging points with a trail, and another for drawing freeform trails with the mouse.

    Package Exports

    • chartjs-plugin-interaction-tools

    Readme

    chartjs-plugin-interaction-tools

    This package provides two interactive plugins for Chart.js:

    • ๐ŸŸข dragTrailPlugin โ€“ allows you to click and drag a data point, leaving a visual trail.
    • ๐ŸŸก trailPlugin โ€“ lets you draw freeform trails on the chart by clicking and dragging the mouse.

    โœจ Features

    • Click-and-drag individual points
    • Visual trail of movement
    • Customizable trail appearance (radius, color, stroke)
    • Draw freeform trails anywhere on the chart
    • Compatible with Chart.js v4+

    ๐Ÿ“ฆ Installation

    npm install chartjs-plugin-interaction-tools

    ๐Ÿงฉ Usage

    1. Register the plugins
    import {
      dragTrailPlugin,
      trailPlugin
    } from 'chartjs-plugin-interaction-tools';
    
    Chart.register(dragTrailPlugin, trailPlugin);
    1. Add to your chart config
    const chart = new Chart(ctx, {
      type: 'scatter',
      data: {
        datasets: [...]
      },
      options: {
        plugins: {
          dragTrail: {
            trailFillColor: '#cccccc',
            trailBorderColor: '#999999',
            trailRadius: 4
          },
          Trail: {
            trailFillColor: '#ffaaaa',
            trailBorderColor: '#aa0000',
            trailRadius: 4
          }
        }
      },
      plugins: ['dragTrail', 'Trail']
    });

    ๐Ÿงน Clearing the Trail

    You can clear trails manually with:

    dragTrailPlugin.clearTrail(chart);
    trailPlugin.clearTrail(chart);

    ๐Ÿ› ๏ธ Advanced Options

    Both plugins accept the following options under the plugins section of your chart config:

    trailFillColor:   // Color to fill the trail points (default: '#c7c7c7')
    trailBorderColor: // Color for the trail border (default: '#9c9c9c')
    trailBorderWidth: // Width of the trail border (default: 1)
    trailRadius:      // Radius of the trail points (default: 3)

    Example:

    plugins: {
      dragTrail: {
        trailFillColor: '#00ff00',
        trailBorderColor: '#006600',
        trailBorderWidth: 2,
        trailRadius: 5
      },
      Trail: {
        trailFillColor: '#ffaaaa',
        trailBorderColor: '#aa0000',
        trailBorderWidth: 2,
        trailRadius: 5
      }
    }

    Questions

    If you have any questions, feel free to reach out to Noemi Vital (noemimvital.14@gmail.com).