From 8bf22bc2e602fd3901e358b63239a999637a65f0 Mon Sep 17 00:00:00 2001 From: paleface001 Date: Wed, 18 Mar 2020 14:57:20 +0800 Subject: [PATCH] fix: remove lodash in gauge shape --- src/plots/gauge/geometry/shape/gauge-shape.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/plots/gauge/geometry/shape/gauge-shape.ts b/src/plots/gauge/geometry/shape/gauge-shape.ts index 321271b6b2..fed354da07 100644 --- a/src/plots/gauge/geometry/shape/gauge-shape.ts +++ b/src/plots/gauge/geometry/shape/gauge-shape.ts @@ -2,7 +2,7 @@ * @author linhuiw * @description 仪表盘形状 */ -import { get, sortedLastIndex } from 'lodash'; +import { get, each, clone } from '@antv/util'; import { registerShape } from '@antv/g2'; import { IGroup, IShape } from '@antv/g-base'; import { GaugeViewConfig } from '../../options'; @@ -45,6 +45,20 @@ interface RingStyle { axis: AxisStyle; } +function sortedLastIndex(arr: number[], value: number) { + const array = clone(arr); + array.sort((a, b) => { + return a - b; + }); + let last = 0; + each(array, (v, index) => { + if (v < value) { + last = index; + } + }); + return last + 1; +} + /** * 仪表盘指针图形 * 指针主体由梯形和一大一小圆形组成, @@ -265,6 +279,7 @@ export class GaugeShape { }); const index = sortedLastIndex(result1, start); + console.log(index); /** 最后一个值也在最后一个区间内 */ const colorIndex = Math.min(index, range.length - 1); fillColor = colors[colorIndex - 1] || background;