@WidgetProperties({
@WidgetProperty(key = MeasureFilterTreemapWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, optional = false),
@WidgetProperty(key = MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true),
- @WidgetProperty(key = MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true, options = "type:PERCENT")
+ @WidgetProperty(key = MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true, options = "type:PERCENT"),
+ @WidgetProperty(key = MeasureFilterTreemapWidget.HEIGHT_PERCENTS_PROPERTY, type = WidgetPropertyType.INTEGER, optional = true, defaultValue = "55", description = "Height in percents of width")
})
public class MeasureFilterTreemapWidget extends CoreWidget {
public static final String FILTER_PROPERTY = "filter";
public static final String SIZE_METRIC_PROPERTY = "sizeMetric";
public static final String COLOR_METRIC_PROPERTY = "colorMetric";
+ public static final String HEIGHT_PERCENTS_PROPERTY = "heightInPercents";
public static final String ID = "measure_filter_treemap";
public MeasureFilterTreemapWidget() {
import org.sonar.api.web.WidgetPropertyType;
@WidgetProperties({
- @WidgetProperty(key = "sizeMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.NCLOC_KEY, description = "Default metric for size"),
- @WidgetProperty(key = "colorMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.VIOLATIONS_DENSITY_KEY, description = "Default metric for color")
+ @WidgetProperty(key = "sizeMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.NCLOC_KEY, description = "Metric used for square size"),
+ @WidgetProperty(key = "colorMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.VIOLATIONS_DENSITY_KEY, description = "Metric used for square color"),
+ @WidgetProperty(key = "heightInPercents", type = WidgetPropertyType.INTEGER, optional = true, defaultValue = "55", description = "Height in percents of width")
})
public class TreemapWidget extends CoreWidget {
public TreemapWidget() {
filter.set_criteria_value(:tmColor, color_metric.key)
url_options[:tmColor]=color_metric.key
end
+ filter.set_criteria_value(:tmHeight, widget_properties['heightInPercents'])
+
if !filter.require_authentication? || logged_in?
filter.execute(self, :user => current_user)
color_metric = widget_properties['colorMetric']
filter = MeasureFilter.new
- filter.set_criteria_value('baseId', @resource.id)
- filter.set_criteria_value('display', 'treemap')
- filter.set_criteria_value('tmSize', size_metric.key) if size_metric
- filter.set_criteria_value('tmColor', color_metric.key) if color_metric
+ filter.set_criteria_value(:baseId, @resource.id)
+ filter.set_criteria_value(:display, 'treemap')
+ filter.set_criteria_value(:tmSize, size_metric.key) if size_metric
+ filter.set_criteria_value(:tmColor, color_metric.key) if color_metric
+ filter.set_criteria_value(:tmHeight, widget_properties['heightInPercents'])
filter.execute(self, :user => current_user)
%>
<%= render :partial => "measures/display_treemap", :locals => {:edit_mode => false, :widget => widget, :filter => filter} %>
KEY = :treemap
PROPERTY_KEYS = Set.new([:tmSize, :tmColor])
MAX_RESULTS = 1000
- attr_reader :id, :size, :size_metric, :color_metric
+ DEFAULT_HEIGHT_PERCENTS = 55
+ attr_reader :id, :size, :size_metric, :color_metric, :height_percents
def initialize(filter, options)
super(filter, options)
@size_metric = Metric.by_key(@filter.criteria(:tmSize)||'ncloc')
@color_metric = Metric.by_key(@filter.criteria(:tmColor)||'violations_density')
+ @height_percents = (@filter.criteria(:tmHeight) || DEFAULT_HEIGHT_PERCENTS).to_i
+ @height_percents = DEFAULT_HEIGHT_PERCENTS if @height_percents<=0
@filter.metrics=([@size_metric, @color_metric].compact)
@id_count = 0
<td class="right" valign="bottom">
<a href="#" class="button" id="exit-edit"><%= message 'close' -%></a>
<% if filter.owner?(current_user) %>
- <a id="save-columns" href="<%= url_for params.merge({:action => 'save_form', :id => filter.id}) -%>" class="button open-modal"><%= message('save_and_close') -%></a>
+ <a id="save-columns" href="<%= url_for params.merge({:action => 'save_form', :id => filter.id}) -%>" class="button open-modal"><%= message('measure_filter.close_and_save') -%></a>
<% end %>
</td>
</tr>
</div>
<script>
- new Treemap(<%= treemap_id -%>, '<%= filter.display.size_metric.key -%>', '<%= filter.display.color_metric ? filter.display.color_metric.key : '' -%>');
+ new Treemap(<%= treemap_id -%>, '<%= filter.display.size_metric.key -%>', '<%= filter.display.color_metric ? filter.display.color_metric.key : '' -%>', <%= filter.display.height_percents -%>);
</script>
<% end %>
\ No newline at end of file
* tm-bc-#{id} : required breadcrumb
* tm-loading-#{id} : optional loading icon
*/
-var Treemap = function (id, sizeMetric, colorMetric) {
+var Treemap = function (id, sizeMetric, colorMetric, heightPercents) {
this.id = id;
this.sizeMetric = sizeMetric;
this.colorMetric = colorMetric;
this.breadcrumb = [];
treemaps[id] = this;
- this.rootNode().height(this.rootNode().width() * 0.55);
+ this.rootNode().height(this.rootNode().width() * heightPercents / 100);
this.initNodes();
};