From 6e3fe5f7eec21b748526d7bf3bbf090640b4b75b Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 11 Jul 2022 12:51:21 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=80=D0=B5=D0=BD=D0=B4=D0=B5=D1=80=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=B8=D1=85=20=D0=BE=D0=B1=D0=BB=D0=B0=D1=81=D1=82=D0=B5=D0=B9?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/d3/renders/index.ts | 1 + src/components/d3/renders/rect_area.ts | 37 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/components/d3/renders/rect_area.ts diff --git a/src/components/d3/renders/index.ts b/src/components/d3/renders/index.ts index 3ba343e..4caba1d 100644 --- a/src/components/d3/renders/index.ts +++ b/src/components/d3/renders/index.ts @@ -2,3 +2,4 @@ export * from './area' export * from './line' export * from './needle' export * from './points' +export * from './rect_area' diff --git a/src/components/d3/renders/rect_area.ts b/src/components/d3/renders/rect_area.ts new file mode 100644 index 0000000..8e25e94 --- /dev/null +++ b/src/components/d3/renders/rect_area.ts @@ -0,0 +1,37 @@ +import { getByAccessor } from '../functions' +import { ChartRegistry } from '../types' + +export const renderRectArea = >( + xAxis: (value: d3.NumberValue) => number, + yAxis: (value: d3.NumberValue) => number, + chart: ChartRegistry +) => { + if ( + chart.type !== 'rect_area' || + !chart.minXAccessor || + !chart.maxXAccessor || + !chart.minYAccessor || + !chart.maxYAccessor || + !chart.data + ) return + + const data = chart.data + const xMin = getByAccessor(chart.minXAccessor) + const xMax = getByAccessor(chart.maxXAccessor) + const yMin = getByAccessor(chart.minYAccessor) + const yMax = getByAccessor(chart.maxYAccessor) + + chart().attr('fill', 'currentColor') + + const rects = chart().selectAll('rect').data(data) + + rects.exit().remove() + rects.enter().append('rect') + + const actualRects = chart() + .selectAll>('rect') + .attr('x1', (d) => xAxis(xMin(d))) + .attr('x2', (d) => xAxis(xMax(d))) + .attr('y1', (d) => yAxis(yMin(d))) + .attr('y2', (d) => yAxis(yMax(d))) +}