Skip to content

Commit

Permalink
make an approximation as a straight line.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum committed Jul 8, 2024
1 parent 6ab1cd9 commit cce0555
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions ui/shared/chart/ChartArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ChartArea = ({ id, xScale, yScale, color, data, disableAnimation, ...props

const d = React.useMemo(() => {
const area = d3.area<TimeChartItem>()
.defined(({ isApproximate }) => !isApproximate)
.x(({ date }) => xScale(date))
.y1(({ value }) => yScale(value))
.y0(() => yScale(yScale.domain()[0]))
Expand Down
3 changes: 2 additions & 1 deletion ui/shared/chart/ChartLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { TimeChartItem } from 'ui/shared/chart/types';

import type { AnimationType } from './utils/animations';
import { ANIMATIONS } from './utils/animations';
import { getIncompleteDataLineSource } from './utils/formatters';

interface Props extends React.SVGProps<SVGPathElement> {
xScale: d3.ScaleTime<number, number> | d3.ScaleLinear<number, number>;
Expand Down Expand Up @@ -49,7 +50,7 @@ const ChartLine = ({ xScale, yScale, data, animation, ...props }: Props) => {
<>
<path
ref={ incompleteDataPathRef }
d={ line(data) || undefined }
d={ line(getIncompleteDataLineSource(data)) || undefined }
strokeWidth={ 1 }
strokeLinecap="round"
fill="none"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions ui/shared/chart/utils/formatters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { TimeChartItem } from '../types';

export const getIncompleteDataLineSource = (data: Array<TimeChartItem>): Array<TimeChartItem> => {
const result: Array<TimeChartItem> = [];

for (let index = 0; index < data.length; index++) {
const current = data[index];
if (current.isApproximate) {
const prev = data[index - 1];
const next = data[index + 1];

prev && !prev.isApproximate && result.push(prev);
result.push(current);
next && !next.isApproximate && result.push(next);
}
}

return result;
};

0 comments on commit cce0555

Please sign in to comment.