import React from 'react'; import { forwardRef } from 'react'; import { withBluefish, withBluefishFn, BBox } from '../../../../bluefish'; import { NewBBox } from '../../../../NewBBox'; import { PlotContext } from '../Plot'; import { scaleLinear } from 'd3-scale'; import { max } from 'lodash'; import { Row } from '../../../../components/Row'; export type NewBarYProps = Omit, 'x' | 'y' | 'fill' | 'width' | 'height'> & { x: keyof T; y: keyof T; color: keyof T; data?: T[]; totalWidth?: number; spacing?: number; }; export const NewBarY = forwardRef(function NewBarY(props: NewBarYProps, ref: any) { const context = React.useContext(PlotContext); const data = props.data ?? context.data; const totalWidth = props.totalWidth ?? context.dimensions.width; const colorScale = context.scales.colorScale; console.log('colorScale', colorScale); return ( {(data as any[]).map((d) => ( scaleLinear([0, max(data.map((d: any) => +d[props.y]))!], [0, height])} /> ))} ); }); NewBarY.displayName = 'NewBarY'; export type RectScaleProps = React.SVGProps & { yScale: (d: any) => (y: number) => number; }; export const RectScale = withBluefishFn( (props: RectScaleProps) => { const { x, y, width, height } = props; return (_, constraints) => { const scaledY = y !== undefined ? props.yScale(constraints.height)(+y) : undefined; const scaledHeight = height !== undefined ? props.yScale(constraints.height)(+height) : undefined; return { left: x !== undefined ? +x : undefined, top: scaledY, width: width !== undefined ? +width : undefined, height: scaledHeight, }; }; }, forwardRef((props: RectScaleProps & { $bbox?: Partial }, ref: any) => { const { $bbox, yScale, ...rest } = props; return ( // translate and scale based on $bbox.coord ); }), ); RectScale.displayName = 'RectScale';