Skip to content

Commit

Permalink
Merge pull request #392 from adobe/cleanup
Browse files Browse the repository at this point in the history
chore: fix smells
  • Loading branch information
marshallpete authored Aug 13, 2024
2 parents 9553809 + 172e5ea commit 9959660
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/RscChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
useChartImperativeHandle(forwardedRef, { chartView, title });

const {
hiddenSeriesState,
setHiddenSeries,
legendHiddenSeries,
setLegendHiddenSeries,
descriptions: legendDescriptions,
isToggleable: legendIsToggleable,
onClick: onLegendClick,
Expand Down Expand Up @@ -175,7 +175,6 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
<LegendTooltip
value={value}
descriptions={legendDescriptions}
// TODO: support multiple legends
domain={chartView.current?.scale('legend0Entries').domain()}
/>
);
Expand Down Expand Up @@ -212,13 +211,13 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
backgroundColor: getColorValue('gray-50', colorScheme),
};
if (legendIsToggleable) {
signals.hiddenSeries = hiddenSeriesState;
signals.hiddenSeries = legendHiddenSeries;
}
signals[SELECTED_ITEM] = selectedData?.[MARK_ID] ?? null;
signals[SELECTED_SERIES] = selectedData?.[SERIES_ID] ?? null;

return signals;
}, [colorScheme, hiddenSeriesState, legendIsToggleable]);
}, [colorScheme, legendHiddenSeries, legendIsToggleable]);

return (
<>
Expand Down Expand Up @@ -262,7 +261,7 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
});
if (popovers.length || legendIsToggleable || onLegendClick) {
if (legendIsToggleable) {
view.signal('hiddenSeries', hiddenSeriesState);
view.signal('hiddenSeries', legendHiddenSeries);
}
setSelectedSignals({
selectedData: selectedData.current,
Expand All @@ -272,12 +271,12 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
'click',
getOnMarkClickCallback(
chartView,
hiddenSeriesState,
legendHiddenSeries,
chartId,
selectedData,
selectedDataBounds,
selectedDataName,
setHiddenSeries,
setLegendHiddenSeries,
legendIsToggleable,
onLegendClick
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Annotation/Annotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { FC } from 'react';

import { AnnotationProps } from '../../types';

const Annotation: FC<AnnotationProps> = ({ textKey = 'annotation', style }) => {
const Annotation: FC<AnnotationProps> = ({ textKey = 'annotation' }) => {
return null;
};

Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { Legend } from '../components/Legend';
import { ChartChildElement, LegendDescription, LegendElement } from '../types';

interface UseLegendProps {
hiddenSeriesState: string[];
setHiddenSeries: (hiddenSeries: string[]) => void;
legendHiddenSeries: string[];
setLegendHiddenSeries: (legendHiddenSeries: string[]) => void;
descriptions?: LegendDescription[];
isToggleable?: boolean;
onClick?: (seriesName: string) => void;
Expand All @@ -31,8 +31,8 @@ export default function useLegend(children: ChartChildElement[]): UseLegendProps
const legend = useMemo(() => {
return getElement(createElement(Chart, { data: [] }, children), Legend);
}, [children]) as LegendElement;
const [hiddenSeriesState, setHiddenSeries] = useState<string[]>(legend?.props?.defaultHiddenSeries ?? []);
if (!legend) return { hiddenSeriesState, setHiddenSeries };
const [legendHiddenSeries, setLegendHiddenSeries] = useState<string[]>(legend?.props?.defaultHiddenSeries ?? []);
if (!legend) return { legendHiddenSeries, setLegendHiddenSeries };
const { descriptions, isToggleable, onClick, onMouseOut, onMouseOver } = legend.props;
return { hiddenSeriesState, setHiddenSeries, descriptions, isToggleable, onClick, onMouseOut, onMouseOver };
return { legendHiddenSeries, setLegendHiddenSeries, descriptions, isToggleable, onClick, onMouseOut, onMouseOver };
}
2 changes: 1 addition & 1 deletion src/specBuilder/axis/axisTrellisUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getTrellisAxisProps = (scaleName: string): Partial<AxisSpecProps> =
if (scaleName.includes('TrellisBand')) {
// shift the labels up/left half the scale bandwidth
const labelOffsetSignal = `bandwidth('${scaleName}') / -2`;
const axisType = scaleName[0] === 'x' ? 'x' : 'y';
const axisType = scaleName.startsWith('x') ? 'x' : 'y';
trellisAxisProps = {
position: axisType === 'x' ? 'top' : 'left',
labelFontWeight: 'bold',
Expand Down

0 comments on commit 9959660

Please sign in to comment.