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

Ability to customize vega-lite charts via configuration #726

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 2 additions & 12 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@ import { Provider } from 'react-redux';

import 'font-awesome-sass-loader';

import {Config} from 'vega-lite/build/src/config';
import { Data } from 'vega-lite/build/src/data';
import {App} from './components/app';
import { VOYAGER_CONFIG } from './constants';
import { VoyagerConfig } from './models/config';
import { configureStore } from './store';

const store = configureStore();
let config: VoyagerConfig = VOYAGER_CONFIG;
const config: VoyagerConfig = VOYAGER_CONFIG;

const data: Data = undefined;
// Demo of how vegalite config is passed.
const vegaliteConfig: Config = {
"mark": {
"color": "black"
}
};
config = {
...config,
vegaliteConfig
};

ReactDOM.render(
<Provider store={store}>
<App
Expand Down
33 changes: 3 additions & 30 deletions src/lib-voyager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export interface VoyagerParams {
config?: VoyagerConfig;
};

const DEFAULT_VOYAGER_PARAMS = {
data: {values: ([] as any)},
config: DEFAULT_VOYAGER_CONFIG
};
const DEFAULT_DATA: any = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this? (We can just not assign default data below.)


/**
* The Voyager class encapsulates the voyager application and allows for easy
Expand All @@ -45,8 +42,8 @@ export class Voyager {
private data: Data;
private filename: string;

constructor(container: Container, params: VoyagerParams = DEFAULT_VOYAGER_PARAMS) {
const {config, data} = params;
constructor(container: Container, params: VoyagerParams) {
const {config = DEFAULT_VOYAGER_CONFIG, data = DEFAULT_DATA} = params;
if (isString(container)) {
this.container = document.querySelector(container) as HTMLElement;
// TODO throw error if not found
Expand Down Expand Up @@ -239,27 +236,3 @@ export class Voyager {
export function createVoyager(container: Container, params: VoyagerParams): Voyager {
return new Voyager(container, params);
}


/**
* Create an instance of the voyager application.
*
* @param {Container} container css selector or HTMLElement that will be the parent
* element of the application
* @param {Object} config configuration options
* @param {Array} data data object. Can be a string or an array of objects.
*/
export function CreateVoyager(container: Container, data: Data, config: VoyagerConfig): Voyager {
const voyagerParams: VoyagerParams = {
config,
data
};
if (console.warn) {
// TODO: Not sure about the language.
console.warn(
`"createVoyager(container, {data, config})" is favored over CreateVoyager.`
+ `Please check documentation for new API`
);
}
return createVoyager(container, voyagerParams);
}