Skip to content

Commit

Permalink
replaced older IM and circumvention charts (#785)
Browse files Browse the repository at this point in the history
Signed-off-by: GermaVinsmoke <[email protected]>
Co-authored-by: Maja Komel <[email protected]>
  • Loading branch information
GermaVinsmoke and majakomel authored Jan 8, 2023
1 parent 9c5dfdd commit ebcabdc
Show file tree
Hide file tree
Showing 25 changed files with 337 additions and 1,655 deletions.
43 changes: 13 additions & 30 deletions components/network/Chart.js → components/Chart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo } from 'react'
import { useIntl } from 'react-intl'
import { useRouter } from 'next/router'
import { FormattedMessage } from 'react-intl'
import { Heading, Box, Flex } from 'ooni-components'
import useSWR from 'swr'
import GridChart, { prepareDataForGridChart } from 'components/aggregation/mat/GridChart'
Expand All @@ -14,33 +14,16 @@ const swrOptions = {
}

const Chart = React.memo(function Chart({testName, testGroup = null, title, queryParams = {}}) {
const intl = useIntl()
const router = useRouter()
const { query: {since, until, asn} } = router

const name = testName || testGroup.name

const params = useMemo(() => ({
...queryParams,
axis_x: 'measurement_start_day'
}), [queryParams])

const query = useMemo(() => ({
...params,
probe_asn: asn,
since: since,
until: until,
...testName && {test_name: testName}
}), [since, until, asn, params, testName])

const apiQuery = useMemo(() => {
const qs = new URLSearchParams(query).toString()
const qs = new URLSearchParams(queryParams).toString()
return qs
}, [query])
}, [queryParams])

const { data, error } = useSWR(
testGroup ? { query: apiQuery,
testNames: testGroup.tests,
testGroup ? { query: apiQuery,
testNames: testGroup.tests,
groupKey: name
} : apiQuery,
testGroup ? MATMultipleFetcher : MATFetcher,
Expand All @@ -51,23 +34,23 @@ const Chart = React.memo(function Chart({testName, testGroup = null, title, quer
return [null, 0]
}
let chartData = testGroup ? data : data.data
const graphQuery = testGroup ? {...query, axis_y: name} : query
const [reshapedData, rowKeys, rowLabels] = prepareDataForGridChart(chartData, graphQuery, intl.locale)
const graphQuery = testGroup ? {...queryParams, axis_y: name} : queryParams
const [reshapedData, rowKeys, rowLabels] = prepareDataForGridChart(chartData, graphQuery)
return [reshapedData, rowKeys, rowLabels]
}, [data, query, name, testGroup, intl])
}, [data, queryParams, name, testGroup])

const headerOptions = { probe_cc: false, subtitle: false }

return (
<MATContextProvider key={name} test_name={name} {...params}>
<MATContextProvider key={name} test_name={name} {...queryParams}>
<Flex flexDirection='column' mb={60}>
<Box><Heading h={3} mt={40} mb={20}>{title}</Heading></Box>
<Box>
{(!chartData && !error) ? (
<div>{intl.formatMessage({id: 'General.Loading'})}</div>
<FormattedMessage id="General.Loading" />
) : (
chartData === null || chartData.length === 0 ? (
<Heading h={5}>{intl.formatMessage({id: 'General.NoData'})}</Heading>
<Heading h={5}><FormattedMessage id="General.NoData" /></Heading>
) : (
<GridChart
data={chartData}
Expand All @@ -82,7 +65,7 @@ const Chart = React.memo(function Chart({testName, testGroup = null, title, quer
{error &&
<DetailsBox collapsed={false} content={<>
<details>
<summary><span>{intl.formatMessage({id: 'General.Error'})}: {error.message}</span></summary>
<summary><span>Error: {error.message}</span></summary>
<Box as='pre'>
{JSON.stringify(error, null, 2)}
</Box>
Expand All @@ -95,4 +78,4 @@ const Chart = React.memo(function Chart({testName, testGroup = null, title, quer
)
})

export default Chart
export default Chart
2 changes: 1 addition & 1 deletion components/aggregation/mat/XAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export const XAxis = ({ data }) => {
</Box>
</StyledFlex>
)
}
}
31 changes: 0 additions & 31 deletions components/country/ASNSelector.js

This file was deleted.

60 changes: 43 additions & 17 deletions components/country/Apps.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,64 @@
import React from 'react'
import { FormattedMessage } from 'react-intl'
import { useMemo } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'
import { Text } from 'ooni-components'

import SectionHeader from './SectionHeader'
import { SimpleBox } from './boxes'
// import PeriodFilter from './PeriodFilter'
import AppsStatsGroup from './AppsStats'
import AppsStatsCircumvention from './AppsStatsCircumvention'
import Chart from 'components/Chart'
import FormattedMarkdown from '../FormattedMarkdown'
import { useRouter } from 'next/router'

const messagingTestNames = ['signal', 'telegram', 'whatsapp', 'facebook_messenger']
const circumventionTestNames = ['vanilla_tor', 'psiphon', 'tor', 'torsf']

const ChartsContainer = () => {
const intl = useIntl()
const router = useRouter()
const { query: { since, until, countryCode } } = router

const queryMessagingApps = useMemo(() => ({
axis_x: 'measurement_start_day',
probe_cc: countryCode,
since,
until,
}), [countryCode, since, until])

const queryCircumventionTools = useMemo(() => ({
axis_x: 'measurement_start_day',
probe_cc: countryCode,
since,
until,
}), [countryCode, since, until])

return (
<>
<Chart
testGroup={{name: 'messaging_apps', tests: messagingTestNames}}
title={intl.formatMessage({id: 'Tests.Groups.Instant Messagging.Name'})}
queryParams={queryMessagingApps}
/>
<Chart
testGroup={{name: 'circumvention_tools', tests: circumventionTestNames}}
title={intl.formatMessage({id: 'Tests.Groups.Circumvention.Name'})}
queryParams={queryCircumventionTools}
/>
</>
)
}

const AppsSection = () => (
<>
<SectionHeader>
<SectionHeader.Title name='apps'>
<FormattedMessage id='Country.Heading.Apps' />
</SectionHeader.Title>
{/* <Box ml='auto'>
<PeriodFilter onChange={onPeriodChange} />
</Box> */}
</SectionHeader>
<SimpleBox>
<Text fontSize={16}>
<FormattedMarkdown id='Country.Apps.Description' />
</Text>
</SimpleBox>
{/* App-wise graphs */}
<AppsStatsGroup
title={<FormattedMessage id='Country.Overview.TestsByClass.InstantMessaging' />}
testGroup='im'
/>
{<AppsStatsCircumvention
title={<FormattedMessage id='Country.Overview.TestsByClass.Circumvention'/>}
testGroup='circumvention'
/>}
<ChartsContainer />
</>
)

Expand Down
77 changes: 0 additions & 77 deletions components/country/AppsStats.js

This file was deleted.

Loading

1 comment on commit ebcabdc

@vercel
Copy link

@vercel vercel bot commented on ebcabdc Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

explorer – ./

explorer-one.vercel.app
explorer-git-master-ooni1.vercel.app
explorer-ooni1.vercel.app

Please sign in to comment.