All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scripts.views.sonar-sqale-sunburst-view.js Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
/*
 * Licensed to Marvelution under one or more contributor license 
 * agreements.  See the NOTICE file distributed with this work 
 * for additional information regarding copyright ownership.
 * Marvelution licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

AJS.$.namespace("AJS.sonar.views.sqale.sunburst");

AJS.sonar.views.sqale.sunburst.VIEW_NAME = "sqale.sunburst";

AJS.sonar.views.sqale.sunburst.METRICS = 'sqale_rating';

AJS.sonar.views.sqale.sunburst.DEPTH_OPTIONS = [{key: 1, name: 1}, {key: 2, name: 2}, {key: 3, name: 3}];

var labelType, useGradients, nativeTextSupport, animate;

(function() {
	var ua = navigator.userAgent,
		iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i),
		typeOfCanvas = typeof HTMLCanvasElement,
		nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'),
		textSupport = nativeCanvasSupport && (typeof document.createElement('canvas').getContext('2d').fillText == 'function');
	labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native': 'HTML';
	nativeTextSupport = labelType == 'Native';
	useGradients = nativeCanvasSupport;
	animate = !(iStuff || !nativeCanvasSupport);
})();

/**
 * Generate the Sonar Sunburst view.
 * Using this method, the Sunburst will have the dimensions of the <body/> for the width and height of the Sunburst.
 * 
 * @see AJS.sonar.views.treemap.generateViewDetailed
 * 
 * @param baseUrl the base url of the system displaying the view
 * @param server the Sonar server object
 * @param measureData the measure data of a project on Sonar
 * @param metricsDetails the details of the coverage measures
 * @return the jQuery wrapped view object
 */
AJS.sonar.views.sqale.sunburst.generateView = function(baseUrl, server, measureData, metricsDetails) {
	var bodyTag = AJS.$("body");
	var dimensions = {width: (bodyTag.width() - 20), height: (bodyTag.width() - 20)};
	return AJS.sonar.views.sqale.sunburst.generateViewDetaile(baseUrl, server, measureData, 3, dimensions, null);
}

/**
 * Generate the Sonar SQALE Sunburst view
 * 
 * @param baseUrl the base url of the system displaying the view
 * @param server the Sonar server object
 * @param measureData the measure data of a project on Sonar
 * @param dimensions the dimensions to create the sunburst in
 * @param onChangeCallback the onChange function to call when the depth setting is changed
 * @return the jQuery wrapped view object
 */
AJS.sonar.views.sqale.sunburst.generateViewDetaile = function(baseUrl, server, measureData, depth, dimensions, onChangeCallback) {
	AJS.sonar.text.load(baseUrl);
	var view = AJS.sonar.views.createViewContainer();
	var header = AJS.$("
").addClass("sunburst-header"); view.append(header); var sunburstContainer = AJS.$("
").attr({id: "sonarSunburst"}); view.append(sunburstContainer); AJS.$("
").addClass("sunburst-tip-title").text(node.data.n)); if ("$angularWidth" in node.data) { AJS.$(tip).append(AJS.format(AJS.sonar.text.getMsg("sonar.views.sqale.sunburst.cost.tip"), node.data.$angularWidth)); } } }, Events: { enable: true, onClick: function(node) { if (!node) return; var href = server.host + "/drilldown/"; if ("r" in node.data) { href += "violations/" + resourceKey + "?rule=" + node.data.r; } else { href += "measures/" + resourceKey + "?metric=sqale_index&model=SQALE&characteristic_id=" + node.id; } if (window.parent) { window.parent.location.href = href; } else { window.location.href = href; } } }, onCreateLabel: function(domElement, node) { var labels = sb.config.Label.type, aw = node.getData("angularWidth"); if (labels === "HTML" && (node._depth < 2 || aw > 2000)) { domElement.innerHTML = node.name; } else if (labels === "SVG" && (node._depth < 2 || aw > 2000)) { domElement.firstChild.appendChild(document.createTextNode(node.name)); } }, onPlaceLabel: function(domElement, node) { var labels = sb.config.Label.type; if (labels === "SVG") { var fch = domElement.firstChild; var style = fch.style; style.display = ""; style.cursor = "pointer"; style.fontSize = "0.8em"; fch.setAttribute("fill", "#fff"); } else if (labels === "HTML") { var style = domElement.style; style.display = ""; style.cursor = "pointer"; style.fontSize = "0.8em"; style.color = "#ddd"; var left = parseInt(style.left); var w = domElement.offsetWidth; style.left = (left - w / 2) + "px"; } } }); sb.loadJSON(json); sb.refresh(); AJS.$("#sunburst-loading").hide(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy