@explorable-viz/fluid 0.9.8 → 0.10.0

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.
Files changed (31) hide show
  1. package/dist/fluid/fluid/lib/pi.fld +1 -0
  2. package/dist/fluid/fluid/lib/prelude.fld +213 -251
  3. package/dist/fluid/shared/fluid.mjs +4585 -1030
  4. package/dist/fluid/shared/load-figure.js +4601 -7056
  5. package/dist/fluid/shared/webtest-lib.js +3958 -3958
  6. package/package.json +1 -1
  7. package/website/article/convolution/index.html +10 -3
  8. package/website/article/fluid/1805.02474v1-10.fld +46 -0
  9. package/website/article/fluid/bar-chart-line-chart.fld +37 -0
  10. package/website/article/fluid/convolution/emboss.fld +3 -5
  11. package/website/article/fluid/convolution/testImage.fld +9 -7
  12. package/website/article/fluid/convolution.fld +25 -23
  13. package/website/article/fluid/dataset/renewable-new.json +91 -0
  14. package/website/article/fluid/dataset/scigen/1805.02474v1-10.json +17 -0
  15. package/website/article/fluid/dataset/scigen/_1805_02474v1_10.fld +2 -0
  16. package/website/article/fluid/methane.fld +1 -1
  17. package/website/article/fluid/moving-average.fld +22 -19
  18. package/website/article/fluid/non-renewables.fld +29 -21
  19. package/website/article/fluid/nonRenewables.fld +5 -2
  20. package/website/article/fluid/renewables.fld +1 -0
  21. package/website/article/fluid/scigen.fld +48 -0
  22. package/website/article/fluid/util.fld +39 -0
  23. package/website/article/index.html +3 -1
  24. package/website/article/moving-average/index.html +8 -2
  25. package/website/article/non-renewables/index.html +8 -2
  26. package/website/article/renewables-linked/index.html +60 -0
  27. package/website/article/scigen-1805.02474v1-10/index.html +50 -0
  28. package/website/article/test.mjs +5 -0
  29. package/website/article/convolution/spec.json +0 -6
  30. package/website/article/moving-average/spec.json +0 -6
  31. package/website/article/non-renewables/spec.json +0 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorable-viz/fluid",
3
- "version": "0.9.8",
3
+ "version": "0.10.0",
4
4
  "description": "A functional programming language which integrates a bidirectional dynamic analysis, connecting outputs to data sources in a fine-grained way. Fluid is implemented in PureScript and runs in the browser.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -82,9 +82,16 @@
82
82
  </div>
83
83
 
84
84
  <script type="module">
85
- import { loadFigure, drawCode } from "../shared/load-figure.js"
86
- drawCode("../fluid/lib/matrix.fld")()
87
- loadFigure("spec.json")("../fluid/convolution.fld")()
85
+ import { loadFigureSpec, drawCode } from "../shared/load-figure.js"
86
+ drawCode("../fluid/convolution.fld")()
87
+ const jsonSpec = {
88
+ "fluidSrcPath": ["../fluid"],
89
+ "inputs": [ "inputImage", "filter" ],
90
+ "query": true,
91
+ "linking": false
92
+ }
93
+
94
+ loadFigureSpec(jsonSpec)("../fluid/convolution.fld")()
88
95
  </script>
89
96
  </body>
90
97
  </html>
