Skip to content

Commit

Permalink
Merge pull request #268 from Dessia-tech/feat/update_plot_canvas
Browse files Browse the repository at this point in the history
feat(update_plot_canvas): add html_plot function in python
  • Loading branch information
Tanguylo authored Jun 15, 2023
2 parents 161a964 + 4cf32a1 commit 1f7f668
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 460 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.14.0]
### Add
- to_html method in Python so that it is possible to create a plot data file without opening it in web browser
- Allow to draw all points of a Dataset in Graph objects

### Fix
- Smart writing of axes' names in ParallelPlot
Expand Down
20 changes: 9 additions & 11 deletions code_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,36 @@

from pylint.lint import Run

MIN_NOTE = 9.10
MIN_NOTE = 9.50
# RATCHET_NOTE = 0.4
# RATCHET_ERRORS = 3

UNWATCHED_ERRORS = ['fixme', 'trailing-whitespace', 'import-error', 'missing-final-newline', 'trailing-newlines']

MAX_ERROR_BY_TYPE = {
'protected-access': 26,
'invalid-name': 13,
'consider-using-f-string': 2,
'protected-access': 1,
'invalid-name': 6,
'no-else-return': 17,
'arguments-differ': 13,
'arguments-differ': 2,
'no-member': 1,
'too-many-locals': 3,
'too-many-locals': 2,
'wrong-import-order': 1,
'too-many-branches': 1,
'unused-import': 1,
'unused-argument': 4,
'cyclic-import': 11,
'no-self-use': 6,
'unused-variable': 1,
'trailing-whitespace': 11,
'empty-docstring': 7,
'missing-module-docstring': 4,
'too-many-arguments': 15,
'too-few-public-methods': 7,
'too-many-arguments': 16,
'too-few-public-methods': 5,
'unnecessary-comprehension': 5,
'no-value-for-parameter': 2,
'too-many-return-statements': 8,
'raise-missing-from': 6,
'consider-merging-isinstance': 6,
'abstract-method': 25,
'abstract-method': 26,
'import-outside-toplevel': 7,
'too-many-instance-attributes': 3,
'consider-iterating-dictionary': 4,
Expand Down Expand Up @@ -146,7 +144,7 @@ def extract_messages_by_type(type_):


if error_detected:
raise RuntimeError('Too many errors\nRun pylint dessia_common to get the errors')
raise RuntimeError('Too many errors\nRun pylint plot_data to get the errors')

if error_over_ratchet_limit:
raise RuntimeError('Please lower the error limits in code_pylint.py MAX_ERROR_BY_TYPE according to warnings above')
Expand Down
3 changes: 2 additions & 1 deletion plot_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pkg_resources
""" Plot data package init. """

import pkg_resources
from .core import *

__version__ = pkg_resources.require("plot_data")[0].version
51 changes: 20 additions & 31 deletions plot_data/colors.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,48 @@

""" Basics and methods for color handling in plot_data. """

import dessia_common.core as dc
from dessia_common.serialization import SerializableObject
from dessia_common.typings import JsonSerializable
from matplotlib.colors import hsv_to_rgb


class Color(dc.DessiaObject):
def __init__(self, red: float, green: float, blue: float):
""" Base class for handling colors as objects. """

def __init__(self, red: float, green: float, blue: float, name: str = ""):
self.red = red
self.green = green
self.blue = blue

self.rgb = (red, green, blue)
dc.DessiaObject.__init__(self, name=name)

@classmethod
def from_hex(cls, hex_code):
"""
:param hex_code: an hexadecimal string
:type hex_code: str
:return: a Color object
:rtype: Color
"""
""" Get REB color from hexadecimal color. """
hex_code = hex_code.replace('#', '')
r, g, b = (int(hex_code[i:i + 2], 16) / 255. for i in (0, 2, 4))
return cls(r, g, b)
red, green, blue = (int(hex_code[i:i + 2], 16) / 255. for i in (0, 2, 4))
return cls(red, green, blue)

@classmethod
def from_hsv(cls, h: float, s: float, v: float):
"""
:return: a Color object
:rtype: Color
"""
red, green, blue = hsv_to_rgb(h, s, v)
def from_hsv(cls, hue: float, saturation: float, value: float):
""" Get RGB color from HSV color. """
red, green, blue = hsv_to_rgb(hue, saturation, value)
return cls(red=red, green=green, blue=blue)

def __str__(self):
"""
:return: a string rgb(r, g, b) in rgb255
"""
return 'rgb({},{},{})'.format(round(self.red * 255),
round(self.green * 255),
round(self.blue * 255))
return f"rgb({round(self.red * 255)},{round(self.green * 255)},{round(self.blue * 255)})"

def to_dict(self, *args, **kwargs):
def to_dict(self, **_) -> JsonSerializable:
""" Get dict of color. """
# TODO: change this!!! it cannot be deserialized in generic way
return str(self)

@classmethod
def dict_to_object(cls, d):
"""
:return: a Color object
"""
if not d.startswith('rgb('):
def dict_to_object(cls, dict_: JsonSerializable, **_) -> SerializableObject:
""" Get color object from dict. """
if not dict_.startswith('rgb('):
raise ValueError('Color should be string starting with rgb(')
return cls(*(int(v) / 255. for v in d[4:-1].split(',')))
return cls(*(int(v) / 255. for v in dict_[4:-1].split(',')))


RED = Color.dict_to_object('rgb(247,0,0)')
Expand Down
Loading

0 comments on commit 1f7f668

Please sign in to comment.