mirror of
https://github.com/mum4k/termdash.git
synced 2026-04-26 19:05:52 +03:00
[GH-ISSUE #327] allow non-adaptive custom scale #152
Labels
No labels
bug
cleanup
enhancement
enhancement
enhancement
good first issue
help wanted
help wanted
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/termdash#152
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tcurdt on GitHub (Apr 30, 2022).
Original GitHub issue: https://github.com/mum4k/termdash/issues/327
I've set
linechart.YAxisCustomScale(-20, 20)and I want the position of 0 to always stay at the same place.Looking at the code, unfortunately
the LineChart would still rescale the Y axis if a value is encountered that is outside of the range specified hereTo me it seems adaptive should be an entirely separate option.
@mum4k commented on GitHub (May 3, 2022):
Agreed, in retrospect tying these two options together was ill-advised. We could try to address this by providing a new option
YScaleModeAnchoredthat will set the Y axis mode back to Anchored. We would have to also add a unit test to confirm this actually works. The code is likely to crash since the current implementation might be depending on the fact that the axis adapts, so some minor changes may be needed deeper in the stack.Open to other suggestions.
@tcurdt is this something you would be interested in contributing?
@tcurdt commented on GitHub (May 3, 2022):
I am sure I could add the option. Just not sure about the changes need deeper in the stack.
@mum4k commented on GitHub (May 5, 2022):
I would start by just adding the option and a test case that verifies how it behaves. If we are lucky, it will just work. If it won't, I can help dissect the code on the PR that is adding the option.
@tcurdt commented on GitHub (Jul 14, 2022):
It seems there already is an
YScaleModeAnchoredon the axes - which just isn't exposed.https://github.com/mum4k/termdash/blob/master/widgets/linechart/internal/axes/scale.go#L46
I know it would be a breaking change, but frankly speaking just
would make so much more sense.
And it would just require to add
YAxisAdaptiveas another option to get back to the old behaviour.@tcurdt commented on GitHub (Jul 14, 2022):
Hm. Odd. Even this refuses to work. Still expands beyond the min/max.
@tcurdt commented on GitHub (Jul 14, 2022):
Seems like this also need to change
https://github.com/mum4k/termdash/blob/master/widgets/linechart/linechart.go#L174
but then the draw panics
@mum4k commented on GitHub (Jul 15, 2022):
Sorry it would be great if I could be more helpful, but I am afraid I forgot all the details of the code in question.
Setting a custom scale may need more code changes, because this either breaks some assumptions or simply triggers a bug when the scale is set manually.
I think you likely picked this up from the error message above - when the custom scale was set, the code attempted to place a point outside of the scale (out of bounds). We will have to track down the piece of code that determines the placement and debug it. What I would recommend is taking the very case from the error message above and converting it into a unit test.
@tcurdt commented on GitHub (Jul 15, 2022):
This seems to be already covered by the existing tests:
Here the test of course still expresses the wrong expectations.
@tcurdt commented on GitHub (Jul 15, 2022):
That's with
@tcurdt commented on GitHub (Jul 18, 2022):
I guess this something I could work around by limiting the input data - not great but a workaround.
If I find a way to disallow the zooming via mouse.
@mum4k commented on GitHub (Jul 18, 2022):
@tcurdt I would like to help advise here, but I am having a hard time figuring out the current state of things. Would you mind summarizing the current behavior Vs. the desired one?
@tcurdt commented on GitHub (Jul 18, 2022):
Alright - the summary is as follows:
opts.yAxisMode = axes.YScaleModeAdaptiveshould be just removed (unfortunately that does not make it just work)opts.yAxisMode = axes.YScaleModeAnchored) already does show up in the tests as errorDoes that make things clearer?
@mum4k commented on GitHub (Jul 18, 2022):
I was more after the high level. I think what you commented describes how to adjust the existing test.
I am trying to understand what our goal is. Linechart already supports custom scale, but I think that doesn't work for your use case, because it still scales if a value outside of the range is encountered. Is our goal to work on a mode where that automatic scaling is disabled.
I am not sure how mouse zoom falls into the story. We can indeed add an option to disable zooming, but if we implement this, we need to also make sure that while enabled, mouse zooming works with the custom scale.
Do I understand this correctly?
@tcurdt commented on GitHub (Jul 18, 2022):
Ah! OK, well, I think it would be nice to be able to disable zooming - but that's really for another ticket I guess.
The idea was just to limit the data myself. So if the user is not able to zoom (s)he wouldn't notice the difference.
It was just an idea of a quick work around.
My use case: I assume you know what an oscilloscope is? I want to implement something similar.
For this it's important that neither the position of 0 nor the scale changes automatically.
It needs to have the same visual reference all the time.
If values go beyond min/max they just leave the visible window - not repositioning or scaling it.
Does that make more sense now?
Frankly speaking it sounds so simple:
It's basically just plotting the data on the canvas with a fix scale.
Maybe the work around could be to write an entirely different more dumb widget instead?
That said, just writing my own widget would still leave it broken IMO.
I do think that
opts.yAxisMode = axes.YScaleModeAdaptiveshould not be the default forYAxisCustomScale.Which then requires fixing anyway.
WDYT is the best path forward?
@mum4k commented on GitHub (Jul 18, 2022):
Thank you, I think I now have a good idea of what is needed. I do happen to know what an oscilloscope is, used to play with one years ago, so that explanation was a good one.
I think we should do a few things:
YAxisCustomScalebehaves, because its behavior is pretty well documented. We should instead add a new option likeYAxisCustomScaleFixedand document that when values outside of the range are encountered, an empty space is drawn on the linechart. Then we need to modify the code to support this functionality.Would this support the use case you have in mind?
@tcurdt commented on GitHub (Jul 18, 2022):
I still think
YAxisCustomScaleis very much mixing concerns withYAxisAdaptive.And it seems like
XAxisUnscaledwould also somehow suggestYAxisUnscaled.The zooming already provides a way show a slice/window of the data, too.
Isn't that functionality already a more powerful superset of the scaling?
So there might also be some overlap?
Just writing down some random thoughts here.
...but in the end it's of course all your decision - and it sounds like the approach you outlined will also work for me!
@mum4k commented on GitHub (Jul 19, 2022):
Sorry for not being clear, I do agree with you that YAxisCustomScale is mixing concerns. Please do keep the suggestions coming, this is how we make better software together.
My concern is about breaking a behavior that someone out there might depend on regardless how weird the behavior is in retrospect. Or rather I think we should brake it in a more user friendly way. It would be ok to fix bugs, but this would radically change how an established option behaves and we have no way of figuring out if there are users who depend on it.
Therefore my suggestion is to fix it forward in a compatible manner. We can design a set of new options that unlike YAxisCustomScale behave sanely. We can even mark YAxisCustomScale as deprecated in documentation and emit a warning when it is used indicating that users should move and we might eventually delete it completely, telling users how to migrate to the replacement options. All of this would be acceptable, but it feels that changing the behavior of an established option would create a hard to debug scenario for someone already using it.
What do you think?
@tcurdt commented on GitHub (Jul 19, 2022):
That certainly would be the path of good engineering. That said, I've seen other breaking changes in the release notes and the version is pre-1.0. The fix would essentially be a trivial "add this option". So I figured...
But if you want to treat your users well, deprecating certainly is the better way to go! Totally agree.
Taking a step back I am really wondering if the scaling isn't really just setting the initial zoom and anchor.
Maybe everything is already there - we just need to find a good way of expressing it via options.
WDYT?
@mum4k commented on GitHub (Jul 19, 2022):
Sorry I think I need to clarify one more detail. Breaking changes are indeed ok all the way until we get into post 1.0. What I am trying to prevent is a silent behavior breakage. I.e. it is ok (if we have to) to break code in a way that makes the compiler complain, as that makes users look at the changelog. However a silent change of behavior on an already established option is what I think we should avoid as there is no warning. Users will have to notice the change in the behavior of their application.
You raise a good point, I also think that most of the code that we need is there already and agree that we just need to find the right set of options. Maybe some minor tweaks will be needed. I wish I could advise more, but linechart is one of the more complicated widgets and I no longer remember the details.
@tcurdt commented on GitHub (Jul 19, 2022):
That's fair.
Maybe it's better I start with a simpler version then and see if they somehow converge.