Ext JS provides easy-to-use charting components that satisfy common needs, but sometimes you want to deliver an exceptional, unique user experience. This presentation will discuss how Ext JS leverages the popular and extremely powerful D3 library to create sophisticated, data-driven visualizations. This functionality helps your users understand the story behind their data, so they can make informed decisions.
5. So how did we create
these charts?
That’s
it!
then cycle through other x-types
items: {
xtype: 'd3-treemap',
}
•define the x-type of the D3 component
viewModel: vm,
• define a view model
bind: {
store: '{letters}'
}
• bind component’s store to the store
from a view model
6. The data is a tree of
objects with
•the name field
•the children array
{
name: 'A',
expanded: true,
children: [
{
name: 'B',
expanded: true,
children: [
{
name: 'D'
},
{
name: 'E'
}
]
},
{
name: 'C'
}
]
}
Data
8. How do we know to fetch
the name?
• name and text are the defaults nodeText: ['name', 'text']
nodeText: 'foo'• but it can be anything
nodeText: function (component, node) {
var record = node.data;
return record.get('firstName')
+ ' '
+ record.get('lastName');
}
• including a calculated value
9. • use the tooltip config
tooltip: {
}
When you can’t show
everything
• it’s just a Ext.tip.ToolTip
• with the extra renderer property
renderer: function (cmp, tooltip, node) {
tooltip.setHtml(node.data.get('hint'));
}
showDelay: 500,
trackMouse: false
13. Change the
colors!
• use the colorAxis config
colorAxis: {
}
range
• field - what values to colorize
field: 'name',
• scale - how to do it
scale: {
type: 'ordinal',
range: 'd3.schemeCategory20c'
}
domain
40. How D3 selections work?
a quick aside
d3.select('body') // a selection (a transient object that holds the 'body' element)
d3.select('body').selectAll('div') // a selection of all 'div' elements in the body
// joining data with selected 'div' elements:
var update = d3.select('body').selectAll('div').data([0, 1, 2, 3, 4])
// existing DOM elements in the selection
// for which no new datum was found:
update.exit()
// a selection of successfully updated DOM elements:
update
// a selection with placeholder nodes
// for data that has no corresponding DOM elements:
update.enter()
update.enter().append('div')
<div>.__data__ = 0
<div>.__data__ = 1
...
<div>.__data__ = 4
41. How ExtJS Hierarchy components work?
var layout = d3.tree();
var layoutRoot = layout(d3.hierarchy(storeRoot));
var nodes = layoutRoot.descendants();
var update = scene.selectAll(‘.x-d3-node').data(nodes);
this.addNodes(update.enter());
this.updateNodes(update);
this.removeNodes(update.exit());
51. Custom
visualizations
• d3-svg (aliased as d3)
- creates an SVG document for you
- takes care about the size
- responds to store changes
- has a life cycle of a component
onSceneSetup: function (component, scene) {
var data = ['A', 'B', 'C', 'D', ‘E',
'F', 'G', 'H', 'I', ‘J'],
color = d3.scaleOrdinal(d3.schemeCategory20c),
selection = scene.selectAll().data(data).enter(),
position = (d, i) => i * 30;
selection.append('circle')
.attr('fill', d => color(d))
.attr('cx', position)
.attr('r', 10);
selection.append('text')
.text((d, i) => i < 5 ? d : '')
.attr('x', position)
.attr('y', 30)
.attr('text-anchor', 'middle')
.attr('font-weight', 'bold');
}
{
xtype: 'd3',
listeners: {
scenesetup: 'onSceneSetup'
}
}
• d3-canvas - same as d3, but for
Canvas
- resolution independence
52.
53.
54. What’s New?
• D3 version 4.x based
- future proof
• Immutable selections
- less unexpected side effects
• Immutable data
- store data is not polluted by layout data,
due to separation between layout nodes and
data
• New and Improved APIs
- on both the Ext package and D3 library levels
• Better animations
- FTW!