go-hep.org/x/hep@v0.38.1/groot/rbase/attaxis.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rbase 6 7 import ( 8 "reflect" 9 10 "go-hep.org/x/hep/groot/rbytes" 11 "go-hep.org/x/hep/groot/root" 12 "go-hep.org/x/hep/groot/rtypes" 13 "go-hep.org/x/hep/groot/rvers" 14 ) 15 16 type AttAxis struct { 17 Ndivs int32 // number of divisions (10000*n3 + 100*n2 + n1) 18 AxisColor int16 // color of the line axis 19 LabelColor int16 // color of labels 20 LabelFont int16 // font for labels 21 LabelOffset float32 // offset of labels 22 LabelSize float32 // size of labels 23 Ticks float32 // length of tick marks 24 TitleOffset float32 // offset of axis title 25 TitleSize float32 // size of axis title 26 TitleColor int16 // color of axis title 27 TitleFont int16 // font for axis title 28 } 29 30 func NewAttAxis() *AttAxis { 31 return &AttAxis{ 32 Ndivs: 510, // FIXME(sbinet) 33 AxisColor: 1, 34 LabelColor: 1, 35 LabelFont: 42, 36 LabelOffset: 0.005, 37 LabelSize: 0.035, 38 Ticks: 0.03, 39 TitleOffset: 1, 40 TitleSize: 0.035, 41 TitleColor: 1, 42 TitleFont: 42, 43 } 44 } 45 46 func (*AttAxis) RVersion() int16 { 47 return rvers.AttAxis 48 } 49 50 func (*AttAxis) Class() string { 51 return "TAttAxis" 52 } 53 54 func (a *AttAxis) MarshalROOT(w *rbytes.WBuffer) (int, error) { 55 if w.Err() != nil { 56 return 0, w.Err() 57 } 58 59 hdr := w.WriteHeader(a.Class(), a.RVersion()) 60 w.WriteI32(a.Ndivs) 61 w.WriteI16(a.AxisColor) 62 w.WriteI16(a.LabelColor) 63 w.WriteI16(a.LabelFont) 64 w.WriteF32(a.LabelOffset) 65 w.WriteF32(a.LabelSize) 66 w.WriteF32(a.Ticks) 67 w.WriteF32(a.TitleOffset) 68 w.WriteF32(a.TitleSize) 69 w.WriteI16(a.TitleColor) 70 w.WriteI16(a.TitleFont) 71 72 return w.SetHeader(hdr) 73 } 74 75 func (a *AttAxis) UnmarshalROOT(r *rbytes.RBuffer) error { 76 if r.Err() != nil { 77 return r.Err() 78 } 79 80 hdr := r.ReadHeader(a.Class(), a.RVersion()) 81 a.Ndivs = r.ReadI32() 82 a.AxisColor = r.ReadI16() 83 a.LabelColor = r.ReadI16() 84 a.LabelFont = r.ReadI16() 85 a.LabelOffset = r.ReadF32() 86 a.LabelSize = r.ReadF32() 87 a.Ticks = r.ReadF32() 88 a.TitleOffset = r.ReadF32() 89 a.TitleSize = r.ReadF32() 90 a.TitleColor = r.ReadI16() 91 a.TitleFont = r.ReadI16() 92 93 r.CheckHeader(hdr) 94 95 return r.Err() 96 } 97 98 func (a *AttAxis) RMembers() (mbrs []rbytes.Member) { 99 mbrs = append(mbrs, []rbytes.Member{ 100 {Name: "fNdivisions", Value: &a.Ndivs}, 101 {Name: "fAxisColor", Value: &a.AxisColor}, 102 {Name: "fLabelColor", Value: &a.LabelColor}, 103 {Name: "fLabelFont", Value: &a.LabelFont}, 104 {Name: "fLabelOffset", Value: &a.LabelOffset}, 105 {Name: "fLabelSize", Value: &a.LabelSize}, 106 {Name: "fTickLength", Value: &a.Ticks}, 107 {Name: "fTitleOffset", Value: &a.TitleOffset}, 108 {Name: "fTitleSize", Value: &a.TitleSize}, 109 {Name: "fTitleColor", Value: &a.TitleColor}, 110 {Name: "fTitleFont", Value: &a.TitleFont}, 111 }...) 112 return mbrs 113 } 114 115 func init() { 116 f := func() reflect.Value { 117 o := NewAttAxis() 118 return reflect.ValueOf(o) 119 } 120 rtypes.Factory.Add("TAttAxis", f) 121 } 122 123 var ( 124 _ root.Object = (*AttAxis)(nil) 125 _ rbytes.Marshaler = (*AttAxis)(nil) 126 _ rbytes.Unmarshaler = (*AttAxis)(nil) 127 )