SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
React + Redux + d3
Teemu Kurppa, ŌURA
teemu@ouraring.com
www.ouraring.com
the world's first wellness ring
Head of Cloud
I work at
• Declarative UI Library
• Battle-tested by Facebook
• Component-based
• Inline HTML with JSX
• Predictable state management for JS Apps
• Great tooling: logging, hot loading, time travel,…
d3.js
d3 - a lot of good stuff
• Handling data: Scales, Interpolators, Time Intervals, Time & Number formats
• Drawing: Paths, Areas, Shapes, Curves, Axes
• Data Structures for Visualization: Voronoi, Stack, Quadtrees, Polygons
• Drawing maps: Projections, Spherical Math, Geopaths
• Animations and Behaviour: Transitions, Easing, Zooming, Dragging, Forces
d3 - problems
• No components: code gets unwieldy very quickly
• State management mixed with UI code
d3 class pattern
class D3SeriesBarChart {
constructor(el, props, state) {
// setup code
}
update(el, props, state) {
// data-dependent code
}
}
React wrapper for d3
class SeriesBarChart extends Component {
componentDidMount() {
this.chart = new D3SeriesBarChart(this.svg,
this.props,
this.state);
}
componentDidUpdate() {
this.chart.update(this.svg, this.props, this.state);
}
render() {
return (
<svg ref={svg => this.svg = svg}
width={this.props.width}
height={this.props.height}>
</svg>
);
}
}
React wrapper for d3
class SeriesBarChart extends Component {
componentDidMount() {
this.chart = new D3SeriesBarChart(this.svg,
this.props,
this.state);
}
componentDidUpdate() {
this.chart.update(this.svg, this.props, this.state);
}
render() {
return (
<svg ref={svg => this.svg = svg}
width={this.props.width}
height={this.props.height}>
</svg>
);
}
}
React wrapper for d3
var T = React.PropTypes;
SeriesBarChart.propTypes = {
width: T.number.isRequired,
height: T.number.isRequired,
data: T.shape({
x: T.arrayOf(T.number),
y: T.arrayOf(T.arrayOf(T.number)),
}).isRequired,
mode: T.string.isRequired
}
Demo Component
class Demo extends Component {
render() {
return (
<div className={classNames(styles.demo)}>
<form>
{this.makeRadio('grouped', this.props.onSelectGrouped)}
{this.makeRadio('stacked', this.props.onSelectStacked)}
</form>
<SeriesBarChart width={960} height={500}
data={this.props.data}
mode={this.props.mode}/>
<div>
<button onClick={this.props.onGenerateData}>
Generate Data
</button>
</div>
</div>
);
}
// …
}
Demo Component
class Demo extends Component {
// …
makeRadio(mode, onChange) {
return (
<label><input type=“radio"
name=“mode"
value={mode}
onChange={onChange}
checked={this.props.mode === mode}/>
{mode}
</label>
)
}
}
Redu Reducer
// reducers.js
const initialState = {
data: createData(),
mode: 'grouped'
};
function demo(state = initialState, action) {
switch (action.type) {
case CHANGE_MODE:
return { ...state, mode: action.mode };
case GENERATE_DATA:
return { ...state, data: createData() };
default:
return state;
}
}
const rootReducer = combineReducers({
demo,
});
export default rootReducer;
Component CSS
// SeriesBarChart.jsx
import classNames from 'classnames';
const styles = require('./SeriesBarChart.scss');
class SeriesBarChart extends Component {
render() {
return (
<svg className={classNames(styles.seriesbarchart)}
ref={svg => this.svg = svg}
width={this.props.width}
height={this.props.height}>
</svg>
);
}
}
Component CSS
// SeriesBarChart.scss
.seriesbarchart {
:global {
.axis text {
fill: blue;
}
}
}
Thanks! Questions?
We are hiring:
Python backend developers
web front-end developers
Follow @teemu on Twitter to stay in touch.
Email: teemu@ouraring.com

Mais conteúdo relacionado

Semelhante a React + Redux + d3.js

Stat Design3 18 09
Stat Design3 18 09Stat Design3 18 09
Stat Design3 18 09
stat
 

Semelhante a React + Redux + d3.js (20)

Introduction to D3
Introduction to D3 Introduction to D3
Introduction to D3
 
D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute intro
 
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tdd
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
 
D3
D3D3
D3
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
The D3 Toolbox
The D3 ToolboxThe D3 Toolbox
The D3 Toolbox
 
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web Apps
 
D3 data visualization
D3 data visualizationD3 data visualization
D3 data visualization
 
Dreamforce 2014 - Introduction to d3.js
Dreamforce 2014 - Introduction to d3.jsDreamforce 2014 - Introduction to d3.js
Dreamforce 2014 - Introduction to d3.js
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
Stat Design3 18 09
Stat Design3 18 09Stat Design3 18 09
Stat Design3 18 09
 
wk5ppt1_Titanic
wk5ppt1_Titanicwk5ppt1_Titanic
wk5ppt1_Titanic
 
