Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add data support for layer #66

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/react-vega-demo/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import ReactVegaDemo from './ReactVegaDemo';
import ReactVegaLiteDemo from './ReactVegaLiteDemo';
import './style.css';

storiesOf('react-vega', module).add('Vega', () => <ReactVegaDemo />);
storiesOf('react-vega', module).add('VegaLite', () => <ReactVegaLiteDemo />);
storiesOf('react-vega', module)
.add('Vega', () => <ReactVegaDemo />)
.add('VegaLite', () => <ReactVegaLiteDemo />);
1 change: 0 additions & 1 deletion packages/react-vega-demo/stories/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
body{
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
text-align: center;
}

h1, h2, h3{
Expand Down
36 changes: 36 additions & 0 deletions packages/react-vega-demo/stories/vegaLiteWithLayers.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable react/jsx-filename-extension */
import React from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { storiesOf } from '@storybook/react';
import { VegaLite } from '../../react-vega/src';

const DATA = {
myData: [
{ a: "A", b: 20 },
{ a: "B", b: 34 },
{ a: "C", b: 55 },
{ a: "D", b: 19 },
{ a: "E", b: 40 },
{ a: "F", b: 34 },
{ a: "G", b: 91 },
{ a: "H", b: 78 },
{ a: "I", b: 25 }
]
};

const SPEC = {
description: "A simple bar chart with embedded data.",
layer: [
{
data: { name: "myData" },
encoding: {
x: { field: "a", type: "ordinal" },
y: { field: "b", type: "quantitative" }
},
mark: "bar"
}
]
};

storiesOf('react-vega', module)
.add('VegaLite with layers', () => <><VegaLite spec={SPEC} data={DATA} /><div><pre>{JSON.stringify(SPEC, null, 2)}</pre></div></>);
5 changes: 2 additions & 3 deletions packages/react-vega/src/Vega.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import isFunction from './utils/isFunction';
import { PlainObject, View, ViewListener } from './types';
import shallowEqual from './utils/shallowEqual';
import { NOOP } from './constants';
import getDatasetNamesFromSpec from './utils/getDatasetNamesFromSpec';

export type VegaProps = VegaEmbedProps & {
data?: PlainObject;
Expand Down Expand Up @@ -53,10 +52,10 @@ export default class Vega extends React.PureComponent<VegaProps> {
};

update() {
const { data, spec } = this.props;
const { data } = this.props;

if (data) {
const datasetNames = getDatasetNamesFromSpec(spec).filter(name => data[name]);
const datasetNames = Object.keys(data);

if (this.vegaEmbed.current && datasetNames.length > 0) {
this.vegaEmbed.current.modifyView(view => {
Expand Down