Skip to content
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

Added the ability to put "real" labels on the dials. #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 72 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
docu_color=svgwrite.rgb(10, 10, 16, '%')
docu_width=0.5

# if you want red 'X' labels, leave dummy_labels set to 1
# for "real" labels, change dummy_labels=0
# if dummy_labels == 0, then:
# rotate_text turns on/off rotating the text to match the angle of the tics
# you must fill label_array[] with the values/strings of your labels, before full_label() is called
# set debug_labels=1 to see the labels printed out to console as they are put in the svg
# the "demo" labels work "correctly" in either mode: real or dummy
dummy_labels=1
rotate_text=0
label_array=[]
debug_labels=0
label_x_fudge=[]
xoffset=0
yoffset=0

# a constant for approximate sizing
szfactor=5.64

Expand All @@ -29,8 +44,8 @@
# ang_n is between 0 (min deflection) and 1 (max deflection)
def toxy(h, ang_n):
a=(ang_n*mechangle) - (mechangle/2)
y=0-math.cos(a)*h
x=math.sin(a)*h
y=yoffset + 0 - math.cos(a)*h
x=xoffset + math.sin(a)*h
return x, y

# draw a full arc at height h, with p points
Expand Down Expand Up @@ -168,22 +183,52 @@ def log_full_ticks(h, d, len_L, len_M, len_S):

# text labels at height h, total of p points.
def full_label(h, p):
if dummy_labels==0:
# compute the x fudge factors based on outer end of tick mark
for i in range (0, p):
x,y = toxy(h, (i/(p-1)))
x1,y1=toxy(h+big_tick_length, (i/(p-1)))
label_x_fudge.append(x1-x)
# adjust values so right-most x fudge factor is 0.0
max_x1=label_x_fudge[p-1]
for i in range (0, p):
label_x_fudge[i]=label_x_fudge[i]-max_x1
if debug_labels>0:
print(label_x_fudge)
for i in range (0, p):
rotate=[]
a=((i/(p-1))*mechangle) - (mechangle/2)
if debug_labels>0:
print("a1 =", a)
a=a*360/(2*math.pi)
if debug_labels>0:
print("a2 =", a)
rotate.append(a)
x,y = toxy(h, (i/(p-1)))
dwg.add(dwg.text(
"x", insert=(x, y), fill='red', rotate=rotate)
)
if dummy_labels>0:
dwg.add(dwg.text( 'x', insert=(x, y), fill='red', rotate=rotate))
else:
if debug_labels>0:
print("before fudge h =", h, ", i/(p-1) =", i/(p-1), ", x =", x, " y =", y)
x=x+label_x_fudge[i]
if debug_labels>0:
print("after fudge h =", h, ", i/(p-1) =", i/(p-1), ", x =", x, " y =", y)
if rotate_text>0:
if debug_labels>0:
print(i, " -> ", label_array[i])
dwg.add(dwg.text( label_array[i], insert=(x, y), fill='black', rotate=rotate))

else:
if debug_labels>0:
print(i, " -> ", label_array[i])
dwg.add(dwg.text( label_array[i], insert=(x, y), fill='black'))

################# create output file #######################

dwg = svgwrite.Drawing('out.svg', profile='tiny')
# add crosshair at meter spindle
dwg.add(dwg.line((-1, 0), (1, 0), stroke=docu_color, stroke_width=docu_width))
dwg.add(dwg.line((0, -1), (0, 1), stroke=docu_color, stroke_width=docu_width))
dwg.add(dwg.line((-1+xoffset, yoffset), (1+xoffset, yoffset), stroke=docu_color, stroke_width=docu_width))
dwg.add(dwg.line((xoffset, -1+yoffset), (xoffset, 1+yoffset), stroke=docu_color, stroke_width=docu_width))


################ main code #################################
Expand All @@ -194,9 +239,14 @@ def full_label(h, p):
# have a total of 31 ticks (i.e. per half degree)
# every 10 ticks (5 deg C) for large markings
# every 2 ticks (1 deg C) for medium markings

for i in range (15,31):
label_array.append(i)

h=265 # 265 / 5.64 = 47mm
full_arc(h, 31)
full_ticks(h, 31, 10, 5, 4, 10, 2)
big_tick_length=10
full_label(h+12, 16)
# partial arcs, ideal for adornment on a meter dial, etc
#for i in range (0,15):
Expand All @@ -210,10 +260,17 @@ def full_label(h, p):

# Humidity indication:
# sector style. 20-90 percent RH, this is a total of 7 sectors

label_array=[]
for i in range (2,10):
label_array.append(i * 10)
label_array[6]="%RH"

h=225
sectors=7
for i in range (0,sectors):
sector(h, 10, 6, i, sectors)
label_x_fudge=[]
full_label(h+12, 8)
# half-sectors for shading in green:
sectors=14
Expand All @@ -223,9 +280,13 @@ def full_label(h, p):
# VOC indication:
# traditional meter style, but with log ticks
# need 5 decades

label_array=["1", "10", "100", "1K", "VOC", "100k"]

h=185
full_arc(h, 51)
log_full_ticks(h, 5, 10, 4, 4)
label_x_fudge=[]
full_label(h+12, 6)
# no safe definition for general VOC, but a sector will be shown for less than 27 ppb (formaldehyde):
sectors=3.5
Expand All @@ -234,9 +295,13 @@ def full_label(h, p):
# Co2 indication:
# traditional meter style, but with log ticks
# need 3 decades

label_array=["1K", "10K", "CO2", "100k"]

h=145
full_arc(h, 61)
log_full_ticks(h, 3, 10, 4, 4)
label_x_fudge=[]
full_label(h+12, 4)
# 250-1000ppm is good. The settings below will draw a sector for 300-1000ppm which is good enough
sectors=6
Expand Down