Remove common prefix from networks to increase color separation

This commit is contained in:
David Kaltschmidt
2016-05-25 11:26:31 +02:00
committed by Simon Howe
parent e95f46bfd8
commit 478a4a6d66
5 changed files with 33 additions and 2 deletions

View File

@@ -10,4 +10,15 @@ describe('StringUtils', () => {
expect(formatMetric(0)).toBe('0.00');
});
});
describe('longestCommonPrefix', () => {
const fun = StringUtils.longestCommonPrefix;
it('it should return the longest common prefix', () => {
expect(fun(['interspecies', 'interstellar'])).toBe('inters');
expect(fun(['space', 'space'])).toBe('space');
expect(fun([''])).toBe('');
expect(fun(['prefix', 'suffix'])).toBe('');
});
});
});

View File

@@ -1,7 +1,7 @@
import React from 'react';
import filesize from 'filesize';
import d3 from 'd3';
import LCP from 'lcp';
const formatLargeValue = d3.format('s');
@@ -69,3 +69,7 @@ const CLEAN_LABEL_REGEX = /\W/g;
export function slugify(label) {
return label.replace(CLEAN_LABEL_REGEX, '').toLowerCase();
}
export function longestCommonPrefix(strArr) {
return (new LCP(strArr)).lcp();
}