@@ -0,0 +1,46 @@
1
+ import scigen
2
+ import util
3
+ import dataset.scigen._1805_02474v1_10
4
+
5
+ def model_BiLSTM: model("BiLSTM", tableData)
6
+ def model_LSTM: model("LSTM", tableData)
7
+ def model_2_stacked_BiLSTM: model("2 stacked BiLSTM", tableData)
8
+ def model_3_stacked_BiLSTM: model("3 stacked BiLSTM", tableData)
9
+ def model_S_LSTM: model("S-LSTM", tableData)
10
+ def model_CNN: model("CNN", tableData)
11
+ def model_3_stacked_CNN: model("3 stacked CNN", tableData)
12
+ def mostEfficient:
13
+ findWithKey_("time_s", minimum(map(lambda y: y.time_s, tableData)), tableData)
14
+
15
+ """As shown in Table 3, BiLSTM gives significantly
16
+ ${trendWord(model_BiLSTM.acc, model_LSTM.acc, betterWorse)}
17
+ accuracies compared to uni-directional LSTM2, with the training time per epoch
18
+ ${trendWord(model_BiLSTM.time_s, model_LSTM.time_s, growShrink)} from
19
+ ${model_LSTM.time_s} seconds to ${model_BiLSTM.time_s} seconds.
20
+ Stacking 2 layers of BiLSTM gives ${trendWord(model_2_stacked_BiLSTM.acc, model_BiLSTM.acc, improve)}
21
+ to development results, with a ${trendWord(model_2_stacked_BiLSTM.time_s, model_BiLSTM.time_s, smallerHigher)}
22
+ time of ${model_2_stacked_BiLSTM.time_s} seconds. 3 layers of stacked BiLSTM
23
+ ${trendWord(model_3_stacked_BiLSTM.acc, model_BiLSTM.acc, improve)} the results.
24
+ In contrast, S-LSTM gives a development result of ${model_S_LSTM.acc}%, which is significantly
25
+ ${trendWord(model_S_LSTM.acc, model_2_stacked_BiLSTM.acc, betterWorse)}
26
+ compared to 2-layer stacked BiLSTM, with a
27
+ ${trendWord(model_S_LSTM.param, model_2_stacked_BiLSTM.param, smallerHigher)}
28
+ number of model parameters and a
29
+ ${trendWord(model_S_LSTM.time_s, model_2_stacked_BiLSTM.time_s, shorterLonger)}
30
+ time of ${model_S_LSTM.time_s} seconds. We additionally make comparisons with
31
+ stacked CNNs and hierarchical attention (Vaswani et al., 2017), shown in Table 3 (the CNN and Transformer rows),
32
+ ${mostEfficient.model} is the
33
+ ${rankLabel("most efficient", findIndex("model", "CNN", insertionSort(lambda a, b: a.time_s < b.time_s, tableData)))}
34
+ among all models compared, with the
35
+ ${rankLabel("smallest", findIndex("model", "CNN", insertionSort(lambda a, b: a.param < b.param, tableData)))}
36
+ model size. On the other hand, a 3-layer stacked CNN gives an accuracy of
37
+ ${model_3_stacked_CNN.acc}%, which is also the
38
+ ${rankLabel("lowest", findIndex("model", "CNN", insertionSort(lambda a, b: a.time_s < b.time_s, tableData)))}
39
+ compared with BiLSTM, hierarchical attention and S-LSTM. The
40
+ ${rankLabel("best", findIndex("model", "S-LSTM+Attention", insertionSort(lambda a, b: b.acc < a.acc, tableData)))}
41
+ performance of hierarchical attention is obtained by S-LSTM+Attention in terms of both accuracy and efficiency.
42
+ S-LSTM gives significantly ${trendWord(model_S_LSTM.acc, model_CNN.acc, betterWorse)}
43
+ accuracies compared with both CNN and hierarchical attention. Table 3 additionally shows the results of
44
+ BiLSTM and S-LSTM when external attention is used Attention leads to improved accuracies for both BiLSTM and
45
+ S-LSTM in classification, with S-LSTM still
46
+ ${trendWord(model_S_LSTM.acc, model_BiLSTM.acc, underOverPerforming)} BiLSTM significantly."""
@@ -0,0 +1,37 @@
1
+ import renewables
2
+
3
+ def totalFor(c, rows): sum([row.output for row in rows if row.country == c])
4
+
5
+ def data2015: [row for row in renewables if row.year == 2015]
6
+
7
+ def countryData: [{
8
+ x: c,
9
+ segments: [{ y: "output", z: totalFor(c, data2015) }]
10
+ } for c in ["China", "USA", "Germany"]]
11
+
12
+ def series(type, country):
13
+ [
14
+ { x: row.year, y: row.output }
15
+ for year in [2013 .. 2018] for row in renewables
16
+ if row.year == year if row.energyType == type if row.country == country
17
+ ]
18
+
19
+ MultiView({
20
+ barChart: BarChart({
21
+ caption: "Total output by country",
22
+ size: { width: 275, height: 185 },
23
+ stackedBars: countryData
24
+ }),
25
+ lineChart: LineChart({
26
+ tickLabels: { x: Rotated, y: Default },
27
+ size: { width: 330, height: 285 },
28
+ caption: "Output of USA relative to China",
29
+ plots: [
30
+ LinePlot({ name: energyType, points: plot })
31
+ for energyType in ["Bio", "Hydro", "Solar", "Wind"]
32
+ for plot in [
33
+ zipWith((lambda p1, p2: { x: p1.x, y: p1.y / p2.y }), series(energyType, "USA"), series(energyType, "China"))
34
+ ]
35
+ ]
36
+ })
37
+ })
@@ -1,5 +1,3 @@
1
- let filter =
2
- let emboss = [[-2, -1, 0],
3
- [-1, 1, 1],
4
- [ 0, 1, 2]] in
5
- [| nth2 i j emboss | (i, j) in (3, 3) |];
1
+ def filter:
2
+ def emboss: [[-2, -1, 0], [-1, 1, 1], [0, 1, 2]]
3
+ [| nth2(i, j, emboss) for (i, j) in (3, 3) |]
@@ -1,7 +1,9 @@
1
- let inputImage =
2
- let image = [[15, 13, 6, 9, 16],
3
- [12, 5, 15, 4, 13],
4
- [14, 9, 20, 8, 1],
5
- [ 4, 10, 3, 7, 19],
6
- [ 3, 11, 15, 2, 9]] in
7
- [| nth2 i j image | (i, j) in (5, 5) |];
1
+ def inputImage:
2
+ def image: [
3
+ [15, 13, 6, 9, 16],
4
+ [12, 5, 15, 4, 13],
5
+ [14, 9, 20, 8, 1],
6
+ [4, 10, 3, 7, 19],
7
+ [3, 11, 15, 2, 9]
8
+ ]
9
+ [| nth2(i, j, image) for (i, j) in (5, 5) |]
@@ -1,28 +1,30 @@
1
1
  import convolution.testImage
