Skip to content

Commit 8666df5

Browse files
committed
Rename to chart
1 parent d1f419c commit 8666df5

36 files changed

+457
-463
lines changed

.github/workflows/template.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
paths:
66
- 'template/**'
77
- '.github/workflows/template.yml'
8-
branches:
9-
- beta
108

119
permissions:
1210
contents: read

js/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The repository contains a template and modules for the code interpreter sandbox.
55
## Key Features
66

77
- **Stateful Execution**: Unlike traditional sandboxes that treat each code execution independently, this package maintains context across executions.
8-
- **Displaying Graph & Data**: Implements parts of the [Jupyter Kernel messaging protocol](https://jupyter-client.readthedocs.io/en/latest/messaging.html), which support for interactive features like plotting charts, rendering DataFrames, etc.
8+
- **Displaying Charts & Data**: Implements parts of the [Jupyter Kernel messaging protocol](https://jupyter-client.readthedocs.io/en/latest/messaging.html), which support for interactive features like plotting charts, rendering DataFrames, etc.
99

1010
## Installation
1111

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* Graph types
2+
* Chart types
33
*/
4-
export enum GraphType {
4+
export enum ChartType {
55
LINE = 'line',
66
SCATTER = 'scatter',
77
BAR = 'bar',
88
PIE = 'pie',
99
BOX_AND_WHISKER = 'box_and_whisker',
10-
SUPERGRAPH = 'supergraph',
10+
SUPERCHART = 'superchart',
1111
UNKNOWN = 'unknown',
1212
}
1313

@@ -27,13 +27,13 @@ export enum ScaleType {
2727
ASINH = "asinh",
2828
}
2929

30-
export type Graph = {
31-
type: GraphType
30+
export type Chart = {
31+
type: ChartType
3232
title: string
3333
elements: any[]
3434
}
3535

36-
type Graph2D = Graph & {
36+
type Chart2D = Chart & {
3737
x_label?: string
3838
y_label?: string
3939
x_unit?: string
@@ -45,7 +45,7 @@ export type PointData = {
4545
points: [number | string, number | string][]
4646
}
4747

48-
type PointGraph = Graph2D & {
48+
type PointChart = Chart2D & {
4949
x_ticks: (number | string)[]
5050
x_scale: ScaleType
5151
x_tick_labels: string[]
@@ -55,12 +55,12 @@ type PointGraph = Graph2D & {
5555
elements: PointData[]
5656
}
5757

58-
export type LineGraph = PointGraph & {
59-
type: GraphType.LINE
58+
export type LineChart = PointChart & {
59+
type: ChartType.LINE
6060
}
6161

62-
export type ScatterGraph = PointGraph & {
63-
type: GraphType.SCATTER
62+
export type ScatterChart = PointChart & {
63+
type: ChartType.SCATTER
6464
}
6565

6666
export type BarData = {
@@ -69,8 +69,8 @@ export type BarData = {
6969
group: string
7070
}
7171

72-
export type BarGraph = Graph2D & {
73-
type: GraphType.BAR
72+
export type BarChart = Chart2D & {
73+
type: ChartType.BAR
7474
elements: BarData[]
7575
}
7676

@@ -80,8 +80,8 @@ export type PieData = {
8080
radius: number
8181
}
8282

83-
export type PieGraph = Graph & {
84-
type: GraphType.PIE
83+
export type PieChart = Chart & {
84+
type: ChartType.PIE
8585
elements: PieData[]
8686
}
8787

@@ -94,43 +94,43 @@ export type BoxAndWhiskerData = {
9494
max: number
9595
}
9696

97-
export type BoxAndWhiskerGraph = Graph2D & {
98-
type: GraphType.BOX_AND_WHISKER
97+
export type BoxAndWhiskerChart = Chart2D & {
98+
type: ChartType.BOX_AND_WHISKER
9999
elements: BoxAndWhiskerData[]
100100
}
101101

102-
export type SuperGraph = Graph & {
103-
type: GraphType.SUPERGRAPH
104-
elements: Graph[]
102+
export type SuperChart = Chart & {
103+
type: ChartType.SUPERCHART
104+
elements: Chart[]
105105
}
106106

107-
export type GraphTypes =
108-
| LineGraph
109-
| ScatterGraph
110-
| BarGraph
111-
| PieGraph
112-
| BoxAndWhiskerGraph
113-
| SuperGraph
114-
export function deserializeGraph(data: any): Graph {
107+
export type ChartTypes =
108+
| LineChart
109+
| ScatterChart
110+
| BarChart
111+
| PieChart
112+
| BoxAndWhiskerChart
113+
| SuperChart
114+
export function deserializeChart(data: any): Chart {
115115
switch (data.type) {
116-
case GraphType.LINE:
117-
return { ...data } as LineGraph
118-
case GraphType.SCATTER:
119-
return { ...data } as ScatterGraph
120-
case GraphType.BAR:
121-
return { ...data } as BarGraph
122-
case GraphType.PIE:
123-
return { ...data } as PieGraph
124-
case GraphType.BOX_AND_WHISKER:
125-
return { ...data } as BoxAndWhiskerGraph
126-
case GraphType.SUPERGRAPH:
127-
const graphs = data.data.map((g: any) => deserializeGraph(g))
116+
case ChartType.LINE:
117+
return { ...data } as LineChart
118+
case ChartType.SCATTER:
119+
return { ...data } as ScatterChart
120+
case ChartType.BAR:
121+
return { ...data } as BarChart
122+
case ChartType.PIE:
123+
return { ...data } as PieChart
124+
case ChartType.BOX_AND_WHISKER:
125+
return { ...data } as BoxAndWhiskerChart
126+
case ChartType.SUPERCHART:
127+
const charts = data.data.map((g: any) => deserializeChart(g))
128128
delete data.data
129129
return {
130130
...data,
131-
data: graphs,
132-
} as SuperGraph
131+
data: charts,
132+
} as SuperChart
133133
default:
134-
return { ...data, type: GraphType.UNKNOWN } as Graph
134+
return { ...data, type: ChartType.UNKNOWN } as Chart
135135
}
136136
}

js/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ export type {
1313
} from './messaging'
1414
export type {
1515
ScaleType,
16-
GraphType,
17-
GraphTypes,
18-
Graph,
19-
BarGraph,
16+
ChartType,
17+
ChartTypes,
18+
Chart,
19+
BarChart,
2020
BarData,
21-
LineGraph,
22-
ScatterGraph,
23-
BoxAndWhiskerGraph,
21+
LineChart,
22+
ScatterChart,
23+
BoxAndWhiskerChart,
2424
BoxAndWhiskerData,
25-
PieGraph,
25+
PieChart,
2626
PieData,
27-
SuperGraph,
27+
SuperChart,
2828
PointData,
29-
} from './graphs'
29+
} from './charts'
3030
import { Sandbox } from './sandbox'
3131

3232
export default Sandbox

js/src/messaging.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NotFoundError, SandboxError, TimeoutError } from 'e2b'
2-
import { GraphTypes } from './graphs'
2+
import { ChartTypes } from './charts'
33

44
export async function extractError(res: Response) {
55
if (res.ok) {
@@ -61,7 +61,7 @@ export type MIMEType = string
6161

6262
type E2BData = {
6363
data: Record<string, unknown>
64-
graph: GraphTypes
64+
chart: ChartTypes
6565
}
6666

6767
/**
@@ -126,9 +126,9 @@ export class Result {
126126
*/
127127
readonly data?: Record<string, unknown>
128128
/**
129-
* Contains the graph data.
129+
* Contains the chart data.
130130
*/
131-
readonly graph?: GraphTypes
131+
readonly chart?: ChartTypes
132132
/**
133133
* Extra data that can be included. Not part of the standard types.
134134
*/
@@ -155,7 +155,7 @@ export class Result {
155155
this.raw = data
156156

157157
this.data = data['data']
158-
this.graph = data['graph']
158+
this.chart = data['chart']
159159

160160
this.extra = {}
161161

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ import matplotlib.pyplot as plt
1111
authors = ['Author A', 'Author B', 'Author C', 'Author D']
1212
sales = [100, 200, 300, 400]
1313
14-
# Create and customize the bar graph
14+
# Create and customize the bar chart
1515
plt.figure(figsize=(10, 6))
1616
plt.bar(authors, sales, label='Books Sold', color='blue')
1717
plt.xlabel('Authors')
1818
plt.ylabel('Number of Books Sold')
1919
plt.title('Book Sales by Authors')
2020
21-
# Display the graph
21+
# Display the chart
2222
plt.tight_layout()
2323
plt.show()
2424
`
2525
const result = await sandbox.runCode(code)
26-
const graph = result.results[0].graph
26+
const chart = result.results[0].chart
2727

28-
expect(graph).toBeDefined()
29-
expect(graph.type).toBe('bar')
30-
expect(graph.title).toBe('Book Sales by Authors')
28+
expect(chart).toBeDefined()
29+
expect(chart.type).toBe('bar')
30+
expect(chart.title).toBe('Book Sales by Authors')
3131

32-
expect(graph.x_label).toBe('Authors')
33-
expect(graph.y_label).toBe('Number of Books Sold')
32+
expect(chart.x_label).toBe('Authors')
33+
expect(chart.y_label).toBe('Number of Books Sold')
3434

35-
expect(graph.x_unit).toBeNull()
36-
expect(graph.y_unit).toBeNull()
35+
expect(chart.x_unit).toBeNull()
36+
expect(chart.y_unit).toBeNull()
3737

38-
const bars = graph.elements
38+
const bars = chart.elements
3939
expect(bars.length).toBe(4)
4040

4141
expect(bars.map((bar) => bar.value)).toEqual([100, 200, 300, 400])
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ plt.tight_layout()
3636
plt.show()
3737
`
3838
const result = await sandbox.runCode(code)
39-
const graph = result.results[0].graph
39+
const chart = result.results[0].chart
4040

41-
expect(graph).toBeDefined()
41+
expect(chart).toBeDefined()
4242

43-
expect(graph.type).toBe('box_and_whisker')
44-
expect(graph.title).toBe('Exam Scores Distribution')
43+
expect(chart.type).toBe('box_and_whisker')
44+
expect(chart.title).toBe('Exam Scores Distribution')
4545

46-
expect(graph.x_label).toBe('Class')
47-
expect(graph.y_label).toBe('Score')
46+
expect(chart.x_label).toBe('Class')
47+
expect(chart.y_label).toBe('Score')
4848

49-
expect(graph.x_unit).toBeNull()
50-
expect(graph.y_unit).toBeNull()
49+
expect(chart.x_unit).toBeNull()
50+
expect(chart.y_unit).toBeNull()
5151

52-
const bars = graph.elements
52+
const bars = chart.elements
5353
expect(bars.length).toBe(3)
5454

5555
bars.forEach((bar: any) => {
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,37 @@ plt.title('Plot of sin(x) and cos(x)')
3030
plt.show()
3131
`
3232
const result = await sandbox.runCode(code)
33-
const graph = result.results[0].graph
33+
const chart = result.results[0].chart
3434

35-
expect(graph).toBeDefined()
36-
expect(graph.type).toBe('line')
35+
expect(chart).toBeDefined()
36+
expect(chart.type).toBe('line')
3737

38-
expect(graph.title).toBe('Plot of sin(x) and cos(x)')
39-
expect(graph.x_label).toBe('Time (s)')
40-
expect(graph.y_label).toBe('Amplitude (Hz)')
38+
expect(chart.title).toBe('Plot of sin(x) and cos(x)')
39+
expect(chart.x_label).toBe('Time (s)')
40+
expect(chart.y_label).toBe('Amplitude (Hz)')
4141

42-
expect(graph.x_scale).toBe('datetime')
43-
expect(graph.y_scale).toBe('linear')
42+
expect(chart.x_scale).toBe('datetime')
43+
expect(chart.y_scale).toBe('linear')
4444

45-
expect(graph.x_unit).toBe('s')
46-
expect(graph.y_unit).toBe('Hz')
45+
expect(chart.x_unit).toBe('s')
46+
expect(chart.y_unit).toBe('Hz')
4747

48-
expect(graph.x_ticks.every((tick: number) => typeof tick === 'string')).toBe(
48+
expect(chart.x_ticks.every((tick: number) => typeof tick === 'string')).toBe(
4949
true,
5050
)
51-
expect(new Date(graph.x_ticks[0])).toBeInstanceOf(Date)
52-
expect(graph.y_ticks.every((tick: number) => typeof tick === 'number')).toBe(
51+
expect(new Date(chart.x_ticks[0])).toBeInstanceOf(Date)
52+
expect(chart.y_ticks.every((tick: number) => typeof tick === 'number')).toBe(
5353
true,
5454
)
5555

5656
expect(
57-
graph.y_tick_labels.every((label: string) => typeof label === 'string'),
57+
chart.y_tick_labels.every((label: string) => typeof label === 'string'),
5858
).toBe(true)
5959
expect(
60-
graph.x_tick_labels.every((label: string) => typeof label === 'string'),
60+
chart.x_tick_labels.every((label: string) => typeof label === 'string'),
6161
).toBe(true)
6262

63-
const lines = graph.elements
63+
const lines = chart.elements
6464
expect(lines.length).toBe(2)
6565

6666
const [firstLine, secondLine] = lines

0 commit comments

Comments
 (0)