Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group options in patent trends chart's dropdown #387

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 74 additions & 12 deletions web/gui-v2/src/components/DetailViewPatents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,78 @@ const chartLayoutChanges = {
const startIx = overall.years.findIndex(e => e === overall.startPatentYear);
const endIx = overall.years.findIndex(e => e === overall.endPatentYear);

const PATENT_DROPDOWN_CATEGORIES = [
{ text: "AI (all)", key: "ai_patents" },
{
header: "Applications",
subentry_keys: [
"Analytics_and_Algorithms",
"Computer_Vision",
"Control",
"Distributed_AI",
"Knowledge_Representation",
"Language_Processing",
"Measuring_and_Testing",
"Planning_and_Scheduling",
"Robotics",
"Speech_Processing",
],
},
{
header: "Industry areas",
subentry_keys: [
"Agricultural",
"Banking_and_Finance",
"Business",
"Computing_in_Government",
"Document_Mgt_and_Publishing",
"Education",
"Energy_Management",
"Entertainment",
"Industrial_and_Manufacturing",
"Life_Sciences",
"Military",
"Nanotechnology",
"Networks__eg_social_IOT_etc",
"Personal_Devices_and_Computing",
"Physical_Sciences_and_Engineering",
"Security__eg_cybersecurity",
"Semiconductors",
"Telecommunications",
"Transportation",
],
},
];

const PATENT_DROPDOWN_OPTIONS = PATENT_DROPDOWN_CATEGORIES
.flatMap((entry) => {
const { key, text, header, subentry_keys } = entry;
if ( key && text ) {
// Top-level dropdown option, not categorized into a group.
// (returned as a single-element array b/c flatMap and the other case)
return [{
val: key,
text,
}];
} else if ( header && subentry_keys ) {
// Options that are grouped under a common header.
const subentryOptions = subentry_keys
.map((key) => ({
val: key,
text: patentMap[key].replace(/ patents/i, ''),
}))
.sort((a, b) => a.text.localeCompare(b.text, 'en', { sensitivity: 'base' }));

return [
{ header },
...subentryOptions,
]
} else {
console.warn("Warning: shape of patent dropdown category entry does not match expectations and has been skipped:", entry);
return [];
}
});

const DetailViewPatents = ({
data,
}) => {
Expand Down Expand Up @@ -91,8 +163,6 @@ const DetailViewPatents = ({
const patentApplicationAreas = patentSubkeys
.filter(key => data.patents[key].table === "application")
.map((key) => {
const startVal = data.patents[key].counts[startIx];
const endVal = data.patents[key].counts[endIx];
return {
subfield: patentMap[key],
patents: data.patents[key].total,
Expand All @@ -104,8 +174,6 @@ const DetailViewPatents = ({
const patentIndustryAreas = patentSubkeys
.filter(key => data.patents[key].table === "industry")
.map((key) => {
const startVal = data.patents[key].counts[startIx];
const endVal = data.patents[key].counts[endIx];
return {
subfield: patentMap[key],
patents: data.patents[key].total,
Expand All @@ -114,11 +182,6 @@ const DetailViewPatents = ({
})
.sort((a, b) => b.patents - a.patents);

const aiSubfieldOptions = patentSubkeys
.filter(k => !!data.patents[k]?.counts)
.map(k => ({ text: patentMap[k].replace(/ patents/i, ''), val: k }))
.sort((a, b) => a.text.localeCompare(b.text, 'en', { sensitivity: 'base' }));

return (
<>
<HeaderWithLink title="Patents" />
Expand Down Expand Up @@ -150,7 +213,7 @@ const DetailViewPatents = ({
css={styles.section}
data={[
[
`${aiSubfieldOptions.find(e => e.val === aiSubfield)?.text} patents at ${data.name}`,
`${PATENT_DROPDOWN_OPTIONS.find(e => e.val === aiSubfield)?.text} patents at ${data.name}`,
data.patents[aiSubfield].counts
],
data.groups.sp500 && [
Expand All @@ -170,9 +233,8 @@ const DetailViewPatents = ({
Trends in {data.name}'s patenting in
<Dropdown
css={styles.trendsDropdown}
disableClearable={true}
inputLabel="patent subfield"
options={aiSubfieldOptions}
options={PATENT_DROPDOWN_OPTIONS}
selected={aiSubfield}
setSelected={setAiSubfield}
showLabel={false}
Expand Down
Loading