prefig 0.4.8__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {prefig-0.4.8 → prefig-0.5.0}/PKG-INFO +1 -1
  2. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/diagram.py +9 -0
  3. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/grid_axes.py +2 -0
  4. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/line.py +92 -1
  5. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/schema/pf_schema.rnc +3 -1
  6. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/schema/pf_schema.rng +4 -0
  7. {prefig-0.4.8 → prefig-0.5.0}/pyproject.toml +1 -1
  8. {prefig-0.4.8 → prefig-0.5.0}/LICENSE +0 -0
  9. {prefig-0.4.8 → prefig-0.5.0}/README.md +0 -0
  10. {prefig-0.4.8 → prefig-0.5.0}/prefig/__init__.py +0 -0
  11. {prefig-0.4.8 → prefig-0.5.0}/prefig/cli.py +0 -0
  12. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/CTM.py +0 -0
  13. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/__init__.py +0 -0
  14. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/annotations.py +0 -0
  15. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/area.py +0 -0
  16. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/arrow.py +0 -0
  17. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/axes.py +0 -0
  18. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/calculus.py +0 -0
  19. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/circle.py +0 -0
  20. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/clip.py +0 -0
  21. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/compat.py +0 -0
  22. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/coordinates.py +0 -0
  23. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/definition.py +0 -0
  24. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/diffeqs.py +0 -0
  25. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/graph.py +0 -0
  26. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/group.py +0 -0
  27. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/image.py +0 -0
  28. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/implicit.py +0 -0
  29. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/label.py +0 -0
  30. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/label_tools.py +0 -0
  31. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/legend.py +0 -0
  32. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/math_utilities.py +0 -0
  33. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/network.py +0 -0
  34. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/parametric_curve.py +0 -0
  35. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/parse.py +0 -0
  36. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/path.py +0 -0
  37. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/point.py +0 -0
  38. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/polygon.py +0 -0
  39. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/read.py +0 -0
  40. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/rectangle.py +0 -0
  41. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/repeat.py +0 -0
  42. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/riemann_sum.py +0 -0
  43. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/shape.py +0 -0
  44. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/slope_field.py +0 -0
  45. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/statistics.py +0 -0
  46. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/tags.py +0 -0
  47. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/tangent_line.py +0 -0
  48. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/user_namespace.py +0 -0
  49. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/utilities.py +0 -0
  50. {prefig-0.4.8 → prefig-0.5.0}/prefig/core/vector.py +0 -0
  51. {prefig-0.4.8 → prefig-0.5.0}/prefig/engine.py +0 -0
  52. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/diagcess/diagcess.html +0 -0
  53. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/diagcess/diagcess.js +0 -0
  54. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/de-system.xml +0 -0
  55. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/derivatives.xml +0 -0
  56. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/diffeqs.xml +0 -0
  57. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/implicit.xml +0 -0
  58. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/projection.xml +0 -0
  59. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/riemann.xml +0 -0
  60. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/roots_of_unity.xml +0 -0
  61. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/examples/tangent.xml +0 -0
  62. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/fonts/Braille29.ttf +0 -0
  63. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/js/mj-sre-page.js +0 -0
  64. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/js/package.json +0 -0
  65. {prefig-0.4.8 → prefig-0.5.0}/prefig/resources/template/pf_publication.xml +0 -0
  66. {prefig-0.4.8 → prefig-0.5.0}/prefig/scripts/__init__.py +0 -0
  67. {prefig-0.4.8 → prefig-0.5.0}/prefig/scripts/install_mj.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prefig
3
- Version: 0.4.8
3
+ Version: 0.5.0
4
4
  Summary: An authoring system for mathematical diagrams
5
5
  Home-page: https://prefigure.org
6
6
  License: GPL-3.0-or-later
@@ -79,6 +79,9 @@ class Diagram:
79
79
  # a dictionary for holding shapes
80
80
  self.shape_dict = {}
81
81
 
