got rid of mouse selection code (prototype didn't work very well, decided to go with mouse <- -> selections later on)
This commit is contained in:
parent
cb7a41694d
commit
324d76d149
|
@ -32,8 +32,7 @@ func (self *Handler) HandleEvents() {
|
||||||
payload := e.Payload.(ui.Resize)
|
payload := e.Payload.(ui.Resize)
|
||||||
self.Layout.ChangeDimensions(payload.Width, payload.Height)
|
self.Layout.ChangeDimensions(payload.Width, payload.Height)
|
||||||
case EventMouseClick:
|
case EventMouseClick:
|
||||||
payload := e.Payload.(ui.Mouse)
|
//payload := e.Payload.(ui.Mouse)
|
||||||
self.handleMouseClick(payload.X, payload.Y)
|
|
||||||
case EventKeyboardLeft:
|
case EventKeyboardLeft:
|
||||||
// here we are going to move selection (special type of layout item)
|
// here we are going to move selection (special type of layout item)
|
||||||
//layout.GetItem("").Move(-1, 0)
|
//layout.GetItem("").Move(-1, 0)
|
||||||
|
@ -47,10 +46,3 @@ func (self *Handler) HandleEvents() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Handler) handleMouseClick(x, y int) {
|
|
||||||
for _, chart := range self.Layout.GetComponents(widgets.TypeRunChart) {
|
|
||||||
runChart := chart.(*widgets.RunChart)
|
|
||||||
runChart.SelectPoint(x, y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ type RunChart struct {
|
||||||
grid ChartGrid
|
grid ChartGrid
|
||||||
precision int
|
precision int
|
||||||
timescale time.Duration
|
timescale time.Duration
|
||||||
selection *time.Time
|
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,12 +104,9 @@ func (self *RunChart) Draw(buffer *Buffer) {
|
||||||
self.Inner.Max.X, self.Inner.Max.Y-xAxisLabelsHeight-1,
|
self.Inner.Max.X, self.Inner.Max.Y-xAxisLabelsHeight-1,
|
||||||
)
|
)
|
||||||
|
|
||||||
selectedPoints := self.getSelectedTimePoints()
|
|
||||||
|
|
||||||
self.renderAxes(buffer)
|
self.renderAxes(buffer)
|
||||||
self.renderItems(buffer, drawArea)
|
self.renderLines(buffer, drawArea)
|
||||||
self.renderSelection(buffer, drawArea, selectedPoints)
|
self.renderLegend(buffer, drawArea)
|
||||||
self.renderLegend(buffer, drawArea, selectedPoints)
|
|
||||||
self.mutex.Unlock()
|
self.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,54 +148,6 @@ func (self *RunChart) ConsumeSample(sample data.Sample) {
|
||||||
self.mutex.Unlock()
|
self.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RunChart) SelectPoint(x int, y int) {
|
|
||||||
|
|
||||||
point := image.Point{X: x, Y: y}
|
|
||||||
|
|
||||||
if !point.In(self.Rectangle) {
|
|
||||||
self.selection = nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
timeDeltaToPaddingRelation := (self.grid.maxTimeWidth - x) / xAxisGridWidth
|
|
||||||
timeDeltaWithGridMaxTime := timeDeltaToPaddingRelation * int(self.timescale.Nanoseconds())
|
|
||||||
selection := self.grid.timeExtremum.max.Add(-time.Duration(timeDeltaWithGridMaxTime) * time.Nanosecond)
|
|
||||||
|
|
||||||
self.selection = &selection
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *RunChart) getSelectedTimePoints() []TimePoint {
|
|
||||||
|
|
||||||
selected := []TimePoint{}
|
|
||||||
|
|
||||||
if self.selection == nil {
|
|
||||||
return selected
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range self.lines {
|
|
||||||
|
|
||||||
if len(line.points) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
closest := line.points[0]
|
|
||||||
|
|
||||||
for _, point := range line.points {
|
|
||||||
|
|
||||||
diffWithClosest := math.Abs(float64(self.selection.UnixNano() - closest.time.UnixNano()))
|
|
||||||
diffWithCurrent := math.Abs(float64(self.selection.UnixNano() - point.time.UnixNano()))
|
|
||||||
|
|
||||||
if diffWithClosest > diffWithCurrent {
|
|
||||||
closest = point
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
selected = append(selected, closest)
|
|
||||||
}
|
|
||||||
|
|
||||||
return selected
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *RunChart) trimOutOfRangeValues() {
|
func (self *RunChart) trimOutOfRangeValues() {
|
||||||
|
|
||||||
historyReserve := self.timescale * time.Duration(self.grid.linesCount) * chartHistoryReserve
|
historyReserve := self.timescale * time.Duration(self.grid.linesCount) * chartHistoryReserve
|
||||||
|
@ -221,7 +169,7 @@ func (self *RunChart) trimOutOfRangeValues() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RunChart) renderItems(buffer *Buffer, drawArea image.Rectangle) {
|
func (self *RunChart) renderLines(buffer *Buffer, drawArea image.Rectangle) {
|
||||||
|
|
||||||
canvas := NewCanvas()
|
canvas := NewCanvas()
|
||||||
canvas.Rectangle = drawArea
|
canvas.Rectangle = drawArea
|
||||||
|
@ -344,10 +292,12 @@ func (self *RunChart) renderAxes(buffer *Buffer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RunChart) renderLegend(buffer *Buffer, rectangle image.Rectangle, selectedPoints []TimePoint) {
|
func (self *RunChart) renderLegend(buffer *Buffer, rectangle image.Rectangle) {
|
||||||
|
|
||||||
for i, line := range self.lines {
|
for i, line := range self.lines {
|
||||||
|
|
||||||
|
extremum := getLineValueExtremum(line.points)
|
||||||
|
|
||||||
buffer.SetString(
|
buffer.SetString(
|
||||||
string(DOT),
|
string(DOT),
|
||||||
NewStyle(line.color),
|
NewStyle(line.color),
|
||||||
|
@ -358,32 +308,6 @@ func (self *RunChart) renderLegend(buffer *Buffer, rectangle image.Rectangle, se
|
||||||
NewStyle(line.color),
|
NewStyle(line.color),
|
||||||
image.Pt(self.Inner.Max.X-xAxisLegendWidth, self.Inner.Min.Y+1+i*5),
|
image.Pt(self.Inner.Max.X-xAxisLegendWidth, self.Inner.Min.Y+1+i*5),
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(selectedPoints) > 0 {
|
|
||||||
|
|
||||||
index := -1
|
|
||||||
|
|
||||||
for i, p := range selectedPoints {
|
|
||||||
if p.line.label == line.label {
|
|
||||||
index = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if index != -1 {
|
|
||||||
buffer.SetString(
|
|
||||||
fmt.Sprintf("time: %v", selectedPoints[index].time.Format("15:04:05.000")),
|
|
||||||
NewStyle(ColorWhite),
|
|
||||||
image.Pt(self.Inner.Max.X-xAxisLegendWidth, self.Inner.Min.Y+2+i*5),
|
|
||||||
)
|
|
||||||
buffer.SetString(
|
|
||||||
fmt.Sprintf("value: %s", formatValue(selectedPoints[index].value, self.precision)),
|
|
||||||
NewStyle(ColorWhite),
|
|
||||||
image.Pt(self.Inner.Max.X-xAxisLegendWidth, self.Inner.Min.Y+3+i*5),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
extremum := getLineValueExtremum(line.points)
|
|
||||||
|
|
||||||
buffer.SetString(
|
buffer.SetString(
|
||||||
fmt.Sprintf("cur %s", formatValue(line.points[len(line.points)-1].value, self.precision)),
|
fmt.Sprintf("cur %s", formatValue(line.points[len(line.points)-1].value, self.precision)),
|
||||||
NewStyle(ColorWhite),
|
NewStyle(ColorWhite),
|
||||||
|
@ -401,31 +325,6 @@ func (self *RunChart) renderLegend(buffer *Buffer, rectangle image.Rectangle, se
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (self *RunChart) renderSelection(buffer *Buffer, drawArea image.Rectangle, selectedPoints []TimePoint) {
|
|
||||||
|
|
||||||
for _, timePoint := range selectedPoints {
|
|
||||||
|
|
||||||
timeDeltaWithGridMaxTime := self.grid.timeExtremum.max.Sub(timePoint.time).Nanoseconds()
|
|
||||||
timeDeltaToPaddingRelation := float64(timeDeltaWithGridMaxTime) / float64(self.timescale.Nanoseconds())
|
|
||||||
x := self.grid.maxTimeWidth - (int(float64(xAxisGridWidth) * timeDeltaToPaddingRelation))
|
|
||||||
|
|
||||||
var y int
|
|
||||||
if self.grid.valueExtremum.max-self.grid.valueExtremum.min == 0 {
|
|
||||||
y = (drawArea.Dy() - 2) / 2
|
|
||||||
} else {
|
|
||||||
valuePerY := (self.grid.valueExtremum.max - self.grid.valueExtremum.min) / float64(drawArea.Dy()-2)
|
|
||||||
y = int(float64(timePoint.value-self.grid.valueExtremum.min) / valuePerY)
|
|
||||||
}
|
|
||||||
|
|
||||||
point := image.Pt(x, drawArea.Max.Y-y-1)
|
|
||||||
|
|
||||||
if point.In(drawArea) {
|
|
||||||
buffer.SetCell(NewCell('▲', NewStyle(timePoint.line.color)), point)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *RunChart) getMaxValueLength() int {
|
func (self *RunChart) getMaxValueLength() int {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue