📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
(improvments) captcha project (#349)
Maksim Mrugdf07633c9a54
diff --git a/app/pages/Captcha/View/ViewCaptcha.helpers.tsx b/app/pages/Captcha/View/ViewCaptcha.helpers.tsxindex 3454f2209..533f916fa 100644--- a/app/pages/Captcha/View/ViewCaptcha.helpers.tsx+++ b/app/pages/Captcha/View/ViewCaptcha.helpers.tsx@@ -20,11 +20,12 @@ import _round from 'lodash/round'import JSZip from 'jszip'import {- TimeFormat, chartTypes, tbsFormatMapper, tbsFormatMapper24h,+ TimeFormat, chartTypes, tbsFormatMapper, tbsFormatMapper24h, tbsFormatMapperTooltip, tbsFormatMapperTooltip24h,} from 'redux/constants'import countries from 'utils/isoCountries'// @ts-ignoreimport * as d3 from 'd3'+import { nFormatter } from 'utils/generic'const getExportFilename = (prefix: string) => {// turn something like 2022-03-02T19:31:00.100Z into 2022-03-02@@ -123,8 +124,6 @@ const getSettings = (chart: any, timeBucket: string, activeChartMetrics: {[key: string]: boolean,}, applyRegions: boolean, timeFormat: string, rotateXAxias: boolean, chartType: string) => {const xAxisSize = _size(chart.x)- const lines: any[] = []- const modifiedChart = { ...chart }let regionsif (applyRegions) {@@ -151,19 +150,23 @@ const getSettings = (chart: any, timeBucket: string, activeChartMetrics: {return {data: {x: 'x',- columns: getColumns(modifiedChart, activeChartMetrics),+ columns: getColumns({+ ...chart,+ }, activeChartMetrics),types: {- results: chartType === chartTypes.line ? area() : bar(),+ results: chartType === chartTypes.line ? area() : bar()},colors: {results: '#2563EB',},regions,},- grid: {- x: {- lines,- },+ transition: {+ duration: 500,+ },+ resize: {+ auto: true,+ timer: false,},axis: {x: {@@ -171,31 +174,40 @@ const getSettings = (chart: any, timeBucket: string, activeChartMetrics: {tick: {fit: true,rotate: rotateXAxias ? 45 : 0,- format: timeFormat === TimeFormat['24-hour'] ? (x: any) => d3.timeFormat(tbsFormatMapper24h[timeBucket])(x) : null,+ format: timeFormat === TimeFormat['24-hour'] ? (x: string) => d3.timeFormat(tbsFormatMapper24h[timeBucket])(x) : (x: string) => d3.timeFormat(tbsFormatMapper[timeBucket])(x),},localtime: timeFormat === TimeFormat['24-hour'],type: 'timeseries',},+ y: {+ tick: {+ format: (d: number) => nFormatter(d, 1),+ },+ },},tooltip: {- format: {- title: (x: any) => d3.timeFormat(tbsFormatMapper[timeBucket])(x),- },- contents: {- template: `- <ul class='bg-gray-100 dark:text-gray-50 dark:bg-slate-800 rounded-md shadow-md px-3 py-1'>- <li class='font-semibold'>{=TITLE}</li>- <hr class='border-gray-200 dark:border-gray-600' />- {{- <li class='flex justify-between'>- <div class='flex justify-items-start'>- <div class='w-3 h-3 rounded-sm mt-1.5 mr-2' style=background-color:{=COLOR}></div>- <span>{=NAME}</span>- </div>- <span class='pl-4'>{=VALUE}</span>- </li>- }}- </ul>`,+ contents: (item: any, _: any, __: any, color: any) => {+ return `<ul class='bg-gray-100 dark:text-gray-50 dark:bg-slate-800 rounded-md shadow-md px-3 py-1'>+ <li class='font-semibold'>${timeFormat === TimeFormat['24-hour'] ? d3.timeFormat(tbsFormatMapperTooltip24h[timeBucket])(item[0].x) : d3.timeFormat(tbsFormatMapperTooltip[timeBucket])(item[0].x)}</li>+ <hr class='border-gray-200 dark:border-gray-600' />+ ${_map(item, (el: {+ id: string,+ index: number,+ name: string,+ value: string,+ x: Date,+ }) => {++ return `+ <li class='flex justify-between'>+ <div class='flex justify-items-start'>+ <div class='w-3 h-3 rounded-sm mt-1.5 mr-2' style=background-color:${color(el.id)}></div>+ <span>${el.name}</span>+ </div>+ <span class='pl-4'>${el.value}</span>+ </li>+ `+ }).join('')}`},},point: {@@ -220,7 +232,6 @@ const getSettings = (chart: any, timeBucket: string, activeChartMetrics: {},padding: {right: rotateXAxias && 35,- left: 40,},bindto: '#dataChart',}diff --git a/app/pages/Captcha/View/ViewCaptcha.tsx b/app/pages/Captcha/View/ViewCaptcha.tsxindex e6ddc5c26..b2ac79739 100644--- a/app/pages/Captcha/View/ViewCaptcha.tsx+++ b/app/pages/Captcha/View/ViewCaptcha.tsx@@ -50,7 +50,7 @@ import {} from './Panels'import {onCSVExportClick, getFormatDate, panelIconMapping, typeNameMapping, validFilters, validPeriods,- validTimeBacket, noRegionPeriods, getSettings, CHART_METRICS_MAPPING,+ validTimeBacket, noRegionPeriods, getSettings, CHART_METRICS_MAPPING, getColumns} from './ViewCaptcha.helpers'import CCRow from './components/CCRow'import RefRow from './components/RefRow'@@ -126,6 +126,7 @@ const ViewProject = ({const [ref, size] = useSize() as anyconst rotateXAxias = useMemo(() => (size.width > 0 && size.width < 500), [size])const [chartType, setChartType] = useState<string>(getItem('chartType') as string || chartTypes.line)+ const [mainChart, setMainChart] = useState<any>(null)const { name } = project as IProject@@ -252,10 +253,12 @@ const ViewProject = ({customs,})- const generete = bb.generate(bbSettings)- generete.data.names(dataNames)-setIsPanelsDataEmpty(false)+ setMainChart(() => {+ const generete = bb.generate(bbSettings)+ generete.data.names(dataNames)+ return generete+ })}setAnalyticsLoading(false)@@ -269,6 +272,14 @@ const ViewProject = ({}}+ useEffect(() => {+ if (mainChart) {+ mainChart.load({+ columns: getColumns({ ...chartData }, activeChartMetrics),+ })+ }+ }, [chartData])+// this funtion is used for requesting the data from the API when the filter is changedconst filterHandler = (column: any, filter: any, isExclusive: boolean = false) => {let newFilters@@ -672,7 +683,7 @@ const ViewProject = ({</span></div><Dropdown- items={periodPairs}+ items={_filter(periodPairs, (item) => !_includes(['all', '1h'], item.period))}title={activePeriod.label}labelExtractor={(pair) => pair.dropdownLabel || pair.label}keyExtractor={(pair) => pair.label}@@ -804,12 +815,12 @@ const ViewProject = ({tnMapping={tnMapping}/>{dataLoading && (- <div className='loader bg-transparent static mt-4' id='loader'>- <div className='loader-head dark:bg-slate-800'>- <div className='first dark:bg-slate-600' />- <div className='second dark:bg-slate-600' />+ <div className='!bg-transparent static mt-4' id='loader'>+ <div className='loader-head dark:!bg-slate-800'>+ <div className='first dark:!bg-slate-600' />+ <div className='second dark:!bg-slate-600' />+ </div></div>- </div>)}<div className='mt-5 grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3'>{/* {!_isEmpty(project.overall) && (@@ -829,18 +840,30 @@ const ViewProject = ({const panelIcon = panelIconMapping[type]if (type === 'cc') {+ const rowMapper = (entry: any) => {+ const { name: entryName, cc } = entry++ if (cc) {+ return (+ <CCRow cc={cc} name={entryName} language={language} />+ )+ }++ return (+ <CCRow cc={entryName} language={language} />+ )+ }+return (<Panelt={t}+ key={type}icon={panelIcon}id={type}- key={type}onFilter={filterHandler}name={panelName}data={panelsData.data[type]}- rowMapper={({ name: entryName, cc }) => (- <CCRow cc={cc} name={entryName} language={language} />- )}+ rowMapper={rowMapper}/>)}diff --git a/app/pages/Captcha/View/components/InteractiveMap.tsx b/app/pages/Captcha/View/components/InteractiveMap.tsxindex d7fc9e493..150791589 100644--- a/app/pages/Captcha/View/components/InteractiveMap.tsx+++ b/app/pages/Captcha/View/components/InteractiveMap.tsx@@ -5,13 +5,10 @@ import _reduce from 'lodash/reduce'import { useTranslation } from 'react-i18next'import PropTypes from 'prop-types'import countries from 'utils/isoCountries'-import { PROJECT_TABS } from 'redux/constants'-import { StateType } from 'redux/store'-import { getTimeFromSeconds, getStringFromTime, nFormatter } from 'utils/generic'+import { nFormatter } from 'utils/generic'import { IEntry } from 'redux/models/IEntry'import countriesList from 'utils/countries'-import { useSelector } from 'react-redux'interface IInteractiveMap {data: IEntry[],@@ -40,9 +37,6 @@ const InteractiveMap = ({ data, onClickCountry, total }: IInteractiveMap) => {const [cursorPosition, setCursorPosition] = useState<ICursorPosition>({} as ICursorPosition)const countryMap: ICountryMap = useMemo(() => _reduce(data, (prev, curr) => ({ ...prev, [curr.cc || curr.name]: curr.count }), {}), [data])- const projectTab = useSelector((state: StateType) => state.ui.projects.projectTab)- const isTrafficTab = projectTab === PROJECT_TABS.traffic-const onMouseMove = (e: React.MouseEvent<SVGSVGElement, MouseEvent>) => {const rect = e.currentTarget.getBoundingClientRect()const pageX = e.clientX - rect.left@@ -62,8 +56,7 @@ const InteractiveMap = ({ data, onClickCountry, total }: IInteractiveMap) => {<pathkey={value}id={value}- className={isTrafficTab- ? cx({+ className={cx({'hover:opacity-90': perc > 0,'fill-[#cfd1d4] dark:fill-[#465d7e46]': perc === 0,'fill-[#92b2e7] dark:fill-[#292d77]': perc > 0 && perc < 3,@@ -71,17 +64,6 @@ const InteractiveMap = ({ data, onClickCountry, total }: IInteractiveMap) => {'fill-[#5689db] dark:fill-[#4842be]': perc >= 10 && perc < 20,'fill-[#3b82f6] dark:fill-[#6357ff]': perc >= 20,'cursor-pointer': Boolean(ccData),- }) : cx({- 'hover:opacity-90': ccData > 0,- 'fill-[#cfd1d4] dark:fill-[#465d7e46]': ccData === 0,- 'fill-[#92b2e7] dark:fill-[#292d77]': ccData > 0 && ccData < 1,- 'fill-[#6f9be3] dark:fill-[#363391]': ccData >= 1 && ccData < 2,- 'fill-[#5689db] dark:fill-[#4842be]': ccData >= 2 && ccData < 3,- 'fill-[#3b82f6] dark:fill-[#6357ff]': ccData >= 3 && ccData < 5,- 'fill-[#f78a8a]': ccData >= 5 && ccData < 7,- 'fill-[#f76b6b]': ccData >= 7 && ccData < 10,- 'fill-[#f74b4b]': ccData >= 10,- 'cursor-pointer': Boolean(ccData),})}d={key.d}onClick={() => perc !== 0 && onClickCountry(value)}@@ -113,16 +95,15 @@ const InteractiveMap = ({ data, onClickCountry, total }: IInteractiveMap) => {><strong>{dataHover.countries}</strong><br />- {isTrafficTab ? t('project.unique') : t('dashboard.pageLoad')}+ {t('project.unique')}: <strongclassName={cx({- 'dark:text-indigo-400': isTrafficTab || dataHover.data < 5,- 'dark:text-red-400': !isTrafficTab && dataHover.data >= 5,+ 'dark:text-indigo-400': dataHover.data < 5,})}>- {isTrafficTab ? nFormatter(dataHover.data, 1) : getStringFromTime(getTimeFromSeconds(dataHover.data), true)}+ {nFormatter(dataHover.data, 1)}</strong></div>)}