import ipywidgets as widgets
import numpy as np
import ipyvolume as ipv

# a scatter plot
x, y, z = np.random.normal(size=(3, 100))
fig = ipv.figure()
scatter = ipv.scatter(x, y, z, marker='box')
scatter.connected = True  # draw connecting lines
ipv.show()

"""
Explanation: Integration with pythreejs
ipyvolume uses parts of pythreejs, giving a lot of flexibility to tweak the visualizations or behaviour.
Materials
The Scatter object has a material and line_material object, which both are a ShaderMaterial pythreejs object: https://pythreejs.readthedocs.io/en/stable/api/materials/ShaderMaterial_autogen.html.
End of explanation
"""


scatter.material.visible = False

"""
Explanation: Using scatter.material we can tweak the material setting:
End of explanation
"""


toggle_lines = widgets.ToggleButton(description="Show lines")
widgets.jslink((scatter.line_material, 'visible'), (toggle_lines, 'value'))
toggle_lines

"""
Explanation: Or even connect a toggle button to a line_material property.
End of explanation
"""


import pythreejs
import ipyvolume as ipv
import numpy as np
fig = ipv.figure()
scatter = ipv.scatter(x, y, z, marker='box')
ipv.show()

control = pythreejs.OrbitControls(controlling=fig.camera)
# assigning to fig.controls will overwrite the builtin controls
fig.controls = control
control.autoRotate = True
# the controls does not update itself, but if we toggle this setting, ipyvolume will update the controls
fig.render_continuous = True



control.autoRotate = True
toggle_rotate = widgets.ToggleButton(description="Rotate")
widgets.jslink((control, 'autoRotate'), (toggle_rotate, 'value'))
toggle_rotate

"""
Explanation: Controls
ipyvolume has builtin controls. For more flexibility, a Controls class from https://pythreejs.readthedocs.io/en/stable/api/controls/index.html can be contructed.
End of explanation
"""


text = widgets.Text()
widgets.jslink((fig.camera, 'position'), (text, 'value'))
text

"""
Explanation: Camera
The camera property of ipyvolume is by default a PerspectiveCamera, but other cameras should also work: https://pythreejs.readthedocs.io/en/stable/api/cameras/index.html
End of explanation
"""


