Skip to content

Commit

Permalink
Merge pull request #450 from Esri/feat/cvds
Browse files Browse the repository at this point in the history
expose option to decode domain values
  • Loading branch information
tomwayson authored Nov 27, 2018
2 parents e4911e4 + 001b933 commit 08ab30f
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 21 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: node_js
notifications:
email: false
node_js:
- 6
- 8
-8
-10
cache:
directories:
- node_modules
Expand Down
40 changes: 40 additions & 0 deletions docs/examples/bar-domain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"type": "bar",
"datasets": [
{
"url": "http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/MapServer/0",
"name": "sheltcap",
"query": {
"where": "facname = 'WHITE EAGLE ELEMENTARY' OR facname = 'FRY ELEMENTARY SCHOOL'"
},
"domains": {
"sheltstat": {
"type": "codedValue",
"name": "ShelterCode",
"description": "Shelter Codes",
"codedValues": [
{
"name": "Open",
"code": 1
},
{
"name": "Closed",
"code": 2
},
{
"name": "Full",
"code": 3
}
]
}
}
}
],
"series": [
{
"category": {"field": "sheltstat", "label": "Status"},
"value": {"field": "sheltcap", "label": "Shelter Capacity"},
"source": "sheltcap"
}
]
}
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ <h3>Chart Type</h3>
editor.getSession().setMode("ace/mode/json");

// build list off styles
var styles = ["bar", "bar-grouped", "bar-stacked", "bar-horizontal", "radar", "bubble", "area", "line", "pie", "scatter"];
var styles = [ "bar", "bar-grouped", "bar-stacked", "bar-horizontal", "bar-domain", "radar", "bubble", "area", "line", "pie", "scatter" ];
buildMenu(styles);

// initialize editor to default style
Expand Down
6 changes: 3 additions & 3 deletions packages/cedar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
"mapCoverage": true
},
"dependencies": {
"@esri/arcgis-rest-common-types": "^1.7.1",
"@esri/arcgis-rest-feature-service": "^1.7.1",
"@esri/arcgis-rest-request": "^1.7.1",
"@esri/arcgis-rest-common-types": "^1.14.1",
"@esri/arcgis-rest-feature-service": "^1.14.1",
"@esri/arcgis-rest-request": "^1.14.1",
"@esri/cedar-amcharts": "^1.0.0-beta.9"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cedar/src/Chart.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cedarAmCharts } from '@esri/cedar-amcharts'
import { getChartData, IDataset, IField, ISeries } from './dataset'
import { getChartData, IDataset, ISeries } from './dataset'
import { queryDatasets } from './query/query'

