Skip to content

Commit

Permalink
Improve displayed name
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierfacq committed Sep 30, 2023
1 parent 402045c commit 6a1c3d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/Graph/ColumnDrilldown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class ColumnDrilldown extends Component<ColumnDrilldownProps, Col
archLevelDrilldownSeries.push({
name: apiDataKey,
id: apiDataKey,
data: Object.keys(r.arch).map(oneArch => {
data: Object.keys(r.arch).sort((a, b) => a.localeCompare(b)).map(oneArch => {
return {
name: oneArch,
y: r.arch[oneArch].data.reduce((a, b) => a + b.y || 0, 0),
Expand All @@ -94,7 +94,7 @@ export default class ColumnDrilldown extends Component<ColumnDrilldownProps, Col
archLevelDrilldownSeries.push({
name: `${apiDataKey}-${oneArch}`,
id: `${apiDataKey}-${oneArch}`,
data: r.arch[oneArch].data
data: r.arch[oneArch].data.sort((a, b) => a.name.localeCompare(b.name))
});

Check warning on line 98 in src/Graph/ColumnDrilldown.tsx

View check run for this annotation

Codecov / codecov/patch

src/Graph/ColumnDrilldown.tsx#L94-L98

Added lines #L94 - L98 were not covered by tests
});

Expand Down
53 changes: 30 additions & 23 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,55 @@ export const formatNum = number => {
}

export const splitDrilldownSeriesByArchAndOs = (data) => {
const mArch = new Map();
const mOs = new Map();
const mArch = new Map()
const mOs = new Map()

mArch.set('sources', {name: 'Sources', id: 'sources', data: []});
mOs.set('sources', {name: 'Sources', id: 'sources', data: []});
mArch.set('sources', { name: 'Sources', id: 'sources', data: [] })
mOs.set('sources', { name: 'Sources', id: 'sources', data: [] })

data.forEach((slddsd) => {
const tokens = slddsd.name.split('_');
const tokens = slddsd.name.split('_')
// console.info("what = " + tokens[0]);
// console.info("arch = " + tokens[1]);
// console.info("os = " + tokens[2]);
// console.info("hotspot = " + tokens[3]);
// console.info("version = " + tokens[4]);

slddsd['name'] = getFormattedName(tokens);
slddsd.name = getFormattedName(tokens)

if(tokens.length === 3 && tokens[0].endsWith("sources")) {
mArch.get('sources').data.push(slddsd);
mOs.get('sources').data.push(slddsd);
} else if(tokens.length >= 5) {
if(!mArch.has(tokens[1])) mArch.set(tokens[1], {name: tokens[1], id: tokens[1], data: []});
if (tokens.length === 3 && tokens[0].endsWith('sources')) {
mArch.get('sources').data.push(slddsd)
mOs.get('sources').data.push(slddsd)
} else if (tokens.length >= 5) {
if (!mArch.has(tokens[1])) mArch.set(tokens[1], { name: tokens[1], id: tokens[1], data: [] })

mArch.get(tokens[1]).data.push(slddsd);
mArch.get(tokens[1]).data.push(slddsd)

if(!mOs.has(tokens[2])) mOs.set(tokens[2], {name: tokens[1], id: tokens[1], data: []});
mOs.get(tokens[2]).data.push(slddsd);
if (!mOs.has(tokens[2])) mOs.set(tokens[2], { name: tokens[1], id: tokens[1], data: [] })
mOs.get(tokens[2]).data.push(slddsd)
}
});
})

if(mArch.get('sources').data.length === 0) mArch.delete('sources');
if(mOs.get('sources').data.length === 0) mOs.delete('sources');
if (mArch.get('sources').data.length === 0) mArch.delete('sources')
if (mOs.get('sources').data.length === 0) mOs.delete('sources')

return {
arch: Object.fromEntries(mArch),
os: Object.fromEntries(mOs)
};
}
}

const getFormattedName = (tokens) => {
if(tokens.length === 3 && tokens[0].endsWith("sources")) return "sources";
else if(tokens.length >= 5) {
const afterCarret = tokens[0].slice(tokens[0].indexOf('-') + 1);
return `${afterCarret} ${tokens[2]}`}
else return tokens.join('_')
if (tokens.length === 3 && tokens[0].endsWith('sources')) return 'sources'
else if (tokens.length >= 5) {
let afterCarret = tokens[0].slice(tokens[0].indexOf('-') + 1)
if (afterCarret === 'jre') afterCarret = 'JRE'
else if (afterCarret === 'jdk') afterCarret = 'JDK'

return `${capitalizeFirst(tokens[2])} (${capitalizeFirst(afterCarret)})`
} else return tokens.join('_')
}

const capitalizeFirst = (text) => {
return text[0].toUpperCase() + text.substring(1)
}

0 comments on commit 6a1c3d8

Please sign in to comment.