(Ebook) Social Data Visualization with HTML5 and JavaScript by Timms, Simon ISBN 9781782166542, 1782166548download
(Ebook) Social Data Visualization with HTML5 and JavaScript by Timms, Simon ISBN 9781782166542, 1782166548download
https://ebooknice.com/product/social-data-visualization-with-
html5-and-javascript-55923426
https://ebooknice.com/product/data-visualization-representing-information-
on-modern-web-55918718
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
https://ebooknice.com/product/source-code-analytics-with-roslyn-and-
javascript-data-visualization-55892642
(Ebook) Data Visualization with Python and JavaScript by Kyran
Dale ISBN 9781098111878, 1098111877
https://ebooknice.com/product/data-visualization-with-python-and-
javascript-45157460
https://ebooknice.com/product/mastering-javascript-design-patterns-6724550
https://ebooknice.com/product/data-visualization-with-javascript-5097604
https://ebooknice.com/product/data-visualization-with-python-and-
javascript-scrape-clean-explore-transform-your-data-5391374
https://ebooknice.com/product/data-visualization-with-python-and-
javascript-scrape-clean-explore-transform-your-data-57564128
Social Data Visualization with
HTML5 and JavaScript
Simon Timms
BIRMINGHAM - MUMBAI
Social Data Visualization with HTML5 and JavaScript
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78216-654-2
www.packtpub.com
Author Proofreaders
Simon Timms Amy Guest
Simran Bhogal
Reviewers Ameesha Green
Jonathan Petitcolas
Saurabh Saxena Indexer
Tejal R. Soni
Acquisition Editor
James Jones Graphics
Ronak Dhruv
Commissioning Editor
Mohammed Fahad Production Coordinator
Adonia Jones
Technical Editors
Dennis John Cover Work
Gaurav Thingalaya Adonia Jones
Project Coordinator
Amigya Khurana
About the Author
Simon Timms is a developer who works in the oil and gas industry in Calgary,
Alberta. He has a BSc in Computing Science from the University of Alberta and
a Masters from Athabasca University. He is interested in distributed systems,
visualization, and the acquisition of ice-cream.
This is his first book, but he blogs frequently on diverse topics such as code contracts
and cloud computing at blog.simontimms.com. He is involved in the local .NET and
JavaScript community, and speaks frequently at conferences.
I would like to thank the countless open source developers who have
made books like this possible through their selfless creation of tools
and technologies , such as d3.js and node.js. These are the thinkers,
the makers, and the heroes who make the future possible.
Most of all, I would like to thank my wife and son for their undying
support while I spent my evenings writing. Without them, I would
be without purpose.
About the Reviewers
He holds a rank among the top 100 programmers on Hacker Rank in India. He
loves to experiment with technologies such as JavaScript, HTML5, CSS3, Rails,
and node.js. He is an open source contributor to Spree Commerce. He is used to
spending the rest of his time on Udacity and Code School to learn about new
technologies and tools.
I would like thank my mom and dad who continually gave me their
support when I needed it the most.
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and
as a print book customer, you are entitled to a discount on the eBook copy. Get in touch
with us at service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.
TM
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• On demand and accessible via web browser
Chapter 5: Twitter 55
Getting access to the APIs 56
Setting up a server 58
OAuth 58
Visualization 62
Server side 62
Client side 64
Summary 66
Chapter 6: Stack Overflow 67
Authenticating 67
Creating a visualization 68
Filters 73
Summary 74
Chapter 7: Facebook 75
Creating an app 75
Using the API 78
Retrieving data 80
Visualizing 80
Summary 82
Chapter 8: Google+ 83
Creating an app 83
Retrieving data 84
Visualization 86
Summary 88
Index 89
[ ii ]
Preface
The world is an interesting place, about this there can be no doubt. We experience
the world through our senses, which gather data to be processed by our brains.
Frequently the world is disordered, requiring us to think long and hard to get
meaning out of things. To ease this process, data can be transformed into other forms
that are simpler to understand.
This book is about molding data into a form which is more understandable. It is
about taking some of the richest data sources of our time—social networks—and
turning their vast array of data into an understandable format. To that effect, we
make use of the latest in HTML and JavaScript.
Chapter 2, JavaScript and HTML5 for Visualizations, looks at new features in HTML and
JavaScript that present opportunities for visualizing data. It discusses both canvas
and Scalable Vector Graphics.
Chapter 3, OAuth, examines the often confusing OAuth technology and shows how it
can be used to delegate authority to our application. This is because much of the data
on social media sites is private and there might be times when we need to get this data.
Chapter 4, JavaScript for Visualization, looks at Raphaël.js and d3.js which are great
JavaScript libraries that can reduce the pain involved in building visualizations by
hand, which is otherwise a time-consuming and error-prone task.
Chapter 5, Twitter, looks at how to retrieve data from Twitter and use it to build
a visualization.
Preface
Chapter 6, Stack Overflow, looks at how to retrieve the data API of the ever popular
Stack Overflow, which presents some tantalizing opportunities for visualization that
can be used to create an interactive graph.
Chapter 7, Facebook, explores the Facebook JavaScript API and how to use it to retrieve
data to use as the basis of our next visualization. In my mind, the original and still
the largest social media network on the planet is Facebook.
Chapter 8, Google+, looks at Google's latest foray into social media and how to retrieve
data to create a force-directed graph.
Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows: "Once permissions are assigned, Facebook
will redirect the user back to your redirect_uri allowing you to leverage the token
to query the Facebook API."
[2]
Preface
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
function onSignInCallback(authResult) {
gapi.client.load('plus','v1', function(){
if (authResult['access_token']) {
$('#gConnect').hide();
retrieveFriends();
} else if (authResult['error']) {
console.log('There was an error: ' + authResult['error']);
$('#gConnect').show();
}
console.log('authResult', authResult);
});
}
New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: "This can
be done from the API Access tab in which you should click on Create an OAuth 2.0
client ID…."
[3]
Preface
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for us
to develop titles that you really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you would report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the errata submission form link,
and entering the details of your errata. Once your errata are verified, your submission
will be accepted and the errata will be uploaded on our website, or added to any list of
existing errata, under the Errata section of that title. Any existing errata can be viewed
by selecting your title from http://www.packtpub.com/support.
[4]
Preface
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at questions@packtpub.com if you are having a problem with
any aspect of the book, and we will do our best to address it.
[5]
Visualizing Data
A scant few years ago this book would not have been possible. The rapid expansion
in social media, data processing, and web technologies has enabled a fusion of
divergent fields. From this fusion we can create fascinating displays of data about
exotic topics. The beauty that is inherited in data can be exposed in a fashion that is
accessible to the masses. Visualizations such as the following word map (http://
gigaom.com/2013/07/19/the-week-in-big-data-on-twitter-visualized/), can
unlock hidden information while delighting users with an extraordinary experience:
The size of words in this visualization gives a hint as to their frequency of use.
The placement of words is calculated by an algorithm designed to create a
pleasing visualization.
In this chapter we'll be looking at how the growth in data is so great that we need to
change our tools for looking at it.
Visualizing Data
The growth in data is inevitable as people put more of their lives online. The
adoption of smartphones has turned everybody into a photographer. Instagram, a
popular image sharing site, gathers some 40 million photos a day. One wonders how
many photos of people's meals the world really needs. In the past few months there
has been an explosion of video clip sharing sites such as Vine and Instagram, which
generate massive amounts of data. A myriad of devices are being created to extend
the reach of smartphones beyond gathering photographic data. The latest generation
of smartphones include temperature, humidity, and pressure sensors in addition to
the commonplace GPS, gyroscopic, geomagnetic, and acceleration sensors. These
allow for recording an accurate representation of the world around the user.
[8]
Chapter 1
At the same time, the cost per gigabyte of storing data is decreasing. Cheaper storage
makes it economical to track data that would have previously been thrown away.
In the 1970s, BBC had a policy of destroying recordings of TV programs once they
reached a certain age. This resulted in the loss of more than a hundred episodes of
the cult classic Doctor Who. The low data density of storage media available in the
1960s meant that retaining complete archives was cost-prohibitive. Such deletion
now would be unimaginable as the cost of storing video has dropped substantially.
The cost for storing a gigabyte of information on Amazon's servers is on the order
of a penny-a-month and can be even cheaper if the right expertise are available in
house. The Parkinson's law states the following:
In a restatement of this law, in our case, it would be "the amount of data will grow to fill
the space available to it."
The growth in data has made our lives more difficult. While the amount of data
has been growing, our ability to understand them has remained more or less
stagnant. The tools available to refine and process large quantities of data have not
kept pace. Running simple queries against gigabytes of data is a time-consuming
process. Queries such as "list all the tweets that contain the word 'Pepsi'" cannot be
realistically completed on anything but a cluster of machines working in parallel.
Even when the result is returned, the number of matching records is too large to be
processed by a single person or even a team of people.
The term "Big Data" is commonly used to describe the sorts of very large datasets
that are becoming more common. Like most terms that have become marketing
terms, Big Data is defined differently by different people and companies. In this
book we'll think of it as any quantity where running simple queries using traditional
database tools on consumer grade hardware is difficult due to computational,
storage, or retrieval limits.
[9]
Visualizing Data
Consider a coffee shop; this is not a company that one would expect would produce
a great deal of data. However, consumers who are hungry for data are starting to
demand to know from whence the beans for their favorite coffee came, for how long
they were roasted, and how they were brewed. A similar program called ThisFish
already exists that allows consumers to track the origin of their seafood (http://
thisfish.info) all the way back to when it was caught. Providing data about its
coffee in an easily accessible form becomes a selling feature for the coffee shop. The
following screenshot shows a typical label from a coffee shop showing the source of
the beans, roasting time, and organic certification:
People are very interested in data, especially data about their habits. But as interested
as people are in data, nobody wants to trawl through an Excel file. They would like
to see data presented to them in an accessible and fun way.
The best data visualizations arise from a sense of passion in the subject of your
visualization. Don't we all work better if the subject of our work is something
in which we're really interested? Great visualizations don't just educate their
viewers, they delight their users. They present data in a novel way that is still easily
understood by the audience. Great visualizations strip away the excess information
to reveal a kernel of information. At the same time, great visualizations have a
degree of beauty to them. Don't be fooled into thinking that this beauty serves no
purpose. In a world of ever shortening attention spans, there is still a place for
beauty. We still stop and pause for a moment when presented with as aesthetically
pleasing visualization. The extra few seconds that the beauty buys you may be what
keep people interested long enough to take in your meaning.
[ 10 ]
Chapter 1
Even the most benign data has a story worth telling. To most, there is very little
that seems less interesting than tax revenue statistics. However, there have been
some very compelling stories found within that raft of data. The data tells a story
about which companies are avoiding paying tax revenues. It tells another story
about which cities have the highest per capita income. Within that boring data are
countless interesting stories that can be extracted though a passionate application of
data visualization.
Data is a lot of things, but it is never boring. You can get excited about data too and
uncover the hidden stories in any dataset. In every dataset, there is an interesting
conclusion waiting to be exposed by a data sleuth such as yourself. You should share
your excitement with others in the form of data visualizations.
As we saw previously, the amount of data in the world is huge. The first step in
most data visualizations is to filter and aggregate the data down into a dataset that
contains the key insights you want to share with your users. If it sounds like extracting,
meaning that it is an opinionated process, that's because it is. Presenting an unbiased
visualization is just about impossible. That's okay, though. Not everybody is an expert
on your data, and guiding others to your conclusions is valuable.
You'll find that the data you have from which to derive visualizations is hardly
ever in a format you can use right off the bat. You will need to manipulate the data
to get it into a form you can use. If your source dataset is small enough and your
manipulations sufficiently trivial, you may be able to do your preprocessing in
Microsoft Excel. Excel provides a suite of tools for sorting, filtering, and summarizing
data. There are numerous books and articles available on how to work with data in
Excel as well as how to create graphs, but we won't delve into it here.
The problem with Excel is that it is old news. Everybody has seen the rather
pedestrian graphs you get out of Excel. With the exception of a couple, these are the
same charts which were produced by Excel 95. Where is the excitement about data?
It seems to be missing. If you create your visualizations wholly in Excel, your users
are going to miss out on your enthusiasm for data.
[ 11 ]
Random documents with unrelated
content Scribd suggests to you:
fuggirà più dalle mani.
Nel 1833 Rosas ha trentacinque anni, di aspetto europeo, di biondi
capelli, di colorito bianchissimo, di occhi azzurri, porta soltanto la
barba tagliata all'altezza della bocca. Bello il suo sguardo se fosse
dato giudicarlo, avendo per costume volgerlo a terra anche in faccia
agli amici, ch'egli conosce avergli sempre nemici. Dolce la voce, e
all'uopo, insinuante la parola; d'animo vigliacco e ferocemente
astuto: proclive alle mistificazioni, ne faceva suo scopo esclusivo
prima ch'ei s'occupasse di cose più serie; ora gli è una distrazione e
nulla più. Come si vedrà da questi due esempi, le sue mistificazioni
erano brutali, come il suo carattere che accoppia la scaltrezza alla
ferocia.
Una sera invitato a commensale un amico, nascosto il vino destinato
alla cena, lasciò solo sulla mensa una bottiglia di quel Leroy, alla cui
fama non manca che l'esser nato al tempo di Molière. L'amico,
gustato il liquore e trovatolo abbastanza piacevole, ne votò la
bottiglia lungo la cena, mentre Rosas non prese che acqua. Nella
notte l'amico ebbe quasi a morirne. Rosas ne rise molto, e se quegli
fosse morto ne avrebbe, fuor di dubbio, riso moltissimo.
Era suo passatempo, allorchè veniva a lui qualche pueblero (abitante
della città), costringerlo a salire i più sfrenati cavalli, e la sua gioia
era maggiore, se più grave la caduta del cavaliere.
Nel governo poi tra i più difficili affari, erano suoi consiglieri i giullari
e i buffoni. Nell'assedio di Buenos-Ayres nel 1829, avea quattro di
questi infelici presso di sè; creatili monaci, erasene, di privata
autorità, costituito priore; e li chiamava fray Bygûa, fray Chaja, fray
Lechusa, e fray Biscacha [11]. Amava pure immensamente i confetti,
ed aveane nella sua tenda d'ogni maniera, nè con minore affetto li
amavano i frati. Or come spesso avveniva che ne mancasse buon
numero, Rosas chiamava i fratelli a confessione. Sapendo essi qual
premio la menzogna aspettasse, il reo confessava, che spogliato
all'istante degli abiti, venia vergheggiato da' suoi compagni.
Tutti conoscono in Buenos-Ayres, Eusebio il molatto di Rosas, cui un
giorno di pubblica festa, prese il talento di fare per lui, ciò che
madama Dubbarry faceva a Lucienne del suo negro Zamore; ed
Eusebio vestito degli abiti del governatore ebbe a ricevere gli omaggi
delle autorità al luogo del suo signore.
Costui dunque notissimo, lo ripetiamo a Buenos-Ayres, fu vittima
d'un capriccio terribile, come solo Rosas può averne. Chiamatolo a
sè, accusandolo capo d'una cospirazione per pugnalarlo, ordinò si
arrestasse malgrado le sue proteste di devozione. I giudici, cui
bastava l'accusa di Rosas, per non inquietarsi se Eusebio era
colpevole o no, condannarono l'infelice alla pena del capo.
Preparatosi all'estremo supplizio, si confessò e fu tradotto sul luogo
dell'esecuzione, ove aspettavalo il carnefice co' suoi ministri. Allora
quasi per incanto, comparve Rosas e dicendo al meschino, presso a
morir di paura, che sua figlia Manuelita presa d'amore per lui, voleva
sposarlo, lo graziò!
Manuelita al dì d'oggi è sui vent'otto o trent'anni; se non può dirsi
una donna bella, è, ciò che val meglio, una piacevol persona, di
figura distinta, di tatto profondo, capricciosa come un'europea.
Come figlia di Rosas, fu fatta segno alle calunnie. La dissero erede
dei feroci istinti del padre e dimentica, come quelle figlie di
imperatori romani, dell'amore filiale per un amore più tenero e meno
cristiano.
Niente di più falso. Manuelita è rimasta zitella per molte ragioni;
Rosas talvolta sente il bisogno d'essere amato, e sa che l'unico su cui
possa contare, è l'amor di sua figlia; d'altronde nessuna potente
famiglia di Buenos-Ayres cercò di congiungersi col dittatore. Infine è
pur da notarsi che Rosas ne' suoi sogni di regno crede veder
l'avvenire di Manuelita fecondo di nozze più aristocratiche di quelle
abbia diritto a pretendere in questo momento.
Manuelita non è punto crudele; è anzi noto a tutti coloro cui non
offende amore di parte, che dessa è un freno continuo alla collera
del padre, sempre pronta ad irrompere. Fanciulla ancora, strappava
le grazie da Rosas con un mezzo stranissimo. Spogliato quasi degli
abiti il molatto Eusebio, ordinava gli mettessero la sella e le briglie
come un cavallo: addattati poi a' suoi piccioli piedi andalusi i speroni
del Gaucho, gli saliva sul dorso, e amazzone strana, venía su questo
bucefalo umano davanti a suo padre, che ridendo dei capricci della
fanciulla, accordavale la grazia richiesta.
Ora poi che tai mezzi non hanno più l'antico prestigio, ella circonda
suo padre, quasi sorella di misericordia, di cure incessanti. Studiato il
di lui cuore, ne conosce le vanità più secrete che lo tormentano; ora
indugiando, ora chiedendo, riesce talvolta ad ottenere, e se è vera
l'intimità che le appongono, noi oseremmo quasi asseverare, che il
suo delitto è non solo scusabile agli occhi di Dio, ma potrà tenerle
luogo d'una virtù.
Manuelita è la regina e insieme la schiava del tetto domestico; essa
governa la casa, presta a suo padre le più tenere cure, ed incaricata
di tutte le relazioni diplomatiche, può dirsi il vero ministro degli affari
esteri di Buenos-Ayres.
Diffatti per la tertulìa di Manuelita, ora Manuela, ma a cui suo padre
dà sempre il nome d'infanzia, deve l'agente straniero far la sua
diplomatica entrata presso di Rosas.
Nella sua terlulìa Manuela si rappresenta come entusiasta del padre.
Ivi, senza che cada in dubbio ad alcuno, si uniforma agli avvisi del
dittatore; e colle grazie della gioventù, e colla poca importanza
politica, che si suol dare ad una bocca ridente e a due begli occhi,
avviluppa lo straniero in tal guisa che a gran fatica egli può
sciorsene.
Infine del pari che Rosas è un essere eccezionale e diviso dalla
società, Manuelita è una strana creatura, che, incognita a tutti, passa
solitaria su questa terra, lungi dall'amore degli uomini e della
simpatia delle donne.
Infelice! essa sola può dire quanto è sventurata e quante lacrime
versa quando Iddio le chiede conto delle sue colpe, ed ella chiede
conto a Dio de' propri dolori.
Rosas ha pure un figlio, di nome Juan, di nessun peso nel sistema
politico del padre. Egli è un giovane d'aspetto comune, minore d'un
anno o due di Manuelita; privo di nome può dirsi non avrà mai che
quello che viene dai triviali amori e da corrotti costumi.
Capitolo Secondo
Battuti al di fuori,
Senza armata,
Senza soldati anche nell'interno,
Senza materiale di guerra,
Senza danaro,
Senza rendite,
Senza credito.»
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com