Skip to content

Commit

Permalink
Fix 655e621
Browse files Browse the repository at this point in the history
This commit in question was meant to revert only setting maxCount=100000, levels=1000 and defaultLimit = 100000. But it accidentally also reverted another useful change: giving the SVG graph an ID so other SVG elements on the page don't interfere with the functionality of the "open graph in new window"-button.
  • Loading branch information
runeksvendsen committed Nov 11, 2024
1 parent bba6dea commit 1b813dc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/server/Server/Pages/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ page cfg (SearchEnv graph lookupVertex) srcTxt dstTxt maxCount' mNoGraph = do
resultGraphE
pure $ do
h3_ "Result graph"
let addSvgElemId = T.replace "<svg " ("<svg id=\"" <> svgGraphId <> "\" ") -- hacky way to add an "id" attribute to the SVG graph
svgGraphId = "graph"
either
(const $ mkErrorText "Failed to render result graph")
toHtmlRaw -- 'toHtmlRaw' because 'resultGraph' contains tags we don't want escaped
(toHtmlRaw . addSvgElemId) -- 'toHtmlRaw' because 'resultGraph' contains tags we don't want escaped
resultGraphE
openSvgInNewWindowBtn
openSvgInNewWindowBtn svgGraphId

noResultsText :: (FunGraph.FullyQualifiedType, FunGraph.FullyQualifiedType) -> Html ()
noResultsText (src, dst) =
Expand Down Expand Up @@ -283,8 +285,8 @@ page cfg (SearchEnv graph lookupVertex) srcTxt dstTxt maxCount' mNoGraph = do
mkResultAttribute :: T.Text -> Attribute
mkResultAttribute = data_ "result-number"

openSvgInNewWindowBtn :: Html ()
openSvgInNewWindowBtn = do
openSvgInNewWindowBtn :: T.Text -> Html ()
openSvgInNewWindowBtn svgGraphId = do
button_
[ id_ btnId
, style_ "visibility:hidden; display:none;" -- Hide the button if JS is disabled
Expand All @@ -299,7 +301,7 @@ openSvgInNewWindowBtn = do
, " btnElem.style.visibility = \"visible\";"
, " // open SVG in new window on click"
, " btnElem.onclick = (evt) => {"
, " const svg = document.querySelector(\"svg\");"
, " const svg = document.getElementById(\"" <> svgGraphId <> "\");"
, " const as_text = new XMLSerializer().serializeToString(svg);"
, " const blob = new Blob([as_text], { type: \"image/svg+xml\" });"
, " const url = URL.createObjectURL(blob);"
Expand Down

0 comments on commit 1b813dc

Please sign in to comment.