diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-11-04 16:33:54 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2016-11-09 15:45:51 +0100 |
commit | 26f5f414b64fd9d3963c859da7c8f14616ddb759 (patch) | |
tree | 196580a94df922b817f8ec2dcf75552418597f53 /server/sonar-web/src/main/js | |
parent | 3e176399718337e77e365461397628636c1e38a0 (diff) | |
download | sonarqube-26f5f414b64fd9d3963c859da7c8f14616ddb759.tar.gz sonarqube-26f5f414b64fd9d3963c859da7c8f14616ddb759.zip |
delete widgets/ and dashboard/
Diffstat (limited to 'server/sonar-web/src/main/js')
22 files changed, 0 insertions, 3421 deletions
diff --git a/server/sonar-web/src/main/js/apps/dashboard/app.js b/server/sonar-web/src/main/js/apps/dashboard/app.js deleted file mode 100644 index 2ad7df40aa0..00000000000 --- a/server/sonar-web/src/main/js/apps/dashboard/app.js +++ /dev/null @@ -1,148 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import $ from 'jquery'; -import _ from 'underscore'; - -window.Portal = function (options) { - this.initialize(options); -}; - -window.Portal.prototype = { - - initialize (options) { - this.options = options; - if (!this.options.editorEnabled) { - return; - } - this.createAllSortables(); - this.lastSaveString = ''; - this.saveDashboardsState(); - }, - - createAllSortables () { - const that = this; - const blocks = $('.' + this.options.block); - const columnHandle = $('.' + this.options.columnHandle); - let draggable; - const onDragLeave = function (e) { - $(e.currentTarget).removeClass(that.options.hoverClass); - }; - const onDrop = function (e) { - e.preventDefault(); - draggable.detach().insertBefore($(e.currentTarget)); - onDragLeave(e); - that.saveDashboardsState(); - }; - - blocks - .prop('draggable', true) - .on('selectstart', function () { - this.dragDrop(); - return false; - }) - .on('dragstart', function (e) { - e.originalEvent.dataTransfer.setData('Text', 'drag'); - draggable = $(this); - columnHandle.show(); - }) - .on('dragover', function (e) { - if (draggable.prop('id') !== $(this).prop('id')) { - e.preventDefault(); - $(e.currentTarget).addClass(that.options.hoverClass); - } - }) - .on('drop', onDrop) - .on('dragleave', onDragLeave); - - columnHandle - .on('dragover', function (e) { - e.preventDefault(); - $(e.currentTarget).addClass(that.options.hoverClass); - }) - .on('drop', onDrop) - .on('dragleave', onDragLeave); - }, - - highlightWidget (widgetId) { - const block = $('#block_' + widgetId); - const options = this.options; - block.css('background-color', options.highlightStartColor); - setTimeout(function () { - block.css('background-color', options.highlightEndColor); - }, this.options.highlightDuration); - }, - - saveDashboardsState () { - const options = this.options; - const result = $('.' + this.options.column).map(function () { - const blocks = $(this).find('.' + options.block); - $(this).find('.' + options.columnHandle).toggle(blocks.length === 0); - - return blocks.map(function () { - return $(this).prop('id').substring(options.block.length + 1); - }).get().join(','); - }).get().join(';'); - - if (result === this.lastSaveString) { - return; - } - - const firstTime = this.lastSaveString === ''; - this.lastSaveString = result; - - if (firstTime) { - return; - } - - if (this.options.saveUrl) { - const postBody = this.options.dashboardState + '=' + encodeURIComponent(result); - - $.ajax({ - url: this.options.saveUrl, - type: 'POST', - data: postBody - }); - } - }, - - editWidget (widgetId) { - $('#widget_title_' + widgetId).hide(); - $('#widget_' + widgetId).hide(); - $('#widget_props_' + widgetId).show(); - $($(`#block_${widgetId} a.link-action`)[0]).hide(); - }, - - cancelEditWidget (widgetId) { - $('widget_title_' + widgetId).show(); - $('#widget_' + widgetId).show(); - $('#widget_props_' + widgetId).hide(); - $($(`#block_${widgetId} a.link-action`)[0]).show(); - }, - - deleteWidget (element) { - $(element).closest('.' + this.options.block).remove(); - this.saveDashboardsState(); - } -}; - -window.autoResize = function (everyMs, callback) { - const debounce = _.debounce(callback, everyMs); - $(window).on('resize', debounce); -}; diff --git a/server/sonar-web/src/main/js/widgets/complexity/index.js b/server/sonar-web/src/main/js/widgets/complexity/index.js deleted file mode 100644 index ffa5a9fd551..00000000000 --- a/server/sonar-web/src/main/js/widgets/complexity/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { render } from 'react-dom'; -import { translate } from '../../helpers/l10n'; -import { ComplexityDistribution } from '../../components/shared/complexity-distribution'; - -const Widget = ({ value, of }) => { - return ( - <div> - <span className="widget-label"> - {translate(`metric.${of}_complexity_distribution.name`)} - </span> - <ComplexityDistribution distribution={value} of={of}/> - </div> - ); -}; - -function start ({ el, ...other }) { - window.sonarqube.appStarted.then(() => { - const element = document.querySelector(el); - render(<Widget {...other}/>, element); - }); -} - -export default function (options) { - if (options.value) { - document.addEventListener('DOMContentLoaded', () => start(options), false); - } -} diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/templates/_widget-issue-filter-limit.hbs b/server/sonar-web/src/main/js/widgets/issue-filter/templates/_widget-issue-filter-limit.hbs deleted file mode 100644 index 35f62858dd5..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/templates/_widget-issue-filter-limit.hbs +++ /dev/null @@ -1 +0,0 @@ -<div class="note text-center spacer-top">{{tp 'max_results_reached' maxResults}}</div> diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/templates/_widget-issue-filter-total.hbs b/server/sonar-web/src/main/js/widgets/issue-filter/templates/_widget-issue-filter-total.hbs deleted file mode 100644 index 376ea5611de..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/templates/_widget-issue-filter-total.hbs +++ /dev/null @@ -1,13 +0,0 @@ -<tr> - <td> - <a href="{{issueFilterTotalLink parsedQuery displayMode}}"><strong>{{t 'total'}}</strong></a> - </td> - <td class="text-right nowrap"> - <strong>{{#notNull periodDate}}+{{/notNull}}{{issueFilterValue total displayMode}}</strong> - </td> - <td class="barchart"> - <div class="barchart" style="width: 100%;"> - <div style="width: 100%;"></div> - </div> - </td> -</tr> diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-assignees.hbs b/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-assignees.hbs deleted file mode 100644 index edf58907336..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-assignees.hbs +++ /dev/null @@ -1,26 +0,0 @@ -<table class="data condensed zebra"> - {{> '_widget-issue-filter-total'}} - {{#each items}} - <tr> - <td> - {{#eq val ''}} - <a href="{{issueFilterItemLink ../../parsedQuery 'assigned' 'false' ../../displayMode}}">{{t 'unassigned'}}</a> - {{else}} - <a href="{{issueFilterItemLink ../../parsedQuery 'assignees' val ../../displayMode}}">{{default label val}}</a> - {{/eq}} - </td> - <td class="text-right nowrap"> - {{#notNull ../periodDate}}+{{/notNull}}{{issueFilterValue count ../displayMode}} - </td> - <td class="barchart"> - <div class="barchart" style="width: 100%;"> - <div style="width: {{percent count ../total}};"></div> - </div> - </td> - </tr> - {{/each}} -</table> - -{{#if maxResultsReached}} - {{> '_widget-issue-filter-limit'}} -{{/if}} diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-resolutions.hbs b/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-resolutions.hbs deleted file mode 100644 index 8ba317c707e..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-resolutions.hbs +++ /dev/null @@ -1,26 +0,0 @@ -<table class="data condensed zebra"> - {{> '_widget-issue-filter-total'}} - {{#each items}} - <tr> - <td> - {{#eq val ''}} - <a href="{{issueFilterItemLink ../../parsedQuery 'resolved' 'false' ../../displayMode}}">{{t 'unresolved'}}</a> - {{else}} - <a href="{{issueFilterItemLink ../../parsedQuery 'resolutions' val ../../displayMode}}">{{t 'issue.resolution' val}}</a> - {{/eq}} - </td> - <td class="text-right nowrap"> - {{#notNull ../periodDate}}+{{/notNull}}{{issueFilterValue count ../displayMode}} - </td> - <td class="barchart"> - <div class="barchart" style="width: 100%;"> - <div style="width: {{percent count ../total}};"></div> - </div> - </td> - </tr> - {{/each}} -</table> - -{{#if maxResultsReached}} - {{> '_widget-issue-filter-limit'}} -{{/if}} diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-severities.hbs b/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-severities.hbs deleted file mode 100644 index 04b5dc74ec0..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-severities.hbs +++ /dev/null @@ -1,23 +0,0 @@ -<table class="data condensed zebra"> - <tr> - <td> - <a href="{{issueFilterTotalLink parsedQuery displayMode}}"><strong>{{t 'total'}}</strong></a> - </td> - <td class="text-right"><strong>{{#notNull periodDate}}+{{/notNull}}{{issueFilterValue total displayMode}}</strong></td> - </tr> - {{#each items}} - <tr> - <td> - {{severityIcon val}} - <a href="{{issueFilterItemLink ../parsedQuery ../property val ../displayMode}}">{{t 'severity' val}}</a> - </td> - <td class="text-right nowrap"> - {{#notNull ../periodDate}}+{{/notNull}}{{issueFilterValue count ../displayMode}} - </td> - </tr> - {{/each}} -</table> - -{{#if maxResultsReached}} - {{> '_widget-issue-filter-limit'}} -{{/if}} diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-statuses.hbs b/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-statuses.hbs deleted file mode 100644 index 3c00b9a7999..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter-statuses.hbs +++ /dev/null @@ -1,23 +0,0 @@ -<table class="data condensed zebra"> - {{> '_widget-issue-filter-total'}} - {{#each items}} - <tr> - <td> - {{statusIcon val}} - <a href="{{issueFilterItemLink ../parsedQuery ../property val ../displayMode}}">{{t 'issue.status' val}}</a> - </td> - <td class="text-right nowrap"> - {{#notNull ../periodDate}}+{{/notNull}}{{issueFilterValue count ../displayMode}} - </td> - <td class="barchart"> - <div class="barchart" style="width: 100%;"> - <div style="width: {{percent count ../total}};"></div> - </div> - </td> - </tr> - {{/each}} -</table> - -{{#if maxResultsReached}} - {{> '_widget-issue-filter-limit'}} -{{/if}} diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter.hbs b/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter.hbs deleted file mode 100644 index 44c160cd3a1..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/templates/widget-issue-filter.hbs +++ /dev/null @@ -1,22 +0,0 @@ -<table class="data condensed zebra"> - {{> '_widget-issue-filter-total'}} - {{#each items}} - <tr> - <td> - <a href="{{searchLink}}">{{default label val}}</a> - </td> - <td class="text-right nowrap"> - {{#notNull ../periodDate}}+{{/notNull}}{{issueFilterValue count ../displayMode}} - </td> - <td class="barchart"> - <div class="barchart" style="width: 100%;"> - <div style="width: {{percent count ../total}};"></div> - </div> - </td> - </tr> - {{/each}} -</table> - -{{#if maxResultsReached}} - {{> '_widget-issue-filter-limit'}} -{{/if}} diff --git a/server/sonar-web/src/main/js/widgets/issue-filter/widget.js b/server/sonar-web/src/main/js/widgets/issue-filter/widget.js deleted file mode 100644 index 0b135064a3f..00000000000 --- a/server/sonar-web/src/main/js/widgets/issue-filter/widget.js +++ /dev/null @@ -1,319 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import $ from 'jquery'; -import _ from 'underscore'; -import moment from 'moment'; -import Backbone from 'backbone'; -import Marionette from 'backbone.marionette'; - -import Template from './templates/widget-issue-filter.hbs'; -import AssigneesTemplate from './templates/widget-issue-filter-assignees.hbs'; -import ResolutionsTemplate from './templates/widget-issue-filter-resolutions.hbs'; -import SeveritiesTemplate from './templates/widget-issue-filter-severities.hbs'; -import StatusesTemplate from './templates/widget-issue-filter-statuses.hbs'; - -import { translate } from '../../helpers/l10n'; - -const FACET_LIMIT = 15; - -const defaultComparator = function (item) { - return -item.count; -}; - -const defaultFilter = function (item) { - const items = this.query[this.property]; - return items == null || items.split(',').indexOf(item.val) !== -1; -}; - -const defaultLabel = function (item) { - return item.val; -}; - -const defaultLink = function (item, property, query, index, items, mode) { - const criterion = {}; - criterion[property] = item.val; - const r = _.extend({}, query, criterion); - if (mode === 'effort') { - r.facetMode = 'effort'; - } - if (r.componentKey != null) { - return window.baseUrl + '/component_issues/index?id=' + encodeURIComponent(r.componentKey) + - '#' + getQuery(_.omit(r, 'componentKey')); - } else { - return window.baseUrl + '/issues/search#' + getQuery(r); - } -}; - -const byDistributionConf = { - 'types': { - comparator (item) { - const order = ['BUG', 'VULNERABILITY', 'CODE_SMELL']; - return order.indexOf(item.val); - }, - label (item) { - return translate('issue.type', item.val); - } - }, - 'severities': { - template: SeveritiesTemplate, - comparator (item) { - const order = ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO']; - return order.indexOf(item.val); - } - }, - 'statuses': { - template: StatusesTemplate, - comparator (item) { - const order = ['OPEN', 'REOPENED', 'CONFIRMED', 'RESOLVED', 'CLOSED']; - return order.indexOf(item.val); - }, - filter (item) { - const unresolvedQuery = '' + this.query.resolved === 'false'; - const resolvedStatus = item.val === 'RESOLVED' || item.val === 'CLOSED'; - return !(unresolvedQuery && resolvedStatus); - } - }, - 'resolutions': { - template: ResolutionsTemplate, - comparator (item) { - const order = ['', 'FALSE-POSITIVE', 'WONTFIX', 'FIXED', 'REMOVED']; - return order.indexOf(item.val); - }, - filter (item) { - if ('' + this.query.resolved === 'false') { - return item.val === ''; - } else { - return defaultFilter.call(this, item); - } - } - }, - 'rules': { - label (item, r) { - if (_.isArray(r.rules)) { - const rule = _.findWhere(r.rules, { key: item.val }); - if (rule != null) { - return rule.name; - } - } - } - }, - 'projectUuids': { - label (item, r) { - if (_.isArray(r.components)) { - const project = _.findWhere(r.components, { uuid: item.val }); - if (project != null) { - return project.name; - } - } - } - }, - 'assignees': { - template: AssigneesTemplate, - label (item, r) { - if (_.isArray(r.users)) { - const user = _.findWhere(r.users, { login: item.val }); - if (user != null) { - return user.name; - } - } - }, - filter (item) { - if ('' + this.query.assigned === 'false') { - return item.val === ''; - } else { - return defaultFilter.call(this, item); - } - } - }, - 'languages': { - label (item, r) { - if (_.isArray(r.languages)) { - const lang = _.findWhere(r.languages, { key: item.val }); - if (lang != null) { - return lang.name; - } - } - } - }, - 'createdAt': { - comparator (item) { - return -moment(item.val).unix(); - }, - label (item, r, items, index, query) { - const beginning = moment(item.val); - const endDate = query.createdBefore != null ? moment(query.createdBefore) : moment(); - const ending = index < items.length - 1 ? moment(items[index + 1].val).subtract(1, 'days') : endDate; - const isSameDay = ending.diff(beginning, 'days') <= 1; - return beginning.format('LL') + (isSameDay ? '' : (' – ' + ending.format('LL'))); - }, - link (item, property, query, index, items, mode) { - const createdAfter = moment(item.val); - const endDate = query.createdBefore != null ? moment(query.createdBefore) : moment(); - const createdBefore = index < items.length - 1 ? moment(items[index + 1].val).subtract(1, 'days') : endDate; - const isSameDay = createdBefore.diff(createdAfter, 'days') <= 1; - if (isSameDay) { - createdBefore.add(1, 'days'); - } - const r = _.extend({}, query, { - createdAfter: createdAfter.format('YYYY-MM-DD'), - createdBefore: createdBefore.format('YYYY-MM-DD') - }); - if (mode === 'effort') { - r.facetMode = 'effort'; - } - if (r.componentKey != null) { - return window.baseUrl + '/component_issues/index?id=' + encodeURIComponent(r.componentKey) + - '#' + getQuery(_.omit(r, 'componentKey')); - } else { - return window.baseUrl + '/issues/search#' + getQuery(r); - } - } - } -}; - -function getQuery (query, separator) { - separator = separator || '|'; - const route = []; - _.forEach(query, function (value, property) { - route.push(`${property}=${encodeURIComponent(value)}`); - }); - return route.join(separator); -} - -export default Marionette.ItemView.extend({ - - getTemplate () { - return this.conf != null && this.conf.template != null ? - this.conf.template : Template; - }, - - initialize () { - this.shouldIgnorePeriod = false; - this.model = new Backbone.Model({ - query: this.options.query, - parsedQuery: this.getParsedQuery(), - property: this.options.distributionAxis - }); - - // Ignore the period date if the filter contains any date criteria - // `this.shouldIgnorePeriod` is set in `this.getParsedQuery()` - if (!this.shouldIgnorePeriod) { - this.model.set({ periodDate: this.options.periodDate }); - } - - this.listenTo(this.model, 'change', this.render); - this.conf = byDistributionConf[this.options.distributionAxis]; - this.query = this.getParsedQuery(); - this.requestIssues(); - }, - - getParsedQuery () { - const queryString = this.options.query || ''; - const query = {}; - queryString.split('|').forEach(function (criterionString) { - const criterion = criterionString.split('='); - if (criterion.length === 2) { - query[criterion[0]] = criterion[1]; - } - }); - if (this.options.componentKey != null) { - _.extend(query, { componentKey: this.options.componentKey }); - } - if (!this.hasDateFilter(query) && this.options.periodDate != null) { - _.extend(query, { createdAfter: this.options.periodDate }); - } else { - this.shouldIgnorePeriod = true; - } - return query; - }, - - hasDateFilter (query) { - const q = query || this.model.get('parsedQuery'); - return _.some(['createdAt', 'createdBefore', 'createdAfter', 'createdInLast'], function (p) { - return q[p] != null; - }); - }, - - sortItems (items) { - const comparator = this.conf != null && this.conf.comparator != null ? this.conf.comparator : defaultComparator; - return _.sortBy(items, comparator); - }, - - filterItems (items) { - const filter = this.conf != null && this.conf.filter != null ? this.conf.filter : defaultFilter; - return _.filter(items, filter, { query: this.query, property: this.options.distributionAxis }); - }, - - withLink (items) { - const link = this.conf != null && this.conf.link != null ? this.conf.link : defaultLink; - const property = this.options.distributionAxis; - const mode = this.options.displayMode; - const query = this.model.get('parsedQuery'); - return items.map(function (item, index) { - return _.extend(item, { searchLink: link(item, property, query, index, items, mode) }); - }); - }, - - withLabels (items) { - const label = this.conf != null && this.conf.label != null ? this.conf.label : defaultLabel; - const r = this.model.get('rawResponse'); - const query = this.model.get('parsedQuery'); - return items.map(function (item, index) { - return _.extend(item, { label: label(item, r, items, index, query) }); - }); - }, - - requestIssues () { - const that = this; - const facetMode = this.options.displayMode; - const url = window.baseUrl + '/api/issues/search'; - const options = _.extend({}, this.query, { - facetMode, - ps: 1, - facets: this.options.distributionAxis, - additionalFields: '_all' - }); - if (this.options.componentUuid != null) { - _.extend(options, { componentUuids: this.options.componentUuid }); - } - if (this.options.periodDate != null && !this.shouldIgnorePeriod) { - _.extend(options, { createdAfter: this.options.periodDate }); - } - return $.get(url, options).done(function (r) { - if (_.isArray(r.facets) && r.facets.length === 1) { - // save response object, but do not trigger repaint - that.model.set({ rawResponse: r }, { silent: true }); - const items = that.sortItems(that.withLabels(that.withLink(that.filterItems(r.facets[0].values)))); - that.model.set({ - items, - maxResultsReached: items.length >= FACET_LIMIT, - maxResults: items.length, - total: facetMode === 'effort' ? r.debtTotal : r.total - }); - } - }); - }, - - serializeData () { - return _.extend(Marionette.ItemView.prototype.serializeData.apply(this, arguments), { - displayMode: this.options.displayMode - }); - } -}); diff --git a/server/sonar-web/src/main/js/widgets/old/base.js b/server/sonar-web/src/main/js/widgets/old/base.js deleted file mode 100644 index df3b6294cf4..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/base.js +++ /dev/null @@ -1,115 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import _ from 'underscore'; - -(function () { - - if (window.SonarWidgets == null) { - window.SonarWidgets = {}; - } - - function BaseWidget () { - this.addField('components', []); - this.addField('metrics', []); - this.addField('metricsPriority', []); - this.addField('options', []); - } - - BaseWidget.prototype.lineHeight = 20; - BaseWidget.prototype.colors4 = ['#ee0000', '#f77700', '#80cc00', '#00aa00']; - BaseWidget.prototype.colors4r = ['#00aa00', '#80cc00', '#f77700', '#ee0000']; - BaseWidget.prototype.colors5 = ['#ee0000', '#f77700', '#ffee00', '#80cc00', '#00aa00']; - BaseWidget.prototype.colors5r = ['#00aa00', '#80cc00', '#ffee00', '#f77700', '#ee0000']; - BaseWidget.prototype.colorsLevel = ['#d4333f', '#ff9900', '#85bb43', '##b4b4b4']; - BaseWidget.prototype.colorUnknown = '#777'; - - BaseWidget.prototype.addField = function (name, defaultValue) { - const privateName = '_' + name; - this[privateName] = defaultValue; - this[name] = function (d) { - return this.param.call(this, privateName, d); - }; - return this; - }; - - BaseWidget.prototype.param = function (name, value) { - if (value == null) { - return this[name]; - } - this[name] = value; - return this; - }; - - BaseWidget.prototype.addMetric = function (property, index) { - const key = this.metricsPriority()[index]; - this[property] = _.extend(this.metrics()[key], { - key, - value (d) { - if (d.measures[key] != null) { - if (d.measures[key].text != null) { - return d.measures[key].text; - } else if (d.measures[key].data != null) { - return d.measures[key].data; - } else { - return d.measures[key].val; - } - } - }, - formattedValue (d) { - if (d.measures[key] != null) { - if (d.measures[key].text != null) { - return d.measures[key].text; - } else { - return d.measures[key].fval; - } - } - } - }); - return this; - }; - - BaseWidget.prototype.trans = function (left, top) { - return `translate(${left},${top})`; - }; - - BaseWidget.prototype.render = function (container) { - this.update(container); - return this; - }; - - BaseWidget.prototype.update = function () { - return this; - }; - - BaseWidget.prototype.tooltip = function (d) { - /* jshint nonbsp: false */ - let title = d.longName; - if (this.colorMetric && (this.colorMetric.value(d) != null)) { - title += '\n' + this.colorMetric.name + ': ' + (this.colorMetric.formattedValue(d)); - } - if (this.sizeMetric && (this.sizeMetric.value(d) != null)) { - title += '\n' + this.sizeMetric.name + ': ' + (this.sizeMetric.formattedValue(d)); - } - return title; - }; - - window.SonarWidgets.BaseWidget = BaseWidget; - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/bubble-chart.js b/server/sonar-web/src/main/js/widgets/old/bubble-chart.js deleted file mode 100644 index d133c5e964c..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/bubble-chart.js +++ /dev/null @@ -1,521 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - /* jscs:disable safeContextKeyword */ -import $ from 'jquery'; -import { collapsedDirFromPath, fileFromPath } from '../../helpers/path'; - -window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; - -(function () { - - window.SonarWidgets.BubbleChart = function () { - // Set default values - this._components = []; - this._metrics = []; - this._metricsPriority = []; - this._width = window.SonarWidgets.BubbleChart.defaults.width; - this._height = window.SonarWidgets.BubbleChart.defaults.height; - this._margin = window.SonarWidgets.BubbleChart.defaults.margin; - this._xLog = window.SonarWidgets.BubbleChart.defaults.xLog; - this._yLog = window.SonarWidgets.BubbleChart.defaults.yLog; - this._bubbleColor = window.SonarWidgets.BubbleChart.defaults.bubbleColor; - this._bubbleColorUndefined = window.SonarWidgets.BubbleChart.defaults.bubbleColorUndefined; - this._options = {}; - - // Export global variables - this.metrics = function (_) { - return param.call(this, '_metrics', _); - }; - - this.metricsPriority = function (_) { - return param.call(this, '_metricsPriority', _); - }; - - this.components = function (_) { - return param.call(this, '_components', _); - }; - - this.width = function (_) { - return param.call(this, '_width', _); - }; - - this.height = function (_) { - return param.call(this, '_height', _); - }; - - this.margin = function (_) { - return param.call(this, '_margin', _); - }; - - this.xLog = function (_) { - return param.call(this, '_xLog', _); - }; - - this.yLog = function (_) { - return param.call(this, '_yLog', _); - }; - - this.bubbleColor = function (_) { - return param.call(this, '_bubbleColor', _); - }; - - this.bubbleColorUndefined = function (_) { - return param.call(this, '_bubbleColorUndefined', _); - }; - - this.options = function (_) { - return param.call(this, '_options', _); - }; - }; - - window.SonarWidgets.BubbleChart.prototype.hasValidData = function () { - const widget = this; - let noInvalidEntry = true; - let atLeastOneValueOnX = false; - let atLeastOneValueOnY = false; - this.components().forEach(function (component) { - noInvalidEntry = noInvalidEntry && - !!component.measures[widget.metricsPriority()[0]] && - !!component.measures[widget.metricsPriority()[1]]; - atLeastOneValueOnX = atLeastOneValueOnX || - (component.measures[widget.metricsPriority()[0]] || {}).fval !== '-'; - atLeastOneValueOnY = atLeastOneValueOnY || - (component.measures[widget.metricsPriority()[1]] || {}).fval !== '-'; - }); - return !!noInvalidEntry && !!atLeastOneValueOnX && !!atLeastOneValueOnY; - }; - - window.SonarWidgets.BubbleChart.prototype.init = function (container) { - this.width(container.property('offsetWidth')); - - this.svg = container.append('svg') - .attr('class', 'sonar-d3'); - this.gWrap = this.svg.append('g'); - - this.gxAxis = this.gWrap.append('g'); - this.gyAxis = this.gWrap.append('g'); - - this.gGrid = this.gWrap.append('g'); - this.gxGrid = this.gGrid.append('g'); - this.gyGrid = this.gGrid.append('g'); - - this.plotWrap = this.gWrap.append('g'); - - this.infoWrap = this.gWrap.append('g'); - this.infoDate = this.infoWrap.append('text'); - - this.gWrap - .attr('transform', trans(this.margin().left, this.margin().top)); - }; - - window.SonarWidgets.BubbleChart.prototype.initMetrics = function () { - const widget = this; - - this.xMetric = this.metricsPriority()[0]; - this.getXMetric = function (d) { - return d.measures[widget.xMetric].val; - }; - - this.yMetric = this.metricsPriority()[1]; - this.getYMetric = function (d) { - return d.measures[widget.yMetric].val; - }; - - this.sizeMetric = this.metricsPriority()[2]; - this.getSizeMetric = function (d) { - return d.measures[widget.sizeMetric] ? d.measures[widget.sizeMetric].val : 0; - }; - }; - - window.SonarWidgets.BubbleChart.prototype.initScales = function () { - const widget = this; - this - .xLog(this.options().xLog) - .yLog(this.options().yLog); - - this.x = this.xLog() ? d3.scale.log() : d3.scale.linear(); - this.y = this.yLog() ? d3.scale.log() : d3.scale.linear(); - this.size = d3.scale.linear(); - - this.x.range([0, this.availableWidth]); - this.y.range([this.availableHeight, 0]); - this.size.range([5, 45]); - - if (this.components().length > 1) { - this.x.domain(d3.extent(this.components(), function (d) { - return widget.getXMetric(d); - })); - this.y.domain(d3.extent(this.components(), function (d) { - return widget.getYMetric(d); - })); - this.size.domain(d3.extent(this.components(), function (d) { - return widget.getSizeMetric(d); - })); - } else { - const singleComponent = this.components()[0]; - const xm = this.getXMetric(singleComponent); - const ym = this.getYMetric(singleComponent); - const sm = this.getSizeMetric(singleComponent); - this.x.domain([xm * 0.8, xm * 1.2]); - this.y.domain([ym * 0.8, ym * 1.2]); - this.size.domain([sm * 0.8, sm * 1.2]); - } - }; - - window.SonarWidgets.BubbleChart.prototype.initBubbles = function () { - const widget = this; - - // Create bubbles - this.items = this.plotWrap.selectAll('.item') - .data(this.components()); - - // Render bubbles - this.items.enter().append('g') - .attr('class', 'item') - .attr('name', function (d) { - return d.longName; - }) - .style('cursor', 'pointer') - .append('circle') - .attr('r', function (d) { - return widget.size(widget.getSizeMetric(d)); - }) - .style('fill', function () { - return widget.bubbleColor(); - }) - .style('fill-opacity', 0.2) - .style('stroke', function () { - return widget.bubbleColor(); - }) - .style('transition', 'all 0.2s ease') - - .attr('title', function (d) { - const xMetricName = widget.metrics()[widget.xMetric].name; - const yMetricName = widget.metrics()[widget.yMetric].name; - const sizeMetricName = widget.metrics()[widget.sizeMetric].name; - const xMetricValue = d.measures[widget.xMetric].fval; - const yMetricValue = d.measures[widget.yMetric].fval; - const sizeMetricValue = d.measures[widget.sizeMetric].fval; - - return '<div class="text-left">' + - collapsedDirFromPath(d.longName) + '<br>' + - fileFromPath(d.longName) + '<br>' + '<br>' + - xMetricName + ': ' + xMetricValue + '<br>' + - yMetricName + ': ' + yMetricValue + '<br>' + - sizeMetricName + ': ' + sizeMetricValue + - '</div>'; - }) - .attr('data-placement', 'bottom') - .attr('data-toggle', 'tooltip'); - - this.items.exit().remove(); - - this.items.sort(function (a, b) { - return widget.getSizeMetric(b) - widget.getSizeMetric(a); - }); - }; - - window.SonarWidgets.BubbleChart.prototype.initBubbleEvents = function () { - const widget = this; - this.items - .on('click', function (d) { - window.location = widget.options().baseUrl + '?id=' + encodeURIComponent(d.key); - }) - .on('mouseenter', function () { - d3.select(this).select('circle') - .style('fill-opacity', 0.8); - }) - .on('mouseleave', function () { - d3.select(this).select('circle') - .style('fill-opacity', 0.2); - }); - }; - - window.SonarWidgets.BubbleChart.prototype.initAxes = function () { - // X - this.xAxis = d3.svg.axis() - .scale(this.x) - .orient('bottom'); - - this.gxAxisLabel = this.gxAxis.append('text') - .text(this.metrics()[this.xMetric].name) - .style('font-weight', 'bold') - .style('text-anchor', 'middle'); - - // Y - this.yAxis = d3.svg.axis() - .scale(this.y) - .orient('left'); - - this.gyAxis.attr('transform', trans(60 - this.margin().left, 0)); - - this.gyAxisLabel = this.gyAxis.append('text') - .text(this.metrics()[this.yMetric].name) - .style('font-weight', 'bold') - .style('text-anchor', 'middle'); - }; - - window.SonarWidgets.BubbleChart.prototype.initGrid = function () { - this.gxGridLines = this.gxGrid.selectAll('line').data(this.x.ticks()).enter() - .append('line'); - - this.gyGridLines = this.gyGrid.selectAll('line').data(this.y.ticks()).enter() - .append('line'); - - this.gGrid.selectAll('line') - .style('stroke', '#000') - .style('stroke-opacity', 0.25); - }; - - window.SonarWidgets.BubbleChart.prototype.render = function (container) { - const containerS = container; - - container = d3.select(container); - - if (!this.hasValidData()) { - container.text(this.options().noMainMetric); - return; - } - - this.init(container); - this.initMetrics(); - this.initScales(); - this.initBubbles(); - this.initBubbleEvents(); - this.initAxes(); - this.initGrid(); - this.update(containerS); - - $('[data-toggle="tooltip"]').tooltip({ container: 'body', html: true }); - - return this; - }; - - window.SonarWidgets.BubbleChart.prototype.adjustScalesAfterUpdate = function () { - const widget = this; - - // X - const minX = d3.min(this.components(), function (d) { - return widget.x(widget.getXMetric(d)) - widget.size(widget.getSizeMetric(d)); - }); - const maxX = d3.max(this.components(), function (d) { - return widget.x(widget.getXMetric(d)) + widget.size(widget.getSizeMetric(d)); - }); - const dMinX = minX < 0 ? this.x.range()[0] - minX : this.x.range()[0]; - const dMaxX = maxX > this.x.range()[1] ? maxX - this.x.range()[1] : 0; - this.x.range([dMinX, this.availableWidth - dMaxX]); - - // Y - const minY = d3.min(this.components(), function (d) { - return widget.y(widget.getYMetric(d)) - widget.size(widget.getSizeMetric(d)); - }); - const maxY = d3.max(this.components(), function (d) { - return widget.y(widget.getYMetric(d)) + widget.size(widget.getSizeMetric(d)); - }); - const dMinY = minY < 0 ? this.y.range()[1] - minY : this.y.range()[1]; - const dMaxY = maxY > this.y.range()[0] ? maxY - this.y.range()[0] : 0; - this.y.range([this.availableHeight - dMaxY, dMinY]); - - // Format improvement for log scales - // X - if (this.xLog()) { - this.xAxis.tickFormat(function (d) { - const ticksCount = widget.availableWidth / 50; - return widget.x.tickFormat(ticksCount, d3.format(',d'))(d); - }); - } - - // Y - if (this.yLog()) { - this.yAxis.tickFormat(function (d) { - const ticksCount = widget.availableHeight / 30; - return widget.y.tickFormat(ticksCount, d3.format(',d'))(d); - }); - } - - // Make scale's domains nice - this.x.nice(); - this.y.nice(); - }; - - window.SonarWidgets.BubbleChart.prototype.updateScales = function () { - const widget = this; - this.x.range([0, this.availableWidth]); - this.y.range([this.availableHeight, 0]); - - if (this.components().length > 1) { - this.x.domain(d3.extent(this.components(), function (d) { - return widget.getXMetric(d); - })); - this.y.domain(d3.extent(this.components(), function (d) { - return widget.getYMetric(d); - })); - } else { - const singleComponent = this.components()[0]; - const xm = this.getXMetric(singleComponent); - const ym = this.getYMetric(singleComponent); - const sm = this.getSizeMetric(singleComponent); - this.x.domain([xm * 0.8, xm * 1.2]); - this.y.domain([ym * 0.8, ym * 1.2]); - this.size.domain([sm * 0.8, sm * 1.2]); - } - - if (this.x.domain()[0] === 0 && this.x.domain()[1] === 0) { - this.x.domain([0, 1]); - } - if (this.y.domain()[0] === 0 && this.y.domain()[1] === 0) { - this.y.domain([0, 1]); - } - - // Avoid zero values when using log scale - if (this.xLog) { - const xDomain = this.x.domain(); - this.x - .domain([xDomain[0] > 0 ? xDomain[0] : 0.1, xDomain[1]]) - .clamp(true); - } - - if (this.yLog) { - const yDomain = this.y.domain(); - this.y - .domain([yDomain[0] > 0 ? yDomain[0] : 0.1, yDomain[1]]) - .clamp(true); - } - }; - - window.SonarWidgets.BubbleChart.prototype.updateBubbles = function () { - const widget = this; - this.items - .transition() - .attr('transform', function (d) { - return trans(widget.x(widget.getXMetric(d)), widget.y(widget.getYMetric(d))); - }); - }; - - window.SonarWidgets.BubbleChart.prototype.updateAxes = function () { - // X - this.gxAxis.attr('transform', trans(0, this.availableHeight + this.margin().bottom - 40)); - - this.gxAxis.transition().call(this.xAxis); - - this.gxAxis.selectAll('path') - .style('fill', 'none') - .style('stroke', '#444'); - - this.gxAxis.selectAll('text') - .style('fill', '#444'); - - this.gxAxisLabel - .attr('transform', trans(this.availableWidth / 2, 35)); - - // Y - this.gyAxis.transition().call(this.yAxis); - - this.gyAxis.selectAll('path') - .style('fill', 'none') - .style('stroke', '#444'); - - this.gyAxis.selectAll('text') - .style('fill', '#444'); - - this.gyAxisLabel - .attr('transform', trans(-45, this.availableHeight / 2) + ' rotate(-90)'); - }; - - window.SonarWidgets.BubbleChart.prototype.updateGrid = function () { - const widget = this; - this.gxGridLines - .transition() - .attr({ - x1 (d) { - return widget.x(d); - }, - x2 (d) { - return widget.x(d); - }, - y1: widget.y.range()[0], - y2: widget.y.range()[1] - }); - - this.gyGridLines - .transition() - .attr({ - x1: widget.x.range()[0], - x2: widget.x.range()[1], - y1 (d) { - return widget.y(d); - }, - y2 (d) { - return widget.y(d); - } - }); - }; - - window.SonarWidgets.BubbleChart.prototype.update = function (container) { - container = d3.select(container); - - const width = container.property('offsetWidth'); - - this.width(width > 100 ? width : 100); - - // Update svg canvas - this.svg - .attr('width', this.width()) - .attr('height', this.height()); - - // Update available size - this.availableWidth = this.width() - this.margin().left - this.margin().right; - this.availableHeight = this.height() - this.margin().top - this.margin().bottom; - - this.updateScales(); - this.adjustScalesAfterUpdate(); - this.updateBubbles(); - this.updateAxes(); - this.updateGrid(); - }; - - window.SonarWidgets.BubbleChart.defaults = { - width: 350, - height: 150, - margin: { top: 10, right: 10, bottom: 50, left: 70 }, - xLog: false, - yLog: false, - bubbleColor: '#4b9fd5', - bubbleColorUndefined: '#b3b3b3' - }; - - // Some helper functions - - // Gets or sets parameter - function param (name, value) { - if (value == null) { - return this[name]; - } else { - this[name] = value; - return this; - } - } - - // Helper for create the translate(x, y) string - function trans (left, top) { - return 'translate(' + left + ', ' + top + ')'; - } - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/histogram.js b/server/sonar-web/src/main/js/widgets/old/histogram.js deleted file mode 100644 index 9829f8c2537..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/histogram.js +++ /dev/null @@ -1,183 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -(function () { - - function Histogram () { - window.SonarWidgets.BaseWidget.apply(this, arguments); - this.addField('width', 0); - this.addField('height', window.SonarWidgets.Histogram.defaults.height); - this.addField('margin', window.SonarWidgets.Histogram.defaults.margin); - this.addField('legendWidth', window.SonarWidgets.Histogram.defaults.legendWidth); - this.addField('maxResultsReached', false); - } - - Histogram.prototype = new window.SonarWidgets.BaseWidget(); - - Histogram.prototype.barHeight = 16; - - Histogram.prototype.barFill = '#1f77b4'; - - Histogram.prototype.isDataValid = function () { - const that = this; - return this.components().reduce(function (p, c) { - return p && !!c.measures[that.mainMetric.key]; - }, true); - }; - - Histogram.prototype.truncate = function (text, type) { - const maxLength = 40; - const n = text.length; - - switch (type) { - case 'FIL': - case 'CLA': - if (n > maxLength) { - const shortText = text.substr(n - maxLength + 2, n - 1); - const dotIndex = shortText.indexOf('.'); - return '...' + shortText.substr(dotIndex + 1); - } else { - return text; - } - default: - if (text.length > maxLength) { - return text.substr(0, maxLength - 3) + '...'; - } else { - return text; - } - } - }; - - Histogram.prototype.render = function (container) { - const box = d3.select(container); - this.addMetric('mainMetric', 0); - if (!this.isDataValid()) { - box.text(this.options().noMainMetric); - return; - } - this.width(box.property('offsetWidth')); - this.svg = box.append('svg').classed('sonar-d3', true); - this.gWrap = this.svg.append('g'); - this.gWrap.attr('transform', this.trans(this.margin().left, this.margin().top)); - this.plotWrap = this.gWrap.append('g').classed('plot', true); - this.x = d3.scale.linear(); - this.y = d3.scale.ordinal(); - this.metricLabel = this.gWrap.append('text').text(this.mainMetric.name); - this.metricLabel.attr('dy', '9px').style('font-size', '12px'); - if (this.maxResultsReached()) { - this.maxResultsReachedLabel = this.gWrap.append('text').classed('max-results-reached-message', true); - this.maxResultsReachedLabel.text(this.options().maxItemsReachedMessage); - } - return window.SonarWidgets.BaseWidget.prototype.render.apply(this, arguments); - }; - - Histogram.prototype.update = function (container) { - const that = this; - const box = d3.select(container); - this.width(box.property('offsetWidth')); - const availableWidth = this.width() - this.margin().left - this.margin().right - this.legendWidth(); - const availableHeight = this.barHeight * this.components().length + this.lineHeight; - let totalHeight = availableHeight + this.margin().top + this.margin().bottom; - if (this.maxResultsReached()) { - totalHeight += this.lineHeight; - } - this.height(totalHeight); - this.svg.attr('width', this.width()).attr('height', this.height()); - this.plotWrap.attr('transform', this.trans(0, this.lineHeight)); - let xDomain = d3.extent(this.components(), function (d) { - return that.mainMetric.value(d); - }); - if (!this.options().relativeScale) { - if (this.mainMetric.type === 'PERCENT') { - xDomain = [0, 100]; - } else { - xDomain[0] = 0; - } - } - this.x.domain(xDomain).range([0, availableWidth]); - this.y.domain(this.components().map(function (d, i) { - return i; - })).rangeRoundBands([0, availableHeight], 0); - this.bars = this.plotWrap.selectAll('.bar').data(this.components()); - this.barsEnter = this.bars.enter().append('g').classed('bar', true).attr('transform', function (d, i) { - return that.trans(0, i * that.barHeight); - }); - this.barsEnter.append('rect').style('fill', this.barFill); - this.barsEnter.append('text') - .classed('legend-text component', true) - .style('text-anchor', 'end') - .attr('dy', '-0.35em') - .text(function (d) { - return that.truncate(d.longName, d.qualifier); - }) - .attr('transform', function () { - return that.trans(that.legendWidth() - 10, that.barHeight); - }); - this.barsEnter.append('text') - .classed('legend-text value', true) - .attr('dy', '-0.35em') - .text(function (d) { - return that.mainMetric.formattedValue(d); - }) - .attr('transform', function (d) { - return that.trans(that.legendWidth() + that.x(that.mainMetric.value(d)) + 5, that.barHeight); - }); - this.bars.selectAll('rect') - .transition() - .attr('x', this.legendWidth()) - .attr('y', 0) - .attr('width', function (d) { - return Math.max(2, that.x(that.mainMetric.value(d))); - }) - .attr('height', this.barHeight); - this.bars.selectAll('.component') - .transition() - .attr('transform', function () { - return that.trans(that.legendWidth() - 10, that.barHeight); - }); - this.bars.selectAll('.value') - .transition() - .attr('transform', function (d) { - return that.trans(that.legendWidth() + that.x(that.mainMetric.value(d)) + 5, that.barHeight); - }); - this.bars.exit().remove(); - this.bars.on('click', function (d) { - window.location = that.options().baseUrl + '?id=' + encodeURIComponent(d.key); - }); - this.metricLabel.attr('transform', this.trans(this.legendWidth(), 0)); - if (this.maxResultsReached()) { - this.maxResultsReachedLabel.attr('transform', - this.trans(this.legendWidth(), this.height() - this.margin().bottom - 3)); - } - return window.SonarWidgets.BaseWidget.prototype.update.apply(this, arguments); - }; - - window.SonarWidgets.Histogram = Histogram; - window.SonarWidgets.Histogram.defaults = { - height: 300, - margin: { - top: 4, - right: 50, - bottom: 4, - left: 10 - }, - legendWidth: 220 - }; - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/pie-chart.js b/server/sonar-web/src/main/js/widgets/old/pie-chart.js deleted file mode 100644 index 82799623db2..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/pie-chart.js +++ /dev/null @@ -1,390 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -/*global d3:false */ -/*jshint eqnull:true */ -/* jscs:disable safeContextKeyword */ - -window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; - -(function () { - - window.SonarWidgets.PieChart = function () { - // Set default values - this._components = []; - this._metrics = []; - this._metricsPriority = []; - this._width = window.SonarWidgets.PieChart.defaults.width; - this._height = window.SonarWidgets.PieChart.defaults.height; - this._margin = window.SonarWidgets.PieChart.defaults.margin; - this._legendWidth = window.SonarWidgets.PieChart.defaults.legendWidth; - this._legendMargin = window.SonarWidgets.PieChart.defaults.legendMargin; - this._detailsWidth = window.SonarWidgets.PieChart.defaults.detailsWidth; - this._options = {}; - - this._lineHeight = 20; - - // Export global variables - this.metrics = function (_) { - return param.call(this, '_metrics', _); - }; - - this.metricsPriority = function (_) { - return param.call(this, '_metricsPriority', _); - }; - - this.components = function (_) { - return param.call(this, '_components', _); - }; - - this.width = function (_) { - return param.call(this, '_width', _); - }; - - this.height = function (_) { - return param.call(this, '_height', _); - }; - - this.margin = function (_) { - return param.call(this, '_margin', _); - }; - - this.legendWidth = function (_) { - return param.call(this, '_legendWidth', _); - }; - - this.legendMargin = function (_) { - return param.call(this, '_legendMargin', _); - }; - - this.detailsWidth = function (_) { - return param.call(this, '_detailsWidth', _); - }; - - this.options = function (_) { - return param.call(this, '_options', _); - }; - }; - - window.SonarWidgets.PieChart.prototype.render = function (container) { - const widget = this; - const containerS = container; - - container = d3.select(container); - - const validData = this.components().reduce(function (p, c) { - return p && !!c.measures[widget.metricsPriority()[0]]; - }, true); - - if (!validData) { - container.text(this.options().noMainMetric); - return; - } - - this.width(container.property('offsetWidth')); - - this.svg = container.append('svg') - .attr('class', 'sonar-d3'); - this.gWrap = this.svg.append('g'); - - this.plotWrap = this.gWrap.append('g') - .classed('plot', true); - - this.gWrap - .attr('transform', trans(this.margin().left, this.margin().top)); - - // Configure metrics - this.mainMetric = this.metricsPriority()[0]; - this.getMainMetric = function (d) { - return d.measures[widget.mainMetric].val; - }; - - // Configure scales - this.color = d3.scale.category10(); - - // Configure arc - this.arc = d3.svg.arc() - .innerRadius(0); - - // Configure pie - this.pie = d3.layout.pie() - .sort(null) - .value(function (d) { return widget.getMainMetric(d); }); - - // Configure legend - this.legendWrap = this.gWrap.append('g'); - - // Configure details - this._metricsCount = Object.keys(this.metrics()).length + 1; - this._detailsHeight = this._lineHeight * this._metricsCount; - - this.detailsWrap = this.gWrap.append('g') - .attr('width', this.legendWidth()) - .style('display', 'none'); - - this.detailsColorIndicator = this.detailsWrap.append('rect') - .classed('details-color-indicator', true) - .attr('transform', trans(-1, 0)) - .attr('x', 0) - .attr('y', 0) - .attr('width', 3) - .attr('height', this._detailsHeight) - .style('opacity', 0); - - this.donutLabel = this.plotWrap.append('text') - .style('text-anchor', 'middle') - .style('opacity', 0); - - this.donutLabel2 = this.plotWrap.append('text') - .style('text-anchor', 'middle') - .text(this.metrics()[this.mainMetric].name); - - // Update widget - this.update(containerS); - - return this; - }; - - window.SonarWidgets.PieChart.prototype.updateLegend = function () { - const widget = this; - this.legendWrap - .attr('transform', trans( - this.legendMargin() + 2 * this.radius, - (this.availableHeight - this._legendSize * this._lineHeight) / 2 - )); - - this.legends = this.legendWrap.selectAll('.legend') - .data(this.components().slice(0, this._legendSize)); - - this.legendsEnter = this.legends.enter() - .append('g') - .classed('legend pie-legend', true) - .attr('transform', function (d, i) { return trans(0, 10 + i * widget._lineHeight); }); - - this.legendsEnter.append('circle') - .attr('class', 'legend-bullet') - .attr('r', 4) - .style('fill', function (d, i) { return widget.color(i); }); - - this.legendsEnter.append('text') - .attr('class', 'legend-text') - .attr('dy', '0.1em') - .attr('transform', trans(10, 3)); - - this.legends.selectAll('text') - .text(function (d) { - return d.name.length > widget._legendSymbols ? d.name.substr(0, widget._legendSymbols) + '...' : d.name; - }); - }; - - window.SonarWidgets.PieChart.prototype.updateDetails = function () { - const widget = this; - this.detailsWrap - .attr('width', this.legendWidth()) - .attr('transform', trans( - this.legendMargin() + 2 * this.radius, this.radius - this._detailsHeight / 2 - )); - - this.donutLabel - .transition() - .style('font-size', (this.radius / 6) + 'px'); - - const fz = Math.min( - 12, - this.radius / 10, - 1.5 * this.radius / this.metrics()[this.mainMetric].name.length - ); - this.donutLabel2 - .attr('transform', trans(0, widget.radius / 6)) - .style('font-size', fz + 'px'); - }; - - window.SonarWidgets.PieChart.prototype.configureEvents = function () { - const widget = this; - const updateMetrics = function (metrics) { - widget.detailsMetrics = widget.detailsWrap.selectAll('.details-metric') - .data(metrics); - - widget.detailsMetrics.enter().append('text') - .classed('details-metric', true) - .classed('details-metric-main', function (d, i) { return i === 0; }) - .attr('transform', function (d, i) { return trans(10, i * widget._lineHeight); }) - .attr('dy', '1.2em'); - - widget.detailsMetrics - .text(function (d) { return d.name + (d.value ? ': ' + d.value : ''); }) - .style('opacity', 1); - - widget.detailsMetrics.exit().remove(); - }; - const enterHandler = function (sector, d, i, showDetails) { - if (showDetails) { - const metrics = widget.metricsPriority().map(function (m) { - return { - name: widget.metrics()[m].name, - value: (d.measures[m] ? d.measures[m].fval : '–') - }; - }); - metrics.unshift({ - name: (d.name.length > widget._legendSymbols ? d.name.substr(0, widget._legendSymbols) + '...' : d.name) - }); - updateMetrics(metrics); - - widget.legendWrap - .style('opacity', 0); - - widget.detailsColorIndicator - .style('opacity', 1) - .style('fill', widget.color(i)); - - widget.detailsWrap - .style('display', 'block'); - } - widget.donutLabel - .style('opacity', 1) - .text(d.measures[widget.mainMetric].fval); - widget.donutLabel - .style('opacity', 1); - widget.plotWrap - .classed('hover', true); - sector.classed('hover', true); - }; - const leaveHandler = function (sector) { - widget.legendWrap - .style('opacity', 1); - widget.detailsColorIndicator - .style('opacity', 0); - if (widget.detailsMetrics) { - widget.detailsMetrics - .style('opacity', 0); - } - widget.donutLabel - .style('opacity', 0) - .text(''); - widget.plotWrap - .classed('hover', false); - sector.classed('hover', false); - widget.detailsWrap - .style('display', 'none'); - }; - const clickHandler = function (d) { - window.location = widget.options().baseUrl + '?id=' + encodeURIComponent(d.key); - }; - - this.sectors - .on('mouseenter', function (d, i) { - return enterHandler(d3.select(this), d.data, i, true); - }) - .on('mouseleave', function () { - return leaveHandler(d3.select(this)); - }) - .on('click', function (d) { - return clickHandler(d.data); - }); - - this.legends - .on('mouseenter', function (d, i) { - return enterHandler(d3.select(widget.sectors[0][i]), d, i, false); - }) - .on('mouseleave', function (d, i) { - return leaveHandler(d3.select(widget.sectors[0][i])); - }) - .on('click', function (d) { - return clickHandler(d); - }); - }; - - window.SonarWidgets.PieChart.prototype.update = function (container) { - container = d3.select(container); - - const widget = this; - const width = container.property('offsetWidth'); - this.width(width > 100 ? width : 100); - - // Update svg canvas - this.svg - .attr('width', this.width()) - .attr('height', this.height()); - - // Update available size - this.availableWidth = this.width() - this.margin().left - this.margin().right - - this.legendWidth() - this.legendMargin(); - this.availableHeight = this.height() - this.margin().top - this.margin().bottom; - this.radius = Math.min(this.availableWidth, this.availableHeight) / 2; - this._legendSize = Math.floor(this.availableHeight / this._lineHeight); - this._legendSymbols = Math.floor((this.width() - this.margin().left - this.margin().right - - this.legendMargin() - 2 * this.radius) / 6.2); - - // Update plot - this.plotWrap - .attr('transform', trans(this.radius, this.radius)); - - // Update arc - this.arc - .innerRadius(this.radius / 2) - .outerRadius(this.radius); - - // Configure sectors - this.sectors = this.plotWrap.selectAll('.arc') - .data(this.pie(this.components())); - - this.sectors - .enter() - .append('path') - .classed('arc', true) - .style('fill', function (d, i) { return widget.color(i); }); - - this.sectors - .transition() - .attr('d', this.arc); - - this.sectors - .exit().remove(); - - this.updateLegend(); - this.updateDetails(); - this.configureEvents(); - }; - - window.SonarWidgets.PieChart.defaults = { - width: 350, - height: 300, - margin: { top: 10, right: 10, bottom: 10, left: 10 }, - legendWidth: 160, - legendMargin: 30 - }; - - // Some helper functions - - // Gets or sets parameter - function param (name, value) { - if (value == null) { - return this[name]; - } else { - this[name] = value; - return this; - } - } - - // Helper for create the translate(x, y) string - function trans (left, top) { - return 'translate(' + left + ', ' + top + ')'; - } - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/stack-area.js b/server/sonar-web/src/main/js/widgets/old/stack-area.js deleted file mode 100644 index c1de55441d9..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/stack-area.js +++ /dev/null @@ -1,381 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - /* jscs:disable safeContextKeyword */ -import moment from 'moment'; - -window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; - -(function () { - - window.SonarWidgets.StackArea = function (container) { - - // Ensure container is html id - if (container.indexOf('#') !== 0) { - container = '#' + container; - } - - this.container = d3.select(container); - - // Set default values - this._data = []; - this._metrics = []; - this._snapshots = []; - this._colors = []; - this._width = window.SonarWidgets.StackArea.defaults.width; - this._height = window.SonarWidgets.StackArea.defaults.height; - this._margin = window.SonarWidgets.StackArea.defaults.margin; - - // Export global variables - this.data = function (_) { - return param.call(this, '_data', _); - }; - - this.metrics = function (_) { - return param.call(this, '_metrics', _); - }; - - this.snapshots = function (_) { - return param.call(this, '_snapshots', _); - }; - - this.colors = function (_) { - return param.call(this, '_colors', _); - }; - - this.width = function (_) { - return param.call(this, '_width', _); - }; - - this.height = function (_) { - return param.call(this, '_height', _); - }; - - this.margin = function (_) { - return param.call(this, '_margin', _); - }; - - }; - - window.SonarWidgets.StackArea.prototype.initScales = function () { - const widget = this; - const colorsLength = widget.colors().length; - const timeDomain = this.data() - .map(function (_) { - return d3.extent(_, function (d) { - return d.x; - }); - }) - .reduce(function (p, c) { - return p.concat(c); - }, []); - - this.time = d3.time.scale().domain(d3.extent(timeDomain)); - - this.y = d3.scale.linear() - .domain([0, d3.max(this.stackDataTop, function (d) { - return d.y0 + d.y; - })]) - .nice(); - - this.color = function (i) { - return widget.colors()[i % colorsLength][0]; - }; - }; - - window.SonarWidgets.StackArea.prototype.initAxis = function () { - this.timeAxis = d3.svg.axis() - .scale(this.time) - .orient('bottom') - .ticks(5); - }; - - window.SonarWidgets.StackArea.prototype.initArea = function () { - const widget = this; - this.area = d3.svg.area() - .x(function (d) { return widget.time(d.x); }) - .y0(function (d) { return widget.y(d.y0); }) - .y1(function (d) { return widget.y(d.y0 + d.y); }); - - this.areaLine = d3.svg.line() - .x(function (d) { return widget.time(d.x); }) - .y(function (d) { return widget.y(d.y0 + d.y); }); - }; - - window.SonarWidgets.StackArea.prototype.initInfo = function () { - const widget = this; - this.infoWrap - .attr('class', 'info') - .attr('transform', trans(0, -60)); - - this.infoDate - .attr('class', 'info-text info-text-bold') - .attr('transform', trans(0, 0)); - - this.infoTotal - .attr('class', 'info-text info-text-small') - .attr('transform', trans(0, 18)); - - this.infoSnapshot - .attr('class', 'info-text info-text-small') - .attr('transform', trans(0, 54)); - - this.infoMetrics = []; - let prevX = 120; - this.metrics().forEach(function (d, i) { - const infoMetric = widget.infoWrap.append('g'); - - const infoMetricText = infoMetric.append('text') - .attr('class', 'info-text-small') - .attr('transform', trans(10, 0)) - .text(widget.metrics()[i]); - - infoMetric.append('circle') - .attr('transform', trans(0, -4)) - .attr('r', 4) - .style('fill', function () { return widget.color(i); }); - - // Align metric labels - infoMetric - .attr('transform', function () { - return trans(prevX, -1 + (i % 3) * 18); - }); - - widget.infoMetrics.push(infoMetric); - - if (i % 3 === 2) { - prevX += (infoMetricText.node().getComputedTextLength() + 70); - } - }); - }; - - window.SonarWidgets.StackArea.prototype.initEvents = function () { - const widget = this; - this.events = widget.snapshots() - .filter(function (d) { return d.e.length > 0; }); - - this.gevents = this.gWrap.append('g') - .attr('class', 'axis events') - .selectAll('.event-tick') - .data(this.events); - - this.gevents.enter().append('line') - .attr('class', 'event-tick') - .attr('y2', -8); - - this.selectSnapshot = function (cl) { - const dataX = widget.data()[0][cl].x; - const sx = widget.time(dataX); - let snapshotIndex = null; - let eventIndex = null; - - // Update scanner position - widget.scanner - .attr('x1', sx) - .attr('x2', sx); - - // Update metric labels - const metricsLines = widget.data().map(function (d, i) { - const value = d[cl].fy || d[cl].y; - return widget.metrics()[i] + ': ' + value; - }); - - metricsLines.forEach(function (d, i) { - widget.infoMetrics[i].select('text').text(d); - }); - - // Update snapshot info - this.snapshots().forEach(function (d, i) { - if (d.d - dataX === 0) { - snapshotIndex = i; - } - }); - - if (snapshotIndex != null) { - widget.infoSnapshot - .text(this.snapshots()[snapshotIndex].e.join(', ')); - } - - // Update info - widget.infoDate - .text(moment(widget.data()[0][cl].x).format('LL')); - - const snapshotValue = this.snapshots()[snapshotIndex].fy; - const totalValue = snapshotValue || (widget.stackDataTop[cl].y0 + widget.stackDataTop[cl].y); - widget.infoTotal - .text('Total: ' + totalValue); - - // Update event - this.events.forEach(function (d, i) { - if (d.d - dataX === 0) { - eventIndex = i; - } - }); - - widget.gevents.attr('y2', -8); - d3.select(widget.gevents[0][eventIndex]).attr('y2', -12); - }; - - // Set event listeners - this.svg.on('mousemove', function () { - const mx = d3.mouse(widget.plotWrap.node())[0]; - const cl = closest(widget.data()[0], mx, function (d) { return widget.time(d.x); }); - widget.selectSnapshot(cl); - }); - }; - - window.SonarWidgets.StackArea.prototype.render = function () { - this.svg = this.container.append('svg') - .attr('class', 'sonar-d3'); - - this.gWrap = this.svg.append('g'); - - this.gtimeAxis = this.gWrap.append('g') - .attr('class', 'axis x'); - - this.plotWrap = this.gWrap.append('g') - .attr('class', 'plot'); - - this.scanner = this.plotWrap.append('line'); - - this.infoWrap = this.gWrap.append('g'); - this.infoDate = this.infoWrap.append('text'); - this.infoSnapshot = this.infoWrap.append('text'); - this.infoTotal = this.infoWrap.append('text'); - - this.gWrap - .attr('transform', trans(this.margin().left, this.margin().top)); - - // Configure stack - this.stack = d3.layout.stack(); - this.stackData = this.stack(this.data()); - this.stackDataTop = this.stackData[this.stackData.length - 1]; - - this.initScales(); - this.initAxis(); - this.initArea(); - - // Configure scanner - this.scanner - .attr('class', 'scanner') - .attr('y1', 0); - - this.initInfo(); - this.initEvents(); - this.update(); - - return this; - }; - - window.SonarWidgets.StackArea.prototype.update = function () { - const widget = this; - const width = this.container.property('offsetWidth'); - - this.width(width > 100 ? width : 100); - - // Update svg canvas - this.svg - .attr('width', this.width()) - .attr('height', this.height()); - - // Update available size - this.availableWidth = this.width() - this.margin().left - this.margin().right; - this.availableHeight = this.height() - this.margin().top - this.margin().bottom; - - // Update scales - this.time.range([0, this.availableWidth]); - this.y.range([widget.availableHeight, 0]); - - // Update the axis - this.gtimeAxis.attr('transform', trans(0, this.availableHeight + this.margin().bottom - 30)); - this.gtimeAxis.transition().call(this.timeAxis); - - // Update area - this.garea = this.plotWrap.selectAll('.area') - .data(this.stackData) - .enter() - .insert('path', ':first-child') - .attr('class', 'area') - .attr('d', function (d) { return widget.area(d); }) - .style('fill', function (d, i) { return widget.color(i); }); - - this.gareaLine = this.plotWrap.selectAll('.area-line') - .data(this.stackData) - .enter() - .insert('path') - .attr('class', 'area-line') - .attr('d', function (d) { return widget.areaLine(d); }) - .style('fill', 'none') - .style('stroke', '#808080'); - - // Update scanner - this.scanner.attr('y2', this.availableHeight + 10); - - // Update events - this.gevents - .transition() - .attr('transform', function (d) { - return trans(widget.time(d.d), widget.availableHeight + 10); - }); - - // Select latest values if this it the first update - if (!this.firstUpdate) { - this.selectSnapshot(widget.data()[0].length - 1); - - this.firstUpdate = true; - } - - }; - - window.SonarWidgets.StackArea.defaults = { - width: 350, - height: 150, - margin: { top: 80, right: 10, bottom: 40, left: 40 } - }; - - // Some helper functions - - // Gets or sets parameter - function param (name, value) { - if (value == null) { - return this[name]; - } else { - this[name] = value; - return this; - } - } - - // Helper for create the translate(x, y) string - function trans (left, top) { - return 'translate(' + left + ', ' + top + ')'; - } - - // Helper for find the closest number in array - function closest (array, number, getter) { - let cl = null; - array.forEach(function (value, i) { - if (cl == null || - Math.abs(getter(value) - number) < Math.abs(getter(array[cl]) - number)) { - cl = i; - } - }); - return cl; - } - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/tag-cloud.js b/server/sonar-web/src/main/js/widgets/old/tag-cloud.js deleted file mode 100644 index 8a389ae6ba2..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/tag-cloud.js +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { translate } from '../../helpers/l10n'; - -(function () { - - function TagCloud () { - window.SonarWidgets.BaseWidget.apply(this, arguments); - this.addField('width', []); - this.addField('height', []); - this.addField('tags', []); - this.addField('maxResultsReached', false); - } - - TagCloud.prototype = new window.SonarWidgets.BaseWidget(); - - TagCloud.prototype.sizeHigh = 24; - - TagCloud.prototype.sizeLow = 10; - - TagCloud.prototype.renderWords = function () { - const that = this; - return window.sonarqube.appStarted.then(function () { - const words = that.wordContainer.selectAll('.cloud-word').data(that.tags()); - const wordsEnter = words.enter().append('a').classed('cloud-word', true); - wordsEnter.text(function (d) { - return d.key; - }); - wordsEnter.attr('href', function (d) { - let url = that.options().baseUrl + '|tags=' + d.key; - if (that.options().createdAfter) { - url += '|createdAfter=' + that.options().createdAfter; - } - return url; - }); - wordsEnter.attr('title', function (d) { - return that.tooltip(d); - }); - words.style('font-size', function (d) { - return that.size(d.value) + 'px'; - }); - return words.sort(function (a, b) { - if (a.key.toLowerCase() > b.key.toLowerCase()) { - return 1; - } else { - return -1; - } - }); - }); - }; - - TagCloud.prototype.render = function (container) { - const box = d3.select(container).append('div'); - box.classed('sonar-d3', true); - box.classed('cloud-widget', true); - this.wordContainer = box.append('div'); - const sizeDomain = d3.extent(this.tags(), function (d) { - return d.value; - }); - this.size = d3.scale.linear().domain(sizeDomain).range([this.sizeLow, this.sizeHigh]); - if (this.maxResultsReached()) { - const maxResultsReachedLabel = box.append('div').text(this.options().maxItemsReachedMessage); - maxResultsReachedLabel.classed('max-results-reached-message', true); - } - this.renderWords(); - return window.SonarWidgets.BaseWidget.prototype.render.apply(this, arguments); - }; - - TagCloud.prototype.tooltip = function (d) { - const suffixKey = d.value === 1 ? 'issue' : 'issues'; - const suffix = translate(suffixKey); - return (d.value + '\u00a0') + suffix; - }; - - TagCloud.prototype.parseSource = function (response) { - return this.tags(response.tags); - }; - - window.SonarWidgets.TagCloud = TagCloud; - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/timeline.js b/server/sonar-web/src/main/js/widgets/old/timeline.js deleted file mode 100644 index 654f2133a18..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/timeline.js +++ /dev/null @@ -1,395 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - /* jscs:disable safeContextKeyword */ -import moment from 'moment'; - -window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; - -(function () { - - window.SonarWidgets.Timeline = function (container) { - - // Ensure container is html id - if (container.indexOf('#') !== 0) { - container = '#' + container; - } - - this.container = d3.select(container); - - // Set default values - this._data = []; - this._metrics = []; - this._snapshots = []; - this._events = []; - this._width = window.SonarWidgets.Timeline.defaults.width; - this._height = window.SonarWidgets.Timeline.defaults.height; - this._margin = window.SonarWidgets.Timeline.defaults.margin; - - // Export global variables - this.data = function (_) { - return param.call(this, '_data', _); - }; - - this.metrics = function (_) { - return param.call(this, '_metrics', _); - }; - - this.snapshots = function (_) { - return param.call(this, '_snapshots', _); - }; - - this.events = function (_) { - return param.call(this, '_events', _); - }; - - this.width = function (_) { - return param.call(this, '_width', _); - }; - - this.height = function (_) { - return param.call(this, '_height', _); - }; - - this.margin = function (_) { - return param.call(this, '_margin', _); - }; - - }; - - window.SonarWidgets.Timeline.prototype.initScalesAndAxis = function () { - // Configure scales - const timeDomain = this.data() - .map(function (_) { - return d3.extent(_, function (d) { - return d.x; - }); - }) - .reduce(function (p, c) { - return p.concat(c); - }, []); - - this.time = d3.time.scale().domain(d3.extent(timeDomain)); - - this.y = this.data().map(function (_) { - return d3.scale.linear() - .domain(d3.extent(_, function (d) { return d.y; })); - }); - - this.color = d3.scale.category10(); - - // Configure the axis - this.timeAxis = d3.svg.axis() - .scale(this.time) - .orient('bottom') - .ticks(5); - }; - - window.SonarWidgets.Timeline.prototype.initEvents = function () { - const widget = this; - this.events(this.events().filter(function (event) { - return event.d >= widget.time.domain()[0]; - })); - - this.gevents = this.gWrap.append('g') - .attr('class', 'axis events') - .selectAll('.event-tick') - .data(this.events()); - - this.gevents.enter().append('line') - .attr('class', 'event-tick') - .attr('y2', -8); - - this.gevents.exit().remove(); - - this.selectSnapshot = function (cl) { - const sx = widget.time(widget.data()[0][cl].x); - - widget.markers.forEach(function (marker) { - marker.style('opacity', 0); - d3.select(marker[0][cl]).style('opacity', 1); - }); - - widget.scanner - .attr('x1', sx) - .attr('x2', sx); - - widget.infoDate - .text(moment(widget.data()[0][cl].x).format('LL')); - - const metricsLines = widget.data().map(function (d, i) { - return widget.metrics()[i] + ': ' + d[cl].yl; - }); - - metricsLines.forEach(function (d, i) { - widget.infoMetrics[i].select('text').text(d); - }); - - widget.gevents.attr('y2', -8); - widget.infoEvent.text(''); - widget.events().forEach(function (d, i) { - if (d.d - widget.data()[0][cl].x === 0) { - d3.select(widget.gevents[0][i]).attr('y2', -12); - - widget.infoEvent - .text(widget.events()[i].l - .map(function (e) { return e.n; }) - .join(', ')); - } - }); - }; - - // Set event listeners - this.svg.on('mousemove', function () { - const mx = d3.mouse(widget.plotWrap.node())[0]; - const cl = closest(widget.data()[0], mx, function (d) { return widget.time(d.x); }); - widget.selectSnapshot(cl); - }); - }; - - window.SonarWidgets.Timeline.prototype.render = function () { - const widget = this; - - this.svg = this.container.append('svg') - .attr('class', 'sonar-d3'); - - this.gWrap = this.svg.append('g'); - - this.gtimeAxis = this.gWrap.append('g') - .attr('class', 'axis x'); - - this.plotWrap = this.gWrap.append('g') - .attr('class', 'plot'); - - this.scanner = this.plotWrap.append('line'); - - this.infoWrap = this.gWrap.append('g') - .attr('class', 'info'); - - this.infoDate = this.infoWrap.append('text') - .attr('class', 'info-text info-text-bold'); - - this.infoEvent = this.infoWrap.append('text') - .attr('class', 'info-text info-text-small'); - - this.gWrap - .attr('transform', trans(this.margin().left, this.margin().top)); - - this.initScalesAndAxis(); - this.showLimitHistoryMessage(); - - // Configure lines and points - this.lines = []; - this.glines = []; - this.markers = []; - this.data().forEach(function (_, i) { - const line = d3.svg.line() - .x(function (d) { return widget.time(d.x); }) - .y(function (d) { return widget.y[i](d.y); }) - .interpolate('linear'); - - const gline = widget.plotWrap.append('path') - .attr('class', 'line') - .style('stroke', function () { return widget.color(i); }); - - widget.lines.push(line); - widget.glines.push(gline); - - const marker = widget.plotWrap.selectAll('.marker').data(_); - marker.enter().append('circle') - .attr('class', 'line-marker') - .attr('r', 3) - .style('stroke', function () { return widget.color(i); }); - marker.exit().remove(); - - widget.markers.push(marker); - }); - - // Configure scanner - this.scanner - .attr('class', 'scanner') - .attr('y1', 0); - - // Configure info - this.infoWrap - .attr('transform', trans(0, -30)); - - this.infoDate - .attr('transform', trans(0, 0)); - - this.infoMetrics = []; - this.metrics().forEach(function (d, i) { - const infoMetric = widget.infoWrap.append('g') - .attr('class', 'metric-legend') - .attr('transform', function () { return trans(110 + i * 150, -1); }); - - infoMetric.append('text') - .attr('class', 'info-text-small') - .attr('transform', trans(10, 0)); - - infoMetric.append('circle') - .attr('class', 'metric-legend-line') - .attr('transform', trans(0, -4)) - .attr('r', 4) - .style('fill', function () { return widget.color(i); }); - - widget.infoMetrics.push(infoMetric); - }); - - this.initEvents(); - this.update(); - - return this; - }; - - window.SonarWidgets.Timeline.prototype.showLimitHistoryMessage = function () { - const minEvent = d3.min(this.events(), function (d) { - return d.d; - }); - const minData = this.time.domain()[0]; - if (minEvent < minData) { - const maxResultsReachedLabel = this.container.append('div').text(this.limitedHistoricalData); - maxResultsReachedLabel.classed('max-results-reached-message', true); - } - }; - - window.SonarWidgets.Timeline.prototype.update = function () { - const widget = this; - const width = this.container.property('offsetWidth'); - - this.width(width > 100 ? width : 100); - - // Update svg canvas - this.svg - .attr('width', this.width()) - .attr('height', this.height()); - - // Update available width - this.availableWidth = this.width() - this.margin().left - this.margin().right; - - // Update metric lines - let metricY = -1; - this.infoMetrics.forEach(function (metric, i) { - let x = 120 + i * 170; - const x2 = x + 170; - - if (x2 > widget.availableWidth) { - metricY += 18; - x = 120; - } - - metric - .transition() - .attr('transform', function () { return trans(x, metricY); }); - }); - - if (metricY > -1) { - metricY += 17; - } - - // Update available width - this.availableHeight = this.height() - this.margin().top - this.margin().bottom - metricY; - - // Update scales - this.time - .range([0, this.availableWidth]); - - this.y.forEach(function (scale) { - scale.range([widget.availableHeight, 0]); - }); - - // Update plot - this.plotWrap - .transition() - .attr('transform', trans(0, metricY)); - - // Update the axis - this.gtimeAxis.attr('transform', trans(0, this.availableHeight + this.margin().bottom - 30 + metricY)); - - this.gtimeAxis.transition().call(this.timeAxis); - - // Update lines and points - this.data().forEach(function (_, i) { - widget.glines[i] - .transition() - .attr('d', widget.lines[i](_)); - - widget.markers[i] - .data(_) - .transition() - .attr('transform', function (d) { return trans(widget.time(d.x), widget.y[i](d.y)); }); - }); - - // Update scanner - this.scanner - .attr('y2', this.availableHeight + 10); - - // Update events - this.infoEvent - .attr('transform', trans(0, metricY > -1 ? metricY : 18)); - - this.gevents - .transition() - .attr('transform', function (d) { return trans(widget.time(d.d), widget.availableHeight + 10 + metricY); }); - - // Select latest values if this it the first update - if (!this.firstUpdate) { - this.selectSnapshot(widget.data()[0].length - 1); - - this.firstUpdate = true; - } - - }; - - window.SonarWidgets.Timeline.defaults = { - width: 350, - height: 150, - margin: { top: 50, right: 10, bottom: 40, left: 10 } - }; - - // Some helper functions - - // Gets or sets parameter - function param (name, value) { - if (value == null) { - return this[name]; - } else { - this[name] = value; - return this; - } - } - - // Helper for create the translate(x, y) string - function trans (left, top) { - return 'translate(' + left + ', ' + top + ')'; - } - - // Helper for find the closest number in array - function closest (array, number, getter) { - let cl = null; - array.forEach(function (value, i) { - if (cl == null || - Math.abs(getter(value) - number) < Math.abs(getter(array[cl]) - number)) { - cl = i; - } - }); - return cl; - } - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/treemap.js b/server/sonar-web/src/main/js/widgets/old/treemap.js deleted file mode 100644 index 83224b2bbde..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/treemap.js +++ /dev/null @@ -1,368 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import _ from 'underscore'; - -import { translate } from '../../helpers/l10n'; -import { formatMeasure } from '../../helpers/measures'; -import { getChildren } from '../../api/components'; - -(function () { - - function Treemap () { - this.addField('width', null); - this.addField('height', null); - this.addField('maxResultsReached', false); - window.SonarWidgets.BaseWidget.apply(this, arguments); - } - - Treemap.prototype = new window.SonarWidgets.BaseWidget(); - - Treemap.prototype.sizeLow = 11; - - Treemap.prototype.sizeHigh = 18; - - Treemap.prototype.filterComponents = function () { - const that = this; - const components = this.components().filter(function (d) { - return that.sizeMetric.value(d) != null; - }); - this.components(components); - }; - - Treemap.prototype.getNodes = function () { - return this.treemap - .nodes({ children: this.components() }) - .filter(function (d) { - return !d.children; - }); - }; - - Treemap.prototype.renderTreemap = function () { - const that = this; - this.filterComponents(); - if (!this.components().length) { - this.maxResultsReachedLabel - .text(translate('treemap.all_measures_undefined')) - .style('display', 'block'); - return; - } - const nodes = this.getNodes(); - this.color = that.getColorScale(); - this.cells = this.box.selectAll('.treemap-cell').data(nodes); - this.cells.exit().remove(); - const cellsEnter = this.cells.enter().append('div'); - cellsEnter.classed('treemap-cell', true); - cellsEnter.append('div').classed('treemap-inner', true); - cellsEnter.append('a').classed('treemap-link', true); - this.cells.attr('title', function (d) { - return that.tooltip(d); - }); - this.cells.style('background-color', function (d) { - if (that.colorMetric.value(d) != null) { - return that.color(that.colorMetric.value(d)); - } else { - return that.colorUnknown; - } - }); - this.cells.classed('treemap-cell-drilldown', function (d) { - return (d.qualifier != null) && d.qualifier !== 'FIL' && d.qualifier !== 'CLA'; - }); - const prefix = this.mostCommonPrefix(_.pluck(this.components(), 'longName')); - const prefixLength = prefix.length; - this.cellsInner = this.box.selectAll('.treemap-inner').data(nodes); - this.cellsInner.html(function (d) { - if (prefixLength > 0) { - return prefix + '<br>' + (d.longName.substr(prefixLength)); - } else { - return d.longName; - } - }); - this.cellsLink = this.box.selectAll('.treemap-link').data(nodes); - this.cellsLink.html('<i class="icon-link"></i>'); - this.cellsLink.attr('href', function (d) { - return that.options().baseUrl + '?id=' + encodeURIComponent(d.key); - }); - this.attachEvents(cellsEnter); - return this.maxResultsReachedLabel.style('display', this.maxResultsReached() ? 'block' : 'none'); - }; - - Treemap.prototype.updateTreemap = function (components, maxResultsReached) { - this.components(components); - this.maxResultsReached(maxResultsReached); - this.renderTreemap(); - return this.positionCells(); - }; - - Treemap.prototype.attachEvents = function (cells) { - const that = this; - return cells.on('click', function (d) { - return that.requestChildren(d); - }); - }; - - Treemap.prototype.positionCells = function () { - const that = this; - this.cells.style('left', function (d) { - return d.x + 'px'; - }); - this.cells.style('top', function (d) { - return d.y + 'px'; - }); - this.cells.style('width', function (d) { - return d.dx + 'px'; - }); - this.cellsInner.style('max-width', function (d) { - return d.dx + 'px'; - }); - this.cells.style('height', function (d) { - return d.dy + 'px'; - }); - this.cells.style('line-height', function (d) { - return d.dy + 'px'; - }); - this.cells.style('font-size', function (d) { - return (that.size(d.dx / d.longName.length)) + 'px'; - }); - this.cellsLink.style('font-size', function (d) { - return (that.sizeLink(Math.min(d.dx, d.dy))) + 'px'; - }); - this.cells.classed('treemap-cell-small', function (d) { - return (d.dx / d.longName.length) < 1 || d.dy < 40; - }); - return this.cells.classed('treemap-cell-very-small', function (d) { - return d.dx < 24 || d.dy < 24; - }); - }; - - Treemap.prototype.renderLegend = function (box) { - this.legend = box.insert('div', ':first-child'); - this.legend.classed('legend', true); - this.legend.classed('legend-html', true); - this.legend.append('span') - .classed('legend-text', true) - .html('Size: <span class="legend-text-main">' + this.sizeMetric.name + '</span>'); - return this.legend.append('span') - .classed('legend-text', true) - .html('Color: <span class="legend-text-main">' + this.colorMetric.name + '</span>'); - }; - - Treemap.prototype.renderBreadcrumbs = function (box) { - this.breadcrumbsBox = box.append('div').classed('treemap-breadcrumbs', true); - this.breadcrumbs = []; - const d = { - name: '<i class="icon-home"></i>', - components: this.components(), - maxResultsReached: this.maxResultsReached() - }; - return this.addToBreadcrumbs(d); - }; - - Treemap.prototype.updateBreadcrumbs = function () { - const that = this; - const breadcrumbs = this.breadcrumbsBox.selectAll('.treemap-breadcrumbs-item').data(this.breadcrumbs); - breadcrumbs.exit().remove(); - const breadcrumbsEnter = breadcrumbs.enter().append('span').classed('treemap-breadcrumbs-item', true); - breadcrumbsEnter.attr('title', function (d) { - if (d.longName != null) { - return d.longName; - } else { - return that.options().resource; - } - }); - breadcrumbsEnter.append('i') - .classed('icon-chevron-right', true) - .style('display', function (d, i) { - if (i > 0) { - return 'inline'; - } else { - return 'none'; - } - }); - breadcrumbsEnter.append('i').attr('class', function (d) { - if (d.qualifier != null) { - return 'icon-qualifier-' + (d.qualifier.toLowerCase()); - } else { - return ''; - } - }); - const breadcrumbsEnterLinks = breadcrumbsEnter.append('a'); - breadcrumbsEnterLinks.html(function (d) { - return d.name; - }); - breadcrumbsEnterLinks.on('click', function (d) { - that.updateTreemap(d.components, d.maxResultsReached); - return that.cutBreadcrumbs(d); - }); - this.breadcrumbsBox.style('display', this.breadcrumbs.length < 2 ? 'none' : 'block'); - }; - - Treemap.prototype.addToBreadcrumbs = function (d) { - this.breadcrumbs.push(d); - this.updateBreadcrumbs(); - }; - - Treemap.prototype.cutBreadcrumbs = function (lastElement) { - let index = null; - this.breadcrumbs.forEach(function (d, i) { - if (d.key === lastElement.key) { - index = i; - } - }); - if (index != null) { - this.breadcrumbs = _.initial(this.breadcrumbs, this.breadcrumbs.length - index - 1); - this.updateBreadcrumbs(); - } - }; - - Treemap.prototype.getColorScale = function () { - if (this.colorMetric.type === 'LEVEL') { - return this.getLevelColorScale(); - } - if (this.colorMetric.type === 'RATING') { - return this.getRatingColorScale(); - } - return this.getPercentColorScale(); - }; - - Treemap.prototype.getPercentColorScale = function () { - const color = d3.scale.linear().domain([0, 25, 50, 75, 100]); - color.range(this.colorMetric.direction === 1 ? this.colors5 : this.colors5r); - return color; - }; - - Treemap.prototype.getRatingColorScale = function () { - let domain = [1, 2, 3, 4, 5]; - if (this.components().length > 0) { - const colorMetricSample = this.colorMetric.value(_.first(this.components())); - if (typeof colorMetricSample === 'string') { - domain = ['A', 'B', 'C', 'D', 'E']; - } - } - return d3.scale.ordinal().domain(domain).range(this.colors5r); - }; - - Treemap.prototype.getLevelColorScale = function () { - return d3.scale.ordinal().domain(['ERROR', 'WARN', 'OK', 'NONE']).range(this.colorsLevel); - }; - - Treemap.prototype.render = function (container) { - const that = this; - const box = d3.select(container).append('div'); - box.classed('sonar-d3', true); - this.box = box.append('div').classed('treemap-container', true); - this.addMetric('colorMetric', 0); - this.addMetric('sizeMetric', 1); - this.color = this.getColorScale(); - this.size = d3.scale.linear().domain([3, 15]).range([this.sizeLow, this.sizeHigh]).clamp(true); - this.sizeLink = d3.scale.linear().domain([60, 100]).range([12, 14]).clamp(true); - this.treemap = d3.layout.treemap(); - this.treemap.sort(function (a, b) { - return a.value - b.value; - }); - this.treemap.round(true); - this.treemap.value(function (d) { - return that.sizeMetric.value(d); - }); - this.maxResultsReachedLabel = box.append('div').text(this.options().maxItemsReachedMessage); - this.maxResultsReachedLabel.classed('max-results-reached-message', true); - this.renderLegend(box); - this.renderBreadcrumbs(box); - return window.SonarWidgets.BaseWidget.prototype.render.apply(this, arguments); - }; - - Treemap.prototype.update = function () { - this.width(this.box.property('offsetWidth')); - this.height(this.width() / 100.0 * this.options().heightInPercents); - if (this.components().length) { - this.box.style('height', (this.height()) + 'px'); - this.treemap.size([this.width(), this.height()]); - this.renderTreemap(); - this.positionCells(); - } - }; - - Treemap.prototype.formatComponents = function (components, metrics) { - const nextComponents = components - .filter(component => { - const sizeMeasure = component.measures.find(measure => measure.metric === this.sizeMetric.key); - return sizeMeasure != null; - }) - .map(component => { - const measures = component.measures.map(measure => { - const metric = metrics.find(metric => metric.key === measure.metric); - return { ...measure, metricType: metric.type }; - }); - return { ...component, measures }; - }); - - if (nextComponents.length > 0) { - return nextComponents.map(component => { - const measures = {}; - - component.measures.forEach(measure => { - measures[measure.metric] = { - val: measure.value, - fval: formatMeasure(measure.value, measure.metricType) - }; - }); - - return { - key: component.refKey != null ? component.refKey : component.key, - name: component.name, - longName: component.name, - qualifier: component.qualifier, - measures - }; - }); - } - }; - - Treemap.prototype.requestChildren = function (d) { - return getChildren(d.key, this.metricsPriority(), { additionalFields: 'metrics' }).then(r => { - let components = this.formatComponents(r.components, r.metrics); - if (components != null) { - components = _.sortBy(components, component => -this.sizeMetric.value(component)); - components = _.initial(components, components.length - this.options().maxItems - 1); - this.updateTreemap(components, components.length > this.options().maxItems); - this.addToBreadcrumbs(_.extend(d, { - components, - maxResultsReached: this.maxResultsReached() - })); - } - }); - }; - - Treemap.prototype.mostCommonPrefix = function (strings) { - const sortedStrings = strings.slice(0).sort(); - const firstString = sortedStrings[0]; - const firstStringLength = firstString.length; - const lastString = sortedStrings[sortedStrings.length - 1]; - let i = 0; - while (i < firstStringLength && firstString.charAt(i) === lastString.charAt(i)) { - i++; - } - const prefix = firstString.substr(0, i); - const lastPrefixPart = _.last(prefix.split(/[\s\\\/]/)); - return prefix.substr(0, prefix.length - lastPrefixPart.length); - }; - - window.SonarWidgets.Treemap = Treemap; - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/widget.js b/server/sonar-web/src/main/js/widgets/old/widget.js deleted file mode 100644 index 9d3dfb905b1..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/widget.js +++ /dev/null @@ -1,113 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -/*global d3:false, SonarWidgets:false */ -/*jshint eqnull:true */ - -window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets; - -(function () { - - window.SonarWidgets.Widget = function () { - // Set default values - this._type = null; - this._source = null; - this._metricsPriority = null; - this._height = null; - this._options = {}; - - // Export global variables - this.type = function (_) { - return param.call(this, '_type', _); - }; - - this.source = function (_) { - return param.call(this, '_source', _); - }; - - this.metricsPriority = function (_) { - return param.call(this, '_metricsPriority', _); - }; - - this.height = function (_) { - return param.call(this, '_height', _); - }; - - this.options = function (_) { - return param.call(this, '_options', _); - }; - }; - - window.SonarWidgets.Widget.prototype.render = function (container) { - const that = this; - - this.showSpinner(container); - d3.json(this.source(), function (error, response) { - if (response && !error) { - that.hideSpinner(); - if (typeof response.components === 'undefined' || response.components.length > 0) { - that.widget = new SonarWidgets[that.type()](); - that.widget.metricsPriority(that.metricsPriority()); - that.widget.options(that.options()); - that.widget.metrics(response.metrics); - that.widget.components(response.components); - if (typeof that.widget.parseSource === 'function') { - that.widget.parseSource(response); - } - if (typeof that.widget.maxResultsReached === 'function') { - that.widget.maxResultsReached(response.paging != null && response.paging.pages > 1); - } - if (that.height()) { - that.widget.height(that.height()); - } - that.widget.render(container); - } else { - d3.select(container).html(that.options().noData); - } - } - }); - }; - - window.SonarWidgets.Widget.prototype.showSpinner = function (container) { - this.spinner = d3.select(container).append('i').classed('spinner', true); - }; - - window.SonarWidgets.Widget.prototype.hideSpinner = function () { - if (this.spinner) { - this.spinner.remove(); - } - }; - - window.SonarWidgets.Widget.prototype.update = function (container) { - return this.widget && this.widget.update(container); - }; - - // Some helper functions - - // Gets or sets parameter - function param (name, value) { - if (value == null) { - return this[name]; - } else { - this[name] = value; - return this; - } - } - -})(); diff --git a/server/sonar-web/src/main/js/widgets/old/word-cloud.js b/server/sonar-web/src/main/js/widgets/old/word-cloud.js deleted file mode 100644 index b79d7feb664..00000000000 --- a/server/sonar-web/src/main/js/widgets/old/word-cloud.js +++ /dev/null @@ -1,104 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -(function () { - - function WordCloud () { - this.addField('width', []); - this.addField('height', []); - this.addField('maxResultsReached', false); - window.SonarWidgets.BaseWidget.apply(this, arguments); - } - - WordCloud.prototype = new window.SonarWidgets.BaseWidget(); - - WordCloud.prototype.sizeHigh = 24; - - WordCloud.prototype.sizeLow = 10; - - WordCloud.prototype.formatDirectory = function (path) { - const dirs = path.split('/'); - if (dirs.length > 2) { - return '.../' + dirs[dirs.length - 1]; - } else { - return path; - } - }; - - WordCloud.prototype.renderWords = function () { - const that = this; - const words = this.wordContainer.selectAll('.cloud-word').data(this.components()); - const wordsEnter = words.enter().append('a').classed('cloud-word', true); - wordsEnter.text(function (d) { - return d.qualifier === 'DIR' ? that.formatDirectory(d.name) : d.name; - }); - wordsEnter.attr('href', function (d) { - return that.options().baseUrl + '?id=' + encodeURIComponent(d.key); - }); - wordsEnter.attr('title', function (d) { - return that.tooltip(d); - }); - words.style('color', function (d) { - if (that.colorMetric.value(d) != null) { - return that.color(that.colorMetric.value(d)); - } else { - return that.colorUnknown; - } - }); - words.style('font-size', function (d) { - return (that.size(that.sizeMetric.value(d))) + 'px'; - }); - return words.sort(function (a, b) { - if (a.name.toLowerCase() > b.name.toLowerCase()) { - return 1; - } else { - return -1; - } - }); - }; - - WordCloud.prototype.render = function (container) { - const that = this; - const box = d3.select(container).append('div'); - box.classed('sonar-d3', true); - box.classed('cloud-widget', true); - this.wordContainer = box.append('div'); - this.addMetric('colorMetric', 0); - this.addMetric('sizeMetric', 1); - this.color = d3.scale.linear().domain([0, 33, 67, 100]); - if (this.colorMetric.direction === 1) { - this.color.range(this.colors4); - } else { - this.color.range(this.colors4r); - } - const sizeDomain = d3.extent(this.components(), function (d) { - return that.sizeMetric.value(d); - }); - this.size = d3.scale.linear().domain(sizeDomain).range([this.sizeLow, this.sizeHigh]); - if (this.maxResultsReached()) { - const maxResultsReachedLabel = box.append('div').text(this.options().maxItemsReachedMessage); - maxResultsReachedLabel.classed('max-results-reached-message', true); - } - this.renderWords(); - return window.SonarWidgets.BaseWidget.prototype.render.apply(this, arguments); - }; - - window.SonarWidgets.WordCloud = WordCloud; - -})(); diff --git a/server/sonar-web/src/main/js/widgets/timeMachine/index.js b/server/sonar-web/src/main/js/widgets/timeMachine/index.js deleted file mode 100644 index bd4e6b7191b..00000000000 --- a/server/sonar-web/src/main/js/widgets/timeMachine/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import moment from 'moment'; -import React from 'react'; -import { render } from 'react-dom'; -import d3 from 'd3'; - -import { LineChart } from '../../components/charts/line-chart'; - -const DEFAULTS = { - width: 80, - height: 15, - dateFormat: 'YYYYMMDDHHmmss' -}; - -export default function (selector) { - // use [].slice instead of Array.from, because this code might be executed with polyfill - const elements = [].slice.call(document.querySelectorAll(selector)); - - elements.forEach(element => { - const { dataset } = element; - const width = Number(dataset.width || DEFAULTS.width); - const height = Number(dataset.height || DEFAULTS.height); - - const { x, y } = dataset; - const xData = x.split(',').map(v => moment(v, DEFAULTS.dateFormat).toDate()); - const yData = y.split(',').map(v => Number(v)); - - const data = xData.map((x, index) => { - const y = yData[index]; - return { x, y }; - }); - - const domain = d3.extent(yData); - - render(( - <LineChart - data={data} - domain={domain} - width={width} - height={height} - padding={[1, 1, 1, 1]} - interpolate="linear" - displayBackdrop={false} - displayPoints={false} - displayVerticalGrid={false}/> - ), element); - }); -} diff --git a/server/sonar-web/src/main/js/widgets/widgets.js b/server/sonar-web/src/main/js/widgets/widgets.js deleted file mode 100644 index 157e7f718ec..00000000000 --- a/server/sonar-web/src/main/js/widgets/widgets.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import './old/base'; - -import './old/bubble-chart'; -import './old/histogram'; -import './old/pie-chart'; -import './old/stack-area'; -import './old/tag-cloud'; -import './old/timeline'; -import './old/treemap'; -import './old/word-cloud'; - -import './old/widget'; - -import IssueFilterWidget from './issue-filter/widget'; -import ComplexityDistribution from './complexity'; -import TimeMachine from './timeMachine'; - -window.IssueFilterWidget = IssueFilterWidget; -window.ComplexityDistribution = ComplexityDistribution; -window.TimeMachineWidget = TimeMachine; |