@esri/cedar
Cedar is a library for crafting and sharing data visualizations powered by ArcGIS Services.
You are looking at the documentation for cedar v1.x, which is currently in beta. You can also view the v0.x documentation.
View live examples of how to use cedar
Currently Esri Cedar is in development and should be thought of as a beta or preview.
Types of Charts
Cedar currently provides a set of commonly used chart types including bar
, line
, area
, and pie
, scatter
, and radar
. In the future it will be possible for developers to create unique and custom charts that can be used by other developers with new data sources.
Getting Started
Installing Cedar
You can install cedar and it's dependencies from npm:
npm install @esri/cedar
Alternatively, you can get cedar from the unpkg.com CDN as shown below.
Loading Cedar
You can load Cedar and its dependencies by including script tags that point to the CDN or your locally installed versions of these libraries. This will make the cedar
global available to your application.
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-request@1.1.1/dist/umd/arcgis-rest-request.umd.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-feature-service@1.1.1/dist/umd/arcgis-rest-feature-service.umd.js"></script>
<script src="https://unpkg.com/@esri/cedar/dist/umd/themes/amCharts/calcite.js"></script>
<script src="https://unpkg.com/@esri/cedar/dist/umd/cedar.js"></script>
If you need to use other chart types, or want to use amCharts plugins, load the appropriate amCharts scripts before loading cedar:
<script src="https://www.amcharts.com/lib/3/pie.js"></script>
<script src="https://www.amcharts.com/lib/3/xy.js"></script>
<script src="https://www.amcharts.com/lib/3/radar.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
Using Cedar
Once cedar is loaded you can create and show the chart at a designated element. First create the element:
<div id="chart" style="height: 400px;"></div>
Then add a script that will configure cedar and render the chart:
<script>
var datasets = [{
"url": "https://services.arcgis.com/uDTUpUPbk8X8mXwl/arcgis/rest/services/Public_Schools_in_Onondaga_County/FeatureServer/0",
"name": "schools",
"query": {
"orderByFields": "Number_of_SUM DESC",
"groupByFieldsForStatistics": "Type",
"outStatistics": [{
"statisticType": "sum",
"onStatisticField": "Number_of",
"outStatisticFieldName": "Number_of_SUM"
}]
}
}];
var series = [{
"category": {"field": "Type", "label": "Type"},
"value": {"field": "Number_of_SUM", "label": "Number of Students"},
"source": "schools"
}];
var overrides = {
"categoryAxis": {
"labelRotation": -45
}
}
var elementId = 'chart';
var chart = new cedar.Chart(elementId, {"type": "bar"})
.datasets(datasets)
.series(series)
.overrides(overrides);
chart.show();
</script>
Demos
See this code pen to try creating a simple bar chart like the one above.
You can then see and modify the definitions for different types of charts.
You can also see how to use cedar with an ArcGIS API for JavaScript map in these examples:
Components of a Cedar Chart
Cedar charts are defined by the following ingredients:
- an array of
datasets
, each has, either: - a
url
to an ArcGIS feature yayer along with optional query
parameters; - ...or inline
data
, which can be a feature set, or an array of features or POJOs - an array of
series
that bind the data to the bars, lines, points, etc on the chart - and
overrides
are specific modifications to the cart type's default styles
Development Instructions
This repository is a monorepo managed using yarn workspaces and lerna
- Fork this repository and clone 'cedar' locally
cd
into the cedar
folder- Install the dependencies and initialize the monorepo with
yarn
- to run the docs site locally, start a web server at the root folder and visit
/docs
- to rebuild the script files used by the docs page whenever the source code is updated, run
yarn start
Tests
To run tests one time for all packages, run yarn test
from the monorepo root.
To run tests continually for any package as you update it's soruce code, cd
into that package and run yarn run test:watch
to continually run that package's tests as you update the source code
Dependencies
Cedar is a very thin wrapper around other libraries that do the heavy lifting. Cedar uses the amCharts JavaScripts Charts library as it's charting engine. Cedar also uses @esri/arcgis-rest-feature-service and @esri/arcgis-rest-request to query feature data. You will need to include these libraries along with cedar in your application. If you install cedar using npm or yarn these libraries will be installed for you, but you will have to make sure that your module bundler can resolve and include them in your application. If you are loading cedar from the CDN, please refer to the loading cedar section above for the <script>
tags that you will need to include.
Cedar supports the same browsers as ArcGIS Online, however you may need to include polyfills for fetch
and Promise
, if your application has to support browers that don't support fetch or Promise (i.e. IE or older versions of Safari/Android).
Versioning
For transparency into the release cycle and in striving to maintain backward compatibility, Cedar is maintained under the Semantic Versioning guidelines and will adhere to these rules whenever possible.
Releases will be numbered with the following format:
<major>.<minor>.<patch>
And constructed with the following guidelines:
- Breaking backward compatibility bumps the major while resetting minor and patch
- New additions without breaking backward compatibility bumps the minor while resetting the patch
- Bug fixes and misc changes bumps only the patch
For more information on SemVer, please visit http://semver.org/.
Licensing
Copyright 2018 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
A copy of the license is available in the repository's LICENSE file.