Skip to content

Commit

Permalink
fix: remove lodash in gauge shape
Browse files Browse the repository at this point in the history
  • Loading branch information
paleface001 committed Mar 18, 2020
1 parent c2dbdd0 commit 8bf22bc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/plots/gauge/geometry/shape/gauge-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

/**
* 仪表盘指针图形
* 指针主体由梯形和一大一小圆形组成,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8bf22bc

Please # to comment.