@@ -692,26 +692,38 @@ def boxes_to_svg(self, elements=None, **options) -> str:
692692 svg_body = format_fn (self , elements , data = data , ** options )
693693 return svg_body
694694
695- def create_axes (self , elements , graphics_options , xmin , xmax , ymin , ymax ):
695+ def create_axes (self , elements , graphics_options , xmin , xmax , ymin , ymax ) -> tuple :
696+
697+ # Note that Asymptote has special commands for drawing axes, like "xaxis"
698+ # "yaxis", "xtick" "labelx", "labely". Entend our language
699+ # here and use those in render-like routines.
700+
696701 use_log_for_y_axis = graphics_options .get ("System`LogPlot" , False )
697- axes = graphics_options .get ("System`Axes" )
698- if axes is SymbolTrue :
702+ axes_option = graphics_options .get ("System`Axes" )
703+
704+ if axes_option is SymbolTrue :
699705 axes = (True , True )
700- elif axes .has_form ("List" , 2 ):
701- axes = (axes .elements [0 ] is SymbolTrue , axes .elements [1 ] is SymbolTrue )
706+ elif axes_option .has_form ("List" , 2 ):
707+ axes = (
708+ axes_option .elements [0 ] is SymbolTrue ,
709+ axes_option .elements [1 ] is SymbolTrue ,
710+ )
702711 else :
703712 axes = (False , False )
704- ticks_style = graphics_options .get ("System`TicksStyle" )
705- axes_style = graphics_options .get ("System`AxesStyle" )
713+
714+ ticks_style_option = graphics_options .get ("System`TicksStyle" )
715+ axes_style_option = graphics_options .get ("System`AxesStyle" )
706716 label_style = graphics_options .get ("System`LabelStyle" )
707- if ticks_style .has_form ("List" , 2 ):
708- ticks_style = ticks_style .elements
717+
718+ if ticks_style_option .has_form ("List" , 2 ):
719+ ticks_style = ticks_style_option .elements
709720 else :
710- ticks_style = [ticks_style ] * 2
711- if axes_style .has_form ("List" , 2 ):
712- axes_style = axes_style .elements
721+ ticks_style = [ticks_style_option ] * 2
722+
723+ if axes_style_option .has_form ("List" , 2 ):
724+ axes_style = axes_style_option .elements
713725 else :
714- axes_style = [axes_style ] * 2
726+ axes_style = [axes_style_option ] * 2
715727
716728 ticks_style = [elements .create_style (s ) for s in ticks_style ]
717729 axes_style = [elements .create_style (s ) for s in axes_style ]
@@ -723,12 +735,16 @@ def add_element(element):
723735 element .is_completely_visible = True
724736 elements .elements .append (element )
725737
738+ # Units seem to be in point size units
739+
726740 ticks_x , ticks_x_small , origin_x = self .axis_ticks (xmin , xmax )
727741 ticks_y , ticks_y_small , origin_y = self .axis_ticks (ymin , ymax )
728742
729743 axes_extra = 6
744+
730745 tick_small_size = 3
731746 tick_large_size = 5
747+
732748 tick_label_d = 2
733749
734750 ticks_x_int = all (floor (x ) == x for x in ticks_x )
@@ -791,8 +807,10 @@ def add_element(element):
791807 )
792808 )
793809 ticks_lines = []
810+
794811 tick_label_style = ticks_style [index ].clone ()
795812 tick_label_style .extend (label_style )
813+
796814 for x in ticks :
797815 ticks_lines .append (
798816 [
@@ -816,6 +834,7 @@ def add_element(element):
816834 content = String (
817835 "%g" % tick_value
818836 ) # fix e.g. 0.6000000000000001
837+
819838 add_element (
820839 InsetBox (
821840 elements ,
@@ -839,31 +858,32 @@ def add_element(element):
839858 add_element (LineBox (elements , axes_style [0 ], lines = ticks_lines ))
840859 return axes
841860
842- """if axes[1]:
843- add_element(LineBox(elements, axes_style[1], lines=[[Coords(elements, pos=(origin_x,ymin), d=(0,-axes_extra)),
844- Coords(elements, pos=(origin_x,ymax), d=(0,axes_extra))]]))
845- ticks = []
846- tick_label_style = ticks_style[1].clone()
847- tick_label_style.extend(label_style)
848- for k in range(start_k_y, start_k_y+steps_y+1):
849- if k != origin_k_y:
850- y = k * step_y
851- if y > ymax:
852- break
853- pos = (origin_x,y)
854- ticks.append([Coords(elements, pos=pos),
855- Coords(elements, pos=pos, d=(tick_large_size,0))])
856- add_element(InsetBox(elements, tick_label_style, content=Real(y), pos=Coords(elements, pos=pos,
857- d=(-tick_label_d,0)), opos=(1,0)))
858- for k in range(start_k_y_small, start_k_y_small+steps_y_small+1):
859- if k % sub_y != 0:
860- y = k * step_y_small
861- if y > ymax:
862- break
863- pos = (origin_x,y)
864- ticks.append([Coords(elements, pos=pos),
865- Coords(elements, pos=pos, d=(tick_small_size,0))])
866- add_element(LineBox(elements, axes_style[1], lines=ticks))"""
861+ # Old code?
862+ # if axes[1]:
863+ # add_element(LineBox(elements, axes_style[1], lines=[[Coords(elements, pos=(origin_x,ymin), d=(0,-axes_extra)),
864+ # Coords(elements, pos=(origin_x,ymax), d=(0,axes_extra))]]))
865+ # ticks = []
866+ # tick_label_style = ticks_style[1].clone()
867+ # tick_label_style.extend(label_style)
868+ # for k in range(start_k_y, start_k_y+steps_y+1):
869+ # if k != origin_k_y:
870+ # y = k * step_y
871+ # if y > ymax:
872+ # break
873+ # pos = (origin_x,y)
874+ # ticks.append([Coords(elements, pos=pos),
875+ # Coords(elements, pos=pos, d=(tick_large_size,0))])
876+ # add_element(InsetBox(elements, tick_label_style, content=Real(y), pos=Coords(elements, pos=pos,
877+ # d=(-tick_label_d,0)), opos=(1,0)))
878+ # for k in range(start_k_y_small, start_k_y_small+steps_y_small+1):
879+ # if k % sub_y != 0:
880+ # y = k * step_y_small
881+ # if y > ymax:
882+ # break
883+ # pos = (origin_x,y)
884+ # ticks.append([Coords(elements, pos=pos),
885+ # Coords(elements, pos=pos, d=(tick_small_size,0))])
886+ # add_element(LineBox(elements, axes_style[1], lines=ticks))
867887
868888
869889class FilledCurveBox (_GraphicsElementBox ):
0 commit comments