Skip to content

Commit 4a12599

Browse files
author
Jan Van Bruggen
authored
Merge pull request #1 from JanCVanB/expand_config
Expand config to do a lot more
2 parents 6d36da6 + be747b2 commit 4a12599

File tree

21 files changed

+521
-111
lines changed

21 files changed

+521
-111
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Roc platforms for drawing plots with Plotters
1+
# Roc platform for drawing plots with Plotters
22

33
[Roc](https://roc-lang.org/)
44
+
55
[Plotters](https://github.com/38/plotters)
66
= <3
77

8-
![hello world example image](./examples/hello_world.png)
8+
![hello world example image](./examples/hello_world.svg)
99

1010
## How to example
1111

β€Žexamples/hello_world.jpgβ€Ž

73.5 KB
Loading

β€Žexamples/hello_world.pngβ€Ž

2.09 KB
Loading

β€Žexamples/hello_world.rocβ€Ž

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
11
app "hello_world"
2-
packages { pf: "../platforms/bitmap-chart" }
3-
imports []
4-
provides [ options ] to pf
2+
packages { pf: "../platform" }
3+
imports [ pf.Config.{blue, green, red, cyan} ]
4+
provides [ config ] to pf
55

6-
options = {
7-
outputFilePath: "./examples/hello_world.png",
8-
title: "Hello, World!",
9-
subtitle: "These strings are coming from Roc :)",
10-
width: 1024,
11-
height: 768,
6+
config =
7+
{
8+
outputFilePath: "./examples/hello_world.svg",
9+
title: "Hello, World!",
10+
subtitle: "",
11+
width: 1024,
12+
height: 768,
13+
lines: [
14+
{ name: "cosine", color: green, points: cos },
15+
{ name: "cosine x 2", color: cyan, points: cosX2 },
16+
{ name: "sine", color: blue, points: sin },
17+
{ name: "sine x 2", color: red, points: sinX2 },
18+
],
19+
bounds: {
20+
xMin: -3.2,
21+
xMax: 3.2,
22+
yMin: -2.1,
23+
yMax: 2.1,
24+
},
25+
fonts: {
26+
titleFamily: "sans-serif",
27+
titleSize: 60,
28+
subtitleFamily: "sans-serif",
29+
subtitleSize: 40,
30+
},
31+
labels: {
32+
xCount: 20,
33+
yCount: 10,
34+
},
35+
layout: {
36+
chartMargin: 5,
37+
labelArea: 50,
38+
},
1239
}
40+
41+
pi = 3.141592653589793
42+
ok = \r -> Result.withDefault r 0
43+
domain = List.range -100 101 |> List.map (\i -> pi * (Num.toFloat i) / 100 |> ok)
44+
cos = domain |> List.map (\x -> P2 x (Num.cos x))
45+
sin = domain |> List.map (\x -> P2 x (Num.sin x))
46+
cosX2 = domain |> List.map (\x -> P2 x (2 * Num.cos x))
47+
sinX2 = domain |> List.map (\x -> P2 x (2 * Num.sin x))

β€Žexamples/hello_world.svgβ€Ž

Lines changed: 207 additions & 0 deletions
Loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "host"
1717
path = "src/main.rs"
1818

1919
[dependencies]
20-
roc_std = { path = "../../roc/roc_std" }
20+
roc_std = { path = "../roc/roc_std" }
2121
libc = "0.2"
2222
plotters = "0.3.1"
2323

β€Žplatform/Config.rocβ€Ž

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
interface Config
2+
exposes [ Config, black, white, red, green, blue, cyan, magenta, yellow ]
3+
imports []
4+
5+
Bounds :
6+
{
7+
xMin: F64,
8+
xMax: F64,
9+
yMin: F64,
10+
yMax: F64,
11+
}
12+
13+
# TODO: probably move some of this into a different module.
14+
Color :
15+
{
16+
r: U8,
17+
g: U8,
18+
b: U8,
19+
}
20+
21+
black = { r: 0, g: 0, b: 0 }
22+
white = { r: 255, g: 255, b: 255 }
23+
red = { r: 255, g: 0, b: 0 }
24+
green = { r: 0, g: 255, b: 0 }
25+
blue = { r: 0, g: 0, b: 255 }
26+
cyan = { r: 0, g: 255, b: 255 }
27+
magenta = { r: 255, g: 0, b: 255 }
28+
yellow = { r: 255, g: 255, b: 0 }
29+
30+
Fonts :
31+
{
32+
titleFamily: Str,
33+
titleSize: U32,
34+
subtitleFamily: Str,
35+
subtitleSize: U32,
36+
}
37+
38+
Labels :
39+
{
40+
xCount: Nat,
41+
yCount: Nat,
42+
}
43+
44+
Layout :
45+
{
46+
chartMargin: U32,
47+
labelArea: U32,
48+
}
49+
50+
Line :
51+
{
52+
name: Str,
53+
color: Color,
54+
points: List [P2 F64 F64],
55+
}
56+
57+
# TODO: Make this a `List` and support it in the platform (with `Vec`?)
58+
Config :
59+
{
60+
outputFilePath : Str,
61+
title : Str,
62+
subtitle : Str,
63+
width : U32,
64+
height : U32,
65+
lines : List Line,
66+
bounds : Bounds,
67+
fonts : Fonts,
68+
labels : Labels,
69+
layout : Layout,
70+
}

β€Žplatform/Package-Config.rocβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
platform "roc-plotters/bitmap-chart"
2+
requires {} { config : Config }
3+
exposes [ Config ]
4+
packages {}
5+
imports [ Config.{ Config } ]
6+
provides [ configForHost ]
7+
8+
configForHost : Config
9+
configForHost = config

0 commit comments

Comments
Β (0)