2
2
  import convolution.emboss
3
3
 
4
- let lookup m n image =
5
- let (m_max, n_max) = dims image
6
- -- in image!(((m - 1) `mod` m_max) + 1, ((n - 1) `mod` n_max) + 1);
7
- in if (m >= 1) `and` (m <= m_max) `and` (n >= 1) `and` (n <= n_max)
8
- then image!(m, n)
9
- else 0;
4
+ def lookup(m, n, image):
5
+ def (m_max, n_max): dims(image)
6
+ if m >= 1 |and| m <= m_max |and| n >= 1 |and| n <= n_max:
7
+ image!(m, n)
8
+ else: 0
9
+ # image!((m - 1 |mod| m_max) + 1, (n - 1 |mod| n_max) + 1)
10
10
 
11
- let matrixSum matr =
12
- let (m, n) = dims matr
13
- in foldl (+) 0 [ matr!(i, j) | (i, j) <- range (1, 1) (m, n) ];
11
+ def matrixSum(matr):
12
+ def (m, n): dims(matr)
13
+ foldl((+), 0, [matr!(i, j) for (i, j) in range((1, 1), (m, n))])
14
14
 
15
- let convolve image kernel =
16
- let ((m, n), (i, j)) = (dims image, dims kernel);
17
- (half_i, half_j) = (i `quot` 2, j `quot` 2);
18
- area = i * j
19
- in [| let interMatrix =
20
- @doc("""average these to compute value of element (${m'},${n'})""")
21
- [| let x = m' + i' - 1 - half_i;
22
- y = n' + j' - 1 - half_j in
23
- lookup x y image * kernel!(i', j')
24
- | (i', j') in (i, j) |]
25
- in matrixSum interMatrix `quot` area
26
- | (m', n') in (m, n) |]
27
- in
28
- convolve inputImage filter
15
+ def convolve(image, kernel):
16
+ def ((m, n), (i, j)):
17
+ (dims(image), dims(kernel))
18
+ def (half_i, half_j):
19
+ (i |quot| 2, j |quot| 2)
20
+ def area: i * j
21
+
22
+ def interMatrix(m_, n_):
23
+ # @doc("""average these values to compute element (${m_},${n_})""")
24
+ [| kernel!(i_, j_) *
25
+ lookup(((m_ + i_) - 1) - half_i, ((n_ + j_) - 1) - half_j, image)
26
+ for (i_, j_) in (i, j) |]
27
+
28
+ [| matrixSum(interMatrix(m_, n_)) |quot| area for (m_, n_) in (m, n) |]
29
+
30
+ convolve(inputImage, filter)
@@ -0,0 +1,91 @@
1
+ [
2
+ { "year": 2013, "country": "China", "energyType": "Bio", "output": 6.2 },
3
+ { "year": 2013, "country": "China", "energyType": "Hydro", "output": 260 },
4
+ { "year": 2013, "country": "China", "energyType": "Solar", "output": 19.9 },
5
+ { "year": 2013, "country": "China", "energyType": "Wind", "output": 91 },
6
+
7
+ { "year": 2013, "country": "USA", "energyType": "Bio", "output": 15.8 },
8
+ { "year": 2013, "country": "USA", "energyType": "Hydro", "output": 78 },
9
+ { "year": 2013, "country": "USA", "energyType": "Solar", "output": 12.1 },
10
+ { "year": 2013, "country": "USA", "energyType": "Wind", "output": 61 },
11
+
12
+ { "year": 2013, "country": "Germany", "energyType": "Bio", "output": 8.1 },
13
+ { "year": 2013, "country": "Germany", "energyType": "Hydro", "output": 5.6 },
14
+ { "year": 2013, "country": "Germany", "energyType": "Solar", "output": 36 },
15
+ { "year": 2013, "country": "Germany", "energyType": "Wind", "output": 34 },
16
+
17
+ { "year": 2014, "country": "China", "energyType": "Bio", "output": 10 },
18
+ { "year": 2014, "country": "China", "energyType": "Hydro", "output": 280 },
19
+ { "year": 2014, "country": "China", "energyType": "Solar", "output": 28 },
20
+ { "year": 2014, "country": "China", "energyType": "Wind", "output": 115 },
21
+
22
+ { "year": 2014, "country": "USA", "energyType": "Bio", "output": 16.1 },
23
+ { "year": 2014, "country": "USA", "energyType": "Hydro", "output": 79 },
24
+ { "year": 2014, "country": "USA", "energyType": "Solar", "output": 18 },
25
+ { "year": 2014, "country": "USA", "energyType": "Wind", "output": 66 },
26
+
27
+ { "year": 2014, "country": "Germany", "energyType": "Bio", "output": 8.8 },
28
+ { "year": 2014, "country": "Germany", "energyType": "Hydro", "output": 5.6 },
29
+ { "year": 2014, "country": "Germany", "energyType": "Solar", "output": 38 },
30
+ { "year": 2014, "country": "Germany", "energyType": "Wind", "output": 39 },
31
+
32
+ { "year": 2015, "country": "China", "energyType": "Bio", "output": 10.3 },
33
+ { "year": 2015, "country": "China", "energyType": "Hydro", "output": 96 },
34
+ { "year": 2015, "country": "China", "energyType": "Solar", "output": 44 },
35
+ { "year": 2015, "country": "China", "energyType": "Wind", "output": 145 },
36
+
37
+ { "year": 2015, "country": "USA", "energyType": "Bio", "output": 16.7 },
38
+ { "year": 2015, "country": "USA", "energyType": "Hydro", "output": 80 },
39
+ { "year": 2015, "country": "USA", "energyType": "Solar", "output": 26 },
40
+ { "year": 2015, "country": "USA", "energyType": "Wind", "output": 74 },
41
+
42
+ { "year": 2015, "country": "Germany", "energyType": "Bio", "output": 7.1 },
43
+ { "year": 2015, "country": "Germany", "energyType": "Hydro", "output": 5.6 },
44
+ { "year": 2015, "country": "Germany", "energyType": "Solar", "output": 40 },
45
+ { "year": 2015, "country": "Germany", "energyType": "Wind", "output": 45 },
46
+
47
+ { "year": 2016, "country": "China", "energyType": "Bio", "output": 12 },
48
+ { "year": 2016, "country": "China", "energyType": "Hydro", "output": 305 },
49
+ { "year": 2016, "country": "China", "energyType": "Solar", "output": 77 },
50
+ { "year": 2016, "country": "China", "energyType": "Wind", "output": 169 },
51
+
52
+ { "year": 2016, "country": "USA", "energyType": "Bio", "output": 16.8 },
53
+ { "year": 2016, "country": "USA", "energyType": "Hydro", "output": 80 },
54
+ { "year": 2016, "country": "USA", "energyType": "Solar", "output": 41 },
55
+ { "year": 2016, "country": "USA", "energyType": "Wind", "output": 82 },
56
+
57
+ { "year": 2016, "country": "Germany", "energyType": "Bio", "output": 7.6 },
58
+ { "year": 2016, "country": "Germany", "energyType": "Hydro", "output": 5.6 },
59
+ { "year": 2016, "country": "Germany", "energyType": "Solar", "output": 41 },
60
+ { "year": 2016, "country": "Germany", "energyType": "Wind", "output": 50 },
61
+
62
+ { "year": 2017, "country": "China", "energyType": "Bio", "output": 14.9 },
63
+ { "year": 2017, "country": "China", "energyType": "Hydro", "output": 313 },
64
+ { "year": 2017, "country": "China", "energyType": "Solar", "output": 131 },
65
+ { "year": 2017, "country": "China", "energyType": "Wind", "output": 188},
66
+
67
+ { "year": 2017, "country": "USA", "energyType": "Bio", "output": 16.7 },
68
+ { "year": 2017, "country": "USA", "energyType": "Hydro", "output": 80 },
69
+ { "year": 2017, "country": "USA", "energyType": "Solar", "output": 51 },
70
+ { "year": 2017, "country": "USA", "energyType": "Wind", "output": 89 },
71
+
72
+ { "year": 2017, "country": "Germany", "energyType": "Bio", "output": 8 },
73
+ { "year": 2017, "country": "Germany", "energyType": "Hydro", "output": 5.6 },
74
+ { "year": 2017, "country": "Germany", "energyType": "Solar", "output": 42 },
75
+ { "year": 2017, "country": "Germany", "energyType": "Wind", "output": 56 },
76
+
77
+ { "year": 2018, "country": "China", "energyType": "Bio", "output": 17.8 },
78
+ { "year": 2018, "country": "China", "energyType": "Hydro", "output": 322 },
79
+ { "year": 2018, "country": "China", "energyType": "Solar", "output": 176 },
80
+ { "year": 2018, "country": "China", "energyType": "Wind", "output": 210 },
81
+
82
+ { "year": 2018, "country": "USA", "energyType": "Bio", "output": 16.2 },
83
+ { "year": 2018, "country": "USA", "energyType": "Hydro", "output": 80 },
84
+ { "year": 2018, "country": "USA", "energyType": "Solar", "output": 62 },
85
+ { "year": 2018, "country": "USA", "energyType": "Wind", "output": 96 },
86
+
87
+ { "year": 2018, "country": "Germany", "energyType": "Bio", "output": 8.4 },
88
+ { "year": 2018, "country": "Germany", "energyType": "Hydro", "output": 5.6 },
89
+ { "year": 2018, "country": "Germany", "energyType": "Solar", "output": 45 },
90
+ { "year": 2018, "country": "Germany", "energyType": "Wind", "output": 59 }
91
+ ]
@@ -0,0 +1,17 @@
1
+ [
2
+ {"model": "LSTM", "time_s": 99.0, "acc": 80.72, "param": 5977},
3
+ {"model": "BiLSTM", "time_s": 106, "acc": 81.73, "param": 7059},
4
+ {"model": "2 stacked BiLSTM", "time_s": 207, "acc": 81.97, "param": 9221},
5
+ {"model": "3 stacked BiLSTM", "time_s": 310, "acc": 81.53, "param": 11383},
6
+ {"model": "4 stacked BiLSTM", "time_s": 411, "acc": 81.37, "param": 13546},
7
+ {"model": "S-LSTM", "time_s": 65, "acc": 82.64, "param": 8768},
8
+ {"model": "CNN", "time_s": 34, "acc": 80.35, "param": 5637},
9
+ {"model": "2 stacked CNN", "time_s": 40, "acc": 80.97, "param": 5717},
10
+ {"model": "3 stacked CNN", "time_s": 47, "acc": 81.46, "param": 5808},
11
+ {"model": "4 stacked CNN", "time_s": 51, "acc": 81.39, "param": 5855},
12
+ {"model": "Transformer (N=6)", "time_s": 138, "acc": 81.03, "param": 7234},
13
+ {"model": "Transformer (N=8)", "time_s": 174, "acc": 81.86, "param": 7615},
14
+ {"model": "Transformer (N=10)", "time_s": 214, "acc": 81.63, "param": 8004},
15
+ {"model": "BiLSTM+Attention", "time_s": 126, "acc": 82.37, "param": 7419},
16
+ {"model": "S-LSTM+Attention", "time_s": 87, "acc": 83.07, "param": 8858}
17
+ ]
@@ -0,0 +1,2 @@
1
+ def tableData:
2
+ loadJson("dataset/scigen/1805.02474v1-10.json")
@@ -1 +1 @@
1
- let methane = loadJson "dataset/methane-emissions.json";
1
+ def methane: loadJson("dataset/methane-emissions.json")
@@ -1,21 +1,24 @@
1
1
  import methane
