Skip to content
Open
603 changes: 96 additions & 507 deletions mathics/builtin/box/graphics.py

Large diffs are not rendered by default.

542 changes: 19 additions & 523 deletions mathics/builtin/box/graphics3d.py

Large diffs are not rendered by default.

22 changes: 3 additions & 19 deletions mathics/builtin/box/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

The routines here assist in boxing at the bottom of the hierarchy, typically found when used via a notebook.

Boxing is recursively performed using on the <url>:Head:/doc/reference-of-built-in-symbols/atomic-elements-of-expressions/atomic-primitives/head/</url> of a \Mathics expression
Boxing is recursively performed using on the <url>:Head:/doc/reference-of-built-in-symbols/atomic-elements-of-expressions/atomic-primitives/head/</url> of a \Mathics expression.
"""

# The Box objects are `BoxElementMixin` objects. These objects are literal
Expand All @@ -16,39 +16,23 @@
# output.


from typing import Tuple

from mathics.builtin.box.expression import BoxExpression
from mathics.builtin.options import filter_non_default_values, options_to_rules
from mathics.core.atoms import String
from mathics.core.attributes import A_HOLD_ALL_COMPLETE, A_PROTECTED, A_READ_PROTECTED
from mathics.core.builtin import Builtin
from mathics.core.element import BaseElement, BoxElementMixin, EvalMixin
from mathics.core.element import BoxElementMixin, EvalMixin
from mathics.core.evaluation import Evaluation
from mathics.core.exceptions import BoxConstructError
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.symbols import Symbol
from mathics.format.box import to_boxes
from mathics.format.box.common import elements_to_expressions

# This tells documentation how to sort this module
sort_order = "mathics.builtin.low-level-notebook-structure"


def elements_to_expressions(
self: BoxExpression, elements: Tuple[BaseElement], options: dict
) -> Tuple[BaseElement]:
"""
Return a tuple of Mathics3 normal atoms or expressions.
"""
opts = sorted(options_to_rules(options, filter_non_default_values(self)))
expr_elements = [
elem.to_expression() if isinstance(elem, BoxExpression) else elem
for elem in elements
]
return tuple(expr_elements + opts)


class BoxData(Builtin):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/BoxData.html</url>
Expand Down
5 changes: 3 additions & 2 deletions mathics/builtin/box/uniform_polyhedra.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numbers

from mathics.builtin.box.graphics3d import Coords3D
from mathics.builtin.box.graphics import _GraphicsElementBox
from mathics.builtin.colors.color_directives import Opacity, _ColorObject
from mathics.builtin.drawing.graphics_internals import GLOBALS3D, _GraphicsElementBox
from mathics.builtin.drawing.graphics3d import Coords3D
from mathics.builtin.drawing.graphics_internals import GLOBALS3D
from mathics.core.exceptions import BoxExpressionError
from mathics.core.symbols import Symbol

Expand Down
9 changes: 3 additions & 6 deletions mathics/builtin/drawing/graphics3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
"""

from mathics.builtin.colors.color_directives import RGBColor
from mathics.builtin.graphics import (
CoordinatesError,
Graphics,
Style,
_GraphicsElements,
)
from mathics.builtin.graphics import Graphics
from mathics.core.atoms import Integer, Rational, Real
from mathics.core.builtin import Builtin
from mathics.core.expression import Evaluation, Expression
from mathics.core.symbols import SymbolN
from mathics.eval.nevaluator import eval_N
from mathics.format.box.graphics import CoordinatesError, Style, _GraphicsElements

# This tells documentation how to sort this module
# Here we are also hiding "drawing" since this erroneously appears at the top level.
Expand Down Expand Up @@ -107,6 +103,7 @@ class Graphics3D(Graphics):
. draw(((1,1,-1)--(1,1,1)), rgb(0.4, 0.4, 0.4)+linewidth(1));
. \end{asy}
"""

summary_text = "a three-dimensional graphics image wrapper"
options = Graphics.options.copy()
options.update(
Expand Down
11 changes: 0 additions & 11 deletions mathics/builtin/drawing/graphics_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from abc import ABC

from mathics.builtin.box.expression import BoxExpression
from mathics.core.builtin import BuiltinElement
from mathics.core.exceptions import BoxExpressionError
from mathics.core.symbols import Symbol, system_symbols_dict
Expand All @@ -25,16 +24,6 @@ def create_as_style(klass, graphics, item):
return klass(graphics, item)


class _GraphicsElementBox(BoxExpression, ABC):
def init(self, graphics, item=None, style={}, opacity=1.0):
if item is not None and not item.has_form(self.get_name(), None):
raise BoxExpressionError
self.graphics = graphics
self.style = style
self.opacity = opacity
self.is_completely_visible = False # True for axis elements


def get_class(symbol: Symbol):
"""
Returns the Builtin graphic primitive associated to the
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/drawing/plot_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
SymbolEdgeForm,
SymbolGraphics,
SymbolStyle,
SymbolText,
)
from mathics.eval.drawing.charts import draw_bar_chart, eval_chart
from mathics.eval.drawing.plot import TwoTenths
from mathics.eval.nevaluator import eval_N

# This tells documentation how to sort this module
sort_order = "mathics.builtin.chart"

SymbolDisk = Symbol("Disk")
SymbolFaceForm = Symbol("FaceForm")
SymbolText = Symbol("Text")

TwoTenths = Real(0.2)
MTwoTenths = -TwoTenths


Expand Down
Loading
Loading