0.2.0 • Published 4 months ago

code-heatmap v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

CodeHeatmap

A tool that generates real-time heatmaps of JavaScript execution to show performance bottlenecks.

Installation

npm install code-heatmap

Usage

Basic Usage

import CodeHeatmap from 'code-heatmap';

// Initialize the heatmap
const heatmap = new CodeHeatmap({
  targetSelector: 'body',
  colorScale: ['#e0f7fa', '#80deea', '#26c6da', '#00acc1', '#0097a7', '#00838f', '#006064'],
  updateInterval: 1000
});

// Start monitoring
heatmap.start();

// Later, to stop monitoring
heatmap.stop();

CDN Usage

<script src="https://unpkg.com/code-heatmap@0.1.0/dist/code-heatmap.js"></script>
<script>
  const heatmap = new CodeHeatmap();
  heatmap.start();
</script>

Options

The CodeHeatmap constructor accepts an options object with the following properties:

OptionTypeDefaultDescription
targetSelectorString'body'CSS selector for the target element to monitor
maxIntensityNumber100Maximum intensity value for the heatmap
colorScaleArray'#e0f7fa', '#80deea', '#26c6da', '#00acc1', '#0097a7', '#00838f', '#006064'Array of colors for the heatmap
updateIntervalNumber500Interval in milliseconds for updating the visualization
fadeTimeNumber3000Time in milliseconds for fading out the heatmap
samplingRateNumber10Sampling rate in milliseconds

Methods

start()

Start monitoring JavaScript execution.

pause()

Pause monitoring without removing instrumentation.

stop()

Stop monitoring and remove instrumentation.

clear()

Clear collected data.

exportData()

Export collected data as JSON.

Advanced Usage

Script Instrumentation

To instrument scripts more thoroughly:

import { CodeHeatmap, ScriptInstrumenter } from 'code-heatmap';

const heatmap = new CodeHeatmap();
const instrumenter = new ScriptInstrumenter(heatmap);

// Instrument all scripts in the document
instrumenter.instrumentScripts();

// Start monitoring
heatmap.start();

License

MIT

0.2.0

4 months ago

0.1.0

4 months ago