saikuro_treemap 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ function init(json){
2
+ var tm = new $jit.TM.Squarified({
3
+ injectInto: 'infovis',
4
+ titleHeight: 15,
5
+ animate: false,
6
+ offset: 1,
7
+ Events: {
8
+ enable: true,
9
+ onClick: function(node) {
10
+ if(node) tm.enter(node);
11
+ },
12
+ onRightClick: function() {
13
+ tm.out();
14
+ }
15
+ },
16
+ duration: 1000,
17
+ Tips: {
18
+ enable: true,
19
+ offsetX: 20,
20
+ offsetY: 20,
21
+ onShow: function(tip, node, isLeaf, domElement) {
22
+ var html = "<b>Name:</b> " + node.id + "<br/>";
23
+ var data = node.data;
24
+ if(data.complexity) {
25
+ html += "<b>Complexity:</b> " + data.complexity + "<br/>";
26
+ }
27
+ if(data.lines) {
28
+ html += "<b>Lines:</b> " + data.lines + "<br/>";
29
+ }
30
+ tip.innerHTML = html;
31
+ }
32
+ },
33
+ onCreateLabel: function(domElement, node){
34
+ domElement.innerHTML = node.name;
35
+ var style = domElement.style;
36
+ style.display = '';
37
+ style.border = '1px solid transparent';
38
+ domElement.onmouseover = function() {
39
+ style.border = '1px solid #9FD4FF';
40
+ };
41
+ domElement.onmouseout = function() {
42
+ style.border = '1px solid transparent';
43
+ };
44
+ }
45
+ });
46
+ tm.loadJSON(json);
47
+ tm.refresh();
48
+ };
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
3
+ <head>
4
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
5
+ <meta content='en' http-equiv='Content-Language' />
6
+ <title>Saikuro Treemap</title>
7
+ <style>
8
+ <%= File.read(template('css/treemap.css')) %>
9
+ </style>
10
+ <script type="text/javascript">
11
+ <%= File.read(template('js/jit-min.js')) %>
12
+ <%= File.read(template('js/saikuro-render.js')) %>
13
+ </script>
14
+ </head>
15
+ <body>
16
+ <div id='content'>
17
+ <div id="detail"></div>
18
+ <div id="infovis"></div>
19
+ <script type="text/javascript">
20
+ init(<%= @ccn_node.to_json %>);
21
+ </script>
22
+ </div>
23
+ </body>
24
+ </html>
25
+
26
+
27
+
@@ -0,0 +1,96 @@
1
+ require 'test_helper'
2
+
3
+ class CCNNodeTest < Test::Unit::TestCase
4
+ include SaikuroTreemap
5
+
6
+ def test_to_json_for_single_node
7
+ assert_equal '{"name":"A","data":{},"id":"A","children":[]}', CCNNode.new('A').to_json
8
+ end
9
+
10
+ def test_to_json_for_node_with_children
11
+ root = CCNNode.new('A')
12
+ root.add_child CCNNode.new('A::B')
13
+ assert_equal '{"name":"A","data":{},"id":"A","children":[{"name":"B","data":{},"id":"A::B","children":[]}]}', root.to_json
14
+ end
15
+
16
+ def test_to_json_for_method_node
17
+ assert_equal '{"name":"abc","data":{},"id":"A#abc","children":[]}', CCNNode.new('A#abc').to_json
18
+ end
19
+
20
+ def test_to_json_for_root_node
21
+ assert_equal '{"name":"","data":{},"id":"","children":[]}', CCNNode.new('').to_json
22
+ end
23
+
24
+ def test_to_json_include_complicity_and_lines
25
+ node = CCNNode.new('A', 2, 30)
26
+ node_json = JSON.parse(node.to_json)
27
+ assert_equal 2, node_json['data']['complexity']
28
+ assert_equal 30, node_json['data']['lines']
29
+ assert_equal node.area, node_json['data']['$area']
30
+ assert_equal node.color, node_json['data']['$color']
31
+ end
32
+
33
+ def test_find_node_without_param_should_return_it_self
34
+ node = CCNNode.new('A::B::C')
35
+ assert_equal node, node.find_node()
36
+ end
37
+
38
+ def test_find_node_should_find_it_self_it_path_match
39
+ node = CCNNode.new('A::B::C')
40
+ assert_equal node, node.find_node('A', 'B', 'C')
41
+ assert_equal nil, node.find_node('A', 'B')
42
+ end
43
+
44
+ def test_find_node_should_find_matching_child_node
45
+ parent = CCNNode.new('A')
46
+ child = CCNNode.new('A::B::C')
47
+ parent.add_child child
48
+
49
+ assert_equal child, parent.find_node('A', 'B', 'C')
50
+ assert_equal nil, parent.find_node('A', 'B')
51
+ end
52
+
53
+ def test_create_nodes
54
+ node = CCNNode.new('A')
55
+ node.create_nodes('A', 'B', 'C', 'D')
56
+ assert_equal 'A::B', node.find_node('A', 'B').path
57
+ assert_equal 'A::B::C', node.find_node('A', 'B', 'C').path
58
+ assert_equal 'A::B::C::D', node.find_node('A', 'B', 'C', 'D').path
59
+ end
60
+
61
+ def test_node_should_be_red_when_code_is_ridiculous
62
+ assert_equal "#AE0000", CCNNode.new('A', 15).color
63
+ assert_equal "#AE0000", CCNNode.new('A', 10).color
64
+ end
65
+
66
+ def test_node_should_be_blue_when_code_should_be_noticed
67
+ assert_equal "#4545C2", CCNNode.new('A', 5).color
68
+ assert_equal "#4545C2", CCNNode.new('A', 9).color
69
+ end
70
+
71
+ def test_node_should_be_green_if_code_is_ok
72
+ assert_equal "#006500", CCNNode.new('A', 1).color
73
+ assert_equal "#006500", CCNNode.new('A', 4).color
74
+ end
75
+
76
+ def test_none_left_node_color_is_consistent_dark
77
+ parent = CCNNode.new('A', 10)
78
+ parent.add_child CCNNode.new('A::B::C')
79
+
80
+ assert_equal "#101010", parent.color
81
+ end
82
+
83
+ def test_area_is_same_with_lines_for_leaf_node
84
+ assert_equal 30, CCNNode.new('A', 10, 30).area
85
+ end
86
+
87
+ def test_area_is_sum_of_child_node_area_for_non_leaf_node
88
+ parent = CCNNode.new('A', 10, 10)
89
+ parent.add_child CCNNode.new('A::B::C', 10, 20)
90
+ parent.add_child CCNNode.new('A::B::C', 10, 30)
91
+
92
+ assert_equal 50, parent.area
93
+ end
94
+
95
+
96
+ end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ $: << File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'saikuro_treemap'
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saikuro_treemap
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - ThoughtWorks Studios
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-16 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: Saikuro
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: " Generate CCN Treemap based on saikuro analysis\n"
49
+ email: studios@thoughtworks.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - README.textile
56
+ files:
57
+ - .gitignore
58
+ - MIT-LICENSE.txt
59
+ - README.textile
60
+ - Rakefile
61
+ - lib/saikuro_treemap.rb
62
+ - lib/saikuro_treemap/ccn_node.rb
63
+ - lib/saikuro_treemap/parser.rb
64
+ - saikuro_treemap.gemspec
65
+ - templates/css/treemap.css
66
+ - templates/js/jit-min.js
67
+ - templates/js/jit.js
68
+ - templates/js/saikuro-render.js
69
+ - templates/saikuro.html.erb
70
+ - test/ccn_node_test.rb
71
+ - test/test_helper.rb
72
+ has_rdoc: true
73
+ homepage: http://github.com/ThoughtWorksStudios/saikuro_treemap
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project: saikuro_treemap
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Generate CCN Treemap based on saikuro analysis
106
+ test_files:
107
+ - test/test_helper.rb