121 lines
6.8 KiB
HTML
121 lines
6.8 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
|
<title>Timeline.js by Phyks</title>
|
|
|
|
<link rel="stylesheet" href="stylesheets/styles.css">
|
|
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
</head>
|
|
<body>
|
|
<div class="wrapper">
|
|
<header>
|
|
<h1>Timeline.js</h1>
|
|
<p>A lightweight javascript library to plot simple graphs.</p>
|
|
|
|
<p class="view"><a href="https://github.com/Phyks/timeline.js">View the Project on GitHub <small>Phyks/timeline.js</small></a></p>
|
|
|
|
|
|
<ul>
|
|
<li><a href="https://github.com/Phyks/timeline.js/zipball/master">Download <strong>ZIP File</strong></a></li>
|
|
<li><a href="https://github.com/Phyks/timeline.js/tarball/master">Download <strong>TAR Ball</strong></a></li>
|
|
<li><a href="https://github.com/Phyks/timeline.js">View On <strong>GitHub</strong></a></li>
|
|
</ul>
|
|
</header>
|
|
<section>
|
|
<h1>
|
|
<a name="timelinejs" class="anchor" href="#timelinejs"><span class="octicon octicon-link"></span></a>Timeline.js</h1>
|
|
|
|
<p>Timeline.js is a lightweight JS library to plot graphs using SVG. As it uses SVG, you can add event listeners on the plotted graph very easily.</p>
|
|
|
|
<p>I coded it because I couldn't find any basic JS library to do this, without any external dependencies and extra features. Timeline.js is only 13k once minified, and can be reduced under 10k thanks to obfuscation. Better results may be obtained with a little refactor, but that's enough for me. Plus it can be very easily customised to fit your needs.</p>
|
|
|
|
<h2>
|
|
<a name="live-demos" class="anchor" href="#live-demos"><span class="octicon octicon-link"></span></a>Live demos</h2>
|
|
|
|
<ul>
|
|
<li><a href="http://phyks.github.io/timeline.js/examples/index.html">Single graph example</a></li>
|
|
<li><a href="http://phyks.github.io/timeline.js/examples/index2.html">Multi graph example</a></li>
|
|
<li><a href="http://phyks.github.io/timeline.js/examples/index3.html">Rounded graph example</a></li>
|
|
<li><a href="http://phyks.github.io/timeline.js/examples/index4.html">Dashed graph example</a></li>
|
|
<li><a href="http://phyks.github.io/timeline.js/examples/index5.html">Line only graph example</a></li>
|
|
<li><a href="http://phyks.github.io/timeline.js/examples/index6.html">Graph with legend example</a></li>
|
|
<li><a href="http://phyks.github.io/timeline.js/examples/index7.html">Interactivity with points example</a></li>
|
|
</ul><h2>
|
|
<a name="usage" class="anchor" href="#usage"><span class="octicon octicon-link"></span></a>Usage</h2>
|
|
|
|
<p>(See examples for more info. For live examples, see <a href="http://phyks.github.io/timeline.js/">http://phyks.github.io/timeline.js/</a>)</p>
|
|
|
|
<p>First, you must include the <code>timeline.js</code> or <code>timeline.min.js</code> script.</p>
|
|
|
|
<p>Then, you need to init the SVG drawing, thanks to <code>SVG.init({'id': 'holder', 'height': '100%', 'width': '100%', 'grid': 'both', 'x_axis': true, 'rounded': false, 'x_callback': false});</code>. The arguments are all optional and are:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<code>id</code> : the id of the parent element that will contain the SVG</li>
|
|
<li>
|
|
<code>width</code> / <code>height</code> : width and height of the created SVG</li>
|
|
<li>
|
|
<code>grid</code> : none / small / big / both to choose which type of grid you want</li>
|
|
<li>
|
|
<code>x_axis</code> : true / false to show / hide the x axis</li>
|
|
<li>
|
|
<code>line</code> : none / line / dashed to choose line type. You can edit the dasharray by replacing <code>SVG.dash_style</code> value</li>
|
|
<li>
|
|
<code>fill</code> : true / false to fill the area below the graph or not</li>
|
|
<li>
|
|
<code>rounded</code> : true / false to use splines to smoothen the graph or not</li>
|
|
<li>
|
|
<code>x_callback</code> : callback function to call to get texts for the x legend. Not yet implemented</li>
|
|
</ul><p>Then, you can add as many graphs as you want, thanks to <code>SVG.addGraph(NAME, COLOR);</code> where COLOR must be a valid CSS color.
|
|
And you can add points thanks to <code>SVG.addPoints(GRAPH_NAME, POINTS);</code>. Points is an array of point objects, which are of the type <code>{'x': ABSCISSA, 'y': ORDINATE, 'label': LABEL}</code>. LABEL is the text to display in the infobox when the mouse is over the point. You can use '%x' and '%y' in labels and they will be automatically replaced by the coordinates. You can also use <code><sup></code> and <code><sub></code> HTML tags. You can add another (optional) element <code>click</code> which must be a ffunction to bind to onclick event on this point.</p>
|
|
|
|
<p><em>Note</em> : You don't have to sort the points inside a same list of points in a SVG.addGraph call. They will be sorted for you. But, if you call SVG.addPoints multiple times, you must sort the points yourself between each call. The script won't do it for you and it will result in weird graphs if you don't do it.</p>
|
|
|
|
<p>Finally, you can draw the SVG thanks to <code>SVG.draw();</code>.</p>
|
|
|
|
<h2>
|
|
<a name="other-functions" class="anchor" href="#other-functions"><span class="octicon octicon-link"></span></a>Other functions</h2>
|
|
|
|
<ul>
|
|
<li>
|
|
<code>SVG.clearGraph(GRAPH);</code> to delete the data for the graph GRAPH, or for all graphs + the graphs definition if GRAPH is not specified.</li>
|
|
<li>
|
|
<code>SVG.hasGraph(GRAPH);</code> to check if a graph with name GRAPH has already been defined or not.</li>
|
|
</ul><h2>
|
|
<a name="license" class="anchor" href="#license"><span class="octicon octicon-link"></span></a>License</h2>
|
|
|
|
<pre><code>* --------------------------------------------------------------------------------
|
|
* "THE NO-ALCOHOL BEER-WARE LICENSE" (Revision 42):
|
|
* Phyks (webmaster@phyks.me) wrote this file. As long as you retain this notice you
|
|
* can do whatever you want with this stuff (and you can also do whatever you want
|
|
* with this stuff without retaining it, but that's not cool...). If we meet some
|
|
* day, and you think this stuff is worth it, you can buy me a <del>beer</del> soda
|
|
* in return.
|
|
* Phyks
|
|
* ---------------------------------------------------------------------------------
|
|
</code></pre>
|
|
|
|
<h2>
|
|
<a name="known-bugs--todo" class="anchor" href="#known-bugs--todo"><span class="octicon octicon-link"></span></a>Known bugs / TODO</h2>
|
|
|
|
<p>Feel free to contribute !</p>
|
|
|
|
<ul>
|
|
<li>Y axis is not implemented, but could be implemented easily</li>
|
|
</ul>
|
|
</section>
|
|
<footer>
|
|
<p>This project is maintained by <a href="https://github.com/Phyks">Phyks</a></p>
|
|
<p><small>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
|
|
</footer>
|
|
</div>
|
|
<script src="javascripts/scale.fix.js"></script>
|
|
|
|
</body>
|
|
</html> |