function clone(json) {
Expand Down
22 changes: 20 additions & 2 deletions packages/cedar/src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,30 @@ export interface IField {
label?: string
}

// TODO: move this and IDomain(s) to rest-js
export interface ICodedValue {
name: string,
code: string | number
}

export interface IDomain {
type: string,
name: string,
description?: string,
codedValues?: ICodedValue[]
}

export interface IDomains {
[index: string]: IDomain
}

export interface IDataset {
name: string,
url?: string,
data?: IFeatureSet | Array<{}>,
query?: {},
join?: string
join?: string,
domains?: IDomains
}

// TODO: move to series.ts?
Expand Down Expand Up @@ -66,7 +84,7 @@ function getDatasetData(dataset, datasetsData, name?) {
// return only the attributes for each feature
function flattenData(data) {
const features = getFeatures(data)
if ((features[0] as IFeature).attributes) {
if (features.length > 0 && (features[0] as IFeature).attributes) {
// these really are features, flatten them before
return features.map(getAttributes)
} else {
Expand Down
32 changes: 29 additions & 3 deletions packages/cedar/src/query/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { IQueryFeaturesRequestOptions, queryFeatures } from '@esri/arcgis-rest-feature-service'
import {
decodeValues,
IDecodeValuesRequestOptions,
IQueryFeaturesRequestOptions,
IQueryFeaturesResponse,
queryFeatures
} from '@esri/arcgis-rest-feature-service'
import config from '../config'
import { IDataset } from '../dataset'
import { createQueryParams } from './url'
Expand All @@ -13,6 +19,7 @@ export function queryDatasets(datasets: IDataset[]) {
if (dataset.url) {
// TODO: make name required on datasets, or required if > 1 dataset?
names.push(dataset.name || `dataset${i}`)

const queryParams = createQueryParams(dataset.query)
const options: IQueryFeaturesRequestOptions = {
url: dataset.url,
Expand All @@ -23,15 +30,34 @@ export function queryDatasets(datasets: IDataset[]) {
// send that along to rest-js
options.fetch = config.fetch
}
requests.push(queryFeatures(options))
requests.push(
queryFeatures(options)
.then((queryResponse: IQueryFeaturesResponse) => {
const { domains } = dataset
const fields: any[] = domains && Object.keys(domains).map((name) => ({ name, domain: domains[name]}))
// for now, we only decode CVDs when an array of fields is passed describing codes and names
if (fields && fields.length > 0) {
const decodeOptions: IDecodeValuesRequestOptions = {
url: options.url,
queryResponse,
// TODO: decodeValues() should take `domains?: IDomains` as an alternative to `fields?: IField[]`
fields,
fetch: config.fetch
}
return decodeValues(decodeOptions)
} else {
return queryResponse
}
})
)
}
})
}
return Promise.all(requests)
.then((responses) => {
// turn the array of responses into a hash keyed off the dataset names
const responseHash = responses.reduce((hash, response, i) => {
hash[names[i]] = responses[i]
hash[names[i]] = response
return hash
}, {})
return Promise.resolve(responseHash)
Expand Down
21 changes: 12 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@
esutils "^2.0.2"
js-tokens "^3.0.0"

"@esri/arcgis-rest-common-types@^1.7.1":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@esri/arcgis-rest-common-types/-/arcgis-rest-common-types-1.7.1.tgz#6b0afa228c538eb15c6ec80097fd63d80f9705d0"
"@esri/arcgis-rest-common-types@^1.14.1":
version "1.14.1"
resolved "https://registry.yarnpkg.com/@esri/arcgis-rest-common-types/-/arcgis-rest-common-types-1.14.1.tgz#7f25b767dc2e5713c830690da2aed5a0e6a796f6"
integrity sha512-yWtuxTv88ZKKw4vWF+KD2C1WW9FGc5OIRME/bXiRdvYdkcx5uaM7sbUXZ43Z4rX6ZqFyLPsTlgrYPTgHeYVHlg==

"@esri/arcgis-rest-feature-service@^1.7.1":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@esri/arcgis-rest-feature-service/-/arcgis-rest-feature-service-1.7.1.tgz#7f08db72b127ac4c8c1eea23225b079d569e5692"
"@esri/arcgis-rest-feature-service@^1.14.1":
version "1.14.1"
resolved "https://registry.yarnpkg.com/@esri/arcgis-rest-feature-service/-/arcgis-rest-feature-service-1.14.1.tgz#fc67aa86077a2488083acce2afc49842ac7abeca"
integrity sha512-RD6OHzCbqUl5GLpS3B0rAM3P07cXT3bZswKRf+VdRACobXUZtMwv57SbcqeUXDcfYElUZ/sZ80YWw/vnGMSlDQ==
dependencies:
tslib "^1.7.1"

"@esri/arcgis-rest-request@^1.7.1":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@esri/arcgis-rest-request/-/arcgis-rest-request-1.7.1.tgz#55e400bd98d8417f59a2fede4a96d3034f735412"
"@esri/arcgis-rest-request@^1.14.1":
version "1.14.1"
resolved "https://registry.yarnpkg.com/@esri/arcgis-rest-request/-/arcgis-rest-request-1.14.1.tgz#add564606ebf2ed56cb74a27606c52d0a5d25f44"
integrity sha512-orHfY29vSRY4HTMRTHwOgph/I/mkPbo9U4nLW1mzv7RgbCmKR2wU0gu25+Abf9v4UvQ+fFo9TfK8jZ27+EjlCg==
dependencies:
tslib "^1.7.1"

Expand Down

0 comments on commit 08ab30f

Please sign in to comment.