Skip to content

Commit

Permalink
Merge pull request #3815 from PopulateTools/3812-perspective-dates
Browse files Browse the repository at this point in the history
Bugs in Data
  • Loading branch information
Crashillo authored Apr 12, 2021
2 parents 7f880c6 + 884236e commit 95debfe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 45 deletions.
1 change: 0 additions & 1 deletion app/javascript/gobierto_data/lib/factories/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import axios from "axios";
const endPoint = `${baseUrl}/data.csv`;
const token = getToken();
const headers = {
"Content-type": "application/json",
Authorization: token
};

Expand Down
1 change: 0 additions & 1 deletion app/javascript/gobierto_data/webapp/components/Dataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ export default {
}
this.currentQuery = sql;
this.runCurrentQuery();
},
storeRecentQuery() {
// if the currentQuery does not exist, nor recent, nor in stored queries neither
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export default {
}
}
},
created() {
this.worker = perspective.worker();
},
mounted() {
this.viewer = this.$refs["perspective-viewer"];
this.checkIfQueryResultIsEmpty(this.items)
Expand All @@ -84,70 +87,40 @@ export default {
}
},
checkPerspectiveTypes() {
//Get columns generates from query
const arrayColumnsFromQuery = this.arrayColumnsQuery
//Get columns from API
const arrayColumnsFromAPI = Object.keys(this.objectColumns)
/* We compare the columns, if it returns true we pass the schema to Perspective, if false Perspective will convert the columns*/
const sameColumns = arrayColumnsFromAPI.length === arrayColumnsFromQuery.length && arrayColumnsFromAPI.every(column => arrayColumnsFromQuery.includes(column))
//If columns contains Boolean values goes to replace them
let replaceItems = this.items
if (Object.values(this.objectColumns).some(value => value === "boolean")) {
replaceItems = this.items.replace(/"t"/g, '"true"').replace(/"f"/g, '"false"')
}
if (sameColumns) {
this.initPerspectiveWithSchema(replaceItems)
} else {
this.initPerspective(replaceItems)
}
this.initPerspectiveWithSchema(replaceItems)
},
initPerspectiveWithSchema(data) {
this.viewer.setAttribute('plugin', this.typeChart)
this.viewer.clear();
const transformColumns = this.objectColumns
Object.keys(transformColumns).forEach((key) => {
if (transformColumns[key] === 'hstore' || transformColumns[key] === 'jsonb' || transformColumns[key] === 'text') {
transformColumns[key] = 'string'
} else if (transformColumns[key] === 'decimal') {
transformColumns[key] = 'float'
} else if (transformColumns[key] === 'inet') {
transformColumns[key] = 'integer'
//In some cases, Perspective throw an error when tried to convert column with date format, so we need to change the date to datetime
} else if (transformColumns[key] === 'date') {
transformColumns[key] = 'datetime'
} else if (transformColumns[key] === 'tsvector') {
transformColumns[key] = 'string'
const schema = this.objectColumns
Object.keys(schema).forEach((key) => {
if (['text', 'hstore', 'jsonb', 'tsvector'].includes(schema[key])) {
schema[key] = 'string'
} else if (schema[key] === 'decimal') {
schema[key] = 'float'
} else if (schema[key] === 'inet') {
schema[key] = 'integer'
} else if (schema[key] === 'date') {
schema[key] = 'datetime'
}
});
let schema = transformColumns
const loadSchema = this.viewer.worker.table(schema);
this.viewer.load(loadSchema)
this.viewer.update(data)
if (this.config) {
this.loadConfig()
}
this.listenerPerspective()
},
initPerspective(data) {
this.viewer.setAttribute('plugin', this.typeChart)
this.viewer.clear();
this.worker.table(schema);
this.viewer.load(data)
if (this.config) {
this.loadConfig()
}
this.listenerPerspective()
},
loadConfig() {
this.viewer.restore(this.config);
Expand Down

0 comments on commit 95debfe

Please sign in to comment.