-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Monotone cubic interpolation #3112
Merged
etimberg
merged 7 commits into
chartjs:master
from
MatthieuRivaud:MonotoneCubicInterpolation
Aug 22, 2016
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2409908
Implement monotone cubic interpolation (see issue #3086).
MatthieuRivaud d06fbc7
- Added dataset option |cubicInterpolationMode| to allow for curves w…
MatthieuRivaud 4aabc0c
Recovered a fix lost when branching.
MatthieuRivaud ef66bf5
Fixed splineCurveMonotone unit test
MatthieuRivaud 566ede1
Fixed splineCurveMonotone unit test (for real this time)
MatthieuRivaud 3869dd1
Fix spanGaps probing in updateBezierControlPoints
MatthieuRivaud 7635ab4
Calling |helpers.sign| instead of |Math.sign| directly for IE and Saf…
MatthieuRivaud 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<title>Line Chart - Cubic interpolation mode</title> | ||
<script src="../dist/Chart.bundle.js"></script> | ||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | ||
<style> | ||
canvas{ | ||
-moz-user-select: none; | ||
-webkit-user-select: none; | ||
-ms-user-select: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div style="width:75%;"> | ||
<canvas id="canvas"></canvas> | ||
</div> | ||
<br> | ||
<br> | ||
<button id="randomizeData">Randomize Data</button> | ||
<script> | ||
|
||
var randomScalingFactor = function() { | ||
return Math.round(Math.random() * 100); | ||
//return 0; | ||
}; | ||
var randomColorFactor = function() { | ||
return Math.round(Math.random() * 255); | ||
}; | ||
var randomColor = function(opacity) { | ||
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')'; | ||
}; | ||
|
||
var datapoints = [0, 20, 20, 60, 60, 120, NaN, 180, 120, 125, 105, 110, 170]; | ||
var config = { | ||
type: 'line', | ||
data: { | ||
labels: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"], | ||
datasets: [{ | ||
label: "Cubic interpolation (monotone)", | ||
data: datapoints, | ||
borderColor: 'rgba(255, 0, 0, 0.7)', | ||
backgroundColor: 'rgba(0, 0, 0, 0)', | ||
fill: false, | ||
cubicInterpolationMode: 'monotone' | ||
}, { | ||
label: "Cubic interpolation (default)", | ||
data: datapoints, | ||
borderColor: 'rgba(0, 0, 255, 0.3)', | ||
backgroundColor: 'rgba(0, 0, 0, 0)', | ||
fill: false, | ||
}, { | ||
label: "Linear interpolation", | ||
data: datapoints, | ||
borderColor: 'rgba(0, 0, 0, 0.10)', | ||
backgroundColor: 'rgba(0, 0, 0, 0)', | ||
fill: false, | ||
lineTension: 0 | ||
}] | ||
}, | ||
options: { | ||
responsive: true, | ||
title:{ | ||
display:true, | ||
text:'Chart.js Line Chart - Cubic interpolation mode' | ||
}, | ||
tooltips: { | ||
mode: 'label' | ||
}, | ||
hover: { | ||
mode: 'dataset' | ||
}, | ||
scales: { | ||
xAxes: [{ | ||
display: true, | ||
scaleLabel: { | ||
display: true | ||
} | ||
}], | ||
yAxes: [{ | ||
display: true, | ||
scaleLabel: { | ||
display: true, | ||
labelString: 'Value' | ||
}, | ||
ticks: { | ||
suggestedMin: -10, | ||
suggestedMax: 200, | ||
} | ||
}] | ||
} | ||
} | ||
}; | ||
|
||
window.onload = function() { | ||
var ctx = document.getElementById("canvas").getContext("2d"); | ||
window.myLine = new Chart(ctx, config); | ||
}; | ||
|
||
$('#randomizeData').click(function() { | ||
for (var i = 0, len = datapoints.length; i < len; ++i) { | ||
datapoints[i] = Math.random() < 0.05 ? NaN : randomScalingFactor(); | ||
} | ||
window.myLine.update(); | ||
}); | ||
|
||
</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.
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.
is it right to remove this setting? It's helpful when the graph is zoomed and we want the control points to be allowed to go outside of the drawing area.
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.
It's not removed, if I've done that right. It is moved after the calls to
splineCurve
orsplineCurveMonotone
.I also think it should be faster this way, because very few JavaScript compilers are able to remove or hoist this
needToCap
check (thus ASM jump) in thecapIfNecessary
function (called in the loop). It is also a lot more difficult to avoid/not execute/not compile the loop and call.capControlPoint
should be quite easily inlined by most recent compilers, and the loop can be completely ignored (and even not compiled at all for very recent compilers that do branch pruning). Not that it matters much for loops on < 100 items ^^,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.
Right, I missed that the
capControlPoint
was behind the setting.You are right that it will probably be a bit faster :)