diff options
author | Paul Vorbach <paul@vorba.ch> | 2018-04-29 16:07:15 +0200 |
---|---|---|
committer | Paul Vorbach <paul@vorba.ch> | 2018-05-15 21:27:03 +0200 |
commit | e9fcaed3fed3e1dddae8a0f70503f49f4084c270 (patch) | |
tree | a7cb33cb7de9364fd5901504ab0333fe610f94f9 | |
parent | 2fc6c0d93fcfec1ae2bff504bfd2f8181e5fe3f6 (diff) | |
download | gitlab-ce-e9fcaed3fed3e1dddae8a0f70503f49f4084c270.tar.gz |
Refactor duplicate code
-rw-r--r-- | app/assets/javascripts/pages/projects/graphs/show/stat_graph_contributors_graph.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/app/assets/javascripts/pages/projects/graphs/show/stat_graph_contributors_graph.js b/app/assets/javascripts/pages/projects/graphs/show/stat_graph_contributors_graph.js index 9f73e099066..f3e6c371ead 100644 --- a/app/assets/javascripts/pages/projects/graphs/show/stat_graph_contributors_graph.js +++ b/app/assets/javascripts/pages/projects/graphs/show/stat_graph_contributors_graph.js @@ -13,8 +13,8 @@ import { dateTickFormat } from '~/lib/utils/tick_formats'; const d3 = { extent, max, select, scaleTime, scaleLinear, axisLeft, axisBottom, area, brushX, timeParse }; -const extend = function(child, parent) { for (const key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; const hasProp = {}.hasOwnProperty; +const extend = function(child, parent) { for (const key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; export const ContributorsGraph = (function() { function ContributorsGraph() {} @@ -32,6 +32,12 @@ export const ContributorsGraph = (function() { ContributorsGraph.prototype.dates = []; + ContributorsGraph.prototype.determine_width = function(baseWidth, $parentElement) { + const parentPaddingWidth = parseFloat($parentElement.css('padding-left')) + parseFloat($parentElement.css('padding-right')); + const marginWidth = this.MARGIN.left + this.MARGIN.right; + return baseWidth - parentPaddingWidth - marginWidth; + }; + ContributorsGraph.set_x_domain = function(data) { return ContributorsGraph.prototype.x_domain = data; }; @@ -105,11 +111,10 @@ export const ContributorsMasterGraph = (function(superClass) { function ContributorsMasterGraph(data1) { const $parentElement = $('#contributors-master'); - const parentPadding = parseFloat($parentElement.css('padding-left')) + parseFloat($parentElement.css('padding-right')); this.data = data1; this.update_content = this.update_content.bind(this); - this.width = $('.stat-graph').width() - parentPadding - (this.MARGIN.left + this.MARGIN.right); + this.width = this.determine_width($('.stat-graph').width(), $parentElement); this.height = 200; this.x = null; this.y = null; @@ -217,14 +222,13 @@ export const ContributorsAuthorGraph = (function(superClass) { function ContributorsAuthorGraph(data1) { const $parentElements = $('.person'); - const parentPadding = parseFloat($parentElements.css('padding-left')) + parseFloat($parentElements.css('padding-right')); this.data = data1; // Don't split graph size in half for mobile devices. if ($(window).width() < 768) { - this.width = $('.stat-graph').width() - parentPadding - (this.MARGIN.left + this.MARGIN.right); + this.width = this.determine_width($('.stat-graph').width(), $parentElements); } else { - this.width = ($('.stat-graph').width() / 2) - parentPadding - (this.MARGIN.left + this.MARGIN.right); + this.width = this.determine_width($('.stat-graph').width() / 2, $parentElements); } this.height = 200; this.x = null; |