UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

24 lines (23 loc) 715 B
import { round } from 'lodash'; function getCompareTrend(value) { if (value > 0) { return "up" /* UP */; } if (value < 0) { return "down" /* DOWN */; } return "equal" /* EQUAL */; } export function getDValue(current, compare, formatter) { if (current === void 0) { current = 0; } if (compare === void 0) { compare = 0; } if (!compare) { return !current ? { value: formatter(current), trend: "equal" /* EQUAL */ } : { value: formatter(current), trend: "up" /* UP */ }; } else { var result = round(((current - compare) / compare) * 100, 1); return { value: result + "%", trend: getCompareTrend(result) }; } }