New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedmeter secondary ticks fail if data interval includes negative values #1013

Closed
CDMIUB opened this Issue Sep 23, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@CDMIUB
Copy link

CDMIUB commented Sep 23, 2018

Operating system: ubuntu 16.04 (Linux 4.15.0-34-generic #37-Ubuntu SMP x86_64 GNU/LinuxL)
wxPython version & source: ubuntu repository: python3-wxgtk4.0 (4.0.1+dfsg-2)
Python version & source: python3.6 (3.6.6-1~18.04) from ubuntu rpository

Description of the problem: In wx/lib/agw/speedmeter.py: If SetIntervals() contains positive values, the Speedmeter shows fine. If the lower boundary is negative, the secondary ticks are randomly distributed inside and outside the meter.

runnable example:

import numpy as np
import wx
import wx.lib.agw.speedmeter as speedmeter

class MyFrame(wx.Frame):
 
  def __init__(self, parent, id):
    wx.Frame.__init__(self, parent, id, title='not working',size=(220,220))
    
    self.panel = wx.Panel(self, wx.ID_ANY)
    self.panel.SetMinSize((200,200))
    self.topSizer   = wx.BoxSizer(wx.VERTICAL)
    gauge = speedmeter.SpeedMeter(self.panel,wx.ID_ANY,
                  agwStyle=speedmeter.SM_DRAW_HAND|
                           speedmeter.SM_DRAW_SECTORS|
                           speedmeter.SM_DRAW_MIDDLE_TEXT|
                           speedmeter.SM_DRAW_SECONDARY_TICKS )
    interval=[-5,35]
    breaks=[x for x in range(interval[0],interval[1]+10,10)]
    ticks = ['{}'.format(x).replace('.0','') for x in breaks]
    gauge.SetIntervals(interval)
    gauge.SetAngleRange(start=-np.pi/2.,end=np.pi/2.)
    gauge.SetDirection('Reverse')
    gauge.SetArcColour('black')
    gauge.SetIntervals(breaks)
    gauge.SetIntervalColours(['white']*(len(breaks)-1))
    gauge.SetTicks(ticks)
    gauge.SetNumberOfSecondaryTicks(9)
    font=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
    gauge.SetTicksFont(font)
    gauge.SetMiddleText('°C')
    gauge.SetMiddleTextColour('black')
    gauge.SetHandColour('darkred')
    gauge.SetShadowColour('grey')
    gauge.SetHandStyle('Hand')
    gauge.SetSpeedBackground('darkgrey')
    gauge.SetTicksColour('black')
    
    self.topSizer.Add(gauge, 9, wx.ALL|wx.EXPAND, 5)
    self.panel.SetSizer(self.topSizer)
    self.topSizer.Fit(self)
    self.SetSize((300, 300))
    
def main():
  app = wx.App()
  frame = MyFrame(parent=None, id=-1)
  frame.Show()
  app.MainLoop()    
  
if __name__ == '__main__':
  main()

if the line interval=[-5,35] is replaced by interval=[0,40] the example works well.

Solution:
change calculation for secondary ticks:

974,975c974,975                                                                                                     
<                             oldinterval = (oldinterval + spacing) - start                                         
<                             stint = oldinterval                                                                   
---                                                                                                                 
>                             oldinterval = (oldinterval + spacing) 
>                             stint = oldinterval - start
977c977
<                             oldinterval = start + (oldinterval + spacing)
---
>                             oldinterval = (oldinterval + spacing)
@RobinD42

This comment has been minimized.

Copy link
Member

RobinD42 commented Oct 27, 2018

Fixed by #1055

@RobinD42 RobinD42 closed this Oct 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment