Skip to content

Commit

Permalink
[Yash] revert to code before semgrep fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yashanandan committed Apr 24, 2024
1 parent 33ce6f8 commit e900b62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 31 deletions.
51 changes: 21 additions & 30 deletions src/graphing/components/quadrants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ let prevLeft, prevTop
let quadrantScrollHandlerReference
let scrollFlag = false

const createElement = (tagName, text, attributes) => {
const tag = document.createElement(tagName)
Object.keys(attributes).forEach((keyName) => {
tag.setAttribute(keyName, attributes[keyName])
})
tag.appendChild(document.createTextNode(text))
return tag
}

const replaceChild = (element, child) => {
let elementChild = element.lastElementChild
while (elementChild) {
element.removeChild(elementChild)
elementChild = element.lastElementChild
}
element.appendChild(child)
}

function selectRadarQuadrant(order, startAngle, name) {
const noOfBlips = d3.selectAll('.quadrant-group-' + order + ' .blip-link').size()
d3.select('#radar').classed('no-blips', noOfBlips === 0)
Expand Down Expand Up @@ -217,19 +199,19 @@ function wrapQuadrantNameInMultiLine(elem, isTopQuadrants, quadrantNameGroup, ti
const words = text.split(' ')
let line = ''

replaceChild(element, createElement('tspan', text, { id: 'text-width-check' }))
element.innerHTML = `<tspan id="text-width-check">${text}</tspan >`
const testElem = document.getElementById('text-width-check')

function maxCharactersToFit(testLine, suffix) {
let j = 1
let firstLineWidth = 0
const testElem1 = document.getElementById('text-width-check')
testElem1.textContent = testLine
testElem1.innerHTML = testLine
if (testElem1.getBoundingClientRect().width < maxWidth) {
return testLine.length
}
while (firstLineWidth < maxWidth && testLine.length > j) {
testElem1.textContent = testLine.substring(0, j) + suffix
testElem1.innerHTML = testLine.substring(0, j) + suffix
firstLineWidth = testElem1.getBoundingClientRect().width

j++
Expand All @@ -250,33 +232,42 @@ function wrapQuadrantNameInMultiLine(elem, isTopQuadrants, quadrantNameGroup, ti
if (testElem.getBoundingClientRect().width > maxWidth) {
for (let i = 0; i < words.length; i++) {
let testLine = line + words[i] + ' '
testElem.textContent = testLine
testElem.innerHTML = testLine
const textWidth = testElem.getBoundingClientRect().width

if (textWidth > maxWidth) {
if (i === 0) {
let lineBreakIndex = maxCharactersToFit(testLine, '-')
const elementText = `${words[i].substring(0, lineBreakIndex)}-`
element.appendChild(createElement('tspan', elementText, { x: '0', dy }))
element.innerHTML += '<tspan x="0" dy="' + dy + '">' + words[i].substring(0, lineBreakIndex) + '-</tspan>'
const secondLine = words[i].substring(lineBreakIndex, words[i].length) + ' ' + words.slice(i + 1).join(' ')
lineBreakIndex = maxCharactersToFit(secondLine, '...')
const text = `${secondLine.substring(0, lineBreakIndex)}${ellipsis(lineBreakIndex, secondLine)}`
element.appendChild(createElement('tspan', text, { x: '0', dy: '20' }))
element.innerHTML +=
'<tspan x="0" dy="' +
20 +
'">' +
secondLine.substring(0, lineBreakIndex) +
ellipsis(lineBreakIndex, secondLine) +
'</tspan>'
break
} else {
element.appendChild(createElement('tspan', line, { x: '0', dy }))
element.innerHTML += '<tspan x="0" dy="' + dy + '">' + line + '</tspan>'
const secondLine = words.slice(i).join(' ')
const lineBreakIndex = maxCharactersToFit(secondLine, '...')
const text = `${secondLine.substring(0, lineBreakIndex)}${ellipsis(lineBreakIndex, secondLine)}`
element.appendChild(createElement('tspan', text, { x: '0', dy: '20' }))
element.innerHTML +=
'<tspan x="0" dy="' +
20 +
'">' +
secondLine.substring(0, lineBreakIndex) +
ellipsis(lineBreakIndex, secondLine) +
'</tspan>'
}
line = words[i] + ' '
} else {
line = testLine
}
}
} else {
element.appendChild(createElement('tspan', text, { x: '0' }))
element.innerHTML += '<tspan x="0">' + text + '</tspan>'
}

document.getElementById('text-width-check').remove()
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/images/favicon.ico" rel="icon" />
<link rel="preconnect" href="https://rsms.me/" />
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" integrity="sha512-byor" />
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" integrity="sha512-byor" crossorigin="anonymous" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Bitter:wght@700&display=swap" rel="stylesheet" />
Expand Down

0 comments on commit e900b62

Please sign in to comment.