diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2014-07-15 12:05:27 +0600 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2014-07-15 12:05:27 +0600 |
commit | d4b416add31375531fae4af28ce466a016a8a0b3 (patch) | |
tree | c8bfceff7272ebd17831f4a579c1077c3723d617 /server | |
parent | 5e08c120b428f43c5f2d09bccaae97125a3269bf (diff) | |
download | sonarqube-d4b416add31375531fae4af28ce466a016a8a0b3.tar.gz sonarqube-d4b416add31375531fae4af28ce466a016a8a0b3.zip |
SONAR-5207 Remove ruby treemap
Diffstat (limited to 'server')
10 files changed, 0 insertions, 775 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap.rb deleted file mode 100644 index cd96e3fe436..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# treemap.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -require File.dirname(__FILE__) + '/treemap/node' -require File.dirname(__FILE__) + '/treemap/layout_base' -require File.dirname(__FILE__) + '/treemap/output_base' -require File.dirname(__FILE__) + '/treemap/color_base' -require File.dirname(__FILE__) + '/treemap/slice_layout' -require File.dirname(__FILE__) + '/treemap/squarified_layout' -require File.dirname(__FILE__) + '/treemap/html_output' -require File.dirname(__FILE__) + '/treemap/rectangle' -require File.dirname(__FILE__) + '/treemap/gradient_color' diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/color_base.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/color_base.rb deleted file mode 100644 index 71c649647e0..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/color_base.rb +++ /dev/null @@ -1,61 +0,0 @@ -# -# color_base.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -module Treemap - class ColorBase - def get_hex_color(value) - # base classes override - end - - def get_rgb_color(value) - # base classes override - end - - def red(color) - color.sub!(/^#/, "") - color[0,2].hex - end - - def green(color) - color.sub!(/^#/, "") - color[2,2].hex - end - - def blue(color) - color.sub!(/^#/, "") - color[4,2].hex - end - - def to_rgb(color) - [red(color), green(color), blue(color)] - end - - def to_html(width=1, height=20) - html = "<div>" - index = @min - - while(index <= @max) - html += "<span style=\"display: block; float: left;" - html += "width: " + width.to_s + "px;" - html += "height: " + height.to_s + "px;" - html += "background-color: #" + get_hex_color(index) + ";" - html += "\">" - html += "<img width=\"1\" height=\"1\" />" - html += "</span>" - index += @increment - end - - html += "</div>" - html - end - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/gradient_color.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/gradient_color.rb deleted file mode 100644 index fd4a3bc46f1..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/gradient_color.rb +++ /dev/null @@ -1,71 +0,0 @@ -# -# gradient_color.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -require File.dirname(__FILE__) + "/color_base" - -class Treemap::GradientColor < Treemap::ColorBase - attr_accessor(:min, :max, :min_color, :mean_color, :max_color, :increment) - - def initialize - @min = -100 - @max = 100 - @min_color = "FF0000" # red - @mean_color = "000000" # black - @max_color = "00FF00" # green - @increment = 1 - - yield self if block_given? - - # XXX add in error checking. if min >= max, if colors aren't hex, etc. - @min = @min.to_f - @max = @max.to_f - @mean = (@min + @max) / 2.to_f - @slices = (1.to_f / @increment.to_f) * (@max - @mean).to_f - end - - def get_hex_color(value) - value = @max if(value > @max) - vaue = @min if(value < @min) - - - r1, g1, b1 = to_rgb(@mean_color) - r2, g2, b2 = to_rgb(@min_color) - if(value >= @mean) - r2, g2, b2 = to_rgb(@max_color) - end - - rfactor = ((r1 -r2).abs.to_f / @slices) * value.abs - gfactor = ((g1 -g2).abs.to_f / @slices) * value.abs - bfactor = ((b1 -b2).abs.to_f / @slices) * value.abs - - newr = r1 + rfactor - if(r1 > r2) - newr = r1 - rfactor - end - - newg = g1 + gfactor - if(g1 > g2) - newg = g1 - gfactor - end - - newb = b1 + bfactor - if(b1 > b2) - newb = b1 - bfactor - end - - sprintf("%02X", newr.round) + sprintf("%02X", newg.round) + sprintf("%02X", newb.round) - end - - def get_rgb_color(value) - to_rgb(get_hex_color(value)) - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/html_output.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/html_output.rb deleted file mode 100644 index 63873cc69a6..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/html_output.rb +++ /dev/null @@ -1,137 +0,0 @@ -# -# html_output.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -require 'cgi' -require File.dirname(__FILE__) + "/output_base" -require File.dirname(__FILE__) + "/slice_layout" - -class Treemap::HtmlOutput < Treemap::OutputBase - attr_accessor(:full_html, :details_at_depth, :stylesheets, :javascripts) - - def initialize - super - - # default options for HtmlOutput - @full_html = true - @details_at_depth = nil - @stylesheets = "" - @javascripts = "" - - yield self if block_given? - - @layout.position = :absolute - end - - def default_css - css = <<CSS -.node { - border: 1px solid black; -} -.label { - color: #FFFFFF; - font-size: 11px; -} -.label-heading { - color: #FFFFFF; - font-size: 14pt; - font-weight: bold; - text-decoration: underline; -} -CSS - end - - def node_label(node) - CGI.escapeHTML(node.label) - end - - def node_color(node) - color = "#CCCCCC" - - if(!node.color.nil?) - if(not Numeric === node.color) - color = node.color - else - color = "#" + @color.get_hex_color(node.color) - end - end - - color - end - - def to_html(node) - @bounds = self.bounds - - @layout.process(node, @bounds) - - draw_map(node) - end - - def draw_map(node) - html = "" - - if(@full_html) - html += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " - html += "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" - html += "<html><head>" - html += "<title>Treemap - #{node_label(node)}</title>" - html += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" - html += "<style type=\"text/css\">" + default_css + "</style>" - html += self.stylesheets - html += self.javascripts - html += "</head><body>" - end - - html += draw_node(node) - - if(@full_html) - html += "</body></html>" - end - - html - end - - def draw_label(node) - label= "<span class=\"label\">" - label += node_label(node) - label += "</span>" - label - end - - # Subclass can override to add more html inside <div/> of node - def draw_node_body(node) - draw_label(node) - end - - def draw_node(node) - return "" if node.bounds.nil? - - html = "<div id=\"node-#{node.id}\"" - html += " style=\"" - html += "overflow: hidden; position: absolute; display: inline;" - html += "left: #{node.bounds.x1}px; top: #{node.bounds.y1}px;" - html += "width: #{node.bounds.width}px; height: #{node.bounds.height}px;" - html += "background-color: " + node_color(node) + ";" - html += "\" class=\"node\"" - html += ">" - - html += draw_node_body(node) - - if(!node.children.nil? and node.children.size > 0) - node.children.each do |c| - html += draw_node(c) - end - end - - html + '</div>' - end - -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/layout_base.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/layout_base.rb deleted file mode 100644 index 77b92db85be..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/layout_base.rb +++ /dev/null @@ -1,30 +0,0 @@ -#-- -# layout_base.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -#++ - -module Treemap - class LayoutBase - attr_accessor :position, :color - - def initialize - # Similar to the css style position. If set to :fixed x,y bounds calculations - # should be computed relative to the root bounds. If set to :absolute then they - # should be computed relative to the parent bounds. - # See http://www.w3.org/TR/CSS2/visuren.html#positioning-scheme - @position = :fixed - yield self if block_given? - end - - # Subclasses will override - def process(node, bounds) - end - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/node.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/node.rb deleted file mode 100644 index 3fdfe001a0a..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/node.rb +++ /dev/null @@ -1,138 +0,0 @@ -# -# node.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -require "md5" - -module Treemap - # - # A generic tree node class which is used to represent the data to be - # treemap'ed. The Layout and Output classes expect an object of this - # type to perform the treemap calculations on. - # - # Create a simple tree: - # root = Treemap::Node.new - # root.new_child(:size => 6) - # root.new_child(:size => 6) - # root.new_child(:size => 4) - # root.new_child(:size => 3) - # root.new_child(:size => 2) - # root.new_child(:size => 2) - # root.new_child(:size => 1) - # - # Initialize values: - # root = Treemap::Node.new(:label => "All", :size => 100, :color => "#FFCCFF") - # child1 = Treemap::Node.new(:label => "Child 1", :size => 50) - # child2 = Treemap::Node.new(:label => "Child 2", :size => 50) - # root.add_child(child1) - # root.add_child(child2) - # - # - class Treemap::Node - attr_accessor :id, :label, :color, :size, :bounds, :parent, :tooltip, :url, :title, :rid, :leaf - attr_reader :children - - # - # Create a new Node. You can initialize the node by passing in - # a hash with any of the following keys: - # - # * :size - The size that this node represents. For non-leaf nodes the - # size must be equal to the sum of the sizes of it's children. If size - # is nil then the value will be calculated by recursing the children. - # * :label - The label for this node. Used when displaying. Defaults to "node" - # * :color - The background fill color in hex to render when drawing the - # square. If the value is a number a color will be calculated. An example - # string color would be: ##FFFFFF (white) - # * :id - a unique id to assign to this node. Default id will be generated if - # one is not provided. - # - # - def initialize(opts = {}) - @size = opts[:size] - @label = opts[:label] - @title = opts[:title] - @color = opts[:color] - @id = opts[:id] - @url = opts[:url] - @tooltip = opts[:tooltip] - @children = [] - @rid = opts[:rid] - @leaf = opts[:leaf] - if(@id.nil?) - make_id - end - end - - # - # Returns the depth of the node. 0 for root. - # - def depth - return 0 if parent.nil? - 1 + self.parent.depth - end - - def add_child(node) - # XXX check to see that a node with the same label doesn't already exist. - # having 2 nodes with the same label at the same depth - # doesn't seem to make sense - node.parent = self - @children.push(node) - end - - # - # Creates a new node and adds it as a child. See new method. - # - def new_child(*args) - node = Treemap::Node.new(*args) - self.add_child(node) - end - - def find - @children.find { |c| yield(c) } - end - - def to_s - str = "[:id => " + id + " :label => " + label - str += " :size => " + size.to_s + " :color => " + color.to_s - if(not(bounds.nil?)) - str += " :bounds => " + bounds.to_s - end - str += "]" - str - end - - def size - return @size if !@size.nil? - sum = 0 - @children.each do |c| - sum += c.size - end - - sum - end - - def label - return @label if !@label.nil? - "node - " + size.to_s - end - - def leaf? - return true if @children.nil? - !(@children.size > 0) - end - - private - def make_id - #XXX prob should change this. Create a better way to generate unique id's - @id = MD5.new([self.label, rand(100000000)].join("-")).hexdigest - end - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/output_base.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/output_base.rb deleted file mode 100644 index d7d80ce9cd2..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/output_base.rb +++ /dev/null @@ -1,39 +0,0 @@ -# -# output_base.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -require 'rexml/document' - -module Treemap - class OutputBase - attr_accessor(:width, :height, :layout, :color, :margin_top, :margin_left) - - def initialize - @width = 800 - @height = 600 - @margin_top = 0 - @margin_left = 0 - @layout = Treemap::SquarifiedLayout.new - @color = Treemap::GradientColor.new - yield self if block_given? - end - - protected - def bounds - x1 = self.margin_left - y1 = self.margin_top - x2 = self.width + self.margin_left - y2 = self.height + self.margin_top - bounds = Treemap::Rectangle.new(x1, y1, x2, y2) - return bounds - end - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/rectangle.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/rectangle.rb deleted file mode 100644 index 7ae84dbbd98..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/rectangle.rb +++ /dev/null @@ -1,38 +0,0 @@ -# -# rectangle.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -module Treemap - class Rectangle - attr_accessor :x1, :y1, :x2, :y2 - - def initialize(x1, y1, x2, y2) - @x1 = x1 - @y1 = y1 - @x2 = x2 - @y2 = y2 - - yield self if block_given? - end - - def to_s - "[" + [@x1, @y1, @x2, @y2].join(",") + "]" - end - - def width - @x2 - @x1 - end - - def height - @y2 - @y1 - end - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/slice_layout.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/slice_layout.rb deleted file mode 100644 index 7e94a7ca159..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/slice_layout.rb +++ /dev/null @@ -1,99 +0,0 @@ -# -# slice_layout.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -require File.dirname(__FILE__) + "/layout_base" - -class Treemap::SliceLayout < Treemap::LayoutBase - Vertical = 1 - Horizontal = 2 - - def process(node, bounds, axis=nil) - bounds = bounds.clone - - node.bounds = bounds.clone - - if(@position == :absolute) - bounds.x2 = bounds.width - bounds.y2 = bounds.height - bounds.x1 = 0 - bounds.y1 = 0 - end - - if(!node.leaf?) - process_children(node.children, bounds, axis) - end - end - - def sum(children) - sum = 0 - children.each do |c| - sum += c.size - end - sum - end - - def process_children(children, bounds, axis=nil) - parent_bounds = bounds.clone - bounds = bounds.clone - - axis = axis(bounds) if(axis.nil?) - - width = axis == Vertical ? bounds.width : bounds.height - - sum = sum(children) - - return if sum<=0 - - # XXX should we sort? seems to produce better map but not tested on - # larger data sets - # children.sort {|c1,c2| c2.size <=> c1.size}.each do |c| - children.each do |c| - size = ((c.size.to_f / sum.to_f)*width).round - - if(axis == Vertical) - bounds.x2 = bounds.x1 + size - else - bounds.y2 = bounds.y1 + size - end - - process(c, bounds, flip(axis)) - - axis == Vertical ? bounds.x1 = bounds.x2 : bounds.y1 = bounds.y2 - end - - last = children.last - if(axis == Vertical) - last.bounds.x2 = parent_bounds.x2 - else - last.bounds.y2 = parent_bounds.y2 - end - - end - - def flip(axis) - return Horizontal if axis == Vertical - Vertical - end - - def vertical?(bounds) - bounds.width > bounds.height - end - - def horizontal?(bounds) - bounds.width < bounds.height - end - - def axis(bounds) - return Horizontal if horizontal?(bounds) - Vertical - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/squarified_layout.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/squarified_layout.rb deleted file mode 100644 index 9a5ae944013..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/treemap/squarified_layout.rb +++ /dev/null @@ -1,141 +0,0 @@ -# -# squarified_layout.rb - RubyTreemap -# -# Copyright (c) 2006 by Andrew Bruno <aeb@qnot.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# - -require File.dirname(__FILE__) + "/layout_base" - -class Treemap::SquarifiedLayout < Treemap::SliceLayout - - def process(node, bounds, axis=nil) - - bounds = bounds.clone - - node.bounds = bounds.clone - - if(@position == :absolute) - bounds.x2 = bounds.width - bounds.y2 = bounds.height - bounds.x1 = 0 - bounds.y1 = 0 - end - - if(!node.leaf?) - squarify_children(node, bounds, flip(axis)) - end - end - - def squarify_children(node, bounds, axis) - - parent_bounds = bounds.clone - bounds = bounds.clone - - node.children.sort! {|a,b| b.size <=> a.size} - - if(node.children.size < 2) - process_children(node.children, bounds, flip(axis)) - end - - parent_size = node.size - first_child = node.children.first - - row_size = first_child.size - row_max = row_size.to_f / parent_size.to_f - total = row_max - - prev_aspect = aspect_ratio(bounds, first_child.size.to_f / row_size.to_f, total, axis) - row = [first_child] - - node.children[1 .. node.children.size-1].each do |c| - child_prop = c.size.to_f / parent_size.to_f - aspect = aspect_ratio(bounds, c.size.to_f / row_size.to_f, total + child_prop, axis) - - if(aspect > prev_aspect) - newb = bounds.clone - if(axis == Vertical) - newb.x2 = bounds.x1 + ((bounds.width * total)).round - else - newb.y2 = bounds.y1 + ((bounds.height * total)).round - end - - process_children(row, newb, flip(axis)) - - if(axis == Vertical) - bounds.x1 = newb.x2 - else - bounds.y1 = newb.y2 - end - - axis = flip(axis) - parent_size -= row_size - row_size = c.size - total = row_max = row_size.to_f / parent_size.to_f - prev_aspect = aspect_ratio(bounds, c.size.to_f / row_size.to_f, total, axis) - row = [c] - else - row_size += c.size - total += child_prop - prev_aspect = aspect - row.push(c) - end - end - - process_children(row, bounds, flip(axis)) - end - - def aspect_ratio(bounds, node_prop, row_prop, axis) - height = bounds.height * row_prop - width = bounds.width * node_prop - if(axis == Vertical) - width = bounds.width * row_prop - height = bounds.height * node_prop - end - - return 0 if width == 0 and height == 0 - - a = 0; - b = 0; - if(width > 0) - a = height.to_f / width.to_f - end - if(height > 0) - b = width.to_f / height.to_f - end - - ratio = [a, b].max - - ratio - end - - def axis(bounds) - # XXX experiment with switching - # axis = super(bounds) - # flip(axis) - end - - # XXX another way of computing the aspect ratio - def aspect_ratio_method2(bounds, max, proportion, axis) - - large = bounds.height - small = bounds.width - if(axis == Vertical) - large = bounds.width - small = bounds.height - end - - ratio = (large * proportion).to_f / ((small * max).to_f / proportion.to_f).to_f - - if(ratio < 1) - ratio = 1.to_f / ratio.to_f - end - - ratio - end -end |