@longline/aqua-ui 1.0.238 → 1.0.239
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,14 +13,30 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
};
|
|
14
14
|
return __assign.apply(this, arguments);
|
|
15
15
|
};
|
|
16
|
-
import * as React from
|
|
17
|
-
import styled from
|
|
18
|
-
var HistogramSingleValueBase = function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
import * as React from "react";
|
|
17
|
+
import styled from "styled-components";
|
|
18
|
+
var HistogramSingleValueBase = function (_a) {
|
|
19
|
+
var value = _a.value, className = _a.className;
|
|
20
|
+
var textRef = React.useRef(null);
|
|
21
|
+
var _b = React.useState(1), scale = _b[0], setScale = _b[1];
|
|
22
|
+
React.useEffect(function () {
|
|
23
|
+
if (textRef.current) {
|
|
24
|
+
// measure at default font size
|
|
25
|
+
var bbox = textRef.current.getBBox();
|
|
26
|
+
if (bbox.width && bbox.height) {
|
|
27
|
+
var scaleX = 100 / bbox.width;
|
|
28
|
+
var scaleY = 100 / bbox.height;
|
|
29
|
+
// uniform scale (preserve proportions)
|
|
30
|
+
setScale(Math.min(scaleX, scaleY));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, [value]);
|
|
34
|
+
return (React.createElement("div", { className: className },
|
|
35
|
+
React.createElement("svg", { viewBox: "0 0 100 100", preserveAspectRatio: "xMidYMid meet" },
|
|
36
|
+
React.createElement("g", { transform: "translate(50,50) scale(".concat(scale, ") translate(-50,-50)") },
|
|
37
|
+
React.createElement("text", { ref: textRef, x: "50", y: "50", dominantBaseline: "middle", textAnchor: "middle" }, value)))));
|
|
22
38
|
};
|
|
23
|
-
var HistogramSingleValueStyled = styled(HistogramSingleValueBase)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n
|
|
39
|
+
var HistogramSingleValueStyled = styled(HistogramSingleValueBase)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n inset: 0;\n padding: 16px;\n & > svg {\n width: 100%;\n height: 100%;\n font: ", ";\n fill: #fff;\n user-select: none;\n }\n"], ["\n position: absolute;\n inset: 0;\n padding: 16px;\n & > svg {\n width: 100%;\n height: 100%;\n font: ", ";\n fill: #fff;\n user-select: none;\n }\n"])), function (p) { return p.theme.font.dataSmall; });
|
|
24
40
|
var HistogramSingleValue = function (props) { return React.createElement(HistogramSingleValueStyled, __assign({}, props)); };
|
|
25
41
|
export { HistogramSingleValue };
|
|
26
42
|
var templateObject_1;
|