Skip to content

Commit 72c49c5

Browse files
committed
plot line: sort points by X for plotting lines. fix #280
1 parent 38e10f2 commit 72c49c5

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- new flag `-b, --buffer-size`.
2222
- `csvtk plot line`:
2323
- only add legend for more than one group. [#279](https://github.com/shenwei356/csvtk/issues/279)
24+
- sort points by X for plotting lines. [#280](https://github.com/shenwei356/csvtk/issues/280)
2425
- [csvtk v0.30.0](https://github.com/shenwei356/csvtk/releases/tag/v0.30.0)
2526
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.30.0/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.30.0)
2627
- `csvtk`:

csvtk/cmd/line.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ Notes:
194194
addLegend := len(groupOrders) > 1
195195
for _, gor := range groupOrders {
196196
v := groups[gor.Key]
197+
198+
// sort by x
199+
if !scatter {
200+
sort.Slice(v, func(i, j int) bool {
201+
return v[i].X < v[j].X
202+
})
203+
}
204+
197205
g := gor.Key
198206
if !scatter {
199207
lines, points, err := plotter.NewLinePoints(v)

0 commit comments

Comments
 (0)