82
+ # dictionary for saving graphical data
83
+ self.saved_data = {}
84
+
82
85
  # each SVG element will have an id, we'll store a count of ids here
83
86
  self.ids = {}
84
87
 
@@ -235,6 +238,12 @@ class Diagram:
235
238
  log.error(f"Unable to apply inverse coordinate transform to {p}")
236
239
  return np.array([0,0])
237
240
 
241
+ def save_data(self, element, data):
242
+ self.saved_data[element] = data
243
+
244
+ def retrieve_data(self, element):
245
+ return self.saved_data.get(element, None)
246
+
238
247
  def begin_figure(self):
239
248
  # set up the dimensions of the diagram in SVG coordinates
240
249
  dims = self.diagram_element.get('dimensions')
@@ -251,12 +251,14 @@ def grid(element, diagram, parent, outline_status):
251
251
  if x < bbox[0] or x > bbox[2]:
252
252
  continue
253
253
  line_el = line.mk_line((x,bbox[1]), (x,bbox[3]), diagram)
254
+ line_el.attrib.pop('id')
254
255
  grid.append(line_el)
255
256
 
256
257
  for y in y_positions:
257
258
  if y < bbox[1] or y > bbox[3]:
258
259
  continue
259
260
  line_el = line.mk_line((bbox[0], y), (bbox[2], y), diagram)
261
+ line_el.attrib.pop('id')
260
262
  grid.append(line_el)
261
263
 
262
264
 
@@ -5,7 +5,11 @@ import logging
5
5
  from . import utilities as util
6
6
  from . import math_utilities as math_util
7
7
  from . import user_namespace as un
8
+ import copy
8
9
  from . import arrow
10
+ from . import group
11
+ from . import label
12
+ from . import CTM
9
13
 
10
14
  log = logging.getLogger('prefigure')
11
15
 
@@ -50,12 +54,24 @@ def line(element, diagram, parent, outline_status):
50
54
 
51
55
  line = mk_line(p1, p2, diagram, element.get('id', None),
52
56
  endpoint_offsets=endpoint_offsets)
57
+
58
+ # we need to hold on to the endpoints in case the line is labelled
59
+ # these are endpoints in SVG coordinates
60
+ x1 = float(line.get('x1'))
61
+ x2 = float(line.get('x2'))
62
+ y1 = float(line.get('y1'))
63
+ y2 = float(line.get('y2'))
64
+
65
+ q1 = np.array((x1, y1))
66
+ q2 = np.array((x2, y2))
67
+ diagram.save_data(element, {'q1': q1, 'q2': q2})
68
+
69
+ # now add the graphical attributes
53
70
  util.set_attr(element, 'stroke', 'black')
54
71
  util.set_attr(element, 'thickness', '2')
55
72
  if diagram.output_format() == 'tactile':
56
73
  element.set('stroke', 'black')
57
74
  util.add_attr(line, util.get_1d_attr(element))
58
- # line.set('type', 'line')
59
75
 
60
76
  arrows = int(element.get('arrows', '0'))
61
77
  forward = 'marker-end'
@@ -113,15 +129,38 @@ def line(element, diagram, parent, outline_status):
113
129
  diagram.add_outline(element, line, parent)
114
130
  finish_outline(element, diagram, parent)
115
131
  else:
132
+ original_parent = parent
133
+ parent = add_label(element, diagram, parent)
116
134
  parent.append(line)
117
135
 
136
+ # if no label has been added, then we're done
137
+ if original_parent == parent:
138
+ return
139
+
140
+ # if there is a label, then the id is on the outer <g> element
141
+ # so we need to remove it from the children
142
+ remove_id(parent)
143
+
118
144
  def finish_outline(element, diagram, parent):
145
+ original_parent = parent
146
+ parent = add_label(element, diagram, parent)
147
+
148
+ # if we've added a label, remove the id's from element under the parent <g>
149
+ if original_parent != parent:
150
+ remove_id(parent)
151
+
119
152
  diagram.finish_outline(element,
120
153
  element.get('stroke'),
121
154
  element.get('thickness'),
122
155
  element.get('fill', 'none'),
123
156
  parent)
