11using System ;
22using System . Collections . Generic ;
3- using System . Drawing ;
43using System . Linq ;
54using System . Windows . Forms ;
65using OpenEphys . ProbeInterface . NET ;
@@ -40,8 +39,8 @@ public NeuropixelsV1ChannelConfigurationDialog(NeuropixelsV1ProbeConfiguration p
4039
4140 ProbeConfiguration = probeConfiguration ;
4241
43- ZoomInBoundaryX = 400 ;
44- ZoomInBoundaryY = 400 ;
42+ ZoomInBoundaryX = 200 ;
43+ ZoomInBoundaryY = 200 ;
4544
4645 HighlightEnabledContacts ( ) ;
4746 UpdateContactLabels ( ) ;
@@ -87,7 +86,6 @@ internal override void ZoomEvent(ZedGraphControl sender, ZoomState oldState, Zoo
8786 base . ZoomEvent ( sender , oldState , newState ) ;
8887
8988 UpdateFontSize ( ) ;
90- DrawScale ( ) ;
9189 RefreshZedGraph ( ) ;
9290
9391 OnZoomHandler ( ) ;
@@ -98,90 +96,21 @@ private void OnZoomHandler()
9896 OnZoom ? . Invoke ( this , EventArgs . Empty ) ;
9997 }
10098
99+ internal override bool IsDrawScale ( ) => true ;
100+
101101 internal override void DrawScale ( )
102102 {
103- if ( ProbeConfiguration == null )
103+ if ( ProbeConfiguration == null || zedGraphChannels . MasterPane . PaneList . Count < 2 )
104104 return ;
105105
106- const string ScalePointsTag = "scale_points" ;
107- const string ScaleTextTag = "scale_text" ;
108-
109- zedGraphChannels . GraphPane . GraphObjList . RemoveAll ( obj => obj is TextObj && obj . Tag is string tag && tag == ScaleTextTag ) ;
110- zedGraphChannels . GraphPane . CurveList . RemoveAll ( curve => curve . Tag is string tag && tag == ScalePointsTag ) ;
111-
112- const int MajorTickIncrement = 100 ;
113- const int MajorTickLength = 10 ;
114- const int MinorTickIncrement = 10 ;
115- const int MinorTickLength = 5 ;
116-
117- if ( ProbeConfiguration . ProbeGroup . Probes . ElementAt ( 0 ) . SiUnits != ProbeSiUnits . um )
118- {
119- MessageBox . Show ( "Warning: Expected ProbeGroup units to be in microns, but it is in millimeters. Scale might not be accurate." ) ;
120- }
121-
122- var fontSize = CalculateFontSize ( ) ;
123-
124- var zoomedOut = fontSize <= 2 ;
125-
126- fontSize = zoomedOut ? 6 : fontSize * 3 ;
127- var majorTickOffset = MajorTickLength + CalculateScaleRange ( zedGraphChannels . GraphPane . XAxis . Scale ) * 0.015 ;
128- majorTickOffset = majorTickOffset > 50 ? 50 : majorTickOffset ;
129-
130- var x = GetProbeRight ( zedGraphChannels . GraphPane . GraphObjList ) + 40 ;
131- var minY = GetProbeBottom ( zedGraphChannels . GraphPane . GraphObjList ) ;
132- var maxY = GetProbeTop ( zedGraphChannels . GraphPane . GraphObjList ) ;
133-
134- int textPosition = 0 ;
135-
136- PointPairList pointList = new ( ) ;
137-
138- var countMajorTicks = 0 ;
139-
140- for ( int i = ( int ) minY ; i < maxY ; i += MajorTickIncrement )
141- {
142- PointPair majorTickLocation = new ( x + MajorTickLength , minY + MajorTickIncrement * countMajorTicks ) ;
143-
144- pointList . Add ( new PointPair ( x , minY + MajorTickIncrement * countMajorTicks ) ) ;
145- pointList . Add ( majorTickLocation ) ;
146- pointList . Add ( new PointPair ( x , minY + MajorTickIncrement * countMajorTicks ) ) ;
147-
148- if ( ! zoomedOut || countMajorTicks % 5 == 0 )
149- {
150- TextObj textObj = new ( $ "{ textPosition } µm", majorTickLocation . X + 10 , majorTickLocation . Y , CoordType . AxisXYScale , AlignH . Left , AlignV . Center )
151- {
152- Tag = ScaleTextTag
153- } ;
154- textObj . FontSpec . Border . IsVisible = false ;
155- textObj . FontSpec . Size = fontSize ;
156- zedGraphChannels . GraphPane . GraphObjList . Add ( textObj ) ;
157-
158- textPosition += zoomedOut ? 5 * MajorTickIncrement : MajorTickIncrement ;
159- }
160-
161- if ( ! zoomedOut )
162- {
163- var countMinorTicks = 1 ;
164-
165- for ( int j = i + MinorTickIncrement ; j < i + MajorTickIncrement && i + MinorTickIncrement * countMinorTicks < maxY ; j += MinorTickIncrement )
166- {
167- pointList . Add ( new PointPair ( x , minY + MajorTickIncrement * countMajorTicks + MinorTickIncrement * countMinorTicks ) ) ;
168- pointList . Add ( new PointPair ( x + MinorTickLength , minY + MajorTickIncrement * countMajorTicks + MinorTickIncrement * countMinorTicks ) ) ;
169- pointList . Add ( new PointPair ( x , minY + MajorTickIncrement * countMajorTicks + MinorTickIncrement * countMinorTicks ) ) ;
170-
171- countMinorTicks ++ ;
172- }
173- }
174-
175- countMajorTicks ++ ;
176- }
177-
178- var curve = zedGraphChannels . GraphPane . AddCurve ( ScalePointsTag , pointList , Color . Black , SymbolType . None ) ;
106+ var pane = zedGraphChannels . MasterPane . PaneList [ 1 ] ;
179107
180- const float scaleBarWidth = 1 ;
108+ pane . YAxis . Scale . Min = GetProbeBottom ( zedGraphChannels . GraphPane . GraphObjList ) ;
109+ pane . YAxis . Scale . Max = GetProbeTop ( zedGraphChannels . GraphPane . GraphObjList ) ;
181110
182- curve . Line . Width = scaleBarWidth ;
183- curve . Label . IsVisible = false ;
184- curve . Symbol . IsVisible = false ;
111+ pane . YAxis . Scale . Format = "#####0' " + ProbeGroup . Probes . First ( ) . SiUnits . ToString ( ) + "'" ;
112+ pane . YAxis . Scale . Mag = 0 ;
113+ pane . YAxis . Scale . MagAuto = false ;
185114 }
186115
187116 internal override void HighlightEnabledContacts ( )
0 commit comments