ServState 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -4
  3. data/.travis.yml +13 -0
  4. data/README.md +9 -0
  5. data/ServState.gemspec +5 -2
  6. data/bin/servstate +1 -55
  7. data/lib/ServState/application.rb +118 -0
  8. data/lib/ServState/cpu_usage.rb +36 -0
  9. data/lib/ServState/log_manager.rb +47 -0
  10. data/lib/ServState/network_usage.rb +48 -0
  11. data/lib/ServState/public/css/rickshaw.min.css +1 -0
  12. data/lib/ServState/public/css/style.css +28 -0
  13. data/lib/ServState/public/js/charts.js +89 -0
  14. data/lib/ServState/public/js/d3.layout.min.js +1 -0
  15. data/lib/ServState/public/js/d3.min.js +2 -0
  16. data/lib/ServState/public/js/{app.js → dashboard.js} +7 -19
  17. data/lib/ServState/public/js/jquery.js +6 -0
  18. data/lib/ServState/public/js/notification.js +11 -0
  19. data/lib/ServState/public/js/rickshaw.min.js +3 -0
  20. data/lib/ServState/rotator.rb +17 -0
  21. data/lib/ServState/services_manager.rb +42 -0
  22. data/lib/ServState/usage_manager.rb +121 -0
  23. data/lib/ServState/version.rb +1 -1
  24. data/lib/ServState/views/charts.erb +74 -0
  25. data/lib/ServState/views/error.erb +43 -0
  26. data/lib/ServState/views/index.erb +66 -48
  27. data/lib/ServState/views/login.erb +14 -15
  28. data/lib/ServState.rb +43 -2
  29. data/spec/charts_json_spec.rb +12 -0
  30. data/spec/dashboard_spec.rb +33 -0
  31. data/spec/spec_helper.rb +11 -0
  32. metadata +87 -27
  33. data/.rvmrc +0 -1
  34. data/lib/ServState/info.rb +0 -122
  35. data/lib/ServState/main.rb +0 -61
  36. data/lib/ServState/views/css/base.scss +0 -2
  37. data/lib/ServState/views/css/custom.scss +0 -20
  38. data/lib/ServState/views/css/style.scss +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8094d6f2af00a90fddbe2526287dbddbd1ec7069
4
- data.tar.gz: f959f046a02048c93d73907c8eef2a9d70cc1e56
3
+ metadata.gz: b57d9d6c58f0b65ee3a73b0a41f1201639bfc35d
4
+ data.tar.gz: 5c7b505b6b9aa7b7a2651bbe60b70846d2c76a83
5
5
  SHA512:
6
- metadata.gz: b2c6665fcf7529da5af4e07232fe40d0d8881061dafe89e47a35f58d0bbf0abc709b49b702a5b82a8fb214c3ab707fb25c31aa478955a2f6552edfc6825fe08e
7
- data.tar.gz: 710eeca9e4c2a74aec668421331b959ca9d127653b47982f778fa6616df8cbdadfb4638696ad046acb2002d6aa10eb79249cefb2f86b63549bb812270dea994c
6
+ metadata.gz: a69d0fb5df453d7573212b1e0b4c48ab8b063c76f37fdbf39c9a95a5c5add7fb25e0f5ab2594341e9277d92e629a20d94a3ce0de4b98af7f7232a71d62181f9b
7
+ data.tar.gz: 4af6b3057a5298aab1a927553f205cd9bb1a800ed6bdd0c8bc6f38435907ff8b9d56fe740737a6493351d935eaf057e2ae8cc300b0ce73bbb63d2d52e6413c70
data/.gitignore CHANGED
@@ -3,6 +3,8 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .rspec
7
+ .rvmrc
6
8
  Gemfile.lock
7
9
  InstalledFiles
8
10
  _yardoc
@@ -15,7 +17,5 @@ spec/reports
15
17
  test/tmp
16
18
  test/version_tmp
17
19
  tmp
18
- .rvmrc
19
- ServState/lib/SerState/.sass-cache
20
- bin/.sass-cache
21
- .sass-cache
20
+
21
+
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ bundler_args: --without dev
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - rbx-2.2
7
+ - jruby-19mode
8
+
9
+ branches:
10
+ only:
11
+ - master
12
+
13
+ script: bundle exec rspec
data/README.md CHANGED
@@ -29,6 +29,15 @@ Show help:
29
29
 
30
30
  $ servstate -h
31
31
 
32
+ Also you can write code like this:
33
+ ```ruby
34
+ require 'ServState'
35
+
36
+ ServState.run do
37
+ port 8081
38
+ password 'qwerty'
39
+ end
40
+ ```
32
41
 
33
42
  ## Contributing
34
43
 
data/ServState.gemspec CHANGED
@@ -21,9 +21,12 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "sinatra", "~>1.4"
23
23
  spec.add_dependency "rack", "~>1.5"
24
- spec.add_dependency "sass", "~>3.2"
25
-
24
+ spec.add_dependency "slop", "~> 3.5.0"
25
+
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
27
27
  spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "capybara"
30
+ spec.add_development_dependency "capybara-webkit"
28
31
 
29
32
  end
data/bin/servstate CHANGED
@@ -1,57 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require "rack"
3
- APP_ROOT = File.expand_path(File.dirname(__FILE__)) #пригодится
4
-
5
- pass=false
6
- port=8080
7
-
8
- if ARGV.size==1 and (ARGV[0]=='-h' or ARGV[0]=='--help')
9
- puts "ServState usage\nDefault port: 8080\nDefault password: no password\nSet port: -port XXXX\nSet password: -pass *****"
10
- exit
11
- end
12
-
13
- if ARGV.size.odd?
14
- puts "Something wrong with params"
15
- exit
16
- end
17
-
18
- ARGV.each_slice(2) { |slice|
19
- case slice[0]
20
- when '-port'
21
- port=slice[1].to_i
22
- when '-pass'
23
- pass=slice[1]
24
- end
25
- }
26
-
27
- APP_OPTIONS={
28
- password: pass,
29
- port: port
30
- }
31
-
32
2
  require_relative "./../lib/ServState.rb"
