-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
105 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as plot } from './src/plot.js'; | ||
export { default as plotVega } from './src/plotVega.js'; | ||
export { default as plotHistogram } from './src/plotHistogram.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import plot from './plot.js'; | ||
|
||
/** | ||
* Plot Vega charts | ||
* @param {Function|Object} [chart] A Vega-Lite-API chart or a Vega-Lite spec. | ||
* @param {String} [options] Options | ||
* @param {Boolean} [options.view=true] If true, show the chart in a popup window. | ||
* @param {String} [options.outPath=''] A filepath to write the image. | ||
* @param {String} [options.css] Any CSS that you want injected into the page to tweak styles. | ||
* @param {Boolean} [options.debug] Whether to run the screenshot browser in headfull mode. | ||
*/ | ||
export default async function plotVega(chart, options) { | ||
const c = s => s; | ||
const spec = typeof chart.toSpec === 'function' ? chart.toSpec() : chart; | ||
await plot(c, [spec], { ...options, library: 'vega-lite', view: true }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable no-undef */ | ||
import * as vl from 'vega-lite-api'; | ||
import plotVega from '../src/plotVega.js'; | ||
|
||
const data = { | ||
values: [ | ||
{ a: 'A', b: 28 }, | ||
{ a: 'B', b: 55 }, | ||
{ a: 'C', b: 43 }, | ||
{ a: 'D', b: 91 }, | ||
{ a: 'E', b: 81 }, | ||
{ a: 'F', b: 53 }, | ||
{ a: 'G', b: 19 }, | ||
{ a: 'H', b: 87 }, | ||
{ a: 'I', b: 52 } | ||
] | ||
}; | ||
|
||
const chart = vl | ||
.markBar() | ||
.description('A simple bar chart with embedded data.') | ||
.data(data) | ||
.encode( | ||
vl.x().fieldO('a'), | ||
vl.y().fieldQ('b') | ||
); | ||
|
||
await plotVega(chart, { | ||
outPath: 'test/tmp/vega-lite-api_line-plot.png' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable no-undef */ | ||
import plotVega from '../src/plotVega.js'; | ||
|
||
const data = { | ||
values: [ | ||
{ a: 'A', b: 28 }, | ||
{ a: 'B', b: 55 }, | ||
{ a: 'C', b: 43 }, | ||
{ a: 'D', b: 91 }, | ||
{ a: 'E', b: 81 }, | ||
{ a: 'F', b: 53 }, | ||
{ a: 'G', b: 19 }, | ||
{ a: 'H', b: 87 }, | ||
{ a: 'I', b: 52 } | ||
] | ||
}; | ||
|
||
const spec = { | ||
$schema: 'https://vega.github.io/schema/vega-lite/v5.json', | ||
description: 'A simple bar chart with embedded data.', | ||
data, | ||
mark: 'bar', | ||
encoding: { | ||
x: { field: 'a', type: 'ordinal' }, | ||
y: { field: 'b', type: 'quantitative' } | ||
} | ||
}; | ||
|
||
await plotVega(spec); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters