| 18 | import renderChart from 'vega-embed'; |
| 19 | |
| 20 | export async function plotData(container, xs, ys) { |
| 21 | const xvals = await xs.data(); |
| 22 | const yvals = await ys.data(); |
| 23 | |
| 24 | const values = Array.from(yvals).map((y, i) => { |
| 25 | return {'x': xvals[i], 'y': yvals[i]}; |
| 26 | }); |
| 27 | |
| 28 | const spec = { |
| 29 | '$schema': 'https://vega.github.io/schema/vega-lite/v2.json', |
| 30 | 'width': 300, |
| 31 | 'height': 300, |
| 32 | 'data': {'values': values}, |
| 33 | 'mark': 'point', |
| 34 | 'encoding': { |
| 35 | 'x': {'field': 'x', 'type': 'quantitative'}, |
| 36 | 'y': {'field': 'y', 'type': 'quantitative'} |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | return renderChart(container, spec, {actions: false}); |
| 41 | } |
| 42 | |
| 43 | export async function plotDataAndPredictions(container, xs, ys, preds) { |
| 44 | const xvals = await xs.data(); |