@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
28 lines (27 loc) • 855 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDValue = void 0;
var lodash_1 = require("lodash");
function getCompareTrend(value) {
if (value > 0) {
return "up" /* UP */;
}
if (value < 0) {
return "down" /* DOWN */;
}
return "equal" /* EQUAL */;
}
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 = lodash_1.round(((current - compare) / compare) * 100, 1);
return { value: result + "%", trend: getCompareTrend(result) };
}
}
exports.getDValue = getDValue;