├── MIT-LICENSE.txt
├── test.html
├── README.md
└── assets
└── js
└── jquery.spidergraph.js
/MIT-LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 Jason M. Striegel (@jmstriegel)
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
22 |
23 |
--------------------------------------------------------------------------------
/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Spidergraph Demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
25 | Spidergraph Demo
26 | View source for example usage
27 |
28 |
29 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | jQuery Spidergraph Plugin - Dynamic, interactive spidergraphs in HTML5
2 | ========================================================================
3 |
4 | jquery.spidergraph is a simple module that creates nice looking, interactive spidergraphs in HTML5, using the canvas element.
5 |
6 | What are spidergraphs good for?
7 | ---------------------------------
8 |
9 | - illustrating scaled quantitative data for several subjective attributes
10 | - overlaying multiple data measurements for attribute comparison
11 | - visualizing the intersection of several data measurements
12 |
13 |
14 | How do I use it?
15 | ----------------
16 |
17 | First make a div to contain your graph:
18 |
19 |
25 |
26 |
27 |
28 | Apply the spidergraph and tell it what the data fields are. The spidergraph and labels will be drawn to fill the specified div.
29 |
30 | $('#spidergraphcontainer').spidergraph({
31 | 'fields': ['a','b','c','d','e'],
32 | 'gridcolor': 'rgba(20,20,20,1)'
33 | });
34 |
35 |
36 | Add static layers to your data set. Opacity can be used to see through multiple layers.
37 |
38 | $('#spidergraphcontainer').spidergraph('addlayer', {
39 | 'strokecolor': 'rgba(230,204,0,0.8)',
40 | 'fillcolor': 'rgba(230,204,0,0.6)',
41 | 'data': [5, 4, 9, 8, 1]
42 | });
43 | $('#spidergraphcontainer').spidergraph('addlayer', {
44 | 'strokecolor': 'rgba(230,204,230,0.8)',
45 | 'fillcolor': 'rgba(230,204,230,0.6)',
46 | 'data': [5, 4, 9, 8, 1]
47 | });
48 |
49 | Add a dynamic layer that allows mouse and iPad touch input to control the graph.
50 |
51 |
52 | $('#spidergraphcontainer').spidergraph('setactivedata', {
53 | 'strokecolor': 'rgba(0,204,230,0.8)',
54 | 'fillcolor': 'rgba(0,204,230,0.6)',
55 | 'data': [5, 5, 5, 5, 5]
56 | });
57 |
58 |
59 | Respond to changes in user input on the active layer.
60 |
61 | $('#spidergraphcontainer').bind('spiderdatachange', function( ev, data ) {
62 | alert( 'first field value is ' + data[0] );
63 | });
64 |
65 |
66 | Reset all of the data layers in the spidergraph.
67 |
68 | $('#spidergraphcontainer').spidergraph('resetdata');
69 |
70 |
71 | If you wish to use a linear style layer (no curves), simply add attribute 'linear' with value true.
72 |
73 | $('#spidergraphcontainer').spidergraph('addlayer', {
74 | 'strokecolor': 'rgba(230,204,230,0.8)',
75 | 'fillcolor': 'rgba(230,204,230,0.6)',
76 | 'data': [5, 4, 9, 8, 1],
77 | 'linear': true
78 | });
79 |
80 |
81 |
82 | Can I see an example?
83 | -----------------------
84 |
85 | Yes you can. Right over here:
86 | http://jmstriegel.github.com/jquery.spidergraph/
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/assets/js/jquery.spidergraph.js:
--------------------------------------------------------------------------------
1 | (function($){
2 |
3 | var methods = {
4 |
5 | init: function( options ) {
6 |
7 | var settings = {
8 | 'fields': [ 'Field 1', 'Field 2', 'Field 3' ],
9 | 'gridcolor': 'rgba(0,0,0,0.4)',
10 | 'dotcolor': 'rgba(0,0,0,.6)',
11 | 'strokewidth': 4,
12 | 'handlewidth': 4,
13 | 'increments': 10,
14 | 'minrad': 10
15 | }
16 |
17 | return this.each( function() {
18 |
19 | if ( this.tagName.toUpperCase() != 'DIV' ) {
20 | return false;
21 | }
22 | if ( options ) {
23 | $.extend( settings, options );
24 | }
25 |
26 | var canvasfg;
27 | var canvasbg;
28 | var canvasfixed;
29 | var outercontainer;
30 | var container;
31 | var contextfg;
32 | var contextbg;
33 | var contextfixed;
34 | var cx;
35 | var cy;
36 | var radius;
37 | var minrad = settings['minrad'];
38 | var activedata = {};
39 | var fixeddata = [];
40 | var increments = settings['increments'];
41 | var stroke = settings['strokewidth'];
42 | var handle = settings['handlewidth'];
43 | var mousepressed = false;
44 | var activedrag = 0;
45 | var mouseinmove = false;
46 |
47 | outercontainer = $(this).get(0);
48 | container = $('').get(0);
49 | $(outercontainer).children().remove();
50 | $(outercontainer).append($(container));
51 |
52 | cx = Math.floor( ($(container).width() / 2) - (handle / 2) );
53 | cy = Math.floor( ($(container).height() / 2) - (handle / 2) );
54 | radius = $(container).width();
55 | if ( $(container).height() < $(container).width() ) {
56 | radius = $(container).height();
57 | }
58 | radius = Math.floor( radius / 2 - 50 );
59 |
60 | canvasfg = $('