[PR #188] [MERGED] Y-axis label formatter for LineChart #243

Closed
opened 2026-03-03 16:23:29 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mum4k/termdash/pull/188
Author: @slok
Created: 4/25/2019
Status: Merged
Merged: 5/9/2019
Merged by: @mum4k

Base: develHead: y-axis-label-formatter


📝 Commits (10+)

  • 560aef6 Add linechart y-axis value formatter option API
  • 7157a07 Add formatter support to linechart internal Value type
  • 135edd4 Add formatted values creation if the scale has a value formatter asigned
  • 7571889 Use the y-axis value formatter option on y-axis internal properties
  • a8931e2 Check also for non printable characters on alingfor package text helper method
  • c1bf776 Use variadic args for Value factory options
  • 36f116d Make axes labels length finder compatible with unicode runes
  • b0f8079 Add linechart custom formatter testcases for long strings, non-printable characters and unicode value formatter results
  • e152366 Fix comment
  • 150b7e2 Allow empty Y-axis labels on linechart using a value formatter that returns empty strings

📊 Changes

17 files changed (+758 additions, -35 deletions)

View changed files

📝 CHANGELOG.md (+7 -0)
📝 internal/alignfor/alignfor.go (+9 -1)
📝 internal/alignfor/alignfor_test.go (+6 -0)
📝 internal/wrap/wrap.go (+2 -2)
📝 widgets/linechart/internal/axes/axes.go (+6 -2)
📝 widgets/linechart/internal/axes/axes_test.go (+32 -6)
📝 widgets/linechart/internal/axes/label.go (+1 -1)
📝 widgets/linechart/internal/axes/label_test.go (+2 -2)
📝 widgets/linechart/internal/axes/scale.go (+22 -7)
📝 widgets/linechart/internal/axes/scale_test.go (+3 -3)
📝 widgets/linechart/internal/axes/value.go (+50 -6)
📝 widgets/linechart/internal/axes/value_test.go (+17 -1)
📝 widgets/linechart/linechart.go (+5 -4)
📝 widgets/linechart/linechart_test.go (+194 -0)
📝 widgets/linechart/options.go (+16 -0)
widgets/linechart/value_formatter.go (+146 -0)
widgets/linechart/value_formatter_test.go (+240 -0)

📄 Description

This PR fixes #187

Adds the ability to set custom labels on the Y-axis using a value formatter that accepts a numeric value (float64) and returns the corresponding label to this value (string).

The PR is in WIP state. I'll update the PR accordingly.

Steps:

  • Set the Linechart Y-axis option with the ValueFormatter.
  • Use the formatter on the Value if is present.
  • Create formatter for most common time units.
  • Create formatter to round values (#95).

This approach seems to work fine, I put an image of the project that I'm developing (a Grafana for terminal that I'll make it public soon) using this feature.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mum4k/termdash/pull/188 **Author:** [@slok](https://github.com/slok) **Created:** 4/25/2019 **Status:** ✅ Merged **Merged:** 5/9/2019 **Merged by:** [@mum4k](https://github.com/mum4k) **Base:** `devel` ← **Head:** `y-axis-label-formatter` --- ### 📝 Commits (10+) - [`560aef6`](https://github.com/mum4k/termdash/commit/560aef66d5e9691d7a9179ebe98615348a872ac9) Add linechart y-axis value formatter option API - [`7157a07`](https://github.com/mum4k/termdash/commit/7157a0745736644d1e08914b9f305fc0bcebe84b) Add formatter support to linechart internal Value type - [`135edd4`](https://github.com/mum4k/termdash/commit/135edd42fafa89704c5e1066835be4ae93256cac) Add formatted values creation if the scale has a value formatter asigned - [`7571889`](https://github.com/mum4k/termdash/commit/7571889becdc4ad89bb9aaf23d3edacf2b85313a) Use the y-axis value formatter option on y-axis internal properties - [`a8931e2`](https://github.com/mum4k/termdash/commit/a8931e2820edf62fc9a2f245396d107f3bf67959) Check also for non printable characters on alingfor package text helper method - [`c1bf776`](https://github.com/mum4k/termdash/commit/c1bf776dbacba0382bb76b375b587f19dd70aa22) Use variadic args for Value factory options - [`36f116d`](https://github.com/mum4k/termdash/commit/36f116d9fc6f1a02ddedc7ec89dbada50bb7fd34) Make axes labels length finder compatible with unicode runes - [`b0f8079`](https://github.com/mum4k/termdash/commit/b0f8079a94b8ac3f603903c0c116eaccfd13d9e2) Add linechart custom formatter testcases for long strings, non-printable characters and unicode value formatter results - [`e152366`](https://github.com/mum4k/termdash/commit/e152366a5cef2b8d9190f7df6a4578aba46628de) Fix comment - [`150b7e2`](https://github.com/mum4k/termdash/commit/150b7e26e2c08da18cd5efa40b96b388eb735184) Allow empty Y-axis labels on linechart using a value formatter that returns empty strings ### 📊 Changes **17 files changed** (+758 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+7 -0) 📝 `internal/alignfor/alignfor.go` (+9 -1) 📝 `internal/alignfor/alignfor_test.go` (+6 -0) 📝 `internal/wrap/wrap.go` (+2 -2) 📝 `widgets/linechart/internal/axes/axes.go` (+6 -2) 📝 `widgets/linechart/internal/axes/axes_test.go` (+32 -6) 📝 `widgets/linechart/internal/axes/label.go` (+1 -1) 📝 `widgets/linechart/internal/axes/label_test.go` (+2 -2) 📝 `widgets/linechart/internal/axes/scale.go` (+22 -7) 📝 `widgets/linechart/internal/axes/scale_test.go` (+3 -3) 📝 `widgets/linechart/internal/axes/value.go` (+50 -6) 📝 `widgets/linechart/internal/axes/value_test.go` (+17 -1) 📝 `widgets/linechart/linechart.go` (+5 -4) 📝 `widgets/linechart/linechart_test.go` (+194 -0) 📝 `widgets/linechart/options.go` (+16 -0) ➕ `widgets/linechart/value_formatter.go` (+146 -0) ➕ `widgets/linechart/value_formatter_test.go` (+240 -0) </details> ### 📄 Description This PR fixes #187 Adds the ability to set custom labels on the Y-axis using a value formatter that accepts a numeric value (float64) and returns the corresponding label to this value (string). The PR is in WIP state. I'll update the PR accordingly. Steps: - [x] Set the Linechart Y-axis option with the `ValueFormatter`. - [x] Use the formatter on the `Value` if is present. - [x] Create formatter for most common time units. - [x] Create formatter to round values (#95). This approach seems to work fine, I put an image of the project that I'm developing (a Grafana for terminal that I'll make it public soon) using this feature. ![](https://i.imgur.com/u3fcXJO.png) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 16:23:29 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/termdash#243
No description provided.