Only make 1 collapsible for each run.

Previously, we could possibly make several collapsibles for each run because of how tag names were broken up.
Change: 155305237
This commit is contained in:
A. Unique TensorFlower 2017-05-06 20:46:07 -08:00 committed by TensorFlower Gardener
parent 24a61445f4
commit 1968b8b3f9
4 changed files with 54 additions and 27 deletions

View File

@ -46,6 +46,7 @@ tensorboard_typescript_genrule(
],
typings = [
"@org_definitelytyped//:d3.d.ts",
"@org_definitelytyped//:lodash.d.ts",
"//tensorflow/tensorboard/components/vz_sorting:ts_typings",
],
)

View File

@ -72,24 +72,31 @@ module Categorizer {
if (tags.length === 0) {
return [];
}
let sortedTags = tags.slice().sort(VZ.Sorting.compareTagNames);
let categories: Category[] = [];
let currentCategory = {
name: extractor(sortedTags[0]),
tags: [],
};
sortedTags.forEach((t: string) => {
let topLevel = extractor(t);
if (currentCategory.name !== topLevel) {
categories.push(currentCategory);
currentCategory = {
// Maps between top-level name and category. We use the mapping to avoid
// duplicating categories per run.
const categoryMapping: {[key: string]: Category} = {};
tags.forEach((t: string) => {
const topLevel = extractor(t);
if (!categoryMapping[topLevel]) {
const newCategory = {
name: topLevel,
tags: [],
};
categoryMapping[topLevel] = newCategory;
}
currentCategory.tags.push(t);
categoryMapping[topLevel].tags.push(t);
});
// Sort categories into alphabetical order.
const categories =
_.map(_.keys(categoryMapping).sort(), key => categoryMapping[key]);
_.forEach(categories, (category) => {
// Sort the tags within each category.
category.tags.sort(VZ.Sorting.compareTagNames);
});
categories.push(currentCategory);
return categories;
};
}

View File

@ -62,6 +62,18 @@ module Categorizer {
assert.deepEqual(
topLevelNamespaceCategorizer(['a']), [{name: 'a', tags: ['a']}]);
});
it('only create 1 category per run', () => {
// TensorBoard separates runs from tags using the / and _ characters
// *only* during sorting. The categorizer should group all tags under
// their correct categories - and create only 1 category per run.
const tags = ['foo/bar', 'foo_in_between_run/baz', 'foo/quux'];
const expected = [
{name: 'foo', tags: ['foo/bar', 'foo/quux']},
{name: 'foo_in_between_run', tags: ['foo_in_between_run/baz']},
];
assert.deepEqual(topLevelNamespaceCategorizer(tags), expected);
});
});
describe('customCategorizer', () => {

View File

@ -73,24 +73,31 @@ function extractorToCategorizer(extractor: (s: string) => string): Categorizer {
if (tags.length === 0) {
return [];
}
let sortedTags = tags.slice().sort(compareTagNames);
let categories: Category[] = [];
let currentCategory = {
name: extractor(sortedTags[0]),
tags: [],
};
sortedTags.forEach((t: string) => {
let topLevel = extractor(t);
if (currentCategory.name !== topLevel) {
categories.push(currentCategory);
currentCategory = {
// Maps between top-level name and category. We use the mapping to avoid
// duplicating categories per run.
const categoryMapping: {[key: string]: Category} = {};
tags.forEach((t: string) => {
const topLevel = extractor(t);
if (!categoryMapping[topLevel]) {
const newCategory = {
name: topLevel,
tags: [],
};
categoryMapping[topLevel] = newCategory;
}
currentCategory.tags.push(t);
categoryMapping[topLevel].tags.push(t);
});
// Sort categories into alphabetical order.
const categories =
_.map(_.keys(categoryMapping).sort(), key => categoryMapping[key]);
_.forEach(categories, (category) => {
// Sort the tags within each category.
category.tags.sort(compareTagNames);
});
categories.push(currentCategory);
return categories;
};
}