import { ChartOffset, ChartRegistry } from '@components/d3/types' export const renderNeedle = >( xAxis: (value: d3.NumberValue) => number, yAxis: (value: d3.NumberValue) => number, chart: ChartRegistry, data: DataType[], height: number, offset: ChartOffset ): DataType[] => { if (chart.type !== 'needle') return data data = data.filter(chart.y) const currentNeedles = chart() .selectAll('line') .data(data) currentNeedles.exit().remove() currentNeedles.enter().append('line') chart() .selectAll('line') .transition() .duration(chart.animDurationMs ?? 0) .attr('x1', (d) => xAxis(chart.x(d))) .attr('x2', (d) => xAxis(chart.x(d))) .attr('y1', height - offset.bottom - offset.top) .attr('y2', (d) => yAxis(chart.y(d))) .attr('stroke-dasharray', String(chart.dash ?? '')) return data }