Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jhrcek
Copy link
Contributor

@jhrcek jhrcek commented Oct 2, 2025

No description provided.

yTicks = ticks1D plotH (yNumTicks cfg) (ymin, ymax) True
baseLbl = List.replicate plotH pad

setAt :: [Text] -> Int -> Text -> [Text]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big deal, but this impl. is less efficient than it could be, because it traverses the input list multiple times:

  • length traverses the spine of the list to determine the length
  • take, drop and the two calls to <> repeatedly traverse the initial segment of length i of the list to do their job.

So I'm just adding custom recursive function that only traverses the initial segment of length i once.

It DOES change semantics a bit compared to the first implementation of setAt

setAt row i v = take i row <> [v] <> drop (i + 1) row

which "inserts v in all cases" (even if the index is out of bounds of list indices) - which was probably not the indented behavior?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Not the intended behaviour.

, ("Class D", [65, 70, 72, 68, 75, 80, 73, 71, 69, 74, 77, 76])
]
defPlot{plotTitle = "Test Score Distribution by Class"}
defPlot{plotTitle = "Test Score Distribution by Class", xNumTicks = 4}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only showing the default 3 x labels, which makes one of the labels not appear and makes the demo look broken.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still having trouble with grid axes in general. Was thinking to rewrite parts of this when I get time.

maximum' [] = 1
maximum' xs = maximum xs

safeHead :: [a] -> Maybe a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced this with equivalent function listToMaybe from base.


grid8 = setGridChar grid7 xMid minRow '' (Just col)
grid9 = setGridChar grid8 xMid maxRow '' (Just col)
grid8 = setGridChar grid7 xMid minRow '' (Just col)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These chars were upside down (max should use ┬, min should use ┴)

@jhrcek jhrcek changed the title Use more efficient setAt implementation Collection of small fixes and perf. improvements Oct 4, 2025
, ("Class D", [65, 70, 72, 68, 75, 80, 73, 71, 69, 74, 77, 76])
]
defPlot{plotTitle = "Test Score Distribution by Class"}
defPlot{plotTitle = "Test Score Distribution by Class", xNumTicks = 4}
Copy link
Contributor Author

@jhrcek jhrcek Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only showing the default 3 x labels, which makes one of the labels not appear and makes the demo look broken.
Also the min/max characters are flipped.
The boxes don't look great, but I might improve their rendering in followup PR (by using "corner" box drawing chars).

Image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I don't like the box plots. They are still here more as a gimmick.

( \acc (row, v) ->
setAt acc row (justifyRight left (yFormatter cfg (yEnv row) ySlot v))
setAt acc row
. ellipsisize left
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding call to ellipsisize here, which will truncate overly long labels on y axis, preventing them from breaking the chart by shifting everything to the right.

This is how it works now:

Image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thus should be documented somewhere in the haddock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will mention it in the next PR.

cy = yDot `div` 4
rx = xDot - 2 * cx
ry = yDot - 4 * cy
let (cx, rx) = xDot `divMod` 2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change.

( \acc (row, v) ->
setAt acc row (justifyRight left (yFormatter cfg (yEnv row) ySlot v))
setAt acc row
. ellipsisize left
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thus should be documented somewhere in the haddock.

yTicks = ticks1D plotH (yNumTicks cfg) (ymin, ymax) True
baseLbl = List.replicate plotH pad

setAt :: [Text] -> Int -> Text -> [Text]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Not the intended behaviour.

@mchav mchav merged commit b902b8c into mchav:main Oct 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants