Skip to content

Commit

Permalink
fix: legend tick
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Dec 2, 2021
1 parent 2c61203 commit e261775
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/l7plot/src/layers/dot-layer/helper.ts
Expand Up @@ -9,9 +9,14 @@ export const getColorLegendItems = (legendItems: LegendItemTick[] | LegendItemEx
let items: LegendItemExtent[] = [];

if (isLegendItemI(legendItems)) {
if (legendItems.length === 1) return [];
const cache = new Map<string, number[]>();
if (legendItems.length === 1) {
const { color, value } = legendItems[0];
const range = [value, value] as [number, number];
return [{ color, value: range }];
}

const cache = new Map<string, number[]>();
let preCacheData: number[] | undefined;
for (let index = 0; index < legendItems.length; index++) {
const { color, value } = legendItems[index];
if (cache.has(color)) {
Expand All @@ -20,16 +25,19 @@ export const getColorLegendItems = (legendItems: LegendItemTick[] | LegendItemEx
data.push(value);
}
} else {
cache.set(color, [value]);
const range = [value];
cache.set(color, range);
if (preCacheData) {
preCacheData.push(value);
}
preCacheData = range;
}
}

let preValue: number;
cache.forEach((value, color) => {
const min = value[0];
const max = value[value.length - 1];
const range: [number, number] = [preValue ? preValue : min, max];
preValue = max;
const range: [number, number] = [min, max];
items.push({ color, value: range });
});
} else {
Expand Down

0 comments on commit e261775

Please sign in to comment.