From 99e54ff15d38d1f5c990d4c926395c64424a269b Mon Sep 17 00:00:00 2001 From: Ernest Micklei Date: Fri, 21 Jun 2024 15:18:17 +0200 Subject: [PATCH] add float to zero check --- explorer.go | 23 ++++++++++++----------- field.go | 8 ++++++++ index_builder.go | 2 +- service.go | 14 +++++++------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/explorer.go b/explorer.go index 6332834..d3d6553 100644 --- a/explorer.go +++ b/explorer.go @@ -7,12 +7,12 @@ import ( ) type objectAccess struct { - isRoot bool // set to true if is was one of the values at start - object any - path []string - label string - typeName string - hideNils bool + isRoot bool // set to true if is was one of the values at start + object any + path []string + label string + typeName string + hideZeros bool } func (o objectAccess) Value() any { @@ -65,11 +65,12 @@ func newExplorerOnAll(labelValuePairs ...any) *explorer { continue } s.objectAtPut(i, 0, objectAccess{ - isRoot: true, - object: value, - path: []string{""}, - label: label, - typeName: fmt.Sprintf("%T", value), + isRoot: true, + object: value, + path: []string{""}, + label: label, + hideZeros: true, + typeName: fmt.Sprintf("%T", value), }) } return s diff --git a/field.go b/field.go index c891cef..8a38f59 100644 --- a/field.go +++ b/field.go @@ -265,3 +265,11 @@ func stringToReflectMapKey(hash string, m reflect.Value) reflect.Value { // not found is actually a bug return reflect.ValueOf(nil) } + +func isZeroPrintstring(s string) bool { + switch s { + case `""`, "0", "false", "nil", "0.000000", "0.000": + return true + } + return false +} diff --git a/index_builder.go b/index_builder.go index a17cac7..4892c70 100644 --- a/index_builder.go +++ b/index_builder.go @@ -39,7 +39,7 @@ func (b *indexDataBuilder) build(row, column int, access objectAccess, value any for i, each := range fields { entries[i] = fieldEntry{ fieldAccess: each, - hideZero: access.hideNils, + hideZero: access.hideZeros, } } b.data.Rows[row].Cells[column] = fieldList{ diff --git a/service.go b/service.go index c51f711..4411c1c 100644 --- a/service.go +++ b/service.go @@ -30,9 +30,8 @@ func (s *service) init() { return printString(f.value()) }, "includeField": func(f fieldEntry, s string) bool { - switch s { - case `""`, "0", "false", "nil": - return f.hideZero + if isZeroPrintstring(s) { + return !f.hideZero } return true }, @@ -160,7 +159,7 @@ func (s *service) serveInstructions(w http.ResponseWriter, r *http.Request) { return case "toggleZeros": s.explorer.updateObjectAt(cmd.Row, cmd.Column, func(access objectAccess) objectAccess { - access.hideNils = !access.hideNils + access.hideZeros = !access.hideZeros return access }) return @@ -172,9 +171,10 @@ func (s *service) serveInstructions(w http.ResponseWriter, r *http.Request) { for _, each := range cmd.Selections { newPath := append(fromAccess.path, each) oa := objectAccess{ - object: fromAccess.object, - path: newPath, - label: strings.Join(newPath, "."), + object: fromAccess.object, + path: newPath, + label: strings.Join(newPath, "."), + hideZeros: true, } v := oa.Value() if !canExplore(v) {