-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2dplot small improvements #28
Open
Math-42
wants to merge
7
commits into
uPlot
Choose a base branch
from
2dplot-visual-improvement
base: uPlot
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ba4fa4
scatter: Removed option to change x-axis scale
Math-42 d4b9c12
blockContainer: css auto height update
Math-42 36b238f
catter: add the zoom-wheel plugin
Math-42 62c997a
scatter: fixes mismatch between displayed scale and menu scale
Math-42 f5c59fa
plotly: removing plotly
Math-42 61971e5
uPlot: catching unimplemented block error
Math-42 6758f77
typos: fixing typos and cases erros
Math-42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
110 changes: 110 additions & 0 deletions
110
src/components/blocks/Blocks/uPlot/plugins/zoom-wheel.js
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,110 @@ | ||
|
||
|
||
module.exports = function wheelZoomPlugin(opts) { | ||
let factor = opts.factor || 0.75; | ||
|
||
let xMin, xMax, yMin, yMax, xRange, yRange; | ||
|
||
function clamp(nRange, nMin, nMax, fRange, fMin, fMax) { | ||
if (nRange > fRange) { | ||
nMin = fMin; | ||
nMax = fMax; | ||
} | ||
else if (nMin < fMin) { | ||
nMin = fMin; | ||
nMax = fMin + nRange; | ||
} | ||
else if (nMax > fMax) { | ||
nMax = fMax; | ||
nMin = fMax - nRange; | ||
} | ||
|
||
return [nMin, nMax]; | ||
} | ||
|
||
return { | ||
hooks: { | ||
ready: u => { | ||
xMin = u.scales.x.min; | ||
xMax = u.scales.x.max; | ||
yMin = u.scales.y.min; | ||
yMax = u.scales.y.max; | ||
|
||
xRange = xMax - xMin; | ||
yRange = yMax - yMin; | ||
|
||
let over = u.over; | ||
let rect = over.getBoundingClientRect(); | ||
|
||
over.addEventListener("mousedown", e => { | ||
if (e.button == 1) { | ||
e.preventDefault(); | ||
|
||
let left0 = e.clientX; | ||
|
||
let scXMin0 = u.scales.x.min; | ||
let scXMax0 = u.scales.x.max; | ||
|
||
let xUnitsPerPx = u.posToVal(1, 'x') - u.posToVal(0, 'x'); | ||
|
||
function onMove(e) { | ||
e.preventDefault(); | ||
|
||
let left1 = e.clientX; | ||
|
||
let dx = xUnitsPerPx * (left1 - left0); | ||
|
||
u.setScale('x', { | ||
min: scXMin0 - dx, | ||
max: scXMax0 - dx, | ||
}); | ||
} | ||
|
||
function onUp(e) { | ||
document.removeEventListener("mousemove", onMove); | ||
document.removeEventListener("mouseup", onUp); | ||
} | ||
|
||
document.addEventListener("mousemove", onMove); | ||
document.addEventListener("mouseup", onUp); | ||
} | ||
}); | ||
|
||
over.addEventListener("wheel", e => { | ||
e.preventDefault(); | ||
|
||
let { left, top } = u.cursor; | ||
|
||
let leftPct = left / rect.width; | ||
let btmPct = 1 - top / rect.height; | ||
let xVal = u.posToVal(left, "x"); | ||
let yVal = u.posToVal(top, "y"); | ||
let oxRange = u.scales.x.max - u.scales.x.min; | ||
let oyRange = u.scales.y.max - u.scales.y.min; | ||
|
||
let nxRange = e.deltaY < 0 ? oxRange * factor : oxRange / factor; | ||
let nxMin = xVal - leftPct * nxRange; | ||
let nxMax = nxMin + nxRange; | ||
[nxMin, nxMax] = clamp(nxRange, nxMin, nxMax, xRange, xMin, xMax); | ||
|
||
let nyRange = e.deltaY < 0 ? oyRange * factor : oyRange / factor; | ||
let nyMin = yVal - btmPct * nyRange; | ||
let nyMax = nyMin + nyRange; | ||
[nyMin, nyMax] = clamp(nyRange, nyMin, nyMax, yRange, yMin, yMax); | ||
|
||
u.batch(() => { | ||
u.setScale("x", { | ||
min: nxMin, | ||
max: nxMax, | ||
}); | ||
|
||
u.setScale("y", { | ||
min: nyMin, | ||
max: nyMax, | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
} |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linha vazias