| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,18 @@ export enum GraphType { | |||
| 8 | 8 | UNKNOWN = 'unknown', | |
| 9 | 9 | } | |
| 10 | 10 | ||
| 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 | + | ||
| 11 | 23 | export type Graph = { | |
| 12 | 24 | type: GraphType | |
| 13 | 25 | title: string | |
@@ -28,10 +40,10 @@ export type PointData = { | |||
| 28 | 40 | ||
| 29 | 41 | type PointGraph = Graph2D & { | |
| 30 | 42 | x_ticks: (number | string)[] | |
| 31 | - x_scale: string | ||
| 43 | + x_scale: ScaleType | ||
| 32 | 44 | x_tick_labels: string[] | |
| 33 | 45 | y_ticks: (number | string)[] | |
| 34 | - y_scale: string | ||
| 46 | + y_scale: ScaleType | ||
| 35 | 47 | y_tick_labels: string[] | |
| 36 | 48 | elements: PointData[] | |
| 37 | 49 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ export type { | |||
| 12 | 12 | OutputMessage, | |
| 13 | 13 | } from './messaging' | |
| 14 | 14 | export type { | |
| 15 | + ScaleType, | ||
| 15 | 16 | GraphType, | |
| 16 | 17 | GraphTypes, | |
| 17 | 18 | Graph, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | from typing import List, Tuple, Any, Optional, Union | |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | - class GraphType(enum.Enum): | ||
| 5 | + class GraphType(str, enum.Enum): | ||
| 6 | 6 | LINE = "line" | |
| 7 | 7 | SCATTER = "scatter" | |
| 8 | 8 | BAR = "bar" | |
@@ -12,6 +12,19 @@ class GraphType(enum.Enum): | |||
| 12 | 12 | UNKNOWN = "unknown" | |
| 13 | 13 | ||
| 14 | 14 | ||
| 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 | + | ||
| 15 | 28 | class Graph: | |
| 16 | 29 | type: GraphType | |
| 17 | 30 | title: str | |
@@ -50,23 +63,33 @@ def __init__(self, **kwargs): | |||
| 50 | 63 | class PointGraph(Graph2D): | |
| 51 | 64 | x_ticks: List[Union[str, float]] | |
| 52 | 65 | x_tick_labels: List[str] | |
| 53 | - x_scale: str | ||
| 66 | + x_scale: ScaleType | ||
| 54 | 67 | ||
| 55 | 68 | y_ticks: List[Union[str, float]] | |
| 56 | 69 | y_tick_labels: List[str] | |
| 57 | - y_scale: str | ||
| 70 | + y_scale: ScaleType | ||
| 58 | 71 | ||
| 59 | 72 | elements: List[PointData] | |
| 60 | 73 | ||
| 61 | 74 | def __init__(self, **kwargs): | |
| 62 | 75 | super().__init__(**kwargs) | |
| 63 | 76 | 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 | + | ||
| 65 | 83 | self.x_ticks = kwargs["x_ticks"] | |
| 66 | 84 | self.x_tick_labels = kwargs["x_tick_labels"] | |
| 67 | 85 | ||
| 68 | 86 | 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 | + | ||
| 70 | 93 | self.y_ticks = kwargs["y_ticks"] | |
| 71 | 94 | self.y_tick_labels = kwargs["y_tick_labels"] | |
| 72 | 95 | ||
@@ -171,17 +194,17 @@ def deserialize_graph(data: Optional[dict]) -> Optional[GraphTypes]: | |||
| 171 | 194 | if not data: | |
| 172 | 195 | return None | |
| 173 | 196 | ||
| 174 | - if data["type"] == GraphType.LINE.value: | ||
| 197 | + if data["type"] == GraphType.LINE: | ||
| 175 | 198 | graph = LineGraph(**data) | |
| 176 | - elif data["type"] == GraphType.SCATTER.value: | ||
| 199 | + elif data["type"] == GraphType.SCATTER: | ||
| 177 | 200 | graph = ScatterGraph(**data) | |
| 178 | - elif data["type"] == GraphType.BAR.value: | ||
| 201 | + elif data["type"] == GraphType.BAR: | ||
| 179 | 202 | graph = BarGraph(**data) | |
| 180 | - elif data["type"] == GraphType.PIE.value: | ||
| 203 | + elif data["type"] == GraphType.PIE: | ||
| 181 | 204 | graph = PieGraph(**data) | |
| 182 | - elif data["type"] == GraphType.BOX_AND_WHISKER.value: | ||
| 205 | + elif data["type"] == GraphType.BOX_AND_WHISKER: | ||
| 183 | 206 | graph = BoxAndWhiskerGraph(**data) | |
| 184 | - elif data["type"] == GraphType.SUPERGRAPH.value: | ||
| 207 | + elif data["type"] == GraphType.SUPERGRAPH: | ||
| 185 | 208 | graph = SuperGraph(**data) | |
| 186 | 209 | else: | |
| 187 | 210 | graph = Graph(**data) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments