Skip to content

Commit

Permalink
Remove HTML parsing of item labels
Browse files Browse the repository at this point in the history
  • Loading branch information
neesjanvaneck committed Jun 24, 2024
1 parent 8f1f04b commit 6d57848
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/components/ui/ControlPanel/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useContext, useEffect, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { TextField } from '@mui/material';
import { useDebounce } from 'use-debounce';
import HTMLReactParser from 'html-react-parser';
import parse from 'autosuggest-highlight/parse';
import _sortBy from 'lodash/sortBy';
import _isUndefined from 'lodash/isUndefined';
Expand Down Expand Up @@ -41,14 +40,13 @@ const Find = observer(() => {
const itemList = () => _sortBy(visualizationStore.items, ['label', 'id'])
.filter(item => item.label.toLowerCase().indexOf(uiStore.itemFilterText.toLowerCase()) !== -1)
.map((item, i) => {
const label = HTMLReactParser(item.label);
const matchPosition = label.toLowerCase().indexOf(uiStore.itemFilterText.toLowerCase());
const labelParts = parse(label, [[matchPosition, matchPosition + uiStore.itemFilterText.length]]);
const matchPosition = item.label.toLowerCase().indexOf(uiStore.itemFilterText.toLowerCase());
const labelParts = parse(item.label, [[matchPosition, matchPosition + uiStore.itemFilterText.length]]);
return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<p
className={s.listItem}
key={`${label}-${String(i)}`}
key={`${item.label}-${String(i)}`}
onClick={() => changeClickedItem(item)}
>
{
Expand Down
4 changes: 1 addition & 3 deletions src/store/visualization/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-bitwise */
import HTMLReactParser from 'html-react-parser';
import { makeAutoObservable } from 'mobx';
import { scaleLinear, scaleOrdinal } from 'd3-scale';
import { extent, sum } from 'd3-array';
Expand Down Expand Up @@ -568,8 +567,7 @@ export default class State {
item._fontSize = this.pixelRatio * (scale * labelMinFontSize + labelFontSizeScalingConstant * item._normalizedWeight ** itemSizeVariation);
if (this.labelCanvasContext) {
this.labelCanvasContext.font = `${item._fontSize}px ${fontFamily}`;
const label = HTMLReactParser(item.label);
item._labelText = (label || '').slice(0, maxLabelLength) || '';
item._labelText = (item.label || '').slice(0, maxLabelLength) || '';
item._labelTextWidth = this.labelCanvasContext.measureText(item._labelText).width;
}
});
Expand Down

0 comments on commit 6d57848

Please sign in to comment.