Skip to content

Commit

Permalink
Convert data to generic Vega format, remove opendatafit-types dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
echus committed Jun 1, 2022
1 parent 4ee38d5 commit 32a6ce2
Show file tree
Hide file tree
Showing 5 changed files with 3,911 additions and 51,195 deletions.
2 changes: 0 additions & 2 deletions addon/modifiers/vega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as Vega from 'vega';
import * as VegaLite from 'vega-lite';
import * as VegaTooltip from 'vega-tooltip';

import { Resource, View } from 'opendatafit-types';


const DEFAULT_CONFIG: Vega.Config = {
background: '#fff',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ember-cli-typescript": "^5.1.0",
"ember-lodash": "^4.19.5",
"ember-modifier": "^3.2.7",
"opendatafit-types": "git+ssh://[email protected]:opendatafit/opendatafit-types.git",
"vega": "^5.22.1",
"vega-lite": "^5.2.0",
"vega-tooltip": "^0.28.0"
Expand Down
99 changes: 17 additions & 82 deletions tests/dummy/app/controllers/application.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1,39 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { cloneDeep } from 'lodash';

import { Resource, View } from 'opendatafit-types';
import { Spec } from 'vega';

import {
DATAPACKAGE,
DATA,
FIT_DATA,
DataRecord,
CONFIG,
SPEC,
SPEC_TYPE,
DATA_1,
DATA_2,
FIT_DATA_2
} from '../utils/data';


export default class Application extends Controller {
@tracked dataResource!: Resource;
@tracked fitResource!: Resource;
@tracked spec: Spec;
@tracked specType: string;
@tracked config: object;
@tracked data: DataRecord;

constructor() {
super(...arguments);

this.dataResource = DATAPACKAGE.resources[4] as Resource;
this.dataResource.data = DATA;
this.spec = SPEC;
this.specType = SPEC_TYPE;
this.config = CONFIG;
this.data = DATA_1;

this.fitResource = DATAPACKAGE.resources[5] as Resource;
this.fitResource.data = FIT_DATA;
}

get resources() {
return [
this.dataResource,
this.fitResource
];
}

get data() {
type Data = Record<string, number | null>;
let data: Record<string, Data> = {};
data[this.dataResource.name] = this.dataResource.data as Data;
data[this.fitResource.name] = this.fitResource.data as Data;
return data;
}

get spec() {
return this.view.spec;
}

get specType() {
return this.view.specType;
}

get view() {
return DATAPACKAGE.views[4] as View;
}

get config() {
return {
"background": "#fff",
"arc": {"fill": "#3e5c69"},
"area": {"fill": "#3e5c69"},
"line": {"stroke": "#3e5c69"},
"path": {"stroke": "#3e5c69"},
"rect": {"fill": "#3e5c69"},
"shape": {"stroke": "#3e5c69"},
"symbol": {"fill": "#3e5c69"},
"axis": {
"domainWidth": 0.5,
"grid": true,
"labelPadding": 2,
"tickSize": 5,
"tickWidth": 0.5,
"titleFontWeight": "normal"
},
"axisBand": {"grid": false},
"axisX": {"gridWidth": 0.2},
"axisY": {"gridDash": [3], "gridWidth": 0.4},
"legend": {"labelFontSize": 11, "padding": 1, "symbolType": "square"},
"range": {
"category": [
"#3e5c69",
"#6793a6",
"#182429",
"#0570b0",
"#3690c0",
"#74a9cf",
"#a6bddb",
"#e2ddf2"
]
}
};
console.log('Constructor loaded data:', this.data);
}

@action updateData() {
let updatedDataResource = cloneDeep(this.dataResource)
updatedDataResource.data = DATA_2;
this.dataResource = updatedDataResource;
let updatedFitResource = cloneDeep(this.fitResource)
updatedFitResource.data = FIT_DATA_2;
this.fitResource = updatedFitResource;
this.data = DATA_2;
console.log('Data after update:', this.data);
}
}

Expand Down
Loading

0 comments on commit 32a6ce2

Please sign in to comment.