A minimalistic yet powerful time series plotting library with pattern detection capabilities.
-
Simple Time Series Visualization
- Bar chart visualization with time on X-axis and values on Y-axis
- Responsive and resizable
- Customizable colors and styling
- Mouse-over tooltips showing exact values
-
Pattern Detection
- Low Value Detection: Identifies periods where values remain consistently low
- Stagnation Detection: Identifies periods of minimal change in typically active data
- Visual indicators for detected patterns
- Configurable thresholds and parameters
-
Statistical Analysis
- Mean and median lines
- Moving averages
- Standard deviation calculation
- Percentile calculations
-
Export Options
- Export data to CSV
- Export chart as SVG
- Programmatic access to statistics
-
Accessibility
- Keyboard navigation support
- ARIA attributes
- Screen reader friendly
npm install mtplot
import { MTPlot } from 'mtplot';
// Create a new plot
const plot = new MTPlot('container-id', data, {
width: 1000,
height: 300
});
// Configure pattern detection
plot.setPatternOptions({
lowValue: {
threshold: 0.02, // 2% of value range
consecutiveDays: 2 // 2 consecutive days
},
stagnation: {
consecutiveDays: 3, // 3 consecutive days
changeThreshold: 0.2, // 20% of average change
activeChangePercentage: 0.85 // 85% of days should show change
}
});
// Customize appearance
plot.setTheme({
barColor: 'black',
barHoverColor: 'blue',
lowValueColor: 'rgba(255,0,0,0.2)',
stagnationColor: 'rgba(255,165,0,0.2)'
});
new MTPlot(containerId: string, data?: DataPoint[], options?: PlotOptions)
interface DataPoint {
x: Date; // Date object for the time
y: number; // Value for that time
}
interface PlotOptions {
width?: number;
height?: number;
theme?: Theme;
patterns?: {
lowValue?: {
threshold: number;
consecutiveDays: number;
};
stagnation?: {
consecutiveDays: number;
changeThreshold: number;
activeChangePercentage: number;
};
};
}
addData(point: DataPoint)
: Add a new data pointremoveOldest()
: Remove the oldest data pointreplaceOldest(point: DataPoint)
: Replace the oldest point with a new onesetTheme(theme: Theme)
: Update the visual themesetPatternOptions(options: PatternOptions)
: Update pattern detection settingsgetStatistics()
: Get statistical information about the dataexportToCSV()
: Export data as CSVexportToSVG()
: Export chart as SVG
See the demo/
directory for complete examples and usage patterns.
# Install dependencies
npm install
# Build the library
npm run build
# Run tests
npm test
# Start demo server
npm start
MIT License - see LICENSE file for details