Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphic features refactor #473

Merged
merged 77 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
60e7f60
just a start
kushalkolar Apr 3, 2024
6eec7d5
pushing to continue on my desktop
kushalkolar May 17, 2024
0249125
progress on buffer manager cleanup_key
kushalkolar May 17, 2024
9d891ee
more progress, still lots to do
kushalkolar May 17, 2024
9635bc0
slicing working with PointsDataFeature, negative slices too, still ma…
kushalkolar May 18, 2024
9be017c
comitting stuff
kushalkolar May 18, 2024
0491f8c
_update_range() is pretty good now
kushalkolar May 18, 2024
97b7303
comment
kushalkolar May 18, 2024
4585be2
if statement
kushalkolar May 18, 2024
261a5a9
simply colors setting
kushalkolar May 20, 2024
5d40af8
type annotation
kushalkolar May 20, 2024
697d50e
simpler slice parsing
kushalkolar May 20, 2024
08fd17d
remove cleanup_key :D :D :D git status!
kushalkolar May 20, 2024
a45651d
all fancy and negative indexing working :D
kushalkolar May 20, 2024
9612d60
start tests
kushalkolar May 20, 2024
dda8396
exception message
kushalkolar May 20, 2024
e22fe7c
more on tests
kushalkolar May 20, 2024
9b4082f
refactor sizes, not tested yet
kushalkolar May 20, 2024
2a1869c
start parameterizing buffer tests
kushalkolar May 21, 2024
29a0a76
better buffer tests
kushalkolar May 21, 2024
054c836
more variants
kushalkolar May 21, 2024
f50614f
add array fancy indexing to same parameterization
kushalkolar May 21, 2024
9ed2bf6
parameterize tuple tests
kushalkolar May 21, 2024
5e1471e
remove repr
kushalkolar May 21, 2024
f59fb19
test offset and size
kushalkolar May 21, 2024
4d25daa
test offset and size
kushalkolar May 21, 2024
aa1949b
test create colors
kushalkolar May 21, 2024
c74d7b9
also test with direct truth indices in colors
kushalkolar May 21, 2024
cecb438
points tests, works
kushalkolar May 21, 2024
0a20008
remove imports
kushalkolar May 21, 2024
a1c8c87
sizes test working, other cleanup
kushalkolar May 21, 2024
db93f70
export sizes feature again
kushalkolar May 21, 2024
baca1fc
ideas for sharing and unsharing buffers between graphics
kushalkolar May 21, 2024
a177a7f
ideas for sharing and unsharing buffers between graphics, nto tested
kushalkolar May 21, 2024
c205b10
typing
kushalkolar May 21, 2024
f380b26
attach and detach buffers to a graphic, not tested
kushalkolar May 21, 2024
3585c9e
import
kushalkolar May 21, 2024
8d32134
more int point tests
kushalkolar May 21, 2024
deceeeb
Graphic.add_event_handler
kushalkolar May 21, 2024
66b5e6d
adding and removing data feature event works and tested
kushalkolar May 22, 2024
3a58feb
common features, WIP
kushalkolar May 22, 2024
adcc13f
regular features and refactor line and scatter into positions graphic
kushalkolar May 22, 2024
762fcbb
uniform sizes
kushalkolar May 22, 2024
3017b7e
implement sizes and uniform size for scatter
kushalkolar May 22, 2024
a45b3f9
VertexCmap feature, not yet tested
kushalkolar May 22, 2024
09ce4f5
start image features, not tested, add thickness, not tested
kushalkolar May 22, 2024
93e7a9d
better cmap parsing
kushalkolar May 23, 2024
2be22f6
cleanup
kushalkolar May 23, 2024
eedee8f
image features
kushalkolar May 23, 2024
67ad327
cleanup
kushalkolar May 23, 2024
b417190
start selection feature refactor
kushalkolar May 23, 2024
eb47408
more on selection features
kushalkolar May 23, 2024
ab80033
offset and rotation for base graphic
kushalkolar May 25, 2024
da433de
feature event table
kushalkolar May 25, 2024
d12d4fa
position feature event tables
kushalkolar May 25, 2024
570683a
rotation and offset features
kushalkolar May 25, 2024
ec6b2f4
work on selectors, WIP, linear region selector inits properly and mov…
kushalkolar May 25, 2024
db910d3
proper centering
kushalkolar May 25, 2024
a09386b
much simpliified and better linear region selector
kushalkolar May 26, 2024
49c2108
linear region selector works well on x axis with events and data sele…
kushalkolar May 26, 2024
1ec0f40
vertex cmap fix, delete synchronizer
kushalkolar May 26, 2024
5022753
linear selector works
kushalkolar May 26, 2024
f295356
cleanup
kushalkolar May 26, 2024
4d4d636
update graphic methods mixin
kushalkolar May 26, 2024
1d6adc6
update selector example nbs, still WIP
kushalkolar May 26, 2024
284a1db
type annotation in setter
kushalkolar May 29, 2024
b4fe957
add notes to tests comments
kushalkolar May 31, 2024
e6b9133
refactor image stuff
kushalkolar Jun 4, 2024
820772d
image selector tool
kushalkolar Jun 4, 2024
254f0ba
return selectors as proxies
kushalkolar Jun 4, 2024
2bf33fa
image stuff works
kushalkolar Jun 4, 2024
67404ca
fix offsets adding graphics, fix positions_graphic cmap bug, quicksta…
kushalkolar Jun 4, 2024
b1b297d
fix add_graphic args and mixin
kushalkolar Jun 4, 2024
74f8428
simpler graphic collection stuff
kushalkolar Jun 4, 2024
6eb5a1a
more line collection
kushalkolar Jun 4, 2024
f543e4a
remove old events system
clewis7 Jun 4, 2024
aa1e974
fix some examples
clewis7 Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions examples/notebooks/linear_region_selector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
"source": [
"import fastplotlib as fpl\n",
"import numpy as np\n",
"from ipywidgets import IntRangeSlider, FloatRangeSlider, VBox\n",
"# from ipywidgets import IntRangeSlider, FloatRangeSlider, VBox\n",
"\n",
"fig = fpl.Figure((2, 2))\n",
"\n",
"# preallocated size for zoomed data\n",
"zoomed_prealloc = 1_000\n",
"\n",
"# data to plot\n",
"xs = np.linspace(0, 100, 1_000)\n",
"sine = np.sin(xs) * 20\n",
"xs = np.linspace(0, 10* np.pi, 1_000)\n",
"sine = np.sin(xs)\n",
"sine += 100\n",
"\n",
"# make sine along x axis\n",
"sine_graphic_x = fig[0, 0].add_line(sine)\n",
"sine_graphic_x = fig[0, 0].add_line(np.column_stack([xs, sine]), offset=(10, 0, 0))\n",
"\n",
"# just something that looks different for line along y-axis\n",
"sine_y = sine\n",
Expand All @@ -47,7 +48,7 @@
"ls_y = sine_graphic_y.add_linear_region_selector(axis=\"y\")\n",
"\n",
"# preallocate array for storing zoomed in data\n",
"zoomed_init = np.column_stack([np.arange(zoomed_prealloc), np.random.rand(zoomed_prealloc)])\n",
"zoomed_init = np.column_stack([np.arange(zoomed_prealloc), np.zeros(zoomed_prealloc)])\n",
"\n",
"# make line graphics for displaying zoomed data\n",
"zoomed_x = fig[1, 0].add_line(zoomed_init)\n",
Expand All @@ -62,54 +63,54 @@
" # interpolate to preallocated size\n",
" return np.interp(x, xp, fp=subdata[:, axis]) # use the y-values\n",
"\n",
"\n",
"@ls_x.add_event_handler(\"selection\")\n",
"def set_zoom_x(ev):\n",
" \"\"\"sets zoomed x selector data\"\"\"\n",
" selected_data = ev.pick_info[\"selected_data\"]\n",
" zoomed_x.data = interpolate(selected_data, axis=1) # use the y-values\n",
" # get the selected data\n",
" selected_data = ev.get_selected_data()\n",
" if selected_data.size == 0:\n",
" # no data selected\n",
" zoomed_x.data[:, 1] = 0\n",
"\n",
" # set the y-values\n",
" zoomed_x.data[:, 1] = interpolate(selected_data, axis=1)\n",
" fig[1, 0].auto_scale()\n",
"\n",
"\n",
"def set_zoom_y(ev):\n",
" \"\"\"sets zoomed y selector data\"\"\"\n",
" selected_data = ev.pick_info[\"selected_data\"]\n",
" zoomed_y.data = -interpolate(selected_data, axis=0) # use the x-values\n",
" \"\"\"sets zoomed x selector data\"\"\"\n",
" # get the selected data\n",
" selected_data = ev.get_selected_data()\n",
" if selected_data.size == 0:\n",
" # no data selected\n",
" zoomed_y.data[:, 0] = 0\n",
"\n",
" # set the x-values\n",
" zoomed_y.data[:, 0] = -interpolate(selected_data, axis=1)\n",
" fig[1, 1].auto_scale()\n",
"\n",
"\n",
"# update zoomed plots when bounds change\n",
"ls_x.selection.add_event_handler(set_zoom_x)\n",
"ls_y.selection.add_event_handler(set_zoom_y)\n",
"\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"id": "0bad4a35-f860-4f85-9061-920154ab682b",
"metadata": {},
"source": [
"### On the x-axis we have a 1-1 mapping from the data that we have passed and the line geometry positions. So the `bounds` min max corresponds directly to the data indices."
"fig.show(maintain_aspect=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c96a3ff-c2e7-4683-8097-8491e97dd6d3",
"id": "2f29e913-c4f8-44a6-8692-eb14436849a5",
"metadata": {},
"outputs": [],
"source": [
"ls_x.selection()"
"sine_graphic_x.data[:, 1].ptp()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ec71e3f-291c-43c6-a954-0a082ba5981c",
"id": "1947a477-5dd2-4df9-aecd-6967c6ab45fe",
"metadata": {},
"outputs": [],
"source": [
"ls_x.get_selected_indices()"
"np.clip(-0.1, 0, 10)"
]
},
{
Expand Down
28 changes: 18 additions & 10 deletions examples/notebooks/linear_selector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "a06e1fd9-47df-42a3-a76c-19e23d7b89fd",
"metadata": {},
"source": [
"## `LinearSelector`, draggable selector that can optionally associated with an ipywidget."
"## `LinearSelector`, draggable selector that can also be linked to an ipywidget slider"
]
},
{
Expand All @@ -16,7 +16,6 @@
"outputs": [],
"source": [
"import fastplotlib as fpl\n",
"from fastplotlib.graphics.selectors import Synchronizer\n",
"\n",
"import numpy as np\n",
"from ipywidgets import VBox, IntSlider, FloatSlider\n",
Expand All @@ -35,16 +34,14 @@
"selector2 = sine_graphic.add_linear_selector(20)\n",
"selector3 = sine_graphic.add_linear_selector(40)\n",
"\n",
"ss = Synchronizer(selector, selector2, selector3)\n",
"\n",
"# one of the selectors will change the line colors when it moves\n",
"@selector.add_event_handler(\"selection\")\n",
"def set_color_at_index(ev):\n",
" # changes the color at the index where the slider is\n",
" ix = ev.pick_info[\"selected_index\"]\n",
" g = ev.pick_info[\"graphic\"].parent\n",
" ix = ev.get_selected_index()\n",
" g = ev.graphic.parent\n",
" g.colors[ix] = \"green\"\n",
"\n",
"selector.selection.add_event_handler(set_color_at_index)\n",
"\n",
"# fastplotlib LineSelector can make an ipywidget slider and return it :D \n",
"ipywidget_slider = selector.make_ipywidget_slider()\n",
"ipywidget_slider.description = \"slider1\"\n",
Expand All @@ -57,7 +54,15 @@
"selector3.add_ipywidget_handler(ipywidget_slider3, step=0.1)\n",
"\n",
"fig[0, 0].auto_scale()\n",
"fig.show(add_widgets=[ipywidget_slider])"
"VBox([fig.show(), ipywidget_slider, ipywidget_slider2, ipywidget_slider3])"
]
},
{
"cell_type": "markdown",
"id": "d83caca6-e9b6-45df-b93c-0dfe0498d20e",
"metadata": {},
"source": [
"Double click the first selctor, and then use `Shift` + Right/Left Arrow Key to move it!"
]
},
{
Expand All @@ -67,13 +72,16 @@
"metadata": {},
"outputs": [],
"source": [
"# this controls the step-size of arrow key movements\n",
"selector.step = 0.1"
]
},
{
"cell_type": "markdown",
"id": "3b0f448f-bbe4-4b87-98e3-093f561c216c",
"metadata": {},
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"### Drag linear selectors with the mouse, hold \"Shift\" to synchronize movement of all the selectors"
]
Expand Down
Loading
Loading