From 2b58afb9156dafdf67fc44f6efd76f46472ddd72 Mon Sep 17 00:00:00 2001 From: Eric Radman Date: Mon, 30 Oct 2023 15:18:20 -0400 Subject: [PATCH] Revert "Render counter widgets using relative font size" Undo previous commits 2795e1b7 593b6ae6 --- .../app/components/dashboards/dashboard-grid.less | 1 + viz-lib/src/visualizations/counter/Renderer.tsx | 15 +++++++-------- viz-lib/src/visualizations/counter/render.less | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/app/components/dashboards/dashboard-grid.less b/client/app/components/dashboards/dashboard-grid.less index c76a05e08a..1f5d0b39bf 100644 --- a/client/app/components/dashboards/dashboard-grid.less +++ b/client/app/components/dashboards/dashboard-grid.less @@ -123,6 +123,7 @@ right: 10px; bottom: 15px; height: auto; + overflow: hidden; padding: 0; } } diff --git a/viz-lib/src/visualizations/counter/Renderer.tsx b/viz-lib/src/visualizations/counter/Renderer.tsx index 47d011ec39..3c925e423e 100644 --- a/viz-lib/src/visualizations/counter/Renderer.tsx +++ b/viz-lib/src/visualizations/counter/Renderer.tsx @@ -10,18 +10,17 @@ import "./render.less"; function getCounterStyles(scale: any) { return { - fontSize: `${scale}pt`, + msTransform: `scale(${scale})`, + MozTransform: `scale(${scale})`, + WebkitTransform: `scale(${scale})`, + transform: `scale(${scale})`, }; } function getCounterScale(container: any) { - // size of font in base container - // children use a relative font size (em) - if (container.closest('.visualization-preview') || container.closest('.ant-tabs-tabpane')) { - return "60"; - } - const fontSize = 12 + container.clientHeight / 5; - return fontSize > 60 ? "60" : fontSize.toFixed(); + const inner = container.firstChild; + const scale = Math.min(container.offsetWidth / inner.offsetWidth, container.offsetHeight / inner.offsetHeight); + return Number(isFinite(scale) ? scale : 1).toFixed(2); // keep only two decimal places } export default function Renderer({ data, options, visualizationName }: any) { diff --git a/viz-lib/src/visualizations/counter/render.less b/viz-lib/src/visualizations/counter/render.less index 96ee33f1c9..db19ccb723 100755 --- a/viz-lib/src/visualizations/counter/render.less +++ b/viz-lib/src/visualizations/counter/render.less @@ -2,14 +2,15 @@ display: block; text-align: center; padding: 15px 10px; - position: relative; overflow: hidden; + position: relative; .counter-visualization-content { margin: 0; padding: 0; - font-size: 2em; + font-size: 80px; line-height: normal; + overflow: hidden; display: flex; flex-direction: column; align-items: center;