2 ______________________________________________
4 This document is intended to guide you through the overall design and implementation details
5 of the Drawing and Charting packages. The drawing and charting packages enable you to create
6 cross browser and cross device graphics in a versatile way.
8 The structure of this document will cover three main topics:
10 - Section I: "Draw" a versatile cross-browser/device package to draw general purpose
11 graphics and animations.
12 - Section II: "Chart" A high level presentation of the charting package and how classes are
14 - Section III: "Series" A presentation of the available series and their use.
17 ## I. The Draw Package
18 ______________________
20 The design choices in the graphics team concerning drawing were not just contrained to charting:
21 we needed a versatile tool that would enable us to create custom graphics in a cross-browser/device manner and also perform rich animations with them.
23 The Draw package contains a Surface class that abstracts the underlying graphics implementation
24 and enables the developer to create arbitrarily shaped Sprites or SpriteGroups that respond to
25 interactions like mouse events and also provide rich animations on all attributes like shape, color, size,
28 The underlying/concrete implementations for the Surface class are SVG (for SVG capable browsers) and
29 VML (for the Internet Explorer family - < 9). Surface can be considered as an interface for
30 the SVG and VML rendering engines. Surface is agnostic to its underlying implementations. Most of the methods and ways
31 to create sprites are heavily inspired by the [SVG standard](http://www.w3.org/TR/SVG/).
33 ### Creating a Drawing Surface
35 You can create a simple drawing surface without loading the Charting package at all. This can be useful
36 to create arbitrary graphics that work on all browsers/devices and animate well. For example, you could
37 create an interactive map of the United States where each state is a sprite, or also an infographic where
38 each element is also a sprite. What's interesting about making sprites and not images is that the document
39 acquires a new level of interactivity but also that being VML and SVG based the images will never loose quality
40 and can be printed correctly.
42 In order to use the Draw package directly you can create a Draw Component and (for example) append it to an `Ext.Window`:
45 var drawComponent = Ext.create('Ext.draw.Component', {
56 Ext.create('Ext.Window', {
60 items: [drawComponent]
63 In this case we created a draw component and added a sprite to it. The *type* of the sprite is *circle* so if you run this code
64 you'll see a yellow-ish circle in a Window. When setting `viewBox` to `false` we are responsible for setting the object's position and
65 dimensions accordingly.
67 Sprites can have different types. Some of them are:
69 - *circle* - To draw circles. You can set the radius by using the *radius* parameter in the sprite configuration.
70 - *rect* - To render rectangles. You can set the width and height of the rectangle by using the *width* and *height* parameters
71 in the sprite configuration.
72 - *text* - To render text as a sprite. You can set the font/font-size by using the *font* parameter.
73 - *path* - The most powerful sprite type. With it you can create arbitrary shapes by using the [SVG path syntax](http://www.w3.org/TR/SVG/paths.html).
74 You can find a quick tutorial on to how to get started with
75 the path syntax [here](https://developer.mozilla.org/en/SVG/Tutorial/Paths).
77 A Sprite is an object rendered in a Drawing surface. There are different options and types of sprites.
78 The configuration of a Sprite is an object with the following properties:
80 - **type** - (String) The type of the sprite. Possible options are 'circle', 'path', 'rect', 'text', 'square'.
81 - **width** - (Number) Used in rectangle sprites, the width of the rectangle.
82 - **height** - (Number) Used in rectangle sprites, the height of the rectangle.
83 - **size** - (Number) Used in square sprites, the dimension of the square.
84 - **radius** - (Number) Used in circle sprites, the radius of the circle.
85 - **x** - (Number) The position along the x-axis.
86 - **y** - (Number) The position along the y-axis.
87 - **path** - (Array) Used in path sprites, the path of the sprite written in SVG-like path syntax.
88 - **opacity** - (Number) The opacity of the sprite.
89 - **fill** - (String) The fill color.
90 - **stroke** - (String) The stroke color.
91 - **stroke-width** - (Number) The width of the stroke.
92 - **font** - (String) Used with text type sprites. The full font description. Uses the same syntax as the CSS `font` parameter.
93 - **text** - (String) Used with text type sprites. The text itself.
95 Additionally there are three transform objects that can be set with `setAttributes` which are `translate`, `rotate` and
98 For translate, the configuration object contains x and y attributes for the translation. For example:
100 sprite.setAttributes({
107 For rotate, the configuration object contains x and y attributes for the center of the rotation (which are optional),
108 and a degrees attribute that specifies the rotation in degrees. For example:
110 sprite.setAttributes({
116 For scale, the configuration object contains x and y attributes for the x-axis and y-axis scaling. For example:
118 sprite.setAttributes({
125 ### Interacting with a Sprite
127 Now that we've created a draw surface with a sprite in it, let's dive into how to interact with the sprite.
128 We can get a handle to the sprite we want to modify by adding that sprite imperatively to the surface:
131 // Create a draw component
132 var drawComponent = Ext.create('Ext.draw.Component', {
136 // Create a window to place the draw component in
137 Ext.create('Ext.Window', {
141 items: [drawComponent]
144 // Add a circle sprite
145 var myCircle = drawComponent.surface.add({
153 // Now do stuff with the sprite, like changing its properties:
154 myCircle.setAttributes({
158 // or animate an attribute on the sprite
166 // Add a mouseup listener to the sprite
167 myCircle.addListener('mouseup', function() {
168 alert('mouse upped!');
171 In this example we've seen how we can add events, set sprite attributes and animate these attributes using the
172 draw package. As you can see this package is a versatile abstraction layer over the graphics we can do. What's
173 most interesting about this class is that we aren't tied to a specific shape or structure; also all elements
174 support events, setting attributes and creating animations. Most important of all, all of this is compatible in all browsers and
179 So now that we learnt about the expressive power of the draw package, let's dive into charts. The chart
180 package consists of a hierarchy of classes that define a chart container (something like a surface but more specific for
181 handling charts); axes, legends, series, labels, callouts, tips, cartesian and radial coordinates, and specific series
182 like Pie, Area, Bar, etc.
184 In this section we will cover how these classes are tied together and what bits of functionality go into each of these
185 classes. We won't cover each particular series, since that is done in the next section.
189 The Chart class is the main drawing surface for series. It manages the rendering of each series and also how axes are
190 drawn and defined. Chart also delegates mouse events over to different areas of the Chart like Series, Axes, etc.
191 The Chart class extends Draw Component.
193 A Chart instance has access to:
195 - axes - Accessed through `chart.axes`. All the axes being defined and drawn for this visualization. This is a mixed collection.
196 - series - Accessed through `chart.series`. All the series being drawn for the chart. This could be line, bar, scatter, etc. This is also a mixed collection.
197 - legend - The legend box object and its legend items.
199 The chart instance supports custom events that can be triggered right before and during the rendering of the visualization.
200 We can add handlers for these events by using:
203 'refresh': function() {
204 alert('(re)drawing the chart');
208 Chart also delegates events like `itemmousedown` and `itemmouseup` to the series so that we can append
209 listeners to those objects and get the target sprite of the event.
213 The chart configuration object accepts a `legend` parameter to enable legend items for each series and
214 to set the position of the legend. These options are passed into the constructor of the chart. For example:
216 var chart = Ext.create('Ext.chart.Chart', {
226 axes: [/*set an axis configuration*/],
229 series: [/*set series configuration*/]
232 Each series object needs to have the `showInLegend` parameter set to `true` in order to be in the legend list.
236 The `axis` package contains an `Abstract` axis class that is extended by `Axis` and `Radial` axes. `Axis` represents
237 a `Cartesian` axis and `Radial` uses polar coordinates to represent the information for polar based visualizations like
238 Pie and Radar series. Axes are bound to the type of data we're trying to represent. There are axes for categorical
239 information (called `Category` axis) and also axis for quantitative information like `Numeric`. For time-based information
240 we have the `Time` axis that enables us to render information over a specific period of time, and to update that period of time
241 with smooth animations. If you'd like to know more about each axis please go to the axis package documentation. Also, you will find
242 configuration examples for axis in the bottom series examples.
244 An axis contains divisions and subdivisions of values, represented by major and minor ticks. These can be adjusted automatically
245 or manually to some specified interval, maximum and minimum values. The configuration options `maximum`, `minimum`, `majorTickSteps` and
246 `minorTickSteps` in the `Numeric` axis are used to change the configuration and placement of the major and minor ticks. For example, by
253 title: 'Number of Hits',
255 //one minor tick between two major ticks
261 title: 'Month of the Year'
264 The following configuration will produce minor ticks in the left axis
267 {@img Ticks.jpg Series Image}
272 The drawing and charting package has also the power to create
273 linear gradients. The gradients can be defined in the Chart configuration
274 object as an array of gradient configurations. For each gradient configuration
275 the following parameters are specified:
277 * **id** - string - The unique name of the gradient.
278 * **angle** - number, optional - The angle of the gradient in degrees.
279 * **stops** - object - An object with numbers as keys (from 0 to 100) and style objects as values.
281 Each key in the stops object represents the percentage of the fill on the specified color for
313 You can apply a gradient to a sprite by setting a reference to a gradient **id** in
314 the fill property. This reference is done via a url syntax. For example:
316 sprite.setAttributes({
317 fill: 'url(#gradientId)'
323 A `Series` is an abstract class extended by concrete visualizations like
324 `Line` or `Scatter`. The `Series` class contains code that is common to all of these series, like event handling, animation
325 handling, shadows, gradients, common offsets, etc. The `Series` class is enhanced with a set of *mixins* that provide functionality
326 like highlighting, callouts, tips, etc. A `Series` will contain an array of `items` where each item contains information about the
327 positioning of each element, its associated `sprite` and a `storeItem`. The series also share the `drawSeries` method that updates
328 all positions for the series and then renders the series.
332 The Chart configuration object may have a `theme` property with a string value that references a builtin theme name.
334 var chart = Ext.create('Ext.chart.Chart', {
336 /* Other options... */
339 A Theme defines the style of the shapes, color, font, axes and background
340 of a chart. The theming configuration can be very rich and complex:
418 We can also create a seed of colors that will be the base for the entire theme just by creating
419 a simple array of colors in the configuration object like:
422 colors: ['#aaa', '#bcd', '#eee']
425 When setting a base color the theme will generate an array of colors that match the base color:
431 You can create a custom theme by extending from the base theme. For example, to create a custom `Fancy` theme we can do:
433 var colors = ['#555',
439 var baseColor = '#eee';
441 Ext.define('Ext.chart.theme.Fancy', {
442 extend: 'Ext.chart.theme.Base',
444 constructor: function(config) {
445 this.callParent([Ext.apply({
467 var chart = Ext.create('Ext.chart.Chart', {
470 /* Other options here... */
476 The following section will go through our available series/visualizations, introduce each
477 one of them and show a complete configuration example of the series. The example will include the `Chart`,
478 `Axis` and `Series` configuration options.
482 Creates a Stacked Area Chart. The stacked area chart is useful when displaying multiple aggregated layers of information.
483 As with all other series, the Area Series must be appended in the *series* Chart array configuration.
486 {@img Area.jpg Series Image}
489 A typical configuration object for the area series could be:
491 var chart = Ext.create('Ext.chart.Chart', {
492 renderTo: Ext.getBody(),
501 // Add Numeric and Category axis
506 fields: ['data1', 'data2', 'data3'],
507 title: 'Number of Hits',
517 adjustMinimumByMajorUnit: 0
522 title: 'Month of the Year',
531 // Add the Area Series
537 yField: ['data1', 'data2', 'data3'],
547 Creates a Bar Chart. A Bar Chart is a useful visualization technique to display quantitative information for different
548 categories that can show some progression (or regression) in the dataset.
549 As with all other series, the Bar Series must be appended in the *series* Chart array configuration. See the Chart
550 documentation for more information.
553 {@img Bar.jpg Series Image}
556 A typical configuration object for the bar series could be:
558 var chart = Ext.create('Ext.chart.Chart', {
559 renderTo: Ext.getBody(),
569 title: 'Number of Hits'
574 title: 'Month of the Year'
584 display: 'insideEnd',
586 renderer: Ext.util.Format.numberRenderer('0'),
587 orientation: 'horizontal',
589 'text-anchor': 'middle'
597 Creates a Line Chart. A Line Chart is a useful visualization technique to display quantitative information for different
598 categories or other real values (as opposed to the bar chart), that can show some progression (or regression) in the dataset.
599 As with all other series, the Line Series must be appended in the *series* Chart array configuration. See the Chart
600 documentation for more information.
603 {@img Line.jpg Series Image}
606 A typical configuration object for the line series could be:
608 var chart = Ext.create('Ext.chart.Chart', {
609 renderTo: Ext.getBody(),
620 fields: ['data1', 'data2', 'data3'],
621 title: 'Number of Hits'
626 title: 'Month of the Year'
629 // Add two line series
656 A marker configuration object contains the same properties used to create a Sprite.
657 You can find the properties used to create a Sprite in the Sprite section above.
662 Creates a Pie Chart. A Pie Chart is a useful visualization technique to display quantitative information for different
663 categories that also have a meaning as a whole.
664 As with all other series, the Pie Series must be appended in the *series* Chart array configuration. See the Chart
665 documentation for more information. A typical configuration object for the pie series could be:
668 {@img Pie.jpg Series Image}
671 A typical configuration object for the pie series could be:
673 var chart = Ext.create('Ext.chart.Chart', {
679 renderTo: Ext.getBody(),
684 theme: 'Base:gradients',
706 Creates a Radar Chart. A Radar Chart is a useful visualization technique for comparing different quantitative values for
707 a constrained number of categories.
708 As with all other series, the Radar series must be appended in the *series* Chart array configuration. See the Chart
709 documentation for more information.
711 {@img Radar.jpg Series Image}
713 A typical configuration object for the radar series could be:
715 var chart = Ext.create('Ext.chart.Chart', {
720 renderTo: Ext.getBody(),
731 // Add two series for radar.
764 Creates a Scatter Chart. The scatter plot is useful when trying to display more than two variables in the same visualization.
765 These variables can be mapped into x, y coordinates and also to an element's radius/size, color, etc.
766 As with all other series, the Scatter Series must be appended in the *series* Chart array configuration. See the Chart
767 documentation for more information on creating charts.
769 {@img Scatter.jpg Series Image}
771 A typical configuration object for the scatter series could be:
773 var chart = Ext.create('Ext.chart.Chart', {
778 renderTo: Ext.getBody(),
782 fields: ['data1', 'data2', 'data3'],
783 title: 'Number of Hits'
819 Creates a Gauge Chart. Gauge Charts are used to show progress in a certain variable. There are two ways of using the Gauge chart.
820 One is setting a store element into the Gauge and selecting the field to be used from that store. Another one is instantiating the
821 visualization and using the `setValue` method to adjust the value you want.
823 {@img Gauge.jpg Series Image}
825 A chart/series configuration for the Gauge visualization could look like this:
842 colorSet: ['#F49D10', '#ddd']
847 In this configuration we create a special Gauge axis to be used with the gauge visualization (describing half-circle markers), and also we're
848 setting a maximum, minimum and steps configuration options into the axis. The Gauge series configuration contains the store field to be bound to
849 the visual display and the color set to be used with the visualization.