Skip to content

Commit

Permalink
and field name encoding and ci status
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrochowicz committed Apr 17, 2018
1 parent 9c8840b commit 573bb62
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# chart-builder

[![CircleCI](https://circleci.com/gh/datadotworld/chart-builder.svg?style=svg)](https://circleci.com/gh/datadotworld/chart-builder)

This is an app to generate Vega-Lite visualizations using data from a data.world query.

### Getting started
Expand Down
4 changes: 2 additions & 2 deletions src/util/Store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import { types } from 'mobx-state-tree'
import sparqlTypeToVegaType from './sparqlTypeToVegaType'
import { parseParams } from './util'
import { parseParams, encodeFieldName } from './util'
import type {
EncodingChannel,
EncodingType,
Expand Down Expand Up @@ -214,7 +214,7 @@ export const ChartConfig = types
: sortOrder

const enc = {
field: e.field.name,
field: encodeFieldName(e.field.name),
type: e.appliedType,
bin: e.bin || undefined,
aggregate: e.aggregate === null ? undefined : e.aggregate,
Expand Down
21 changes: 20 additions & 1 deletion src/util/__test__/util.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { parseParams, createParams, getDownloadName } from '../util'
import {
parseParams,
createParams,
getDownloadName,
encodeFieldName
} from '../util'

describe('parseParams', () => {
it('works', () => {
Expand Down Expand Up @@ -29,3 +34,17 @@ describe('getDownloadName', () => {
expect(getDownloadName('base-name', 'png')).toMatchSnapshot()
})
})

describe('encodeFieldName', () => {
const specs = [
[`normal.foo`, `normal\\.foo`],
[`normal.[]foo`, `normal\\.\\[\\]foo`],
[`normal`, `normal`]
]

specs.forEach(([input, expected]) => {
it(`works for ${input}`, () => {
expect(encodeFieldName(input)).toBe(expected)
})
})
})
4 changes: 4 additions & 0 deletions src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ export function getDownloadName(baseName: string, extension: string) {
const dateStr = new Date().toISOString().replace(/[.:]/g, '-')
return `${baseName}-${dateStr}.${extension}`
}

export function encodeFieldName(name: string) {
return name.replace(/([.\[\]])/g, '\\$1')
}

0 comments on commit 573bb62

Please sign in to comment.