diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-11-27 16:50:05 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-11-27 16:50:05 +0100 |
commit | 208886757cf027a931ead00b578a1959f04604dc (patch) | |
tree | 8159b2b78700ddcd9078cdf0df0497385704625b /server/sonar-web/src/main/js/helpers | |
parent | afafb7dc35a9c39d2167fba1e3ac21550a4948fd (diff) | |
download | sonarqube-208886757cf027a931ead00b578a1959f04604dc.tar.gz sonarqube-208886757cf027a931ead00b578a1959f04604dc.zip |
SONAR-7064 Replace treemap on the size overview page with histogram
Diffstat (limited to 'server/sonar-web/src/main/js/helpers')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/path.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/helpers/path.js b/server/sonar-web/src/main/js/helpers/path.js new file mode 100644 index 00000000000..ea389d48cb8 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/path.js @@ -0,0 +1,24 @@ +export function collapsePath (path, limit = 30) { + if (typeof path !== 'string') { + return ''; + } + + var tokens = path.split('/'); + + if (tokens.length <= 2) { + return path; + } + + var head = _.first(tokens), + tail = _.last(tokens), + middle = _.initial(_.rest(tokens)), + cut = false; + + while (middle.join().length > limit && middle.length > 0) { + middle.shift(); + cut = true; + } + + var body = [].concat(head, cut ? ['...'] : [], middle, tail); + return body.join('/'); +} |