plotjs 0.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
plotjs/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ from .main import PlotJS
2
+
3
+ __version__ = "0.0.6"
4
+ __all__: list[str] = [
5
+ "PlotJS",
6
+ ]
plotjs/css.py ADDED
@@ -0,0 +1,100 @@
1
+ import re
2
+ import warnings
3
+
4
+
5
+ def from_dict(css_dict: dict) -> str:
6
+ """
7
+ Get raw CSS in a string from a dictionnary. It's a
8
+ utility function useful to write CSS from a Python
9
+ dictionnary.
10
+
11
+ Args:
12
+ css_dict: A dictionnary with keys (selectors) and value
13
+ (dictionnary of property-value).
14
+
15
+ Returns:
16
+ A string of raw CSS.
17
+
18
+ Examples:
19
+ ```python
20
+ from plotjs import css
21
+
22
+ css.from_dict({
23
+ ".tooltip": {"color": "red", "background": "blue !important"},
24
+ ".point": {"width": "10px", "height": "200px"},
25
+ })
26
+ ```
27
+ """
28
+ css: str = ""
29
+
30
+ for selector, css_props in css_dict.items():
31
+ css += f"{selector}{{"
32
+ for prop, value in css_props.items():
33
+ css += f"{prop}:{value};"
34
+ css += "}"
35
+
36
+ if not is_css_like(css):
37
+ warnings.warn(f"CSS may be invalid: {css}")
38
+
39
+ return css
40
+
41
+
42
+ def from_file(css_file: str) -> str:
43
+ """
44
+ Get raw CSS from a CSS file. This function just
45
+ reads the CSS from a given file and checks that
46
+ it looks like valid CSS.
47
+
48
+ Args:
49
+ css_file: Path to a CSS file.
50
+
51
+ Returns:
52
+ A string of raw CSS
53
+
54
+ Examples:
55
+ ```python
56
+ from plotjs import css
57
+
58
+ css.from_file("path/to/style.css")
59
+ ```
60
+ """
61
+ with open(css_file, "r") as f:
62
+ css: str = f.read()
63
+
64
+ if not is_css_like(css):
65
+ warnings.warn(f"CSS may be invalid: {css}", category=UserWarning)
66
+ return css
67
+
68
+
69
+ def is_css_like(s: str) -> bool:
70
+ """
71
+ Check whether a string looks like valid CSS. This function
72
+ is primarly used internally, but you can use it too.
73
+
74
+ Args:
75
+ s: A string to evaluate.
76
+
77
+ Returns:
78
+ Whether or not `s` looks like valid CSS.
79
+
80
+ Examples:
81
+ ```python
82
+ from plotjs import is_css_like
83
+
84
+ is_css_like("This is not CSS.") # False
85
+ is_css_like(".box { broken }") # False
86
+ is_css_like(".tooltip { color: red; background: blue; }") # True
87
+ ```
88
+ """
89
+ css_block_pattern = re.compile(
90
+ r"""
91
+ [^{]+\s* # Selector (at least one char that's not '{')
92
+ \{\s* # Opening brace
93
+ ([^:{}]+:\s*[^;{}]+;\s*)+ # At least one prop: value; pair
94
+ \} # Closing brace
95
+ """,
96
+ re.VERBOSE,
97
+ )
98
+
99
+ matches = css_block_pattern.findall(s)
100
+ return bool(matches)
@@ -0,0 +1,3 @@
1
+ from .datasets import load_iris, load_mtcars, load_titanic, _load_data
2
+
3
+ __all__: list[str] = ["load_iris", "load_mtcars", "_load_data", "load_titanic"]
@@ -0,0 +1,138 @@
1
+ import narwhals.stable.v2 as nw
2
+ import os
3
+
4
+ from narwhals.stable.v2.typing import Frame
5
+
6
+ PACKAGE_DIR: str = os.path.dirname(os.path.abspath(__file__))
7
+ AVAILABLE_DATASETS: list[str] = ["iris", "mtcars", "titanic"]
8
+
9
+
10
+ def _load_data(dataset_name: str, backend: str) -> Frame:
11
+ """
12
+ Load one of the available datasets in fleur.
13
+
14
+ Args:
15
+ dataset_name: A string specifying the name of the dataset. Currently,
16
+ "iris", "mtcars" and "titanic" are supported.
17
+ backend: The output format of the dataframe.
18
+
19
+ Returns:
20
+ A dataframe with the specified dataset.
21
+ """
22
+ dataset_name: str = dataset_name.lower()
23
+
24
+ if dataset_name not in AVAILABLE_DATASETS:
25
+ raise ValueError(
26
+ f"dataset_name must be one of: {' ,'.join(AVAILABLE_DATASETS)}"
27
+ )
28
+
29
+ dataset_file: str = f"{dataset_name}.csv"
30
+ dataset_path: str = os.path.join(PACKAGE_DIR, dataset_file)
31
+ df: Frame = nw.read_csv(dataset_path, backend=backend)
32
+
33
+ return df.to_native()
34
+
35
+
36
+ def load_iris(output_format: str = "pandas") -> Frame:
37
+ """
38
+ Load the iris dataset.
39
+
40
+ Args:
41
+ output_format: The output format of the dataframe. Note that, for example,
42
+ if you set `output_format="polars"`, you must have polars installed.
43
+ Must be one of the following: "pandas", "polars", "pyarrow", "modin",
44
+ "cudf". Default to "pandas".
45
+
46
+ Returns:
47
+ The iris dataset.
48
+
49
+ Examples:
50
+ ```python
51
+ from plotjs import data
52
+
53
+ df = data.load_iris()
54
+ ```
55
+
56
+ ```python
57
+ from plotjs import data
58
+
59
+ df = data.load_iris("polars")
60
+ ```
61
+
62
+ ```python
63
+ from plotjs import data
64
+
65
+ df = data.load_iris("pyarrow")
66
+ ```
67
+ """
68
+ return _load_data("iris", backend=output_format)
69
+
70
+
71
+ def load_mtcars(output_format: str = "pandas") -> Frame:
72
+ """
73
+ Load the mtcars dataset.
74
+
75
+ Args:
76
+ output_format: The output format of the dataframe. Note that, for example,
77
+ if you set `output_format="polars"`, you must have polars installed.
78
+ Must be one of the following: "pandas", "polars", "pyarrow", "modin",
79
+ "cudf". Default to "pandas".
80
+
81
+ Returns:
82
+ The mtcars dataset.
83
+
84
+ Examples:
85
+ ```python
86
+ from plotjs import data
87
+
88
+ df = data.load_mtcars()
89
+ ```
90
+
91
+ ```python
92
+ from plotjs import data
93
+
94
+ df = data.load_mtcars("polars")
95
+ ```
96
+
97
+ ```python
98
+ from plotjs import data
99
+
100
+ df = data.load_mtcars("pyarrow")
101
+ ```
102
+ """
103
+ return _load_data("mtcars", backend=output_format)
104
+
105
+
106
+ def load_titanic(output_format: str = "pandas") -> Frame:
107
+ """
108
+ Load the titanic dataset.
109
+
110
+ Args:
111
+ output_format: The output format of the dataframe. Note that, for example,
112
+ if you set `output_format="polars"`, you must have polars installed.
113
+ Must be one of the following: "pandas", "polars", "pyarrow", "modin",
114
+ "cudf". Default to "pandas".
115
+
116
+ Returns:
117
+ The titanic dataset.
118
+
119
+ Examples:
120
+ ```python
121
+ from plotjs import data
122
+
123
+ df = data.load_titanic()
124
+ ```
125
+
126
+ ```python
127
+ from plotjs import data
128
+
129
+ df = data.load_titanic("polars")
130
+ ```
131
+
132
+ ```python
133
+ from plotjs import data
134
+
135
+ df = data.load_titanic("pyarrow")
136
+ ```
137
+ """
138
+ return _load_data("titanic", backend=output_format)
plotjs/data/iris.csv ADDED
@@ -0,0 +1,151 @@
1
+ sepal_length,sepal_width,petal_length,petal_width,species
2
+ 5.1,3.5,1.4,0.2,setosa
3
+ 4.9,3.0,1.4,0.2,setosa
4
+ 4.7,3.2,1.3,0.2,setosa
5
+ 4.6,3.1,1.5,0.2,setosa
6
+ 5.0,3.6,1.4,0.2,setosa
7
+ 5.4,3.9,1.7,0.4,setosa
8
+ 4.6,3.4,1.4,0.3,setosa
9
+ 5.0,3.4,1.5,0.2,setosa
10
+ 4.4,2.9,1.4,0.2,setosa
11
+ 4.9,3.1,1.5,0.1,setosa
12
+ 5.4,3.7,1.5,0.2,setosa
13
+ 4.8,3.4,1.6,0.2,setosa
14
+ 4.8,3.0,1.4,0.1,setosa
15
+ 4.3,3.0,1.1,0.1,setosa
16
+ 5.8,4.0,1.2,0.2,setosa
17
+ 5.7,4.4,1.5,0.4,setosa
18
+ 5.4,3.9,1.3,0.4,setosa
19
+ 5.1,3.5,1.4,0.3,setosa
20
+ 5.7,3.8,1.7,0.3,setosa
21
+ 5.1,3.8,1.5,0.3,setosa
22
+ 5.4,3.4,1.7,0.2,setosa
23
+ 5.1,3.7,1.5,0.4,setosa
24
+ 4.6,3.6,1.0,0.2,setosa
25
+ 5.1,3.3,1.7,0.5,setosa
26
+ 4.8,3.4,1.9,0.2,setosa
27
+ 5.0,3.0,1.6,0.2,setosa
28
+ 5.0,3.4,1.6,0.4,setosa
29
+ 5.2,3.5,1.5,0.2,setosa
30
+ 5.2,3.4,1.4,0.2,setosa
31
+ 4.7,3.2,1.6,0.2,setosa
32
+ 4.8,3.1,1.6,0.2,setosa
33
+ 5.4,3.4,1.5,0.4,setosa
34
+ 5.2,4.1,1.5,0.1,setosa
35
+ 5.5,4.2,1.4,0.2,setosa
36
+ 4.9,3.1,1.5,0.1,setosa
37
+ 5.0,3.2,1.2,0.2,setosa
38
+ 5.5,3.5,1.3,0.2,setosa
39
+ 4.9,3.1,1.5,0.1,setosa
40
+ 4.4,3.0,1.3,0.2,setosa
41
+ 5.1,3.4,1.5,0.2,setosa
42
+ 5.0,3.5,1.3,0.3,setosa
43
+ 4.5,2.3,1.3,0.3,setosa
44
+ 4.4,3.2,1.3,0.2,setosa
45
+ 5.0,3.5,1.6,0.6,setosa
46
+ 5.1,3.8,1.9,0.4,setosa
47
+ 4.8,3.0,1.4,0.3,setosa
48
+ 5.1,3.8,1.6,0.2,setosa
49
+ 4.6,3.2,1.4,0.2,setosa
50
+ 5.3,3.7,1.5,0.2,setosa
51
+ 5.0,3.3,1.4,0.2,setosa
52
+ 7.0,3.2,4.7,1.4,versicolor
53
+ 6.4,3.2,4.5,1.5,versicolor
54
+ 6.9,3.1,4.9,1.5,versicolor
55
+ 5.5,2.3,4.0,1.3,versicolor
56
+ 6.5,2.8,4.6,1.5,versicolor
57
+ 5.7,2.8,4.5,1.3,versicolor
58
+ 6.3,3.3,4.7,1.6,versicolor
59
+ 4.9,2.4,3.3,1.0,versicolor
60
+ 6.6,2.9,4.6,1.3,versicolor
61
+ 5.2,2.7,3.9,1.4,versicolor
62
+ 5.0,2.0,3.5,1.0,versicolor
63
+ 5.9,3.0,4.2,1.5,versicolor
64
+ 6.0,2.2,4.0,1.0,versicolor
65
+ 6.1,2.9,4.7,1.4,versicolor
66
+ 5.6,2.9,3.6,1.3,versicolor
67
+ 6.7,3.1,4.4,1.4,versicolor
68
+ 5.6,3.0,4.5,1.5,versicolor
69
+ 5.8,2.7,4.1,1.0,versicolor
70
+ 6.2,2.2,4.5,1.5,versicolor
71
+ 5.6,2.5,3.9,1.1,versicolor
72
+ 5.9,3.2,4.8,1.8,versicolor
73
+ 6.1,2.8,4.0,1.3,versicolor
74
+ 6.3,2.5,4.9,1.5,versicolor
75
+ 6.1,2.8,4.7,1.2,versicolor
76
+ 6.4,2.9,4.3,1.3,versicolor
77
+ 6.6,3.0,4.4,1.4,versicolor
78
+ 6.8,2.8,4.8,1.4,versicolor
79
+ 6.7,3.0,5.0,1.7,versicolor
80
+ 6.0,2.9,4.5,1.5,versicolor
81
+ 5.7,2.6,3.5,1.0,versicolor
82
+ 5.5,2.4,3.8,1.1,versicolor
83
+ 5.5,2.4,3.7,1.0,versicolor
84
+ 5.8,2.7,3.9,1.2,versicolor
85
+ 6.0,2.7,5.1,1.6,versicolor
86
+ 5.4,3.0,4.5,1.5,versicolor
87
+ 6.0,3.4,4.5,1.6,versicolor
88
+ 6.7,3.1,4.7,1.5,versicolor
89
+ 6.3,2.3,4.4,1.3,versicolor
90
+ 5.6,3.0,4.1,1.3,versicolor
91
+ 5.5,2.5,4.0,1.3,versicolor
92
+ 5.5,2.6,4.4,1.2,versicolor
93
+ 6.1,3.0,4.6,1.4,versicolor
94
+ 5.8,2.6,4.0,1.2,versicolor
95
+ 5.0,2.3,3.3,1.0,versicolor
96
+ 5.6,2.7,4.2,1.3,versicolor
97
+ 5.7,3.0,4.2,1.2,versicolor
98
+ 5.7,2.9,4.2,1.3,versicolor
99
+ 6.2,2.9,4.3,1.3,versicolor
100
+ 5.1,2.5,3.0,1.1,versicolor
101
+ 5.7,2.8,4.1,1.3,versicolor
102
+ 6.3,3.3,6.0,2.5,virginica
103
+ 5.8,2.7,5.1,1.9,virginica
104
+ 7.1,3.0,5.9,2.1,virginica
105
+ 6.3,2.9,5.6,1.8,virginica
106
+ 6.5,3.0,5.8,2.2,virginica
107
+ 7.6,3.0,6.6,2.1,virginica
108
+ 4.9,2.5,4.5,1.7,virginica
109
+ 7.3,2.9,6.3,1.8,virginica
110
+ 6.7,2.5,5.8,1.8,virginica
111
+ 7.2,3.6,6.1,2.5,virginica
112
+ 6.5,3.2,5.1,2.0,virginica
113
+ 6.4,2.7,5.3,1.9,virginica
114
+ 6.8,3.0,5.5,2.1,virginica
115
+ 5.7,2.5,5.0,2.0,virginica
116
+ 5.8,2.8,5.1,2.4,virginica
117
+ 6.4,3.2,5.3,2.3,virginica
118
+ 6.5,3.0,5.5,1.8,virginica
119
+ 7.7,3.8,6.7,2.2,virginica
120
+ 7.7,2.6,6.9,2.3,virginica
121
+ 6.0,2.2,5.0,1.5,virginica
122
+ 6.9,3.2,5.7,2.3,virginica
123
+ 5.6,2.8,4.9,2.0,virginica
124
+ 7.7,2.8,6.7,2.0,virginica
125
+ 6.3,2.7,4.9,1.8,virginica
126
+ 6.7,3.3,5.7,2.1,virginica
127
+ 7.2,3.2,6.0,1.8,virginica
128
+ 6.2,2.8,4.8,1.8,virginica
129
+ 6.1,3.0,4.9,1.8,virginica
130
+ 6.4,2.8,5.6,2.1,virginica
131
+ 7.2,3.0,5.8,1.6,virginica
132
+ 7.4,2.8,6.1,1.9,virginica
133
+ 7.9,3.8,6.4,2.0,virginica
134
+ 6.4,2.8,5.6,2.2,virginica
135
+ 6.3,2.8,5.1,1.5,virginica
136
+ 6.1,2.6,5.6,1.4,virginica
137
+ 7.7,3.0,6.1,2.3,virginica
138
+ 6.3,3.4,5.6,2.4,virginica
139
+ 6.4,3.1,5.5,1.8,virginica
140
+ 6.0,3.0,4.8,1.8,virginica
141
+ 6.9,3.1,5.4,2.1,virginica
142
+ 6.7,3.1,5.6,2.4,virginica
143
+ 6.9,3.1,5.1,2.3,virginica
144
+ 5.8,2.7,5.1,1.9,virginica
145
+ 6.8,3.2,5.9,2.3,virginica
146
+ 6.7,3.3,5.7,2.5,virginica
147
+ 6.7,3.0,5.2,2.3,virginica
148
+ 6.3,2.5,5.0,1.9,virginica
149
+ 6.5,3.0,5.2,2.0,virginica
150
+ 6.2,3.4,5.4,2.3,virginica
151
+ 5.9,3.0,5.1,1.8,virginica
plotjs/data/mtcars.csv ADDED
@@ -0,0 +1,33 @@
1
+ model,mpg,cyl,disp,hp,drat,wt,qsec,vs,am,gear,carb
2
+ Mazda RX4,21,6,160,110,3.9,2.62,16.46,0,1,4,4
3
+ Mazda RX4 Wag,21,6,160,110,3.9,2.875,17.02,0,1,4,4
4
+ Datsun 710,22.8,4,108,93,3.85,2.32,18.61,1,1,4,1
5
+ Hornet 4 Drive,21.4,6,258,110,3.08,3.215,19.44,1,0,3,1
6
+ Hornet Sportabout,18.7,8,360,175,3.15,3.44,17.02,0,0,3,2
7
+ Valiant,18.1,6,225,105,2.76,3.46,20.22,1,0,3,1
8
+ Duster 360,14.3,8,360,245,3.21,3.57,15.84,0,0,3,4
9
+ Merc 240D,24.4,4,146.7,62,3.69,3.19,20,1,0,4,2
10
+ Merc 230,22.8,4,140.8,95,3.92,3.15,22.9,1,0,4,2
11
+ Merc 280,19.2,6,167.6,123,3.92,3.44,18.3,1,0,4,4
12
+ Merc 280C,17.8,6,167.6,123,3.92,3.44,18.9,1,0,4,4
13
+ Merc 450SE,16.4,8,275.8,180,3.07,4.07,17.4,0,0,3,3
14
+ Merc 450SL,17.3,8,275.8,180,3.07,3.73,17.6,0,0,3,3
15
+ Merc 450SLC,15.2,8,275.8,180,3.07,3.78,18,0,0,3,3
16
+ Cadillac Fleetwood,10.4,8,472,205,2.93,5.25,17.98,0,0,3,4
17
+ Lincoln Continental,10.4,8,460,215,3,5.424,17.82,0,0,3,4
18
+ Chrysler Imperial,14.7,8,440,230,3.23,5.345,17.42,0,0,3,4
19
+ Fiat 128,32.4,4,78.7,66,4.08,2.2,19.47,1,1,4,1
20
+ Honda Civic,30.4,4,75.7,52,4.93,1.615,18.52,1,1,4,2
21
+ Toyota Corolla,33.9,4,71.1,65,4.22,1.835,19.9,1,1,4,1
22
+ Toyota Corona,21.5,4,120.1,97,3.7,2.465,20.01,1,0,3,1
23
+ Dodge Challenger,15.5,8,318,150,2.76,3.52,16.87,0,0,3,2
24
+ AMC Javelin,15.2,8,304,150,3.15,3.435,17.3,0,0,3,2
25
+ Camaro Z28,13.3,8,350,245,3.73,3.84,15.41,0,0,3,4
26
+ Pontiac Firebird,19.2,8,400,175,3.08,3.845,17.05,0,0,3,2
27
+ Fiat X1-9,27.3,4,79,66,4.08,1.935,18.9,1,1,4,1
28
+ Porsche 914-2,26,4,120.3,91,4.43,2.14,16.7,0,1,5,2
29
+ Lotus Europa,30.4,4,95.1,113,3.77,1.513,16.9,1,1,5,2
30
+ Ford Pantera L,15.8,8,351,264,4.22,3.17,14.5,0,1,5,4
31
+ Ferrari Dino,19.7,6,145,175,3.62,2.77,15.5,0,1,5,6
32
+ Maserati Bora,15,8,301,335,3.54,3.57,14.6,0,1,5,8
33
+ Volvo 142E,21.4,4,121,109,4.11,2.78,18.6,1,1,4,2