33
-
34
- #добавить настройки порта и прочее
35
-
36
- Thread.new{ # thread for calculate cpu and network load and other long time operations
37
- while true
38
- Info.update
39
- sleep(5)
40
- end
41
- }
42
-
43
-
44
- puts " ____ ____ _ _ "
45
- puts "/ ___| ___ _ ____ __/ ___|| |_ __ _| |_ ___ "
46
- puts "\\___ \\ / _ \\ '__\\ \\ / /\\___ \\| __/ _` | __/ _ \\"
47
- puts " ___) | __/ | \\ V / ___) | || (_| | || __/"
48
- puts "|____/ \\___|_| \\_/ |____/ \\__\\__,_|\\__\\___|"
49
- puts "\nPORT: #{port}"
50
- if(pass)
51
- puts "PASSWORD: #{pass}"
52
- else
53
- puts "WITHOUT PASSWORD"
54
- end
55
- puts "\n"*3
56
-
57
- Rack::Handler::WEBrick.run(ServStateApp,:Port => APP_OPTIONS[:port])
3
+ ServState::run!
@@ -0,0 +1,118 @@
1
+
2
+ require 'sinatra/base'
3
+ require 'json'
4
+ require 'date'
5
+ require 'digest/md5'
6
+
7
+ require_relative 'cpu_usage'
8
+ require_relative 'network_usage'
9
+ require_relative 'usage_manager'
10
+ require_relative 'rotator'
11
+ require_relative 'log_manager'
12
+ require_relative 'services_manager'
13
+
14
+ module ServState
15
+ class Application < Sinatra::Base
16
+
17
+ configure do
18
+ ServicesManager.start
19
+ enable :sessions
20
+ set :environment, :test
21
+ set :run, true
22
+ set :show_exceptions, false
23
+ set :raise_errors, false
24
+ set :hostname, ServicesManager.hostname
25
+ end
26
+
27
+ before /^((?!\/login))/ do
28
+ check_auth
29
+ end
30
+
31
+ helpers do
32
+ def check_auth
33
+ if settings.password
34
+ unless Digest::MD5.hexdigest(settings.password) == session[:login]
35
+ redirect '/login'
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ get '/' do
42
+ @name = settings.hostname
43
+ erb :index
44
+ end
45
+
46
+ get '/renew.json' do
47
+ content_type :json
48
+ ServicesManager.json_for_dashboard
49
+ end
50
+
51
+ get '/charts/:type' do
52
+ @name = settings.hostname
53
+ @type = case params[:type]
54
+ when '1day' then "1 day charts"
55
+ when '10min' then "10 min charts"
56
+ else redirect '404'
57
+ end
58
+ erb :charts
59
+ end
60
+
61
+ get '/charts/:type/renew.json' do
62
+ content_type :json
63
+ ServicesManager.json_for_charts(params[:type])
64
+ end
65
+
66
+ get '/login' do
67
+ session[:login] = nil;
68
+ @name = settings.hostname
69
+ erb :login
70
+ end
71
+
72
+ post '/login' do
73
+ unless(settings.password)
74
+ redirect '/'
75
+ end
76
+ if(params[:pass]) == settings.password
77
+ session[:login] = Digest::MD5.hexdigest(settings.password)
78
+ redirect '/'
79
+ else
80
+ redirect '/login'
81
+ end
82
+ end
83
+
84
+ error do
85
+ @name = settings.hostname
86
+ @header = 'Error!'
87
+ @text = "Sorry, but something went wrong."
88
+ erb :error
89
+ end
90
+
91
+ not_found do
92
+ @name = settings.hostname
93
+ @header = 'Not found!'
94
+ @text = "That page doesn't exist"
95
+ erb :error
96
+ end
97
+
98
+
99
+ class << self
100
+
101
+ def set_settings &block
102
+ class_eval(&block)
103
+ end
104
+
105
+ private
106
+
107
+ def password(value)
108
+ set :password, value
109
+ end
110
+
111
+ def port(value)
112
+ set :port, value
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,36 @@
1
+ module ServState
2
+ class CpuUsage
3
+
4
+ attr_reader :usage
5
+
6
+ def update
7
+ usage, total = proc_stat_values
8
+
9
+ usage_diff = usage - @old[:cpu_usage]
10
+ total_diff = total - @old[:cpu_usage_total]
11
+
12
+ @old[:cpu_usage] = usage
13
+ @old[:cpu_usage_total] = total
14
+
15
+ @usage = ((usage_diff / total_diff.to_f) * 100).to_i
16
+ end
17
+
18
+ private
19
+
20
+ def initialize
21
+ @old = Hash.new
22
+ @old[:cpu_usage], @old[:cpu_usage_total] = proc_stat_values
23
+ @usage = 0
24
+ sleep 1
25
+ end
26
+
27
+ def proc_stat_values
28
+ stat_line = IO.readlines('/proc/stat').grep(/^cpu /).first.split
29
+ stat_values = stat_line.map{ |element| element.to_i }
30
+ total = stat_values.inject(:+)
31
+ usage = stat_values[1..3].inject(:+)
32
+ [usage, total]
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,47 @@
1
+ module ServState
2
+ class LogManager
3
+
4
+ class << self
5
+
6
+ def start
7
+ @@min = Rotator.new(120) # with 5 sec delay => 10 minutes
8
+ @@day = Rotator.new(150)
9
+ @@counter = 0
10
+ end
11
+
12
+ def update(params)
13
+ @@counter += 1
14
+ @@min.append(params)
15
+ if @@counter % @@min.size == 0
16
+ @@day.append(normalize(@@min.data))
17
+ end
18
+ end
19
+
20
+ def data(type)
21
+ case type
22
+ when '1day' then get_hash(@@day)
23
+ when '10min' then get_hash(@@min)
24
+ end
25
+
26
+ end
27
+
28
+ private
29
+ def get_hash(object)
30
+ { cpu: object.data.each_with_index.map{ |x, i| { x: i, y: x[0] } },
31
+ ram: object.data.each_with_index.map{ |x, i| { x: i, y: x[1] } },
32
+ down: object.data.each_with_index.map{ |x, i| { x: i, y: x[2] } },
33
+ up: object.data.each_with_index.map{ |x, i| { x: i, y: x[3] } }
34
+ }
35
+ end
36
+ def normalize(data)
37
+ result = Hash.new
38
+ p data
39
+ result[:cpu] = data.inject(0){ |sum, n| sum + n[0] } / data.size
40
+ result[:ram] = data.inject(0){ |sum, n| sum + n[1] } / data.size
41
+ result[:down] = data.inject(0){ |sum, n| sum + n[2] } / data.size
42
+ result[:up] = data.inject(0){ |sum, n| sum + n[3] } / data.size
43
+ result
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,48 @@
1
+ module ServState
2
+ class NetworkUsage
3
+
4
+ BYTES_IN_MB = 1048576
5
+
6
+ attr_reader :speeds
7
+
8
+ def update
9
+ time_diff = Time.new - @old_time
10
+ @old_time = Time.new
11
+
12
+ data = net_dev_data
13
+
14
+ data.each do |interface, values|
15
+ down = values[0] - @old_traffic[interface][0]
16
+ up = values[1] - @old_traffic[interface][1]
17
+
18
+ down_speed = (down / BYTES_IN_MB / time_diff).round(2)
19
+ up_speed = (up / BYTES_IN_MB / time_diff).round(2)
20
+
21
+ @speeds[interface] = [down_speed, up_speed]
22
+ end
23
+
24
+ @old_traffic = data
25
+ end
26
+
27
+
28
+ private
29
+ def initialize
30
+ @speeds = Hash.new
31
+ @old_time = Time.new
32
+ @old_traffic = net_dev_data
33
+ end
34
+
35
+ # returns hash with hash[:interface] = [total download bytes, total upload bytes]
36
+ def net_dev_data
37
+ lines = IO.readlines('/proc/net/dev').grep(/:/)
38
+ data = Hash.new
39
+
40
+ lines.each do |line|
41
+ splited = line.split
42
+ data[splited[0].chop.to_sym] = [splited[1].to_i, splited[9].to_i]
43
+ end
44
+
45
+ data
46
+ end
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ .rickshaw_graph .detail{pointer-events:none;position:absolute;top:0;z-index:2;background:rgba(0,0,0,.1);bottom:0;width:1px;transition:opacity .25s linear;-moz-transition:opacity .25s linear;-o-transition:opacity .25s linear;-webkit-transition:opacity .25s linear}.rickshaw_graph .detail.inactive{opacity:0}.rickshaw_graph .detail .item.active{opacity:1}.rickshaw_graph .detail .x_label{font-family:Arial,sans-serif;border-radius:3px;padding:6px;opacity:.5;border:1px solid #e0e0e0;font-size:12px;position:absolute;background:#fff;white-space:nowrap}.rickshaw_graph .detail .x_label.left{left:0}.rickshaw_graph .detail .x_label.right{right:0}.rickshaw_graph .detail .item{position:absolute;z-index:2;border-radius:3px;padding:.25em;font-size:12px;font-family:Arial,sans-serif;opacity:0;background:rgba(0,0,0,.4);color:#fff;border:1px solid rgba(0,0,0,.4);margin-left:1em;margin-right:1em;margin-top:-1em;white-space:nowrap}.rickshaw_graph .detail .item.left{left:0}.rickshaw_graph .detail .item.right{right:0}.rickshaw_graph .detail .item.active{opacity:1;background:rgba(0,0,0,.8)}.rickshaw_graph .detail .item:after{position:absolute;display:block;width:0;height:0;content:"";border:5px solid transparent}.rickshaw_graph .detail .item.left:after{top:1em;left:-5px;margin-top:-5px;border-right-color:rgba(0,0,0,.8);border-left-width:0}.rickshaw_graph .detail .item.right:after{top:1em;right:-5px;margin-top:-5px;border-left-color:rgba(0,0,0,.8);border-right-width:0}.rickshaw_graph .detail .dot{width:4px;height:4px;margin-left:-2px;margin-top:-2px;border-radius:5px;position:absolute;box-shadow:0 0 2px rgba(0,0,0,.6);background:#fff;border-width:2px;border-style:solid;display:none;background-clip:padding-box}.rickshaw_graph .detail .dot.active{display:block}.rickshaw_graph{position:relative}.rickshaw_graph svg{display:block;overflow:hidden}.rickshaw_graph .x_tick{position:absolute;top:0;bottom:0;width:0;border-left:1px dotted rgba(0,0,0,.2);pointer-events:none}.rickshaw_graph .x_tick .title{position:absolute;font-size:12px;font-family:Arial,sans-serif;opacity:.5;white-space:nowrap;margin-left:3px;bottom:1px}.rickshaw_annotation_timeline{height:1px;border-top:1px solid #e0e0e0;margin-top:10px;position:relative}.rickshaw_annotation_timeline .annotation{position:absolute;height:6px;width:6px;margin-left:-2px;top:-3px;border-radius:5px;background-color:rgba(0,0,0,.25)}.rickshaw_graph .annotation_line{position:absolute;top:0;bottom:-6px;width:0;border-left:2px solid rgba(0,0,0,.3);display:none}.rickshaw_graph .annotation_line.active{display:block}.rickshaw_graph .annotation_range{background:rgba(0,0,0,.1);display:none;position:absolute;top:0;bottom:-6px}.rickshaw_graph .annotation_range.active{display:block}.rickshaw_graph .annotation_range.active.offscreen{display:none}.rickshaw_annotation_timeline .annotation .content{background:#fff;color:#000;opacity:.9;padding:5px;box-shadow:0 0 2px rgba(0,0,0,.8);border-radius:3px;position:relative;z-index:20;font-size:12px;padding:6px 8px 8px;top:18px;left:-11px;width:160px;display:none;cursor:pointer}.rickshaw_annotation_timeline .annotation .content:before{content:"\25b2";position:absolute;top:-11px;color:#fff;text-shadow:0 -1px 1px rgba(0,0,0,.8)}.rickshaw_annotation_timeline .annotation.active,.rickshaw_annotation_timeline .annotation:hover{background-color:rgba(0,0,0,.8);cursor:none}.rickshaw_annotation_timeline .annotation .content:hover{z-index:50}.rickshaw_annotation_timeline .annotation.active .content{display:block}.rickshaw_annotation_timeline .annotation:hover .content{display:block;z-index:50}.rickshaw_graph .y_axis,.rickshaw_graph .x_axis_d3{fill:none}.rickshaw_graph .y_ticks .tick,.rickshaw_graph .x_ticks_d3 .tick{stroke:rgba(0,0,0,.16);stroke-width:2px;shape-rendering:crisp-edges;pointer-events:none}.rickshaw_graph .y_grid .tick,.rickshaw_graph .x_grid_d3 .tick{z-index:-1;stroke:rgba(0,0,0,.2);stroke-width:1px;stroke-dasharray:1 1}.rickshaw_graph .y_grid .tick[data-y-value="0"]{stroke-dasharray:1 0}.rickshaw_graph .y_grid path,.rickshaw_graph .x_grid_d3 path{fill:none;stroke:none}.rickshaw_graph .y_ticks path,.rickshaw_graph .x_ticks_d3 path{fill:none;stroke:gray}.rickshaw_graph .y_ticks text,.rickshaw_graph .x_ticks_d3 text{opacity:.5;font-size:12px;pointer-events:none}.rickshaw_graph .x_tick.glow .title,.rickshaw_graph .y_ticks.glow text{fill:#000;color:#000;text-shadow:-1px 1px 0 rgba(255,255,255,.1),1px -1px 0 rgba(255,255,255,.1),1px 1px 0 rgba(255,255,255,.1),0 1px 0 rgba(255,255,255,.1),0 -1px 0 rgba(255,255,255,.1),1px 0 0 rgba(255,255,255,.1),-1px 0 0 rgba(255,255,255,.1),-1px -1px 0 rgba(255,255,255,.1)}.rickshaw_graph .x_tick.inverse .title,.rickshaw_graph .y_ticks.inverse text{fill:#fff;color:#fff;text-shadow:-1px 1px 0 rgba(0,0,0,.8),1px -1px 0 rgba(0,0,0,.8),1px 1px 0 rgba(0,0,0,.8),0 1px 0 rgba(0,0,0,.8),0 -1px 0 rgba(0,0,0,.8),1px 0 0 rgba(0,0,0,.8),-1px 0 0 rgba(0,0,0,.8),-1px -1px 0 rgba(0,0,0,.8)}.rickshaw_legend{font-family:Arial;font-size:12px;color:#fff;background:#404040;display:inline-block;padding:12px 5px;border-radius:2px;position:relative}.rickshaw_legend:hover{z-index:10}.rickshaw_legend .swatch{width:10px;height:10px;border:1px solid rgba(0,0,0,.2)}.rickshaw_legend .line{clear:both;line-height:140%;padding-right:15px}.rickshaw_legend .line .swatch{display:inline-block;margin-right:3px;border-radius:2px}.rickshaw_legend .label{margin:0;white-space:nowrap;display:inline;font-size:inherit;background-color:transparent;color:inherit;font-weight:400;line-height:normal;padding:0;text-shadow:none}.rickshaw_legend .action:hover{opacity:.6}.rickshaw_legend .action{margin-right:.2em;font-size:10px;opacity:.2;cursor:pointer;font-size:14px}.rickshaw_legend .line.disabled{opacity:.4}.rickshaw_legend ul{list-style-type:none;margin:0;padding:0;margin:2px;cursor:pointer}.rickshaw_legend li{padding:0 0 0 2px;min-width:80px;white-space:nowrap}.rickshaw_legend li:hover{background:rgba(255,255,255,.08);border-radius:3px}.rickshaw_legend li:active{background:rgba(255,255,255,.2);border-radius:3px}
@@ -0,0 +1,28 @@
1
+ #wrapper {
2
+ min-width: 480px;
3
+ max-width: 960px;
4
+ margin: 0 auto;
5
+ padding: 10px;
6
+ }
7
+ .uk-width-medium-1-2 {
8
+ padding: 10px;
9
+ }
10
+ .uk-width-medium-1-4 {
11
+ padding: 10px;
12
+ }
13
+ .uk-panel {
14
+ margin: 5px;
15
+ background-color: #F0F0F0;
16
+ }
17
+ .uk-panel .uk-panel {
18
+ background-color: #EBEBEB;
19
+ }
20
+ .login {
21
+ width: 200px;
22
+ height: 100px;
23
+ margin: 0 auto;
24
+ }
25
+
26
+ .chart {
27
+ height: 200px;
28
+ }
@@ -0,0 +1,89 @@
1
+ $(document).ready(function() {
2
+ renew();
3
+
4
+ setInterval(renew,5000);
5
+ });
6
+
7
+ function renew(){
8
+ $.getJSON($(location).attr('href')+"/renew.json",function(data){
9
+ console.log(data);
10
+
11
+ $('#cpu_chart').text('');
12
+ $('#ram_chart').text('');
13
+ $('#down_chart').text('');
14
+ $('#up_chart').text('');
15
+
16
+ var cpu_graph = new Rickshaw.Graph( {
17
+ element: document.querySelector("#cpu_chart"),
18
+ renderer: 'line',
19
+ height: 200,
20
+ max: 102,
21
+ min: -2,
22
+ series: [{
23
+ data: data.cpu,
24
+ color: 'steelblue'
25
+ }]
26
+ });
27
+ var down_graph = new Rickshaw.Graph( {
28
+ element: document.querySelector("#down_chart"),
29
+ renderer: 'line',
30
+ height: 200,
31
+ series: [{
32
+ data: data.down,
33
+ color: 'steelblue'
34
+ }]
35
+ });
36
+ var up_graph = new Rickshaw.Graph( {
37
+ element: document.querySelector("#up_chart"),
38
+ renderer: 'line',
39
+ height: 200,
40
+ series: [{
41
+ data: data.up,
42
+ color: 'steelblue'
43
+ }]
44
+ });
45
+
46
+ var ram_graph = new Rickshaw.Graph( {
47
+ element: document.querySelector("#ram_chart"),
48
+ renderer: 'line',
49
+ height: 200,
50
+ max: 102,
51
+ min: -2,
52
+ series: [{
53
+ data: data.ram,
54
+ color: 'steelblue'
55
+ }]
56
+ });
57
+
58
+ var yAxisCpu = new Rickshaw.Graph.Axis.Y({
59
+ graph: cpu_graph
60
+ });
61
+
62
+ var yAxisDown = new Rickshaw.Graph.Axis.Y({
63
+ graph: down_graph
64
+ });
65
+ var yAxisUp = new Rickshaw.Graph.Axis.Y({
66
+ graph: up_graph
67
+ });
68
+
69
+ var yAxisRam = new Rickshaw.Graph.Axis.Y({
70
+ graph: ram_graph
71
+ });
72
+
73
+
74
+
75
+ cpu_graph.render();
76
+ ram_graph.render();
77
+ down_graph.render();
78
+ up_graph.render();
79
+ yAxisDown.render();
80
+ yAxisUp.render();
81
+ yAxisCpu.render();
82
+ yAxisRam.render();
83
+
84
+ removeNotify($('#notification'));
85
+ }).fail(function() {
86
+ createNotify('Connection lost!', $('#notification'));
87
+ });
88
+
89
+ }
@@ -0,0 +1 @@
1
+ (function(){function a(a){var b=a.source,d=a.target,e=c(b,d),f=[b];while(b!==e)b=b.parent,f.push(b);var g=f.length;while(d!==e)f.splice(g,0,d),d=d.parent;return f}function b(a){var b=[],c=a.parent;while(c!=null)b.push(a),a=c,c=c.parent;return b.push(a),b}function c(a,c){if(a===c)return a;var d=b(a),e=b(c),f=d.pop(),g=e.pop(),h=null;while(f===g)h=f,f=d.pop(),g=e.pop();return h}function g(a){a.fixed|=2}function h(a){a!==f&&(a.fixed&=1)}function i(){j(),f.fixed&=1,e=f=null}function j(){f.px+=d3.event.dx,f.py+=d3.event.dy,e.resume()}function k(a,b,c){var d=0,e=0;a.charge=0;if(!a.leaf){var f=a.nodes,g=f.length,h=-1,i;while(++h<g){i=f[h];if(i==null)continue;k(i,b,c),a.charge+=i.charge,d+=i.charge*i.cx,e+=i.charge*i.cy}}if(a.point){a.leaf||(a.point.x+=Math.random()-.5,a.point.y+=Math.random()-.5);var j=b*c[a.point.index];a.charge+=a.pointCharge=j,d+=j*a.point.x,e+=j*a.point.y}a.cx=d/a.charge,a.cy=e/a.charge}function l(a){return 20}function m(a){return 1}function o(a){return a.x}function p(a){return a.y}function q(a,b,c){a.y0=b,a.y=c}function t(a){var b=1,c=0,d=a[0][1],e,f=a.length;for(;b<f;++b)(e=a[b][1])>d&&(c=b,d=e);return c}function u(a){return a.reduce(v,0)}function v(a,b){return a+b[1]}function w(a,b){return x(a,Math.ceil(Math.log(b.length)/Math.LN2+1))}function x(a,b){var c=-1,d=+a[0],e=(a[1]-d)/b,f=[];while(++c<=b)f[c]=e*c+d;return f}function y(a){return[d3.min(a),d3.max(a)]}function z(a,b){return a.sort=d3.rebind(a,b.sort),a.children=d3.rebind(a,b.children),a.links=D,a.value=d3.rebind(a,b.value),a.nodes=function(b){return E=!0,(a.nodes=a)(b)},a}function A(a){return a.children}function B(a){return a.value}function C(a,b){return b.value-a.value}function D(a){return d3.merge(a.map(function(a){return(a.children||[]).map(function(b){return{source:a,target:b}})}))}function F(a,b){return a.value-b.value}function G(a,b){var c=a._pack_next;a._pack_next=b,b._pack_prev=a,b._pack_next=c,c._pack_prev=b}function H(a,b){a._pack_next=b,b._pack_prev=a}function I(a,b){var c=b.x-a.x,d=b.y-a.y,e=a.r+b.r;return e*e-c*c-d*d>.001}function J(a){function l(a){b=Math.min(a.x-a.r,b),c=Math.max(a.x+a.r,c),d=Math.min(a.y-a.r,d),e=Math.max(a.y+a.r,e)}var b=Infinity,c=-Infinity,d=Infinity,e=-Infinity,f=a.length,g,h,i,j,k;a.forEach(K),g=a[0],g.x=-g.r,g.y=0,l(g);if(f>1){h=a[1],h.x=h.r,h.y=0,l(h);if(f>2){i=a[2],O(g,h,i),l(i),G(g,i),g._pack_prev=i,G(i,h),h=g._pack_next;for(var m=3;m<f;m++){O(g,h,i=a[m]);var n=0,o=1,p=1;for(j=h._pack_next;j!==h;j=j._pack_next,o++)if(I(j,i)){n=1;break}if(n==1)for(k=g._pack_prev;k!==j._pack_prev;k=k._pack_prev,p++)if(I(k,i)){p<o&&(n=-1,j=k);break}n==0?(G(g,i),h=i,l(i)):n>0?(H(g,j),h=j,m--):(H(j,h),g=j,m--)}}}var q=(b+c)/2,r=(d+e)/2,s=0;for(var m=0;m<f;m++){var t=a[m];t.x-=q,t.y-=r,s=Math.max(s,t.r+Math.sqrt(t.x*t.x+t.y*t.y))}return a.forEach(L),s}function K(a){a._pack_next=a._pack_prev=a}function L(a){delete a._pack_next,delete a._pack_prev}function M(a){var b=a.children;b&&b.length?(b.forEach(M),a.r=J(b)):a.r=Math.sqrt(a.value)}function N(a,b,c,d){var e=a.children;a.x=b+=d*a.x,a.y=c+=d*a.y,a.r*=d;if(e){var f=-1,g=e.length;while(++f<g)N(e[f],b,c,d)}}function O(a,b,c){var d=a.r+c.r,e=b.x-a.x,f=b.y-a.y;if(d&&(e||f)){var g=b.r+c.r,h=Math.sqrt(e*e+f*f),i=Math.max(-1,Math.min(1,(d*d+h*h-g*g)/(2*d*h))),j=Math.acos(i),k=i*(d/=h),l=Math.sin(j)*d;c.x=a.x+k*e+l*f,c.y=a.y+k*f-l*e}else c.x=a.x+d,c.y=a.y}function P(a){return 1+d3.max(a,function(a){return a.y})}function Q(a){return a.reduce(function(a,b){return a+b.x},0)/a.length}function R(a){var b=a.children;return b&&b.length?R(b[0]):a}function S(a){var b=a.children,c;return b&&(c=b.length)?S(b[c-1]):a}function T(a,b){return a.parent==b.parent?1:2}function U(a){var b=a.children;return b&&b.length?b[0]:a._tree.thread}function V(a){var b=a.children,c;return b&&(c=b.length)?b[c-1]:a._tree.thread}function W(a,b){var c=a.children;if(c&&(e=c.length)){var d,e,f=-1;while(++f<e)b(d=W(c[f],b),a)>0&&(a=d)}return a}function X(a,b){return a.x-b.x}function Y(a,b){return b.x-a.x}function Z(a,b){return a.depth-b.depth}function $(a,b){function c(a,d){var e=a.children;if(e&&(i=e.length)){var f,g=null,h=-1,i;while(++h<i)f=e[h],c(f,g),g=f}b(a,d)}c(a,null)}function _(a){var b=0,c=0,d=a.children,e=d.length,f;while(--e>=0)f=d[e]._tree,f.prelim+=b,f.mod+=b,b+=f.shift+(c+=f.change)}function ba(a,b,c){a=a._tree,b=b._tree;var d=c/(b.number-a.number);a.change+=d,b.change-=d,b.shift+=c,b.prelim+=c,b.mod+=c}function bb(a,b,c){return a._tree.ancestor.parent==b.parent?a._tree.ancestor:c}function bc(a){return{x:a.x,y:a.y,dx:a.dx,dy:a.dy}}function bd(a,b){var c=a.x+b[3],d=a.y+b[0],e=a.dx-b[1]-b[3],f=a.dy-b[0]-b[2];return e<0&&(c+=e/2,e=0),f<0&&(d+=f/2,f=0),{x:c,y:d,dx:e,dy:f}}d3.layout={},d3.layout.bundle=function(){return function(b){var c=[],d=-1,e=b.length;while(++d<e)c.push(a(b[d]));return c}},d3.layout.chord=function(){function j(){var a={},j=[],l=d3.range(e),m=[],n,o,p,q,r;b=[],c=[],n=0,q=-1;while(++q<e){o=0,r=-1;while(++r<e)o+=d[q][r];j.push(o),m.push(d3.range(e)),n+=o}g&&l.sort(function(a,b){return g(j[a],j[b])}),h&&m.forEach(function(a,b){a.sort(function(a,c){return h(d[b][a],d[b][c])})}),n=(2*Math.PI-f*e)/n,o=0,q=-1;while(++q<e){p=o,r=-1;while(++r<e){var s=l[q],t=m[s][r],u=d[s][t],v=o,w=o+=u*n;a[s+"-"+t]={index:s,subindex:t,startAngle:v,endAngle:w,value:u}}c.push({index:s,startAngle:p,endAngle:o,value:(o-p)/n}),o+=f}q=-1;while(++q<e){r=q-1;while(++r<e){var x=a[q+"-"+r],y=a[r+"-"+q];(x.value||y.value)&&b.push(x.value<y.value?{source:y,target:x}:{source:x,target:y})}}i&&k()}function k(){b.sort(function(a,b){return i((a.source.value+a.target.value)/2,(b.source.value+b.target.value)/2)})}var a={},b,c,d,e,f=0,g,h,i;return a.matrix=function(f){return arguments.length?(e=(d=f)&&d.length,b=c=null,a):d},a.padding=function(d){return arguments.length?(f=d,b=c=null,a):f},a.sortGroups=function(d){return arguments.length?(g=d,b=c=null,a):g},a.sortSubgroups=function(c){return arguments.length?(h=c,b=null,a):h},a.sortChords=function(c){return arguments.length?(i=c,b&&k(),a):i},a.chords=function(){return b||j(),b},a.groups=function(){return c||j(),c},a},d3.layout.force=function(){function A(a){return function(b,c,d,e,f){if(b.point!==a){var g=b.cx-a.x,h=b.cy-a.y,i=1/Math.sqrt(g*g+h*h);if((e-c)*i<t){var j=b.charge*i*i;return a.px-=g*j,a.py-=h*j,!0}if(b.point&&isFinite(i)){var j=b.pointCharge*i*i;a.px-=g*j,a.py-=h*j}}return!b.charge}}function B(){var a=v.length,d=w.length,e,f,g,h,i,j,l,m,p;for(f=0;f<d;++f){g=w[f],h=g.source,i=g.target,m=i.x-h.x,p=i.y-h.y;if(j=m*m+p*p)j=n*y[f]*((j=Math.sqrt(j))-x[f])/j,m*=j,p*=j,i.x-=m*(l=h.weight/(i.weight+h.weight)),i.y-=p*l,h.x+=m*(l=1-l),h.y+=p*l}if(l=n*s){m=c[0]/2,p=c[1]/2,f=-1;if(l)while(++f<a)g=v[f],g.x+=(m-g.x)*l,g.y+=(p-g.y)*l}if(r){k(e=d3.geom.quadtree(v),n,z),f=-1;while(++f<a)(g=v[f]).fixed||e.visit(A(g))}f=-1;while(++f<a)g=v[f],g.fixed?(g.x=g.px,g.y=g.py):(g.x-=(g.px-(g.px=g.x))*o,g.y-=(g.py-(g.py=g.y))*o);return b.tick({type:"tick",alpha:n}),(n*=.99)<.005}function C(b){g(f=b),e=a}var a={},b=d3.dispatch("tick"),c=[1,1],d,n,o=.9,p=l,q=m,r=-30,s=.1,t=.8,u,v=[],w=[],x,y,z;return a.on=function(c,d){return b.on(c,d),a},a.nodes=function(b){return arguments.length?(v=b,a):v},a.links=function(b){return arguments.length?(w=b,a):w},a.size=function(b){return arguments.length?(c=b,a):c},a.linkDistance=function(b){return arguments.length?(p=d3.functor(b),a):p},a.distance=a.linkDistance,a.linkStrength=function(b){return arguments.length?(q=d3.functor(b),a):q},a.friction=function(b){return arguments.length?(o=b,a):o},a.charge=function(b){return arguments.length?(r=typeof b=="function"?b:+b,a):r},a.gravity=function(b){return arguments.length?(s=b,a):s},a.theta=function(b){return arguments.length?(t=b,a):t},a.start=function(){function k(a,c){var d=l(b),e=-1,f=d.length,g;while(++e<f)if(!isNaN(g=d[e][a]))return g;return Math.random()*c}function l(){if(!i){i=[];for(d=0;d<e;++d)i[d]=[];for(d=0;d<f;++d){var a=w[d];i[a.source.index].push(a.target),i[a.target.index].push(a.source)}}return i[b]}var b,d,e=v.length,f=w.length,g=c[0],h=c[1],i,j;for(b=0;b<e;++b)(j=v[b]).index=b,j.weight=0;x=[],y=[];for(b=0;b<f;++b)j=w[b],typeof j.source=="number"&&(j.source=v[j.source]),typeof j.target=="number"&&(j.target=v[j.target]),x[b]=p.call(this,j,b),y[b]=q.call(this,j,b),++j.source.weight,++j.target.weight;for(b=0;b<e;++b)j=v[b],isNaN(j.x)&&(j.x=k("x",g)),isNaN(j.y)&&(j.y=k("y",h)),isNaN(j.px)&&(j.px=j.x),isNaN(j.py)&&(j.py=j.y);z=[];if(typeof r=="function")for(b=0;b<e;++b)z[b]=+r.call(this,v[b],b);else for(b=0;b<e;++b)z[b]=r;return a.resume()},a.resume=function(){return n=.1,d3.timer(B),a},a.stop=function(){return n=0,a},a.drag=function(){d||(d=d3.behavior.drag().on("dragstart",C).on("drag",j).on("dragend",i)),this.on("mouseover.force",g).on("mouseout.force",h).call(d)},a};var e,f;d3.layout.partition=function(){function c(a,b,d,e){var f=a.children;a.x=b,a.y=a.depth*e,a.dx=d,a.dy=e;if(f&&(h=f.length)){var g=-1,h,i,j;d=a.value?d/a.value:0;while(++g<h)c(i=f[g],b,j=i.value*d,e),b+=j}}function d(a){var b=a.children,c=0;if(b&&(f=b.length)){var e=-1,f;while(++e<f)c=Math.max(c,d(b[e]))}return 1+c}function e(e,f){var g=a.call(this,e,f);return c(g[0],0,b[0],b[1]/d(g[0])),g}var a=d3.layout.hierarchy(),b=[1,1];return e.size=function(a){return arguments.length?(b=a,e):b},z(e,a)},d3.layout.pie=function(){function f(g,h){var i=g.map(function(b,c){return+a.call(f,b,c)}),j=+(typeof c=="function"?c.apply(this,arguments):c),k=((typeof e=="function"?e.apply(this,arguments):e)-c)/d3.sum(i),l=d3.range(g.length);b!=null&&l.sort(b===n?function(a,b){return i[b]-i[a]}:function(a,c){return b(g[a],g[c])});var m=l.map(function(a){return{data:g[a],value:d=i[a],startAngle:j,endAngle:j+=d*k}});return g.map(function(a,b){return m[l[b]]})}var a=Number,b=n,c=0,e=2*Math.PI;return f.value=function(b){return arguments.length?(a=b,f):a},f.sort=function(a){return arguments.length?(b=a,f):b},f.startAngle=function(a){return arguments.length?(c=a,f):c},f.endAngle=function(a){return arguments.length?(e=a,f):e},f};var n={};d3.layout.stack=function(){function g(h,i){var j=h.map(function(b,c){return a.call(g,b,c)}),k=j.map(function(a,b){return a.map(function(a,b){return[e.call(g,a,b),f.call(g,a,b)]})}),l=b.call(g,k,i);j=d3.permute(j,l),k=d3.permute(k,l);var m=c.call(g,k,i),n=j.length,o=j[0].length,p,q,r;for(q=0;q<o;++q){d.call(g,j[0][q],r=m[q],k[0][q][1]);for(p=1;p<n;++p)d.call(g,j[p][q],r+=k[p-1][q][1],k[p][q][1])}return h}var a=Object,b=r["default"],c=s.zero,d=q,e=o,f=p;return g.values=function(b){return arguments.length?(a=b,g):a},g.order=function(a){return arguments.length?(b=typeof a=="function"?a:r[a],g):b},g.offset=function(a){return arguments.length?(c=typeof a=="function"?a:s[a],g):c},g.x=function(a){return arguments.length?(e=a,g):e},g.y=function(a){return arguments.length?(f=a,g):f},g.out=function(a){return arguments.length?(d=a,g):d},g};var r={"inside-out":function(a){var b=a.length,c,d,e=a.map(t),f=a.map(u),g=d3.range(b).sort(function(a,b){return e[a]-e[b]}),h=0,i=0,j=[],k=[];for(c=0;c<b;++c)d=g[c],h<i?(h+=f[d],j.push(d)):(i+=f[d],k.push(d));return k.reverse().concat(j)},reverse:function(a){return d3.range(a.length).reverse()},"default":function(a){return d3.range(a.length)}},s={silhouette:function(a){var b=a.length,c=a[0].length,d=[],e=0,f,g,h,i=[];for(g=0;g<c;++g){for(f=0,h=0;f<b;f++)h+=a[f][g][1];h>e&&(e=h),d.push(h)}for(g=0;g<c;++g)i[g]=(e-d[g])/2;return i},wiggle:function(a){var b=a.length,c=a[0],d=c.length,e=0,f,g,h,i,j,k,l,m,n,o=[];o[0]=m=n=0;for(g=1;g<d;++g){for(f=0,i=0;f<b;++f)i+=a[f][g][1];for(f=0,j=0,l=c[g][0]-c[g-1][0];f<b;++f){for(h=0,k=(a[f][g][1]-a[f][g-1][1])/(2*l);h<f;++h)k+=(a[h][g][1]-a[h][g-1][1])/l;j+=k*a[f][g][1]}o[g]=m-=i?j/i*l:0,m<n&&(n=m)}for(g=0;g<d;++g)o[g]-=n;return o},expand:function(a){var b=a.length,c=a[0].length,d=1/b,e,f,g,h=[];for(f=0;f<c;++f){for(e=0,g=0;e<b;e++)g+=a[e][f][1];if(g)for(e=0;e<b;e++)a[e][f][1]/=g;else for(e=0;e<b;e++)a[e][f][1]=d}for(f=0;f<c;++f)h[f]=0;return h},zero:function(a){var b=-1,c=a[0].length,d=[];while(++b<c)d[b]=0;return d}};d3.layout.histogram=function(){function e(e,f){var g=[],h=e.map(b,this),i=c.call(this,h,f),j=d.call(this,i,h,f),k,f=-1,l=h.length,m=j.length-1,n=a?1:1/l,o;while(++f<m)k=g[f]=[],k.dx=j[f+1]-(k.x=j[f]),k.y=0;f=-1;while(++f<l)o=h[f],o>=i[0]&&o<=i[1]&&(k=g[d3.bisect(j,o,1,m)-1],k.y+=n,k.push(e[f]));return g}var a=!0,b=Number,c=y,d=w;return e.value=function(a){return arguments.length?(b=a,e):b},e.range=function(a){return arguments.length?(c=d3.functor(a),e):c},e.bins=function(a){return arguments.length?(d=typeof a=="number"?function(b){return x(b,a)}:d3.functor(a),e):d},e.frequency=function(b){return arguments.length?(a=!!b,e):a},e},d3.layout.hierarchy=function(){function e(f,h,i){var j=b.call(g,f,h),k=E?f:{data:f};k.depth=h,i.push(k);if(j&&(m=j.length)){var l=-1,m,n=k.children=[],o=0,p=h+1;while(++l<m)d=e(j[l],p,i),d.parent=k,n.push(d),o+=d.value;a&&n.sort(a),c&&(k.value=o)}else c&&(k.value=+c.call(g,f,h)||0);return k}function f(a,b){var d=a.children,e=0;if(d&&(i=d.length)){var h=-1,i,j=b+1;while(++h<i)e+=f(d[h],j)}else c&&(e=+c.call(g,E?a:a.data,b)||0);return c&&(a.value=e),e}function g(a){var b=[];return e(a,0,b),b}var a=C,b=A,c=B;return g.sort=function(b){return arguments.length?(a=b,g):a},g.children=function(a){return arguments.length?(b=a,g):b},g.value=function(a){return arguments.length?(c=a,g):c},g.revalue=function(a){return f(a,0),a},g};var E=!1;d3.layout.pack=function(){function c(c,d){var e=a.call(this,c,d),f=e[0];f.x=0,f.y=0,M(f);var g=b[0],h=b[1],i=1/Math.max(2*f.r/g,2*f.r/h);return N(f,g/2,h/2,i),e}var a=d3.layout.hierarchy().sort(F),b=[1,1];return c.size=function(a){return arguments.length?(b=a,c):b},z(c,a)},d3.layout.cluster=function(){function d(d,e){var f=a.call(this,d,e),g=f[0],h,i=0,j,k;$(g,function(a){var c=a.children;c&&c.length?(a.x=Q(c),a.y=P(c)):(a.x=h?i+=b(a,h):0,a.y=0,h=a)});var l=R(g),m=S(g),n=l.x-b(l,m)/2,o=m.x+b(m,l)/2;return $(g,function(a){a.x=(a.x-n)/(o-n)*c[0],a.y=(1-a.y/g.y)*c[1]}),f}var a=d3.layout.hierarchy().sort(null).value(null),b=T,c=[1,1];return d.separation=function(a){return arguments.length?(b=a,d):b},d.size=function(a){return arguments.length?(c=a,d):c},z(d,a)},d3.layout.tree=function(){function d(d,e){function h(a,c){var d=a.children,e=a._tree;if(d&&(f=d.length)){var f,g=d[0],i,k=g,l,m=-1;while(++m<f)l=d[m],h(l,i),k=j(l,i,k),i=l;_(a);var n=.5*(g._tree.prelim+l._tree.prelim);c?(e.prelim=c._tree.prelim+b(a,c),e.mod=e.prelim-n):e.prelim=n}else c&&(e.prelim=c._tree.prelim+b(a,c))}function i(a,b){a.x=a._tree.prelim+b;var c=a.children;if(c&&(e=c.length)){var d=-1,e;b+=a._tree.mod;while(++d<e)i(c[d],b)}}function j(a,c,d){if(c){var e=a,f=a,g=c,h=a.parent.children[0],i=e._tree.mod,j=f._tree.mod,k=g._tree.mod,l=h._tree.mod,m;while(g=V(g),e=U(e),g&&e)h=U(h),f=V(f),f._tree.ancestor=a,m=g._tree.prelim+k-e._tree.prelim-i+b(g,e),m>0&&(ba(bb(g,a,d),a,m),i+=m,j+=m),k+=g._tree.mod,i+=e._tree.mod,l+=h._tree.mod,j+=f._tree.mod;g&&!V(f)&&(f._tree.thread=g,f._tree.mod+=k-j),e&&!U(h)&&(h._tree.thread=e,h._tree.mod+=i-l,d=a)}return d}var f=a.call(this,d,e),g=f[0];$(g,function(a,b){a._tree={ancestor:a,prelim:0,mod:0,change:0,shift:0,number:b?b._tree.number+1:0}}),h(g),i(g,-g._tree.prelim);var k=W(g,Y),l=W(g,X),m=W(g,Z),n=k.x-b(k,l)/2,o=l.x+b(l,k)/2,p=m.depth||1;return $(g,function(a){a.x=(a.x-n)/(o-n)*c[0],a.y=a.depth/p*c[1],delete a._tree}),f}var a=d3.layout.hierarchy().sort(null).value(null),b=T,c=[1,1];return d.separation=function(a){return arguments.length?(b=a,d):b},d.size=function(a){return arguments.length?(c=a,d):c},z(d,a)},d3.layout.treemap=function(){function i(a,b){var c=-1,d=a.length,e,f;while(++c<d)f=(e=a[c]).value*(b<0?0:b),e.area=isNaN(f)||f<=0?0:f}function j(a){var b=a.children;if(b&&b.length){var c=e(a),d=[],f=b.slice(),g,h=Infinity,k,n=Math.min(c.dx,c.dy),o;i(f,c.dx*c.dy/a.value),d.area=0;while((o=f.length)>0)d.push(g=f[o-1]),d.area+=g.area,(k=l(d,n))<=h?(f.pop(),h=k):(d.area-=d.pop().area,m(d,n,c,!1),n=Math.min(c.dx,c.dy),d.length=d.area=0,h=Infinity);d.length&&(m(d,n,c,!0),d.length=d.area=0),b.forEach(j)}}function k(a){var b=a.children;if(b&&b.length){var c=e(a),d=b.slice(),f,g=[];i(d,c.dx*c.dy/a.value),g.area=0;while(f=d.pop())g.push(f),g.area+=f.area,f.z!=null&&(m(g,f.z?c.dx:c.dy,c,!d.length),g.length=g.area=0);b.forEach(k)}}function l(a,b){var c=a.area,d,e=0,f=Infinity,g=-1,i=a.length;while(++g<i){if(!(d=a[g].area))continue;d<f&&(f=d),d>e&&(e=d)}return c*=c,b*=b,c?Math.max(b*e*h/c,c/(b*f*h)):Infinity}function m(a,c,d,e){var f=-1,g=a.length,h=d.x,i=d.y,j=c?b(a.area/c):0,k;if(c==d.dx){if(e||j>d.dy)j=j?d.dy:0;while(++f<g)k=a[f],k.x=h,k.y=i,k.dy=j,h+=k.dx=j?b(k.area/j):0;k.z=!0,k.dx+=d.x+d.dx-h,d.y+=j,d.dy-=j}else{if(e||j>d.dx)j=j?d.dx:0;while(++f<g)k=a[f],k.x=h,k.y=i,k.dx=j,i+=k.dy=j?b(k.area/j):0;k.z=!1,k.dy+=d.y+d.dy-i,d.x+=j,d.dx-=j}}function n(b){var d=g||a(b),e=d[0];return e.x=0,e.y=0,e.dx=c[0],e.dy=c[1],g&&a.revalue(e),i([e],e.dx*e.dy/e.value),(g?k:j)(e),f&&(g=d),d}var a=d3.layout.hierarchy(),b=Math.round,c=[1,1],d=null,e=bc,f=!1,g,h=.5*(1+Math.sqrt(5));return n.size=function(a){return arguments.length?(c=a,n):c},n.padding=function(a){function b(b){var c=a.call(n,b,b.depth);return c==null?bc(b):bd(b,typeof c=="number"?[c,c,c,c]:c)}function c(b){return bd(b,a)}if(!arguments.length)return d;var f;return e=(d=a)==null?bc:(f=typeof a)==="function"?b:f==="number"?(a=[a,a,a,a],c):c,n},n.round=function(a){return arguments.length?(b=a?Math.round:Number,n):b!=Number},n.sticky=function(a){return arguments.length?(f=a,g=null,n):f},n.ratio=function(a){return arguments.length?(h=a,n):h},z(n,a)}})();