Skip to content
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

enhancing Curved Lines support: differentiating between "real" datapoints and interpolated spline points #123

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions examples/curved-lines.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
grid: { hoverable: true }, //important! flot.tooltip requires this
tooltip: {
show: true,
content: "%s | x: %x; y: %y"
content: "%s | x: %x; y: %y",
},
yaxes: [{ min:10, max: 90}, {position: 'right'}]
};
Expand All @@ -45,14 +45,58 @@
points: { show: true }
}
], options);


var d1 = []; var last = 0;
for (var i = 0; i <= 40; i += (2 + parseInt(Math.random() * 5))) {
last = last + ((Math.random() * 3) - 1.5)
d1.push([i, parseInt(last)]);
}
//flot options
var options = {
grid: { hoverable: true },
tooltip: {
show: true,
// content: "%x, %y",
content: "%s | x: %x; y: %y",
showRealVsInterpolatedData: true,
},
series: {
curvedLines: {
active: true,
nrSplinePoints: 20 // <- control nr of helper points
} // between two poins
}
};
//plotting
$.plot($("#flotContainer2"),[
{ //curved line
data: d1,
lines: {show: true, lineWidth: 3},
curvedLines: {apply: true } // <- curve line
}, { //original data points
data: d1,
points: {show: true}
}
], options);

});
</script>




</script>
</head>

<body>

<h4>CurvedLines Example</h4>
<div id="flotContainer" class="chart-style"></div>

<h4>CurvedLines: random data points, displaying Interpolated vs. Real Data Points</h4>
<div id="flotContainer2" class="chart-style"></div>


<a href="index.html">Return to examples list</a>

</body>
Expand Down
20 changes: 18 additions & 2 deletions js/jquery.flot.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* authors: Krzysztof Urbas @krzysu [myviews.pl],Evan Steinkerchner @Roundaround
* website: https://github.com/krzysu/flot.tooltip
*
* build on 2015-06-12
* build on 2015-07-16
* released under MIT License, 2012
*/
(function ($) {
Expand Down Expand Up @@ -37,7 +37,8 @@
defaultTheme: true,
snap: true,
lines: false,

showRealVsInterpolatedData: false, // used with curvedLines plugin

// callbacks
onHover: function (flotItem, $tooltipEl) {},

Expand Down Expand Up @@ -351,6 +352,21 @@
else if (typeof item.series.curvedLines !== "undefined") {
x = item.datapoint[0];
y = item.datapoint[1];

// differentiate between real and interpolated data points
if(this.tooltipOptions.showRealVsInterpolatedData){
pointStr = x +'-' +y;
var pointsArr = [];
for (var i=0; i<item.series.data.length; i++ ) {
pointsArr.push(item.series.data[i][0] + '-' + item.series.data[i][1]);
}
if (pointsArr.indexOf(pointStr)<0) {
content = content + " (Interpolated Point)";
}
else {
content = content + " (Real Data Point)";
}
}
}

else if (typeof item.series.lines !== "undefined" && item.series.lines.steps) {
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.flot.tooltip.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading