mirror of https://github.com/mum4k/termdash.git
The LineChart now continuous to accept mouse events after terminal resize.
And allowing it to receive global mouse events to be able to cancel highlight on clicks outside of the widget.
This commit is contained in:
parent
1d3071e969
commit
a2642ea039
|
@ -492,7 +492,7 @@ func (lc *LineChart) Options() widgetapi.Options {
|
|||
|
||||
return widgetapi.Options{
|
||||
MinimumSize: lc.minSize(),
|
||||
WantMouse: widgetapi.MouseScopeWidget,
|
||||
WantMouse: widgetapi.MouseScopeGlobal,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1303,6 +1303,65 @@ func TestLineChartDraws(t *testing.T) {
|
|||
return ft
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "tracks mouse clicks when canvas size increases, regression for #148",
|
||||
opts: []Option{
|
||||
ZoomHightlightColor(cell.ColorNumber(13)),
|
||||
},
|
||||
canvas: image.Rect(0, 0, 20, 10),
|
||||
writes: func(lc *LineChart) error {
|
||||
if err := lc.Series("first", []float64{0, 100}); err != nil {
|
||||
return err
|
||||
}
|
||||
// Draw twice with different canvas size to simulate resize.
|
||||
{
|
||||
cvs := testcanvas.MustNew(image.Rect(0, 0, 20, 7))
|
||||
if err := lc.Draw(cvs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
{
|
||||
cvs := testcanvas.MustNew(image.Rect(0, 0, 20, 10))
|
||||
if err := lc.Draw(cvs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return lc.Mouse(&terminalapi.Mouse{
|
||||
Position: image.Point{6, 7},
|
||||
Button: mouse.ButtonLeft,
|
||||
})
|
||||
},
|
||||
wantCapacity: 28,
|
||||
want: func(size image.Point) *faketerm.Terminal {
|
||||
ft := faketerm.MustNew(size)
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
|
||||
// Y and X axis.
|
||||
lines := []draw.HVLine{
|
||||
{Start: image.Point{5, 0}, End: image.Point{5, 8}},
|
||||
{Start: image.Point{5, 8}, End: image.Point{19, 8}},
|
||||
}
|
||||
testdraw.MustHVLines(c, lines)
|
||||
|
||||
// Value labels.
|
||||
testdraw.MustText(c, "0", image.Point{4, 7})
|
||||
testdraw.MustText(c, "51.68", image.Point{0, 3})
|
||||
testdraw.MustText(c, "0", image.Point{6, 9})
|
||||
testdraw.MustText(c, "1", image.Point{19, 9})
|
||||
|
||||
// Braille line.
|
||||
graphAr := image.Rect(6, 0, 20, 8)
|
||||
bc := testbraille.MustNew(graphAr)
|
||||
testdraw.MustBrailleLine(bc, image.Point{0, 31}, image.Point{26, 0})
|
||||
|
||||
// Highlighted area for zoom.
|
||||
testbraille.MustSetAreaCellOpts(bc, image.Rect(0, 0, 1, 8), cell.BgColor(cell.ColorNumber(13)))
|
||||
|
||||
testbraille.MustCopyTo(bc, c)
|
||||
testcanvas.MustApply(c, ft)
|
||||
return ft
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "zoom in on unscaled X axis",
|
||||
opts: []Option{
|
||||
|
|
|
@ -136,6 +136,7 @@ func (t *Tracker) Update(baseX *axes.XDetails, cvsAr, graphAr image.Rectangle) e
|
|||
ac, sc := t.axisChanged(baseX), t.sizeChanged(cvsAr, graphAr)
|
||||
if sc {
|
||||
t.highlight.reset()
|
||||
t.fsm.UpdateArea(graphAr)
|
||||
}
|
||||
if ac || sc {
|
||||
if t.zoomX != nil {
|
||||
|
|
|
@ -149,6 +149,48 @@ func TestTracker(t *testing.T) {
|
|||
},
|
||||
),
|
||||
},
|
||||
{
|
||||
desc: "highlights single column in a new canvas portion after size increase, regression for #148",
|
||||
xp: &axes.XProperties{
|
||||
Min: 0,
|
||||
Max: 4,
|
||||
ReqYWidth: 2,
|
||||
},
|
||||
cvsAr: image.Rect(0, 0, 4, 4),
|
||||
graphAr: image.Rect(2, 0, 4, 4),
|
||||
mutate: func(tr *Tracker) error {
|
||||
newX, err := axes.NewXDetails(image.Rect(0, 0, 6, 6), &axes.XProperties{
|
||||
Min: 0,
|
||||
Max: 4,
|
||||
ReqYWidth: 2,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tr.Update(
|
||||
newX,
|
||||
image.Rect(0, 0, 6, 6),
|
||||
image.Rect(2, 0, 6, 6),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
return tr.Mouse(&terminalapi.Mouse{
|
||||
Position: image.Point{2, 5},
|
||||
Button: mouse.ButtonLeft,
|
||||
})
|
||||
},
|
||||
wantHighlight: true,
|
||||
wantHighlightRange: &Range{Start: 0, End: 1, last: 0},
|
||||
wantZoom: mustNewXDetails(
|
||||
image.Rect(0, 0, 6, 6),
|
||||
&axes.XProperties{
|
||||
Min: 0,
|
||||
Max: 4,
|
||||
ReqYWidth: 2,
|
||||
},
|
||||
),
|
||||
},
|
||||
{
|
||||
desc: "highlights multiple columns to the right of start",
|
||||
xp: &axes.XProperties{
|
||||
|
|
Loading…
Reference in New Issue