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

Add analysis metrics menu to chart #860

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { useTheme } from 'styled-components';
import { extent, scaleLinear, ScaleTime, line, ScaleLinear } from 'd3';
import { useAtomValue } from 'jotai';
import { AnimatePresence, motion } from 'framer-motion';

import styled from 'styled-components';
import {
CollecticonCog,
} from '@devseed-ui/collecticons';
import { isExpandedAtom } from '../../atoms/timeline';
import { RIGHT_AXIS_SPACE } from '../../constants';
import { DatasetTrackMessage } from './dataset-track-message';
import { DataMetric } from './analysis-metrics';

import LayerChartAnalysisMenu from './layer-chart-analysis-menu';
import { getNumForChart } from '$components/common/chart/utils';
import {
TimelineDatasetAnalysisSuccess,
Expand All @@ -24,10 +27,19 @@ interface DatasetChartProps {
dataset: TimelineDatasetSuccess;
activeMetrics: DataMetric[];
highlightDate?: Date;
onUpdateSettings: (type: string, m: DataMetric[]) => void;
}

const ChartAnalysisMenu = styled.div`
width: inherit;
position: relative;
display: flex;
justify-content: end;
margin-right: 2.3rem;
`;

export function DatasetChart(props: DatasetChartProps) {
const { xScaled, width, isVisible, dataset, activeMetrics, highlightDate } =
const { xScaled, width, isVisible, dataset, activeMetrics, highlightDate, onUpdateSettings } =
props;

const analysisData = dataset.analysis as TimelineDatasetAnalysisSuccess;
Expand Down Expand Up @@ -58,13 +70,18 @@ export function DatasetChart(props: DatasetChartProps) {
);
}, [yExtent, height]);

const chartAnalysisIconTrigger: JSX.Element = <CollecticonCog meaningful title='View layer options' />;

return (
<div>
{!activeMetrics.length && (
<DatasetTrackMessage>
There are no active metrics to visualize.
</DatasetTrackMessage>
)}
<ChartAnalysisMenu>
<LayerChartAnalysisMenu activeMetrics={activeMetrics} onChange={onUpdateSettings} triggerIcon={chartAnalysisIconTrigger} />
</ChartAnalysisMenu>
<svg width={width + RIGHT_AXIS_SPACE} height={height}>
<clipPath id='data-clip'>
<rect width={width} height={height} />
Expand Down Expand Up @@ -195,12 +212,13 @@ function AxisGrid(props: AxisGridProps) {
>
{yLabel && (
<text
y={width + RIGHT_AXIS_SPACE - 20}
y={width + RIGHT_AXIS_SPACE - 45}
x={-height / 2}
transform='rotate(-90)'
textAnchor='middle'
fontSize='0.75rem'
fill={theme.color?.base}
margin-right='2rem'
>
{yLabel}
</text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { useDatasetHover } from '$components/exploration/hooks/use-dataset-hover';
import {
useTimelineDatasetAtom,
useTimelineDatasetSettings,
useTimelineDatasetVisibility
} from '$components/exploration/atoms/hooks';
import {
Expand Down Expand Up @@ -102,6 +103,8 @@ export function DatasetListItem(props: DatasetListItemProps) {

const [isVisible, setVisible] = useTimelineDatasetVisibility(datasetAtom);
const [modalLayerInfo, setModalLayerInfo] = React.useState<LayerInfoModalData>();
const [, setSetting] = useTimelineDatasetSettings(datasetAtom);

const queryClient = useQueryClient();

const retryDatasetMetadata = useCallback(() => {
Expand Down Expand Up @@ -252,6 +255,7 @@ export function DatasetListItem(props: DatasetListItemProps) {
dataset={dataset}
activeMetrics={analysisMetrics}
highlightDate={dataPoint?.date}
onUpdateSettings={setSetting}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import styled from 'styled-components';
import { Dropdown } from '@devseed-ui/dropdown';
import AnalysisMetrics, { DataMetric } from './analysis-metrics';
import { TipButton } from '$components/common/tip-button';


interface ChartAnalysisProps {
triggerIcon: JSX.Element;
onChange: (changeType: string, item) => void;
activeMetrics: DataMetric[];
}

const IconButton = styled(TipButton)`
z-index: 1;
`;

export default function LayerChartAnalysisMenu ({activeMetrics, triggerIcon, onChange}: ChartAnalysisProps) {
return (
<Dropdown
alignment='right'
direction='up'
triggerElement={(props) => (
<IconButton
tipContent='Analysis metrics'
variation='base-text'
size='small'
fitting='skinny'
{...props}
>
{triggerIcon}
</IconButton>
)}
>
<AnalysisMetrics
activeMetrics={activeMetrics}
onMetricsChange={(m) => onChange('analysisMetrics', m)}
/>
</Dropdown>
);
}
Loading