Skip to content

Commit

Permalink
Merge pull request #153 from GNS-Science/feature/MFD_bar_chart
Browse files Browse the repository at this point in the history
Feature/mfd bar chart
  • Loading branch information
benjamineac authored Jun 30, 2023
2 parents d3cca8d + 921fcad commit 35e6f71
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gns-science/toshi-nest",
"version": "3.9.4",
"version": "3.9.5",
"description": "The toshi-nest is for fledgling work e.g. reusable Node components to share across TUI and other projects",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
Expand Down
25 changes: 21 additions & 4 deletions src/MfdPlot/MfdPlot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Axis, AnimatedLineSeries, Tooltip, XYChart } from '@visx/xychart';
import { Axis, AnimatedLineSeries, AnimatedBarSeries, Tooltip, XYChart } from '@visx/xychart';
import { FormControlLabel, Menu, Radio, RadioGroup, MenuItem, IconButton, Typography } from '@mui/material';
import { LegendOrdinal } from '@visx/legend';
import { scaleOrdinal } from '@visx/scale';
Expand All @@ -8,9 +8,24 @@ import { Group } from '@visx/group';
import SettingsIcon from '@mui/icons-material/Settings';

import { MfdPlotProps, Datum } from './MfdPlot.types';
export const MfdPlot = ({ data, width, height, xLabel, yLabel, labelProps, xLabelOffset, yLabelOffset, header, lineColours, xScaleDomain, yScaleDomain, legendDomain }: MfdPlotProps) => {
export const MfdPlot = ({
data,
width,
height,
xLabel,
yLabel,
labelProps,
xLabelOffset,
yLabelOffset,
header,
lineColours,
xScaleDomain,
yScaleDomain,
legendDomain,
defaultLinesVisible,
}: MfdPlotProps) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [linesToDisplay, setLinesToDisplay] = useState<string>('Incremental');
const [linesToDisplay, setLinesToDisplay] = useState<string>(defaultLinesVisible || 'Both');
const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>, value: string) => {
setLinesToDisplay(value);
};
Expand Down Expand Up @@ -74,7 +89,9 @@ export const MfdPlot = ({ data, width, height, xLabel, yLabel, labelProps, xLabe
<Axis orientation="left" label={yLabel} labelProps={labelProps} labelOffset={yLabelOffset} />
<RectClipPath id={'clip'} x={50} y={-50} width={width} height={height} />
<Group clipPath={'url(#clip)'}>
{['Incremental', 'Both'].includes(linesToDisplay) && <AnimatedLineSeries dataKey="key" data={data} xAccessor={(d) => d?.bin_center} yAccessor={(d) => d?.rate} stroke={lineColours[0]} />}
{['Incremental', 'Both'].includes(linesToDisplay) && (
<AnimatedBarSeries dataKey="key" data={data} xAccessor={(d) => d?.bin_center} yAccessor={(d) => d?.rate} colorAccessor={() => lineColours[0]} />
)}
{['Cumulative', 'Both'].includes(linesToDisplay) && (
<AnimatedLineSeries dataKey="cumulativeKey" data={data} xAccessor={(d) => d?.bin_center} yAccessor={(d) => d?.cumulative_rate} stroke={lineColours[1]} />
)}
Expand Down
1 change: 1 addition & 0 deletions src/MfdPlot/MfdPlot.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export interface MfdPlotProps {
fill?: string;
};
header?: string;
defaultLinesVisible?: string;
}

0 comments on commit 35e6f71

Please sign in to comment.