func (l LabelMap) Sorted() []Label {
	out := make([]Label, 0, len(l))

	for k, v := range l {
		v.Label = k
		out = append(out, v)
	}

	sort.Slice(out, func(i, j int) bool {
		// By default we will sort by ID
		x, y := float64(out[i].ID), float64(out[j].ID)

		// If a column has a sort order, use that instead of its ID.
		if xprime := out[i].SortOrder; xprime != 0 {
			x = xprime
		}

		if yprime := out[j].SortOrder; yprime != 0 {
			y = yprime
		}

		return x < y
	})

	return out
}
// Sorted permits sorting by arbitrary criteria - may be useful for reordering
// labels for different blocks of segmentation. Internally, all mapping is done
// based on the explicitly set ID, so the sort order does not matter (except
// perhaps for performance in for loops).
Sorted permits sorting by arbitrary criteria - may be useful for reordering
labels for different blocks of segmentation. Internally, all mapping is done
based on the explicitly set ID, so the sort order does not matter (except
perhaps for performance in for loops).
// Sorted permits sorting by arbitrary criteria - may be useful for reordering // labels for different blocks of segmentation . Internally all mapping is done // based on the explicitly set ID so the sort order does not matter ( except // perhaps for performance in for loops ) .
func (l LabelMap) Sorted() []Label {
	out := make([]Label, 0, len(l))
	for k, v := range l {
		v.Label = k
		out = append(out, v)
	}
	sort.Slice(out, func(i, j int) bool {
		x, y := float64(out[i].ID), float64(out[j].ID)
		if xprime := out[i].SortOrder; xprime != 0 {
			x = xprime
		}
		if yprime := out[j].SortOrder; yprime != 0 {
			y = yprime
		}
		return x < y
	})
	return out
}
func ( l LabelMap ) Sorted ( ) [ ] Label { out := make ( [ ] Label , 0 , len ( l ) ) for k , v := range l { v . Label = k out = append ( out , v ) } sort . Slice ( out , func ( i , j int ) bool { x , y := float64 ( out [ i ] . ID ) , float64 ( out [ j ] . ID ) if xprime := out [ i ] . SortOrder ; xprime != 0 { x = xprime } if yprime := out [ j ] . SortOrder ; yprime != 0 { y = yprime } return x < y } ) return out }
Sorted permits sorting by arbitrary criteria - may be useful for reordering
labels for different blocks of segmentation.
Sorted permits sorting by arbitrary criteria - may be useful for reordering labels for different blocks of segmentation .
// By default we will sort by ID // If a column has a sort order, use that instead of its ID.