-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow cursor & drag sync using scales instead of coords. close #215
- Loading branch information
Showing
6 changed files
with
300 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Zoom Ranger XY</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<link rel="stylesheet" href="../dist/uPlot.min.css"> | ||
<style> | ||
.uplot { | ||
display: block; | ||
width: 800px; | ||
} | ||
|
||
.uplot .select { | ||
background: rgba(127,0,256,0.3); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<script src="../dist/uPlot.iife.js"></script> | ||
<script> | ||
var loop = 100; | ||
|
||
let data = [ | ||
Array(loop), | ||
Array(loop), | ||
]; | ||
|
||
for (var i = 0; i < loop; i++) { | ||
let x = 2 * Math.PI * i / loop; | ||
let y = Math.sin(x); | ||
|
||
data[0][i] = x; | ||
data[1][i] = y; | ||
} | ||
|
||
let initXmin = 1; | ||
let initXmax = 4.5; | ||
|
||
const rangerOpts = { | ||
width: 800, | ||
height: 100, | ||
cursor: { | ||
points: { | ||
show: false, | ||
}, | ||
drag: { | ||
setScale: false, | ||
x: true, | ||
y: true, | ||
uni: 10 | ||
}, | ||
sync: { | ||
key: "moo", | ||
scales: ["x", "y"] | ||
} | ||
}, | ||
legend: { | ||
show: false | ||
}, | ||
scales: { | ||
x: { | ||
time: false, | ||
}, | ||
}, | ||
series: [ | ||
{}, | ||
{ | ||
stroke: "rgba(0,0,0,0.8)", | ||
} | ||
], | ||
hooks: { | ||
ready: [ | ||
uRanger => { | ||
let left = Math.round(uRanger.valToPos(initXmin, 'x')); | ||
let width = Math.round(uRanger.valToPos(initXmax, 'x')) - left; | ||
let height = uRanger.bbox.height / devicePixelRatio; | ||
uRanger.setSelect({left, width, height}, false); | ||
} | ||
] | ||
} | ||
}; | ||
|
||
let uRanger = new uPlot(rangerOpts, data, document.body); | ||
|
||
const zoomedOpts = { | ||
// title: "Zoomed Area", | ||
width: 800, | ||
height: 400, | ||
cursor: { | ||
drag: { | ||
x: true, | ||
y: true, | ||
uni: 40 | ||
}, | ||
sync: { | ||
key: "moo", | ||
scales: ["x", "y"] | ||
} | ||
}, | ||
scales: { | ||
x: { | ||
time: false, | ||
min: initXmin, | ||
max: initXmax, | ||
}, | ||
}, | ||
series: [ | ||
{ | ||
label: "x", | ||
}, | ||
{ | ||
label: "sin(x)", | ||
stroke: "purple", | ||
} | ||
] | ||
}; | ||
|
||
let uZoomed = new uPlot(zoomedOpts, data, document.body); | ||
</script> | ||
</body> | ||
</html> |
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
Oops, something went wrong.