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

857/chart style #903

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion app/scripts/components/analysis/define/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
const onDatasetLayerChange = useCallback(
(e) => {
const id = e.target.id;
let newDatasetsLayers = [...(datasetsLayers || [])];

Check warning on line 295 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
if (e.target.checked) {
const newDatasetLayer = allAvailableDatasetsLayers.find(
(l) => l.id === id
Expand Down Expand Up @@ -333,7 +333,7 @@
setAnalysisParam('datasetsLayers', cleanedDatasetsLayers);
// Only update when stac search gets updated to avoid triggering an infinite
// read/set state loop
}, [selectableDatasetLayers, setAnalysisParam]);

Check warning on line 336 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'datasetsLayers'. Either include it or remove the dependency array

const notReady = !readyToLoadDatasets || !datasetsLayers?.length;

Expand Down Expand Up @@ -431,7 +431,7 @@
value={end ? dateToInputFormat(end) : ''}
onChange={onEndDateChange}
min={dateToInputFormat(start)}
max='2022-12-31'
max='2023-12-31'
hanbyul-here marked this conversation as resolved.
Show resolved Hide resolved
/>
</FormGroupStructureCustom>
</FormBlock>
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/components/exploration/atoms/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ export const timelineSizesAtom = atom((get) => {
};
});

// Whether or not the dataset rows are expanded.
export const isExpandedAtom = atom<boolean>(true);
84 changes: 57 additions & 27 deletions app/scripts/components/exploration/components/chart-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
useState
} from 'react';
import { createPortal } from 'react-dom';
import styled from 'styled-components';
import styled, {css} from 'styled-components';
import {
useFloating,
autoUpdate,
Expand All @@ -14,12 +14,10 @@ import {
shift
} from '@floating-ui/react';
import { bisector, ScaleTime, sort } from 'd3';
import { useAtomValue } from 'jotai';
import { format } from 'date-fns';
import { glsp, themeVal } from '@devseed-ui/theme-provider';

import { AnalysisTimeseriesEntry, TimeDensity } from '../types.d.ts';
import { isExpandedAtom } from '../atoms/timeline';
import { AnalysisTimeseriesEntry, TimeDensity, TimelineDatasetSuccess } from '../types.d.ts';
import { DataMetric } from './datasets/analysis-metrics';

import { getNumForChart } from '$components/common/chart/utils';
Expand Down Expand Up @@ -48,12 +46,16 @@ const MetricList = styled.ul`
list-style: none;
margin: 0 -${glsp()};
padding: 0;
padding-top: ${glsp(0.25)};
gap: ${glsp(0.25)};

> li {
padding: ${glsp(0, 1)};
}
`;
const MetricLi = styled.li`
display: flex;
justify-content: space-between;
`;

const MetricItem = styled.p<{ metricThemeColor: string }>`
display: flex;
Expand All @@ -71,46 +73,74 @@ const MetricItem = styled.p<{ metricThemeColor: string }>`
}
`;

type DivProps = JSX.IntrinsicElements['div'];
const fadedtext = css`
color: #83868A;
`;

const TitleBox = styled.div`
background-color: #FAFAFA;
${fadedtext};
padding: ${glsp(0.5)};
font-size: 0.75rem;
`;

const ContentBox = styled.div`
padding: ${glsp(0.5)};
font-size: 0.75rem;
`;
const MetaBox = styled.div`
display: flex;
align-items: center;
gap: ${glsp(1)};
`;

const UnitBox = styled.div`
${fadedtext};
`;

type DivProps = JSX.IntrinsicElements['div'];
interface DatasetPopoverProps extends DivProps {
data: AnalysisTimeseriesEntry;
activeMetrics: DataMetric[];
timeDensity: TimeDensity;
dataset: TimelineDatasetSuccess;
}

function DatasetPopoverComponent(
props: DatasetPopoverProps,
ref: MutableRefObject<HTMLDivElement>
) {
const { data, activeMetrics, timeDensity, ...rest } = props;

const isExpanded = useAtomValue(isExpandedAtom);

const { data, dataset, activeMetrics, timeDensity, style, ...rest } = props;

// Check if there is no data to show
const hasData = activeMetrics.some(
(metric) => typeof data[metric.id] === 'number'
);

if (!isExpanded || !hasData) return null;
if (!hasData) return null;

return createPortal(
<div ref={ref} {...rest}>
<strong>{timeDensityFormat(data.date, timeDensity)}</strong>
<MetricList>
{activeMetrics.map((metric) => {
const dataPoint = data[metric.id];

return typeof dataPoint !== 'number' ? null : (
<li key={metric.id}>
<MetricItem metricThemeColor={metric.themeColor}>
<strong>{metric.chartLabel}:</strong>
{getNumForChart(dataPoint)}
</MetricItem>
</li>
);
})}
</MetricList>
<div ref={ref} style={{...style, padding: 0, gap: 0}} {...rest}>
<TitleBox>{dataset.data.name}</TitleBox>
<ContentBox>
<MetaBox style={{display: 'flex'}}>
<strong>{timeDensityFormat(data.date, timeDensity)}</strong>
<UnitBox>{dataset.data.info?.unit}</UnitBox>
</MetaBox>
<MetricList>
{activeMetrics.map((metric) => {
const dataPoint = data[metric.id];
return typeof dataPoint !== 'number' ? null : (
<MetricLi key={metric.id}>
<MetricItem metricThemeColor={metric.themeColor}>
{metric.chartLabel}
</MetricItem>
<strong>{getNumForChart(dataPoint)}</strong>
</MetricLi>
);
})}
</MetricList>
</ContentBox>
</div>,
document.body
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export interface DataMetric {
| 'infographicC'
| 'infographicD'
| 'infographicE';
style?: Record<string, string>
}

export const DATA_METRICS: DataMetric[] = [
{
id: 'min',
label: 'Min',
chartLabel: 'Min',
themeColor: 'infographicA'
themeColor: 'infographicA',
style: { "strokeDasharray": "2 2"}
},
{
id: 'mean',
Expand All @@ -33,7 +35,8 @@ export const DATA_METRICS: DataMetric[] = [
id: 'max',
label: 'Max',
chartLabel: 'Max',
themeColor: 'infographicC'
themeColor: 'infographicC',
style: { "strokeDasharray": "2 2"}
},
{
id: 'std',
Expand All @@ -49,6 +52,8 @@ export const DATA_METRICS: DataMetric[] = [
}
];

export const DEFAULT_DATA_METRICS: DataMetric[] = DATA_METRICS.filter(metric => metric.id ==='mean' || metric.id==='std');

const MetricList = styled(DropMenu)`
display: flex;
flex-flow: column;
Expand Down
Loading
Loading