2
2
 
3
- let nthPad n xs =
4
- nth (min (max n 0) (length xs - 1)) xs;
5
- movingAvg ys window =
6
- [ sum [ nthPad n ys | n <- [ i - window .. i + window ] ] / (1 + 2 * window)
7
- | i <- [ 0 .. length ys - 1 ] ];
8
- movingAvg' rs window =
9
- zipWith
10
- (fun x y -> {x: x, y: y})
11
- (map (fun r -> r.x) rs)
12
- (movingAvg (map (fun r -> r.y) rs) window);
13
- let points =
14
- [ { x: r.year, y: r.emissions } | r <- methane, r.type == "Agriculture" ]
15
- in LineChart {
16
- tickLabels: { x: Rotated, y: Default },
17
- size: { width: 330, height: 285 },
18
- caption: "SSP5-8.5 projected methane emissions (Agriculture)",
19
- plots: [ LinePlot { name: "Moving average", points: movingAvg' points 1 },
20
- LinePlot { name: "Original curve", points: points } ]
21
- }
3
+ def nthPad(n, xs):
4
+ nth(min(max(n, 0), length(xs) - 1), xs)
5
+ def movingAvg(ys, window):
6
+ [sum([nthPad(n, ys) for n in [i - window .. i + window]]) / (1 + 2 * window) for i in [0 .. length(ys) - 1]]
7
+ def movingAvg'(rs, window):
8
+ zipWith((lambda x, y: { x: x, y: y }), map((lambda r: r.x), rs), movingAvg(map((lambda r: r.y), rs), window));
9
+
10
+ def points:
11
+ [{ x: r.year, y: r.emissions } for r in methane if r.type == "Agriculture"];
12
+
13
+ LineChart({
14
+ tickLabels: { x: Rotated, y: Default },
15
+ size: { width: 330, height: 285 },
16
+ caption: "SSP5-8.5 projected methane emissions (Agriculture)",
17
+ plots: [
18
+ LinePlot({
19
+ name: "Moving average",
20
+ points: movingAvg'(points, 1)
21
+ }),
22
+ LinePlot({ name: "Original curve", points: points })
23
+ ]
24
+ })
@@ -1,23 +1,31 @@
1
1
  import nonRenewables
2
2
 
3
- let countries = ["BRA", "EGY", "IND", "JPN"];
4
- let totalFor year country =
5
- let [ row ] = [ row | row <- nonRenewables, row.year == year, row.country == country ]
6
- in row.nuclearOut + row.gasOut + row.coalOut + row.petrolOut;
7
- let stack year = [ { y: country, z: totalFor year country } | country <- countries ];
8
- let yearData year = [ row | row <- nonRenewables, row.year == year, row.country `elem` countries ]
9
- in MultiView {
10
- barChart: BarChart {
11
- caption: "Non-renewables output",
12
- size: { width: 275, height: 185 },
13
- stackedBars: [ { x: numToStr year, segments: stack year } | year <- [2014..2018] ]
14
- },
15
- scatterPlot: ScatterPlot {
16
- caption: "",
17
- points: [ {
18
- x: sum [ row.nuclearOut | row <- yearData year ],
19
- y: sum [ row.nuclearCap | row <- yearData year ]
20
- } | year <- [2014..2018] ],
21
- labels: { x: "Nuclear capacity", y: "Nuclear output" }
22
- }
23
- }
3
+ def countries: ["BRA", "EGY", "IND", "JPN"]
4
+
5
+ def totalFor(year, country):
6
+ def [row]:
7
+ [row for row in nonRenewables if row.year == year if row.country == country]
8
+
9
+ row.nuclearOut + row.gasOut + row.coalOut + row.petrolOut
10
+
11
+ def stack(year):
12
+ [{ y: country, z: totalFor(year, country) } for country in countries]
13
+
14
+ def yearData(year):
15
+ [row for row in nonRenewables if row.year == year if row.country |elem| countries]
16
+
17
+ MultiView({
18
+ barChart: BarChart({
19
+ caption: "Non-renewables output",
20
+ size: { width: 275, height: 185 },
21
+ stackedBars: [{ x: numToStr(year), segments: stack(year) } for year in [2014 .. 2018]]
22
+ }),
23
+ scatterPlot: ScatterPlot({
24
+ caption: "",
25
+ points: [{
26
+ x: sum([row.nuclearOut for row in yearData(year)]),
27
+ y: sum([row.nuclearCap for row in yearData(year)])
28
+ } for year in [2014 .. 2018]],
29
+ labels: { x: "Nuclear capacity", y: "Nuclear output" }
30
+ })
31
+ })
@@ -1,2 +1,5 @@
1
- let nonRenewables = loadJson "dataset/non-renewables.json";
2
- let renewables = loadJson "dataset/renewable.json";
1
+ def nonRenewables:
2
+ loadJson("dataset/non-renewables.json")
3
+
4
+ def renewables:
5
+ loadJson("dataset/renewable.json")
@@ -0,0 +1 @@
1
+ def renewables: loadJson("dataset/renewable-new.json")
@@ -0,0 +1,48 @@
1
+ def ordinalMap: [
2
+ { lastDigit: 1, suffix: "st" },
3
+ { lastDigit: 2, suffix: "nd" },
4
+ { lastDigit: 3, suffix: "rd" }
5
+ ]
6
+
7
+ def ordinal(n):
8
+ if n <= 0:
9
+ error("n <= 0 not supported")
10
+ else:
11
+ if n < 4:
12
+ numToStr(n) ++ findWithKey_("lastDigit", n, ordinalMap).suffix
13
+ else:
14
+ if n >= 4 |and| n <= 20:
15
+ numToStr(n) ++ "th"
16
+ else:
17
+ error("n > 20 not supported")
18
+
19
+ def rankLabel(word, n):
20
+ if n == 1: ""
21
+ else: ordinal(n) ++ "-" ++ word
22
+
23
+ def trendWord(n1, n2, compareWord):
24
+ compareWord(compare(n1, n2))
25
+
26
+ def growShrink(EQ): "unchanging"
27
+ def growShrink(LT): "shrinking"
28
+ def growShrink(GT): "growing"
29
+
30
+ def smallerHigher(EQ): "equal"
31
+ def smallerHigher(LT): "smaller"
32
+ def smallerHigher(GT): "larger"
33
+
34
+ def improve(EQ): "does not further improve"
35
+ def improve(LT): "does not further improve"
36
+ def improve(GT): "further improves"
37
+
38
+ def shorterLonger(EQ): "equal"
39
+ def shorterLonger(LT): "shorter"
40
+ def shorterLonger(GT): "longer"
41
+
42
+ def betterWorse(EQ): "equal"
43
+ def betterWorse(LT): "worse"
44
+ def betterWorse(GT): "better"
45
+
46
+ def underOverPerforming(EQ): "performing the same as"
47
+ def underOverPerforming(LT): "performing worse than"
48
+ def underOverPerforming(GT): "outperforming"
@@ -0,0 +1,39 @@
1
+ def insert(lt, x, []): [x]
2
+ def insert(lt, x, y :| ys):
3
+ if x |lt| y: x :| y :| ys
4
+ else:
5
+ y :| insert(lt, x, ys)
6
+
7
+ def insertionSort(lt, lst):
8
+ def helper([], sorted): sorted
9
+ def helper(x :| xs, sorted):
10
+ helper(xs, insert(lt, x, sorted))
11
+
12
+ helper(lst, [])
13
+
14
+ def findIndex(fName, x, []): -1
15
+ def findIndex(fName, x, y :| ys):
16
+ if y[fName] == x: 1
17
+ else:
18
+ findIndex(fName, x, ys) + 1
19
+
20
+ def findWithKey_(fName, x, table):
21
+ fromSome(findWithKey(fName, x, table))
22
+
23
+ def findWhere(pred, table):
24
+ fromSome(find(pred, table))
25
+
26
+ def model(m, t):
27
+ findWithKey_("model", m, t)
28
+
29
+ def maximumBy(f, []):
30
+ error("Empty list!")
31
+ def maximumBy(f, x :| xs):
32
+ def helper([], current): current
33
+ def helper(y :| ys, current):
34
+ if f(y) > f(current):
35
+ helper(ys, y)
36
+ else:
37
+ helper(ys, current)
38
+
39
+ helper(xs, x)
@@ -17,9 +17,11 @@
17
17
  <div></div>
18
18
  <h2>Fluid Demo Articles</h2>
19
19
 
20
- <a href="non-renewables">Non-renewable energy</a><br>
20
+ <a href="non-renewables">Non-renewable energy stacked bar chart/scatter plot</a><br>
21
+ <a href="renewables-linked">Non-renewable energy bar chart/line chart</a><br>
21
22
  <a href="moving-average">Moving average</a><br>
22
23
  <a href="convolution">Matrix convolution</a><br>
24
+ <a href="scigen-1805.02474v1-10">SciGen 1805.02474v1-10 benchmark</a><br>
23
25
  </div>
24
26
  </div>
25
27
  </body>
@@ -50,9 +50,15 @@
50
50
  </div>
51
51
 
52
52
  <script type="module">
53
- import { loadFigure } from "../shared/load-figure.js"
54
- loadFigure("spec.json")("../fluid/moving-average.fld")()
53
+ import { loadFigureSpec } from "../shared/load-figure.js"
54
+ const jsonSpec = {
55
+ "fluidSrcPath": ["../fluid"],
56
+ "inputs": ["methane"],
57
+ "query": false,
58
+ "linking": false
59
+ }
55
60
 
61
+ loadFigureSpec(jsonSpec)("../fluid/moving-average.fld")()
56
62
  </script>
57
63
  </body>
58
64
  </html>
@@ -39,8 +39,14 @@
39
39
  </div>
40
40
 
41
41
  <script type="module">
42
- import { loadFigure } from "../shared/load-figure.js"
43
- loadFigure("spec.json")("../fluid/non-renewables.fld")()
42
+ import { loadFigureSpec } from "../shared/load-figure.js"
43
+ const jsonSpec = {
44
+ "fluidSrcPath": ["../fluid"],
45
+ "inputs": ["nonRenewables"],
46
+ "query": false,
47
+ "linking": true
48
+ }
49
+ loadFigureSpec(jsonSpec)("../fluid/non-renewables.fld")()
44
50
  </script>
45
51
  </body>
46
52
  </html>
@@ -0,0 +1,60 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <link rel="icon" href="/favicon.ico" type="image/x-icon">
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
+ <title>Fluid: Data-Linked Visualisations</title>
9
+ <link href="/css/styles.css" rel="stylesheet" type="text/css">
10
+ <link href="/css/view-styles.css" rel="stylesheet" type="text/css">
11
+ <script src="https://kit.fontawesome.com/20cf8b42c0.js" crossorigin="anonymous"></script>
12
+ <script src="/shared/util.js"></script>
13
+ </head>
14
+ <body class="standalone">
15
+ <div id="grid" class="grid-container data-pane-hidden double-size">
16
+ <div></div>
17
+ <div></div>
18
+ <div>
19
+ <h3>Non-renewables energy output</h3>
20
+ <p>Click the grey toggle and mouse over the bars.
21
+ <br>
22
+ <b>Clicking</b> makes a selection “persistent”.</p>
23
+ </div>
24
+
25
+ <div id="fig-data-pane" class="flex-right-align data-pane">
26
+ <div id="fig-input" class="data-pane-column"></div>
27
+ </div>
28
+ <div onclick="toggleDataPane('grid')">
29
+ <i class="data-pane-button toggle-button fa-solid fa-eye-slash"></i>
30
+ </div>
31
+ <div class="flex-left-align">
32
+ <div id="fig">
33
+ <div class="fig-loading">loading figure(s)</div>
34
+ </div>
35
+ <p>Source code:</p>
36
+ <details>
37
+ <summary>bar-chart-line-chart.fld</summary>
38
+ <div id="codemirror-bar-chart-line-chart"></div>
39
+ </details>
40
+ <details>
41
+ <summary>renewables.fld</summary>
42
+ <div id="codemirror-renewables"></div>
43
+ </details>
44
+ </div>
45
+ </div>
46
+
47
+ <script type="module">
48
+ import { loadFigureSpec, drawCode } from "/shared/load-figure.js"
49
+ const jsonSpec = {
50
+ "fluidSrcPath": ["../fluid"],
51
+ "inputs": ["renewables"],
52
+ "query": false,
53
+ "linking": true
54
+ }
55
+
56
+ drawCode("../fluid/bar-chart-line-chart.fld")()
57
+ loadFigureSpec(jsonSpec)("../fluid/bar-chart-line-chart.fld")()
58
+ </script>
59
+ </body>
60
+ </html>