-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbdf8d8
commit 251b878
Showing
7 changed files
with
129 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Live Data with lots of plugins</title> | ||
</head> | ||
<body> | ||
<h1>Live Data with random gaps and lots of plugins</h1> | ||
<div id="chart-container" height="250" width="500"></div> | ||
<script type="module" src="random-gaps-live-with-plugins.ts"></script> | ||
</body> | ||
</html> |
61 changes: 61 additions & 0 deletions
61
examples/random-gaps-live-with-plugins/random-gaps-live-with-plugins.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
TimeLine, | ||
Point, | ||
xAxisPlugin, | ||
yAxisPlugin, | ||
doubleClickCopyPlugin, | ||
highlightNearestPointPlugin, | ||
nearestPointInfoPopupPlugin, | ||
pointerCrosshairPlugin, | ||
axisLabelPlugin, | ||
} from "../../src"; | ||
|
||
const data: Point[] = []; | ||
const maxPoints = 300; | ||
const chart = new TimeLine({ | ||
container: document.getElementById("chart-container") as HTMLElement, | ||
data, | ||
maxPoints, | ||
xLabel: "Time", | ||
yLabel: "Random numbers", | ||
plugins: [ | ||
xAxisPlugin((x) => new Date(x).toLocaleTimeString()), | ||
yAxisPlugin(), | ||
doubleClickCopyPlugin(), | ||
highlightNearestPointPlugin(), | ||
nearestPointInfoPopupPlugin(), | ||
pointerCrosshairPlugin(), | ||
axisLabelPlugin(), | ||
], | ||
}); | ||
|
||
let prev = 0; | ||
function addPoint() { | ||
setTimeout(addPoint, Math.random() * 50); | ||
|
||
const y = | ||
prev + Math.floor(Math.random() * 10) * (Math.random() > 0.5 ? -1 : 1); | ||
prev = y; | ||
data.push({ | ||
x: Date.now(), | ||
y, | ||
}); | ||
// This is very important! | ||
// You can't have more points in the data array | ||
// than chart.maxPoints, or you'll have weird | ||
// rendering issues. | ||
while (data.length > maxPoints) { | ||
data.shift(); | ||
} | ||
|
||
// Call chart.recompute() when you're done updating `data` | ||
chart.recompute(); | ||
} | ||
addPoint(); | ||
|
||
// Note that you need to call chart.draw() yourself | ||
function renderLoop() { | ||
requestAnimationFrame(renderLoop); | ||
chart.draw(); | ||
} | ||
renderLoop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters