/* The MIT License Copyright (c) 2011 by Michael Zinsmaier and nergal.dev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* ____________________________________________________ what it is: ____________________________________________________ curvedLines is a plugin for flot, that tries to display lines in a smoother way. The plugin is based on nergal.dev's work https://code.google.com/p/flot/issues/detail?id=226 and further extended with a mode that forces the min/max points of the curves to be on the points. Both modes are achieved through adding of more data points => 1) with large data sets you may get trouble => 2) if you want to display the points too, you have to plot them as 2nd data series over the lines This is version 0.1 of curvedLines so it will probably not work in every case. However the basic form of use descirbed next works (: Feel free to further improve the code ____________________________________________________ how to use it: ____________________________________________________ var d1 = [[5,5],[7,3],[9,12]]; var options = { series: { curvedLines: { active: true }}}; $.plot($("#placeholder"), [{data = d1, curvedLines: { show: true}}], options); _____________________________________________________ options: _____________________________________________________ fill: bool true => lines get filled fillColor: null or the color that should be used for filling active: bool true => plugin can be used show: bool true => series will be drawn as curved line fit: bool true => forces the max,mins of the curve to be on the datapoints lineWidth: int width of the line curvePointFactor int defines how many "virtual" points are used per "real" data point to emulate the curvedLines fitPointDist: int defines the x axis distance of the additional two points that are used to enforce the min max condition. (you will get curvePointFactor * 3 * |datapoints| "virtual" points if fit is true) */ /* * v0.1 initial commit * v0.15 negative values should work now (outcommented a negative -> 0 hook hope it does no harm) * v0.2 added fill option (thanks to monemihir) and multi axis support (thanks to soewono effendi) * * */ (function(t){t.plot.plugins.push({init:function(w){function x(r,n){for(var l,u=r.getData(),v=r.getPlotOffset(),s=0;sk[d]?h=o:i=o}o=g[h]-g[i];if(0==o){g=null;break a}var p=(g[h]-k[d])/o,q=(k[d]-g[i])/o;c[d]=p*e[i]+q*e[h]+((p*p*p-p)*j[i]+(q*q*q-q)*j[h])*o*o/6;f.push(k[d]);f.push(c[d])}g=f}m=n;e=axisx;b=axisy;l=l.curvedLines.fill; d=j=null;a=0;m.beginPath();for(k=2;k=i&&f>b.max){if(i>b.max)continue;c=(b.max-f)/(i-f)*(h-c)+c;f=b.max}else if(i>=f&&i>b.max){if(f>b.max)continue;h=(b.max-f)/(i-f)*(h-c)+c;i=b.max}if(c<=h&&c=h&&c>e.max){if(h>e.max)continue;f=(e.max-c)/(h-c)*(i-f)+f;c=e.max}else if(h>=c&&h>e.max){if(c>e.max)continue;i=(e.max-c)/(h-c)*(i-f)+f;h=e.max}(c!=j||f!=d)&&m.lineTo(e.p2c(c),b.p2c(f));null==j&&(a=i);j=h;d=i;m.lineTo(e.p2c(h),b.p2c(i))}l&&(m.lineTo(e.p2c(e.max),b.p2c(b.min)),m.lineTo(e.p2c(e.min),b.p2c(b.min)),m.lineTo(e.p2c(e.min),b.p2c(a)),m.fill());m.stroke();n.restore()}}w.hooks.processOptions.push(function(r,n){n.series.curvedLines.active&& r.hooks.draw.push(x)})},options:{series:{curvedLines:{active:!1,show:!1,fit:!1,fill:!1,fillColor:null,lineWidth:2,curvePointFactor:20,fitPointDist:1.0E-4}}},name:"curvedLines",version:"0.2"})})(jQuery);