Utahjs D3
Utahjs D3Utahjs D3
Utahjs D3
 

Mais de Teemu Kurppa

Mais de Teemu Kurppa (7)

fast.ai - Learning Deep Learning
fast.ai - Learning Deep Learningfast.ai - Learning Deep Learning
fast.ai - Learning Deep Learning
 
Managing data workflows with Luigi
Managing data workflows with LuigiManaging data workflows with Luigi
Managing data workflows with Luigi
 
Quick'n'Dirty Tornado Intro
Quick'n'Dirty Tornado IntroQuick'n'Dirty Tornado Intro
Quick'n'Dirty Tornado Intro
 
Early stage startups
Early stage startupsEarly stage startups
Early stage startups
 
Mobile Startups - Why to focus on mobile?
Mobile Startups - Why to focus on mobile?Mobile Startups - Why to focus on mobile?
Mobile Startups - Why to focus on mobile?
 
Platform = Stage. How to choose a mobile development platform?
Platform = Stage. How to choose a mobile development platform?Platform = Stage. How to choose a mobile development platform?
Platform = Stage. How to choose a mobile development platform?
 
Leaks & Zombies
Leaks & ZombiesLeaks & Zombies
Leaks & Zombies
 

Último

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

React + Redux + d3.js

  • 1. React + Redux + d3 Teemu Kurppa, ŌURA
  • 2. teemu@ouraring.com www.ouraring.com the world's first wellness ring Head of Cloud I work at
  • 3. • Declarative UI Library • Battle-tested by Facebook • Component-based • Inline HTML with JSX
  • 4. • Predictable state management for JS Apps • Great tooling: logging, hot loading, time travel,…
  • 6. d3 - a lot of good stuff • Handling data: Scales, Interpolators, Time Intervals, Time & Number formats • Drawing: Paths, Areas, Shapes, Curves, Axes • Data Structures for Visualization: Voronoi, Stack, Quadtrees, Polygons • Drawing maps: Projections, Spherical Math, Geopaths • Animations and Behaviour: Transitions, Easing, Zooming, Dragging, Forces
  • 7. d3 - problems • No components: code gets unwieldy very quickly • State management mixed with UI code
  • 8.
  • 9. d3 class pattern class D3SeriesBarChart { constructor(el, props, state) { // setup code } update(el, props, state) { // data-dependent code } }
  • 10. React wrapper for d3 class SeriesBarChart extends Component { componentDidMount() { this.chart = new D3SeriesBarChart(this.svg, this.props, this.state); } componentDidUpdate() { this.chart.update(this.svg, this.props, this.state); } render() { return ( <svg ref={svg => this.svg = svg} width={this.props.width} height={this.props.height}> </svg> ); } }
  • 11. React wrapper for d3 class SeriesBarChart extends Component { componentDidMount() { this.chart = new D3SeriesBarChart(this.svg, this.props, this.state); } componentDidUpdate() { this.chart.update(this.svg, this.props, this.state); } render() { return ( <svg ref={svg => this.svg = svg} width={this.props.width} height={this.props.height}> </svg> ); } }
  • 12. React wrapper for d3 var T = React.PropTypes; SeriesBarChart.propTypes = { width: T.number.isRequired, height: T.number.isRequired, data: T.shape({ x: T.arrayOf(T.number), y: T.arrayOf(T.arrayOf(T.number)), }).isRequired, mode: T.string.isRequired }
  • 13. Demo Component class Demo extends Component { render() { return ( <div className={classNames(styles.demo)}> <form> {this.makeRadio('grouped', this.props.onSelectGrouped)} {this.makeRadio('stacked', this.props.onSelectStacked)} </form> <SeriesBarChart width={960} height={500} data={this.props.data} mode={this.props.mode}/> <div> <button onClick={this.props.onGenerateData}> Generate Data </button> </div> </div> ); } // … }
  • 14. Demo Component class Demo extends Component { // … makeRadio(mode, onChange) { return ( <label><input type=“radio" name=“mode" value={mode} onChange={onChange} checked={this.props.mode === mode}/> {mode} </label> ) } }
  • 15. Redu Reducer // reducers.js const initialState = { data: createData(), mode: 'grouped' }; function demo(state = initialState, action) { switch (action.type) { case CHANGE_MODE: return { ...state, mode: action.mode }; case GENERATE_DATA: return { ...state, data: createData() }; default: return state; } } const rootReducer = combineReducers({ demo, }); export default rootReducer;
  • 16. Component CSS // SeriesBarChart.jsx import classNames from 'classnames'; const styles = require('./SeriesBarChart.scss'); class SeriesBarChart extends Component { render() { return ( <svg className={classNames(styles.seriesbarchart)} ref={svg => this.svg = svg} width={this.props.width} height={this.props.height}> </svg> ); } }
  • 17. Component CSS // SeriesBarChart.scss .seriesbarchart { :global { .axis text { fill: blue; } } }
  • 18. Thanks! Questions? We are hiring: Python backend developers web front-end developers Follow @teemu on Twitter to stay in touch. Email: teemu@ouraring.com