FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add typing for scales · e2b-dev/code-interpreter@741c753 · GitHub

Commit 741c753

Browse files
committed
Add typing for scales
1 parent c8eb680 commit 741c753

3 files changed

Lines changed: 49 additions & 13 deletions

File tree

‎js/src/graphs.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ export enum GraphType {
88
UNKNOWN = 'unknown',
99
}
1010

11+
export enum ScaleType {
12+
LINEAR = "linear",
13+
DATETIME = "datetime",
14+
CATEGORICAL = "categorical",
15+
LOG = "log",
16+
SYMLOG = "symlog",
17+
LOGIT = "logit",
18+
FUNCTION = "function",
19+
FUNCTIONLOG = "functionlog",
20+
ASINH = "asinh",
21+
}
22+
1123
export type Graph = {
1224
type: GraphType
1325
title: string
@@ -28,10 +40,10 @@ export type PointData = {
2840

2941
type PointGraph = Graph2D & {
3042
x_ticks: (number | string)[]
31-
x_scale: string
43+
x_scale: ScaleType
3244
x_tick_labels: string[]
3345
y_ticks: (number | string)[]
34-
y_scale: string
46+
y_scale: ScaleType
3547
y_tick_labels: string[]
3648
elements: PointData[]
3749
}

‎js/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type {
1212
OutputMessage,
1313
} from './messaging'
1414
export type {
15+
ScaleType,
1516
GraphType,
1617
GraphTypes,
1718
Graph,

‎python/e2b_code_interpreter/graphs.py‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import List, Tuple, Any, Optional, Union
33

44

5-
class GraphType(enum.Enum):
5+
class GraphType(str, enum.Enum):
66
LINE = "line"
77
SCATTER = "scatter"
88
BAR = "bar"
@@ -12,6 +12,19 @@ class GraphType(enum.Enum):
1212
UNKNOWN = "unknown"
1313

1414

15+
class ScaleType(str, enum.Enum):
16+
LINEAR = "linear"
17+
DATETIME = "datetime"
18+
CATEGORICAL = "categorical"
19+
LOG = "log"
20+
SYMLOG = "symlog"
21+
LOGIT = "logit"
22+
FUNCTION = "function"
23+
FUNCTIONLOG = "functionlog"
24+
ASINH = "asinh"
25+
UNKNOWN = "unknown"
26+
27+
1528
class Graph:
1629
type: GraphType
1730
title: str
@@ -50,23 +63,33 @@ def __init__(self, **kwargs):
5063
class PointGraph(Graph2D):
5164
x_ticks: List[Union[str, float]]
5265
x_tick_labels: List[str]
53-
x_scale: str
66+
x_scale: ScaleType
5467

5568
y_ticks: List[Union[str, float]]
5669
y_tick_labels: List[str]
57-
y_scale: str
70+
y_scale: ScaleType
5871

5972
elements: List[PointData]
6073

6174
def __init__(self, **kwargs):
6275
super().__init__(**kwargs)
6376
self.x_label = kwargs["x_label"]
64-
self.x_scale = kwargs["x_scale"]
77+
78+
try:
79+
self.x_scale = ScaleType(kwargs.get("x_scale"))
80+
except ValueError:
81+
self.x_scale = ScaleType.UNKNOWN
82+
6583
self.x_ticks = kwargs["x_ticks"]
6684
self.x_tick_labels = kwargs["x_tick_labels"]
6785

6886
self.y_label = kwargs["y_label"]
69-
self.y_scale = kwargs["y_scale"]
87+
88+
try:
89+
self.y_scale = ScaleType(kwargs.get("y_scale"))
90+
except ValueError:
91+
self.y_scale = ScaleType.UNKNOWN
92+
7093
self.y_ticks = kwargs["y_ticks"]
7194
self.y_tick_labels = kwargs["y_tick_labels"]
7295

@@ -171,17 +194,17 @@ def deserialize_graph(data: Optional[dict]) -> Optional[GraphTypes]:
171194
if not data:
172195
return None
173196

174-
if data["type"] == GraphType.LINE.value:
197+
if data["type"] == GraphType.LINE:
175198
graph = LineGraph(**data)
176-
elif data["type"] == GraphType.SCATTER.value:
199+
elif data["type"] == GraphType.SCATTER:
177200
graph = ScatterGraph(**data)
178-
elif data["type"] == GraphType.BAR.value:
201+
elif data["type"] == GraphType.BAR:
179202
graph = BarGraph(**data)
180-
elif data["type"] == GraphType.PIE.value:
203+
elif data["type"] == GraphType.PIE:
181204
graph = PieGraph(**data)
182-
elif data["type"] == GraphType.BOX_AND_WHISKER.value:
205+
elif data["type"] == GraphType.BOX_AND_WHISKER:
183206
graph = BoxAndWhiskerGraph(**data)
184-
elif data["type"] == GraphType.SUPERGRAPH.value:
207+
elif data["type"] == GraphType.SUPERGRAPH:
185208
graph = SuperGraph(**data)
186209
else:
187210
graph = Graph(**data)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL