diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..538b077 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,10 +7,6 @@ repos: rev: 22.3.0 hooks: - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.2.0 hooks: diff --git a/README.rst.license b/README.rst.license deleted file mode 100644 index a327a9b..0000000 --- a/README.rst.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya -SPDX-License-Identifier: MIT diff --git a/circuitpython_uplot/ubar.py b/circuitpython_uplot/ubar.py index 7803dc0..1c53ab1 100644 --- a/circuitpython_uplot/ubar.py +++ b/circuitpython_uplot/ubar.py @@ -41,6 +41,7 @@ def __init__( fill: bool = False, bar_space=16, xstart=50, + projection=False, ) -> None: """ :param Uplot plot: Plot object for the scatter to be drawn @@ -50,6 +51,7 @@ def __init__( :param bool fill: boxes fill attribute. Defaults to `False` :param int bar_space: space in pixels between the bars :param int xstart: start point in the x axis for the bar to start. Default to :const:`50` + :param bool projection: creates projection of the bars given them depth. """ self._bar_space = bar_space @@ -72,41 +74,43 @@ def __init__( color_index=plot._index_colorused, ) ) - - delta = 20 - rx = int(delta * math.cos(-0.5)) - ry = int(delta * math.sin(-0.5)) - points = [ - (0, 0), - (self._graphx, 0), - (self._graphx - rx, 0 + ry), - (0 - rx, 0 + ry), - ] - - plot.append( - Polygon( - pixel_shader=plot._plot_palette, - points=points, - x=xstart + (i * self._graphx), - y=plot._newymin - self._graphy * y[i], - color_index=plot._index_colorused - 1, + if projection: + delta = 20 + rx = int(delta * math.cos(-0.5)) + ry = int(delta * math.sin(-0.5)) + points = [ + (0, 0), + (self._graphx, 0), + (self._graphx - rx, 0 + ry), + (0 - rx, 0 + ry), + ] + plot._plot_palette[plot._index_colorused + 6] = color_fader( + plot._plot_palette[plot._index_colorused], 0.7, 1 ) - ) - points = [ - (0, 0), - (0 - rx, 0 + ry), - (0 - rx, self._graphy * y[i]), - (0, self._graphy * y[i]), - ] - plot.append( - Polygon( - pixel_shader=plot._plot_palette, - points=points, - x=xstart + (i * self._graphx), - y=plot._newymin - self._graphy * y[i], - color_index=plot._index_colorused + 1, + plot.append( + Polygon( + pixel_shader=plot._plot_palette, + points=points, + x=xstart + (i * self._graphx), + y=plot._newymin - self._graphy * y[i], + color_index=plot._index_colorused + 6, + ) + ) + points = [ + (0, 0), + (0 - rx, 0 + ry), + (0 - rx, self._graphy * y[i]), + (0, self._graphy * y[i]), + ] + plot.append( + Polygon( + pixel_shader=plot._plot_palette, + points=points, + x=xstart + (i * self._graphx), + y=plot._newymin - self._graphy * y[i], + color_index=plot._index_colorused + 6, + ) ) - ) plot.show_text( str(y[i]), @@ -174,3 +178,38 @@ def _draw_rectangle( draw_line(plot._plotbitmap, x, y, x, y - height, color) draw_line(plot._plotbitmap, x + width, y, x + width, y - height, color) draw_line(plot._plotbitmap, x + width, y - height, x, y - height, color) + + +def color_fader(source_color=None, brightness=1.0, gamma=1.0): + """ + Function taken from https://github.com/CedarGroveStudios + Copyright (c) 2022 JG for Cedar Grove Maker Studios + License: MIT + + Scale a 24-bit RGB source color value in proportion to the brightness + setting (0 to 1.0). Returns an adjusted 24-bit RGB color value or None if + the source color is None (transparent). The adjusted color's gamma value is + typically from 0.0 to 2.0 with a default of 1.0 for no gamma adjustment. + + :param int source_color: The color value to be adjusted. Default is None. + :param float brightness: The brightness value for color value adjustment. + Value range is 0.0 to 1.0. Default is 1.0 (maximum brightness). + :param float gamma: The gamma value for color value adjustment. Value range + is 0.0 to 2.0. Default is 1.0 (no gamma adjustment). + + :return int: The adjusted color value.""" + + if source_color is None: + return source_color + + # Extract primary colors and scale to brightness + r = min(int(brightness * ((source_color & 0xFF0000) >> 16)), 0xFF) + g = min(int(brightness * ((source_color & 0x00FF00) >> 8)), 0xFF) + b = min(int(brightness * ((source_color & 0x0000FF) >> 0)), 0xFF) + + # Adjust result for gamma + r = min(int(round((r**gamma), 0)), 0xFF) + g = min(int(round((g**gamma), 0)), 0xFF) + b = min(int(round((b**gamma), 0)), 0xFF) + + return (r << 16) + (g << 8) + b diff --git a/circuitpython_uplot/uplot.py b/circuitpython_uplot/uplot.py index 59e4da0..ff2c0b1 100644 --- a/circuitpython_uplot/uplot.py +++ b/circuitpython_uplot/uplot.py @@ -127,12 +127,12 @@ def __init__( self._index_colorused = 4 - self._plotbitmap = displayio.Bitmap(width, height, 14) + self._plotbitmap = displayio.Bitmap(width, height, 17) if show_box: self._drawbox() - self._plot_palette = displayio.Palette(14) + self._plot_palette = displayio.Palette(17) self._plot_palette[0] = background_color self._plot_palette[1] = box_color self._plot_palette[2] = self._tickcolor diff --git a/docs/api.rst.license b/docs/api.rst.license deleted file mode 100644 index 4f6adac..0000000 --- a/docs/api.rst.license +++ /dev/null @@ -1,4 +0,0 @@ -SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya - -SPDX-License-Identifier: MIT diff --git a/docs/examples.rst b/docs/examples.rst index 4ac3ad8..d0a74b4 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -71,6 +71,16 @@ ubar example :linenos: .. image:: ../docs/uplot_ex8.jpg +Ubar 3D Example +---------------- + +ubar 3D example + +.. literalinclude:: ../examples/uplot_ubar_3Dbars.py + :caption: examples/uplot_ubar_3Dbars.py + :linenos: +.. image:: ../docs/uplot_3DBars.jpg + Upie Example ---------------- diff --git a/docs/examples.rst.license b/docs/examples.rst.license deleted file mode 100644 index 4f6adac..0000000 --- a/docs/examples.rst.license +++ /dev/null @@ -1,4 +0,0 @@ -SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya - -SPDX-License-Identifier: MIT diff --git a/docs/index.rst.license b/docs/index.rst.license deleted file mode 100644 index 4f6adac..0000000 --- a/docs/index.rst.license +++ /dev/null @@ -1,4 +0,0 @@ -SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya - -SPDX-License-Identifier: MIT diff --git a/docs/logging.png.license b/docs/logging.png.license deleted file mode 100644 index 2e755f1..0000000 --- a/docs/logging.png.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Casainho - -SPDX-License-Identifier: MIT diff --git a/docs/quick_start.rst b/docs/quick_start.rst index b2769f9..b72cf06 100644 --- a/docs/quick_start.rst +++ b/docs/quick_start.rst @@ -141,7 +141,6 @@ You can choose some colors directly from the library. This can be done by import from circuitpython_uplot.uplot import color This will allow you to use the colors in the list as color variable definitions - * WHITE * BLACK * RED @@ -189,7 +188,6 @@ After the initial setup we add our xy plane and show our plot There are some parameters that you can customize: - * rangex and rangey: you could specify the ranges of your graph. Allowing you to move your graph according to your needs. This parameters only accept lists * line color: you could specify the color in HEX * fill: if you selected this as `True` the area under your graph will be filled @@ -264,7 +262,6 @@ Creates a scatter plot with x,y data. You can customize the circle diameter if y There are some parameters that you can customize: - * rangex and rangey: you can specify the ranges of your graph. This allows you to move your graph according to your needs. This parameters only accept lists * radius: circles radius/radii * circle_color: you can specify the color in HEX @@ -284,7 +281,7 @@ Bar Plot =============== Allows you to graph bar plots. You just need to give the values of the bar in a python list. -You can choose to create shell or filled bars +You can choose to create shell or filled bars. .. code-block:: python @@ -308,6 +305,24 @@ You can select the color or and if the bars are filled ubar(plot, a, b, 0xFF1000, True) +with the projection argument you can show the bars with projection. This will give them a 3D +appearance + +.. code-block:: python + + import board + from circuitpython_uplot.uplot import Uplot + from circuitpython_uplot.ubar import ubar + + display = board.DISPLAY + plot = Uplot(0, 0, display.width, display.height) + + + a = ["a", "b", "c", "d"] + b = [3, 5, 1, 7] + ubar(plot, a, b, color=0xFF1000, fill=True, bar_space=30, xstart=70, projection=True) + + =============== Fillbetween =============== @@ -380,7 +395,6 @@ This is a similar to Cartesian but designed to allow the user to use it as a dat The user needs to manually set up the range and tick values in order for this graph to work properly There are some parameters that you can customize: - * rangex and rangey: you need specify the ranges of your graph. This allows you to move your graph according to your needs. This parameters only accept lists * ticksx and ticksy: Specific ticks for the X and Y axes * line_color: you can specify the color in HEX diff --git a/docs/quick_start.rst.license b/docs/quick_start.rst.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/quick_start.rst.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/readme.png.license b/docs/readme.png.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/readme.png.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/readme2.png.license b/docs/readme2.png.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/readme2.png.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_3DBars.jpg b/docs/uplot_3DBars.jpg new file mode 100644 index 0000000..9479954 Binary files /dev/null and b/docs/uplot_3DBars.jpg differ diff --git a/docs/uplot_cartesian.gif.license b/docs/uplot_cartesian.gif.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_cartesian.gif.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex1.jpg.license b/docs/uplot_ex1.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex1.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex10.jpg.license b/docs/uplot_ex10.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex10.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex11.jpg.license b/docs/uplot_ex11.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex11.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex12.jpg.license b/docs/uplot_ex12.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex12.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex15.jpg.license b/docs/uplot_ex15.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex15.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex16.jpg.license b/docs/uplot_ex16.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex16.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex17.jpg.license b/docs/uplot_ex17.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex17.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex22.jpg.license b/docs/uplot_ex22.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex22.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex23.jpg.license b/docs/uplot_ex23.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex23.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex3.jpg.license b/docs/uplot_ex3.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex3.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex4.jpg.license b/docs/uplot_ex4.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex4.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex5.jpg.license b/docs/uplot_ex5.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex5.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex6.jpg.license b/docs/uplot_ex6.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex6.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex7.jpg.license b/docs/uplot_ex7.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex7.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex8.jpg.license b/docs/uplot_ex8.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex8.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/docs/uplot_ex9.jpg.license b/docs/uplot_ex9.jpg.license deleted file mode 100644 index bbbfbaf..0000000 --- a/docs/uplot_ex9.jpg.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2023 Jose David M. - -SPDX-License-Identifier: MIT diff --git a/examples/uplot_ubar_3Dbars.py b/examples/uplot_ubar_3Dbars.py new file mode 100644 index 0000000..f6088cf --- /dev/null +++ b/examples/uplot_ubar_3Dbars.py @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +import board +from circuitpython_uplot.uplot import Uplot +from circuitpython_uplot.ubar import ubar + + +# Setting up the display +display = board.DISPLAY + +plot = Uplot(0, 0, display.width, display.height) + +# Setting up tick parameters +plot.axs_params(axstype="box") +a = ["a", "b", "c", "d", "e"] +b = [3, 5, 1, 9, 7] + +# Creating a 3D bar +ubar(plot, a, b, color=0xFF1000, fill=True, bar_space=30, xstart=70, projection=True) + +# Plotting and showing the plot +display.show(plot) + +# Adding some wait time +while True: + time.sleep(1)