cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Chart editor: one type chip on narrow screens

Dami committed 79791ff
At 60 columns six type chips leave no room for the options, so when
options would be dropped the types become one chip of the current type
(a click moves on) if that shows more of them. The axis bar's key hints
are short enough to fit at 60 columns.
commit
79791ff4a67338cb2a756d5f370d566d40c111a4
parent
e34b72346c07acc6a4059598923fa1d273f3245f
author
Dami <dami.etoile@gmail.com>
3 files changed, +40 -9
Minternal/ui/chartaxes.go2+-
Minternal/ui/chartaxes_test.go12+++++++++-
Minternal/ui/charteditor.go35++++++++++++++++++++++++------
M internal/ui/chartaxes.go +1 -1
M internal/ui/chartaxes_test.go +11 -1
M internal/ui/charteditor.go +28 -7
@@ -169,16 +169,24 @@ func (e *chartEditor) chip(on bool, name, key string) editorPart {
169169 }170170 171171 // parts returns the bar's parts, and how many of them lead it: the172-// types, which are never dropped and have a wider gap after them.173-func (e *chartEditor) parts(m *Model) ([]editorPart, int) {172+// types, which are never dropped and have a wider gap after them. Compact,173+// the types are one chip of the current type, which a click moves on.174+func (e *chartEditor) parts(m *Model, compact bool) ([]editorPart, int) {174175 if e.axes {175176 return e.axisParts(m), 0176177 }177178 c := e.chart(m)178179 var parts []editorPart179180 for i, t := range sheet.ChartTypes {180- parts = append(parts, e.chip(t == c.Type, t.Title(), strconv.Itoa(i+1)))181+ switch {182+ case !compact:183+ parts = append(parts, e.chip(t == c.Type, t.Title(), strconv.Itoa(i+1)))184+ case t == c.Type:185+ next := (i+1)%len(sheet.ChartTypes) + 1186+ parts = append(parts, e.chip(true, "◂ "+t.Title()+" ▸", strconv.Itoa(next)))187+ }181188 }189+ lead := len(parts)182190 parts = append(parts, editorPart{text: m.th.Key.Render(c.Data.String()), key: editorRange})183191 switch {184192 case c.Type.Stackable():
@@ -197,13 +205,26 @@ func (e *chartEditor) parts(m *Model) ([]editorPart, int) {
197205 return append(parts,198206 e.chip(true, series, editorSwitch),199207 e.chip(c.Header, header, editorHeader),200- e.chip(c.Labels, labels, editorLabels)), len(sheet.ChartTypes)208+ e.chip(c.Labels, labels, editorLabels)), lead201209 }202210 203-// spans lays the parts out on the context line, dropping options from the204-// right on narrow screens, and returns each part's x.211+// spans lays the parts out on the context line and returns each part's212+// x. On narrow screens the types become one chip when that leaves room213+// for more options, and options that still don't fit are dropped from the214+// right.205215 func (e *chartEditor) spans(m *Model) ([]editorPart, []int) {206- parts, lead := e.parts(m)216+ parts, xs := e.fit(m, false)217+ if all, _ := e.parts(m, false); len(parts) < len(all) && !e.axes {218+ if cp, cxs := e.fit(m, true); len(cp)+len(sheet.ChartTypes)-1 > len(parts) {219+ return cp, cxs220+ }221+ }222+ return parts, xs223+}224+225+// fit lays out the parts, dropping options from the right until they fit.226+func (e *chartEditor) fit(m *Model, compact bool) ([]editorPart, []int) {227+ parts, lead := e.parts(m, compact)207228 for {208229 xs := make([]int, len(parts))209230 x := 0