124
157
 
158
+ def remove_id(el):
159
+ for child in el:
160
+ if child.get('id', None) is not None:
161
+ child.attrib.pop('id')
162
+ remove_id(child)
163
+
125
164
  # We'll be adding lines in other places so we'll use this more widely
126
165
  def mk_line(p0, p1, diagram, id = None, endpoint_offsets = None, user_coords = True):
127
166
  line = ET.Element('line')
@@ -176,3 +215,55 @@ def infinite_line(p0, p1, diagram, slope = None):
176
215
  if t_min > t_max:
177
216
  return None, None
178
217
  return [p + t * v for t in [t_min, t_max]]
218
+
219
+ def add_label(element, diagram, parent):
220
+ # Is there a label associated with point?
221
+ text = element.text
222
+
223
+ # is there a label here?
224
+ has_text = text is not None and len(text.strip()) > 0
225
+ all_comments = all([subel.tag is ET.Comment for subel in element])
226
+ if has_text or not all_comments:
227
+ # If there's a label, we'll bundle the label and point in a group
228
+ parent_group = ET.SubElement(parent, 'g')
229
+ diagram.add_id(parent_group, element.get('id'))
230
+
231
+ # Now we'll create a new XML element describing the label
232
+ el = copy.deepcopy(element)
233
+ el.tag = 'label'
234
+
235
+ data = diagram.retrieve_data(element)
236
+ q1 = data['q1']
237
+ q2 = data['q2']
238
+
239
+ label_location = un.valid_eval(element.get("label-location", "0.5"))
240
+ if label_location < 0:
241
+ label_location = -label_location
242
+ q1, q2 = q2, q1
243
+
244
+ el.set('user-coords', 'no')
245
+ diff = q2 - q1
246
+ d = math_util.length(diff)
247
+ angle = math.degrees(math.atan2(diff[1], diff[0]))
248
+ if diagram.output_format() == "tactile":
249
+ anchor = q1 + label_location * diff
250
+ el.set("anchor", f"({anchor[0]}, {anchor[1]})")
251
+ direction = (diff[1], diff[0])
252
+ alignment = label.get_alignment_from_direction(direction)
253
+ el.set("alignment", alignment)
254
+ label.label(el, diagram, parent_group)
255
+ else:
256
+ tform = CTM.translatestr(*q1)
257
+ tform += ' ' + CTM.rotatestr(-angle)
258
+ distance = d * label_location
259
+ g = ET.SubElement(parent_group, "g")
260
+ g.set("transform", tform)
261
+ el.set("anchor", f"({distance},0)")
262
+ el.set("alignment", "north")
263
+ label.label(el, diagram, g)
264
+
265
+ return parent_group
266
+
267
+ else:
268
+ return parent
269
+
@@ -584,7 +584,9 @@ Line = element line {
584
584
  attribute reverse {"yes"|"no"}?,
585
585
  attribute additional-arrows {"yes"|"no"}?,
586
586
  StrokeAttributes,
587
- CommonAttributes
587
+ CommonAttributes,
588
+ LabelAttributes,
589
+ LabelText?
588
590
  }
589
591
 
590
592
  Network = element network {
@@ -1613,6 +1613,10 @@
1613
1613
  </optional>
1614
1614
  <ref name="StrokeAttributes"/>
1615
1615
  <ref name="CommonAttributes"/>
1616
+ <ref name="LabelAttributes"/>
1617
+ <optional>
1618
+ <ref name="LabelText"/>
1619
+ </optional>
1616
1620
  </element>
1617
1621
  </define>
1618
1622
  <define name="Network">
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "prefig"
3
- version = "0.4.8"
3
+ version = "0.5.0"
4
4
  description = "An authoring system for mathematical diagrams"
5
5
  readme = "README.md"
6
6
  homepage = "https://prefigure.org"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes