Skip to content

Commit

Permalink
feat(networks): export with clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Sep 30, 2024
1 parent e0d4faf commit 212023a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion client/src/api/networks/network/communities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const communityGetYears = (hits: ElasticHits): Record<string, number> =>
return acc
}, {})

// const communityGetPublications = (hits: ElasticHits): Array<string> => hits.map((hit) => hit.title.default)
const communityGetPublications = (hits: ElasticHits): Array<Record<string, string>> =>
hits.map((hit) => ({
id: hit.id,
title: hit.title.default,
}))

const communityGetDomains = (hits: ElasticHits): Record<string, number> =>
hits.reduce((acc, hit) => {
Expand Down Expand Up @@ -105,6 +109,7 @@ export default async function communitiesCreate(graph: Graph, computeClusters: b
topWeightNodes: communityGetTopWeightNodes(graph, index),
...(hits && {
hits: hits.length,
publications: communityGetPublications(hits),
years: communityGetYears(hits),
domains: communityGetDomains(hits),
oaPercent: communityGetOaPercent(hits),
Expand Down
2 changes: 2 additions & 0 deletions client/src/pages/networks/components/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default function ClustersAnalytics() {
</Container>
)

console.log("clusters", clusters)

const chartData = clusters.slice(0, 10)
const sizeChartOptions = getHorizontalBarChartOptions({ data: chartData, x: "label", y: "size" })
const publicationsChartOptions = getHorizontalBarChartOptions({
Expand Down
8 changes: 7 additions & 1 deletion client/src/pages/networks/hooks/useExportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useMemo, useState } from "react"
import useTab from "./useTab"
import useSearchData from "./useSearchData"
import { NetworkData } from "../../../types/network"
import useClusters from "./useClusters"

const isString = (x: any) => Object.prototype.toString.call(x) === "[object String]"

Expand Down Expand Up @@ -48,11 +49,16 @@ const exportNetwork = (network: NetworkData) => ({
cluster: item.cluster,
})),
links: network.links,
clusters: network.clusters.map((cluster) => ({
cluster: cluster.cluster,
publications: cluster.publications,
})),
})

export default function useExportData() {
const { currentTab } = useTab()
const { search } = useSearchData(currentTab, false)
const { clusters: computeClusters } = useClusters()
const { search } = useSearchData(currentTab, computeClusters)
const [isLoading, setIsLoading] = useState(false)

const exportFile = useCallback(
Expand Down
1 change: 1 addition & 0 deletions client/src/types/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type NetworkCommunity = {
years?: Record<string, number>
domains?: Record<string, number>
oaPercent?: number
publications?: Array<Record<string, string>>
}
export type NetworkConfig = {
terminology?: Record<string, unknown>
Expand Down

0 comments on commit 212023a

Please sign in to comment.