Skip to content

Commit

Permalink
Fix legend font size issue (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
neesjanvaneck authored Sep 16, 2022
1 parent 3b664f8 commit 925cffa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/components/ui/ClusterColorLegend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ const ClusterColorLegend = observer(({ showTopClustersOnly, canvasWidth, legendW

ctx.clearRect(0, 0, canvasWidth * visualizationStore.pixelRatio, canvasHeight * visualizationStore.pixelRatio);

ctx.font = `${12 * visualizationStore.pixelRatio}px ${font}`;
ctx.font = `${0.75 * visualizationStore.pixelRatio}rem ${font}`;
ctx.textBaseline = 'middle';
ctx.lineWidth = lineWidth * visualizationStore.pixelRatio;

const letterWidth = ctx.measureText('a');
const maxTextLength = Math.floor(((itemWidth - radius - textPadding) * visualizationStore.pixelRatio - 2 * letterWidth.width) / letterWidth.width);
let hovered;
legendItems.forEach((item, i) => {
const itemX = i % 2 === 0 ? 0 : itemWidth;
Expand All @@ -72,7 +74,7 @@ const ClusterColorLegend = observer(({ showTopClustersOnly, canvasWidth, legendW
// Draw text.
const x = cx + radius + textPadding;
const y = cy;
const textIsHovered = item.value.length > 18 && mouseCoord.length
const textIsHovered = item.value.length > maxTextLength && mouseCoord.length
&& mouseCoord[0] > itemX
&& mouseCoord[0] < itemX + itemWidth
&& mouseCoord[1] > itemY
Expand All @@ -89,7 +91,7 @@ const ClusterColorLegend = observer(({ showTopClustersOnly, canvasWidth, legendW
text: item.value,
};
}
const itemText = trimTextEnd(item.value, 18);
const itemText = trimTextEnd(item.value, maxTextLength);
ctx.fillStyle = uiStore.darkTheme ? color.colorDarkTheme : color.colorLightTheme;
ctx.fillText(itemText, x * visualizationStore.pixelRatio, y * visualizationStore.pixelRatio);
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/LegendPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ScoreColorLegend from 'components/ui/ScoreColorLegend';
import ScoreOptionsPanel from 'components/ui/ScoreOptionsPanel';
import * as s from './styles';

const sizeLegendPanelWidth = 76;
const sizeLegendPanelWidth = 80;

const LegendPanel = observer(() => {
const configStore = useContext(ConfigStoreContext);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/ScoreColorLegend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ScoreColorLegend = observer(({
const scoreRangeDomain = visualizationStore.scoreColorLegendScoreRange.domain();
tickScale.range([0, colorBarWidth]).domain(scoreRangeDomain);
ctx.fillStyle = uiStore.darkTheme ? tickConfig.colorDarkTheme : tickConfig.colorLightTheme;
ctx.font = `${12 * visualizationStore.pixelRatio}px ${font}`;
ctx.font = `${0.75 * visualizationStore.pixelRatio}rem ${font}`;
ctx.textAlign = 'center';
const ticks = tickScale.ticks(5);
_each(ticks, tick => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/SizeLegend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const SizeLegend = observer(({ canvasWidth, canvasHeight, customFont }) => {

const draw = () => {
ctx.clearRect(0, 0, canvasWidth * visualizationStore.pixelRatio, canvasHeight * visualizationStore.pixelRatio);
ctx.font = `${12 * visualizationStore.pixelRatio}px ${font}`;
ctx.font = `${0.75 * visualizationStore.pixelRatio}rem ${font}`;
ctx.textBaseline = 'middle';
ctx.lineWidth = lineWidth * visualizationStore.pixelRatio;
ctx.strokeStyle = uiStore.darkTheme ? color.colorDarkTheme : color.colorLightTheme;
Expand Down

0 comments on commit 925cffa

Please sign in to comment.