@@ -81,6 +81,18 @@ def __init__(self):
81
81
type = str ,
82
82
dest = "style" , default = 'marks_outwards' ,
83
83
help = "Style of marks" )
84
+ self .arg_parser .add_argument ("--logarithmic_ticks" ,
85
+ type = inkex .Boolean ,
86
+ dest = "logarithmic_ticks" ,
87
+ default = "False" ,
88
+ help = "Whether to space ticks according to a log scale." )
89
+ self .arg_parser .add_argument ("--logarithmic_subticks" ,
90
+ type = inkex .Boolean ,
91
+ dest = "logarithmic_subticks" ,
92
+ default = "False" ,
93
+ help = "Whether to space ticks according to a log scale. " \
94
+ "Using this without the log-scale ticks will make " \
95
+ "an exponential scale." )
84
96
85
97
# Label settings
86
98
self .arg_parser .add_argument ("--labels_enabled" ,
@@ -212,11 +224,22 @@ def draw_tick(self, radius, mark_angle, mark_size, parent):
212
224
self .draw_circle_mark (self .x_offset , self .y_offset , radius , mark_angle , mark_size , parent )
213
225
214
226
def get_tick_angles (self ):
215
- angle = radians (self .options .angle )
216
227
n_ticks = self .options .n_ticks
217
- ticks_delta = angle / (n_ticks - 1 )
228
+ if n_ticks <= 0 :
229
+ return []
230
+
231
+ angle = radians (self .options .angle )
218
232
start_angle = 1.5 * pi - 0.5 * angle
219
- return [start_angle + ticks_delta * i for i in range (n_ticks )]
233
+
234
+ if self .options .logarithmic_ticks :
235
+ tick_angles = []
236
+ for i in range (n_ticks ):
237
+ tick_angle = start_angle + angle * log (i + 1 )/ log (n_ticks )
238
+ tick_angles .append (tick_angle )
239
+ return tick_angles
240
+ else :
241
+ ticks_delta = angle / (n_ticks - 1 )
242
+ return [start_angle + ticks_delta * i for i in range (n_ticks )]
220
243
221
244
def get_tick_labels (self ):
222
245
start_num = self .options .start_value
@@ -235,15 +258,32 @@ def get_tick_labels(self):
235
258
return labels
236
259
237
260
def get_subtick_angles (self ):
238
- angle = radians (self .options .angle )
261
+ if self .options .n_ticks < 2 :
262
+ return []
263
+
239
264
n_ticks = self .options .n_ticks
240
265
n_subticks = self .options .n_subticks
241
- ticks_delta = angle / (n_ticks - 1 )
242
- subticks_delta = ticks_delta / (n_subticks + 1 )
266
+ angle = radians (self .options .angle )
267
+ start_angle = 1.5 * pi - 0.5 * angle
268
+
243
269
subtick_angles = []
244
- for tick_angle in self .get_tick_angles ()[:- 1 ]:
245
- for subtick in range (n_subticks ):
246
- subtick_angles .append (tick_angle + subticks_delta * (subtick + 1 ))
270
+ tick_angles = self .get_tick_angles ()
271
+ for tick , cur_tick_angle in enumerate (tick_angles [:- 1 ]):
272
+ next_tick_angle = tick_angles [tick + 1 ]
273
+ tick_delta = next_tick_angle - cur_tick_angle
274
+ if self .options .logarithmic_ticks :
275
+ for i in range (n_subticks ):
276
+ fraction = (i + 1 ) / (n_subticks + 1 ) + tick
277
+ fraction = log (fraction + 1 ) / log (n_ticks )
278
+ subtick_angles .append (start_angle + angle * fraction )
279
+ elif self .options .logarithmic_subticks :
280
+ for i in range (n_subticks ):
281
+ fraction = log (i + 2 ) / log (n_subticks + 2 )
282
+ subtick_angles .append (cur_tick_angle + tick_delta * fraction )
283
+ else : # linear
284
+ for i in range (n_subticks ):
285
+ fraction = (i + 1 ) / (n_subticks + 1 )
286
+ subtick_angles .append (cur_tick_angle + tick_delta * fraction )
247
287
return subtick_angles
248
288
249
289
def effect (self ):
@@ -280,18 +320,19 @@ def effect(self):
280
320
281
321
# Draw main ticks
282
322
tick_angles = self .get_tick_angles ()
283
- for angle in tick_angles :
284
- self .draw_tick (radius , angle , tick_length , parent )
323
+ for tick_angle in tick_angles :
324
+ self .draw_tick (radius , tick_angle , tick_length , parent )
325
+
326
+ # Draw subticks
327
+ for subtick_angle in self .get_subtick_angles ():
328
+ self .draw_tick (subtick_radius , subtick_angle , subtick_length , parent )
285
329
286
330
if self .options .labels_enabled :
287
331
labels = self .get_tick_labels ()
288
332
label_radius = radius + tick_length + text_spacing
289
333
for angle , label in zip (tick_angles , labels ):
290
334
self .draw_text (label , label_radius , angle , text_size , parent )
291
335
292
- # Draw subticks
293
- for angle in self .get_subtick_angles ():
294
- self .draw_tick (subtick_radius , angle , subtick_length , parent )
295
336
296
337
if __name__ == '__main__' :
297
338
e = Knob_Scale ()
0 commit comments