Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix legend font size issue #33

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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