THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)Future Insights
Data on the Web can be represented in a number of ways and is often represented in more than one way at once. Maintaining entire libraries of templates to support growing applications is become harder and harder as a result. In addition, the requirement that data be live is hampered by existing methodologies. We will work through using and extending D3js to expressively generate representations of data that can be updated live.
This talk covers how to integrate D3 with SVG & Angular to create awesome visualisations, leveraging the modularity of D3 and it's data binding, with angular data binding and the reusability of directives.
Source code for this talk:
https://github.com/adamkleingit/d3-svg-angular
A small presentation with some quick explanation of what D3.js is and a few examples of what it can do for you. It can be used for a quick presentation (20-30 mins) after which you should have an idea of whether you can use D3.js for your project.
THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)Future Insights
Data on the Web can be represented in a number of ways and is often represented in more than one way at once. Maintaining entire libraries of templates to support growing applications is become harder and harder as a result. In addition, the requirement that data be live is hampered by existing methodologies. We will work through using and extending D3js to expressively generate representations of data that can be updated live.
This talk covers how to integrate D3 with SVG & Angular to create awesome visualisations, leveraging the modularity of D3 and it's data binding, with angular data binding and the reusability of directives.
Source code for this talk:
https://github.com/adamkleingit/d3-svg-angular
A small presentation with some quick explanation of what D3.js is and a few examples of what it can do for you. It can be used for a quick presentation (20-30 mins) after which you should have an idea of whether you can use D3.js for your project.
There's no escaping the fact that data visualization is hot right now. Everyone wants to tell their data's story visually, whether it be through a map, chart, or more detailed presentation. The difficulty is there are so many different tools that solve this, each one with their own benefits and limitations. We feel D3.js is the most awesome tool for handling this task -- which is the approach we've used for the sites like the Nation's Report Card, BlueCross BlueShield of North Carolina, GlobalChange, and others.
Presentation / Workshop which will teach you the core patterns, concepts and visualisation options of D3.js (v4). Accompanying exercises can be found here: https://github.com/josdirksen/d3exercises
Introduction to data visualisations with d3.js — Data Driven DocumentsMichał Oniszczuk
Introduction to data visualisations with d3.js and how we use it in ADA lab where we visualise large datasets (adalab.icm.edu.pl) and in the whole ICM (icm.edu.pl).
Presentation for the Data Science Warsaw meetup (http://www.meetup.com/Data-Science-Warsaw/).
This presentation has been prepared by Oleksii Prohonnyi for LvivJS 2015 conference (http://lvivjs.org.ua/)
See the speech in Russian by the following link: https://youtu.be/oi7JhB8eWnA
D3 is a powerful visualization library that allows to create amazing interactive visualizations. In this talk, targeted to a group of new engineers, you will learn a bit about the library, its possibilities, some examples and a detailed explanation of D3 selections and the dread Update, Enter and Exit pattern.
Find the slides online in: http://golodhros.github.io/d3-intro/
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsFlorian Georg
My talk at this year's Jazoon about data visualization and exploration with D3, crossfilter and dc.js
It should give you a good introduction on how/when to use these frameworks and how they relate to each other.
More info on http://datavisual.mybluemix.net
D3.js - A picture is worth a thousand wordsApptension
Here's a short introduction to D3 - a JavaScript library for visualizing data using web standards. This presentation was prepared by our Junior Frontend Developer for our monthly devtalk.
A university lecture for journalism students -- how to use the canvas element to add graphics and animation to Web pages. Updated April 2014. Basics for beginners. See also https://github.com/macloo/canvas
## Agenda
- Introduction
- Examples
- A guide of bar chart
- The analysis of source code
- The Wealth & Health of Nations
- An time series visual design of Adserver svn commit record
- Resources
There's no escaping the fact that data visualization is hot right now. Everyone wants to tell their data's story visually, whether it be through a map, chart, or more detailed presentation. The difficulty is there are so many different tools that solve this, each one with their own benefits and limitations. We feel D3.js is the most awesome tool for handling this task -- which is the approach we've used for the sites like the Nation's Report Card, BlueCross BlueShield of North Carolina, GlobalChange, and others.
Presentation / Workshop which will teach you the core patterns, concepts and visualisation options of D3.js (v4). Accompanying exercises can be found here: https://github.com/josdirksen/d3exercises
Introduction to data visualisations with d3.js — Data Driven DocumentsMichał Oniszczuk
Introduction to data visualisations with d3.js and how we use it in ADA lab where we visualise large datasets (adalab.icm.edu.pl) and in the whole ICM (icm.edu.pl).
Presentation for the Data Science Warsaw meetup (http://www.meetup.com/Data-Science-Warsaw/).
This presentation has been prepared by Oleksii Prohonnyi for LvivJS 2015 conference (http://lvivjs.org.ua/)
See the speech in Russian by the following link: https://youtu.be/oi7JhB8eWnA
D3 is a powerful visualization library that allows to create amazing interactive visualizations. In this talk, targeted to a group of new engineers, you will learn a bit about the library, its possibilities, some examples and a detailed explanation of D3 selections and the dread Update, Enter and Exit pattern.
Find the slides online in: http://golodhros.github.io/d3-intro/
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsFlorian Georg
My talk at this year's Jazoon about data visualization and exploration with D3, crossfilter and dc.js
It should give you a good introduction on how/when to use these frameworks and how they relate to each other.
More info on http://datavisual.mybluemix.net
D3.js - A picture is worth a thousand wordsApptension
Here's a short introduction to D3 - a JavaScript library for visualizing data using web standards. This presentation was prepared by our Junior Frontend Developer for our monthly devtalk.
A university lecture for journalism students -- how to use the canvas element to add graphics and animation to Web pages. Updated April 2014. Basics for beginners. See also https://github.com/macloo/canvas
## Agenda
- Introduction
- Examples
- A guide of bar chart
- The analysis of source code
- The Wealth & Health of Nations
- An time series visual design of Adserver svn commit record
- Resources
Introduction to React in combination with Redux. Redux helps you to develop applications in a simple way while having features like time-travel available during development.
Data visualization has become an essential skill for all digital experiences. As data becomes more available to the public, there is a need to create creative and efficient way of presenting that data on the web. D3 is a javascript library that creates dynamic data driven experiences for the web.
Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. As of 2016, Java is one of the most popular programming languages in use, particularly for client-server web applications.
d3Kit is a set of tools to speed D3 related project development. It is a lightweight library to help you do the basic groundwork tasks you need when building visualization with d3.
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONTomomi Imura
D3.js is a JavaScript library that lets you bring data to create interactive graphs and charts that run on a browser. It is a very powerful tool for creating eye-catching data visualization.
This slide deck is a quick showcase of what can be done with D3 and PubNub data stream. Let's get visual with a bubble chart!
Full tutorial:
http://www.pubnub.com/blog/fun-with-d3js-data-visualization-eye-candy-with-streaming-json/
Learn how can you create Tableau dashboards for OBIEE data that provide you valuable insight from business critical data without wasting a ton of time.
Step-1 Tableau Introduction
Step-2 Connecting to Data
Step-3 Building basic views
Step-4 Data manipulations and Calculated fields
Step-5 Tableau Dashboards
Step-6 Advanced Data Options
Step-7 Advanced graph Options
Employee engagement is not an exact science. So far, the whole concept has been built on HR experience, positive phycology and business models that engage a company’s talent towards a productive culture of success.
At the core of employee engagement, similar to any company’s foundation, are some values. These values determine the why, how and what of that company, presumably.
In today’s economy, you’re building your company brand both through external as well as internal efforts. Playing two battlefields at the same time can prove to be tricky, that’s why some companies decide to focus their resources only on the external branding front. Meanwhile, they neglect their internal environment, failing to provide an engaging, challenging and appealing workplace.
Enters talent management. A grey area where an HR manager meets a Talent Manager/Chief Happiness Officer. Confusing? Yes. And if it’s confusing for the person actually holding that position, imagine what it does to the employees he or she is supposed to be engaging.
So, we came up with 25 ideas that can save a manager in need of some inspiration. Enjoy!
15 Employee Engagement activities that you can start doing nowHppy
Trying to find new employee engagement activities to boost productivity in your company?
We thought you might, now that these long summer days make it difficult to focus and give 110% at work. But we also thought this is a great time to plan a proper employee engagement strategy that focuses on long-term growth and retention.
Whether you’re simply browsing for some ideas that might boost up morale or if you’re putting down the final details for your HR strategy, here are 15 employee engagement activities that you should try!
When I first started out with D3.js 2 years ago, I built things the same way, customising examples and although worked, I was never proud of my code. The chaining of methods makes the graphs concise, but costs a lot in cognitive overload and maintainability. Building this way is painful to modify, reuse or even to understand once you sit back down after lunch!
I had a huge revelation when I discovered the Reusable API (a modular structure to create and reuse d3 elements) and my code was elevated to even higher levels with Test Driven Development.
In this session I'll walk you through my journey toward beautiful, maintainable D3 graphs with step by step examples of refactoring crufty code to be shiny and new and testable.
By the end of the talk you too will know how to build decoupled, composable, encapsulated and consistent D3 graphs and be proud of your code again!
Having fun with graphs, a short introduction to D3.jsMichael Hackstein
This talk is all about drawing on your webpage. We will have a short introduction to d3.js, a library to easily create SVGs in your webpage. Along the way we will render graphs using different layouting strategies. But what are the problems when displaying a graph? Just think of graphs having more vertices then you have pixels on your screen. Or what if you want a user to manupilate the graph and his changes being persistent? Michael will present his answers to this questions, ending up wit a GUI for a graph database.
Andrii Gordiichuk, Software Developer
“Visualization of Big Data in Web Applications”
- Data in our life
- Patterns for data visualization
- Technologies for data visualization
- SVG and Canvas
- Frameworks for data visualization. Selection criteria
- D3.js and Highcharts.js
find us at http://www.meetup.com/NYC-Open-Data/events/137298432/
Hack Session 2: New Yorker Magazine Vis---Inequality and New York’s Subway
Magazine link: http://www.newyorker.com/sandbox/business/subway.html
Techniques to optimize the pagerank algorithm usually fall in two categories. One is to try reducing the work per iteration, and the other is to try reducing the number of iterations. These goals are often at odds with one another. Skipping computation on vertices which have already converged has the potential to save iteration time. Skipping in-identical vertices, with the same in-links, helps reduce duplicate computations and thus could help reduce iteration time. Road networks often have chains which can be short-circuited before pagerank computation to improve performance. Final ranks of chain nodes can be easily calculated. This could reduce both the iteration time, and the number of iterations. If a graph has no dangling nodes, pagerank of each strongly connected component can be computed in topological order. This could help reduce the iteration time, no. of iterations, and also enable multi-iteration concurrency in pagerank computation. The combination of all of the above methods is the STICD algorithm. [sticd] For dynamic graphs, unchanged components whose ranks are unaffected can be skipped altogether.
Explore our comprehensive data analysis project presentation on predicting product ad campaign performance. Learn how data-driven insights can optimize your marketing strategies and enhance campaign effectiveness. Perfect for professionals and students looking to understand the power of data analysis in advertising. for more details visit: https://bostoninstituteofanalytics.org/data-science-and-artificial-intelligence/
Show drafts
volume_up
Empowering the Data Analytics Ecosystem: A Laser Focus on Value
The data analytics ecosystem thrives when every component functions at its peak, unlocking the true potential of data. Here's a laser focus on key areas for an empowered ecosystem:
1. Democratize Access, Not Data:
Granular Access Controls: Provide users with self-service tools tailored to their specific needs, preventing data overload and misuse.
Data Catalogs: Implement robust data catalogs for easy discovery and understanding of available data sources.
2. Foster Collaboration with Clear Roles:
Data Mesh Architecture: Break down data silos by creating a distributed data ownership model with clear ownership and responsibilities.
Collaborative Workspaces: Utilize interactive platforms where data scientists, analysts, and domain experts can work seamlessly together.
3. Leverage Advanced Analytics Strategically:
AI-powered Automation: Automate repetitive tasks like data cleaning and feature engineering, freeing up data talent for higher-level analysis.
Right-Tool Selection: Strategically choose the most effective advanced analytics techniques (e.g., AI, ML) based on specific business problems.
4. Prioritize Data Quality with Automation:
Automated Data Validation: Implement automated data quality checks to identify and rectify errors at the source, minimizing downstream issues.
Data Lineage Tracking: Track the flow of data throughout the ecosystem, ensuring transparency and facilitating root cause analysis for errors.
5. Cultivate a Data-Driven Mindset:
Metrics-Driven Performance Management: Align KPIs and performance metrics with data-driven insights to ensure actionable decision making.
Data Storytelling Workshops: Equip stakeholders with the skills to translate complex data findings into compelling narratives that drive action.
Benefits of a Precise Ecosystem:
Sharpened Focus: Precise access and clear roles ensure everyone works with the most relevant data, maximizing efficiency.
Actionable Insights: Strategic analytics and automated quality checks lead to more reliable and actionable data insights.
Continuous Improvement: Data-driven performance management fosters a culture of learning and continuous improvement.
Sustainable Growth: Empowered by data, organizations can make informed decisions to drive sustainable growth and innovation.
By focusing on these precise actions, organizations can create an empowered data analytics ecosystem that delivers real value by driving data-driven decisions and maximizing the return on their data investment.
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Subhajit Sahu
Abstract — Levelwise PageRank is an alternative method of PageRank computation which decomposes the input graph into a directed acyclic block-graph of strongly connected components, and processes them in topological order, one level at a time. This enables calculation for ranks in a distributed fashion without per-iteration communication, unlike the standard method where all vertices are processed in each iteration. It however comes with a precondition of the absence of dead ends in the input graph. Here, the native non-distributed performance of Levelwise PageRank was compared against Monolithic PageRank on a CPU as well as a GPU. To ensure a fair comparison, Monolithic PageRank was also performed on a graph where vertices were split by components. Results indicate that Levelwise PageRank is about as fast as Monolithic PageRank on the CPU, but quite a bit slower on the GPU. Slowdown on the GPU is likely caused by a large submission of small workloads, and expected to be non-issue when the computation is performed on massive graphs.
Opendatabay - Open Data Marketplace.pptxOpendatabay
Opendatabay.com unlocks the power of data for everyone. Open Data Marketplace fosters a collaborative hub for data enthusiasts to explore, share, and contribute to a vast collection of datasets.
First ever open hub for data enthusiasts to collaborate and innovate. A platform to explore, share, and contribute to a vast collection of datasets. Through robust quality control and innovative technologies like blockchain verification, opendatabay ensures the authenticity and reliability of datasets, empowering users to make data-driven decisions with confidence. Leverage cutting-edge AI technologies to enhance the data exploration, analysis, and discovery experience.
From intelligent search and recommendations to automated data productisation and quotation, Opendatabay AI-driven features streamline the data workflow. Finding the data you need shouldn't be a complex. Opendatabay simplifies the data acquisition process with an intuitive interface and robust search tools. Effortlessly explore, discover, and access the data you need, allowing you to focus on extracting valuable insights. Opendatabay breaks new ground with a dedicated, AI-generated, synthetic datasets.
Leverage these privacy-preserving datasets for training and testing AI models without compromising sensitive information. Opendatabay prioritizes transparency by providing detailed metadata, provenance information, and usage guidelines for each dataset, ensuring users have a comprehensive understanding of the data they're working with. By leveraging a powerful combination of distributed ledger technology and rigorous third-party audits Opendatabay ensures the authenticity and reliability of every dataset. Security is at the core of Opendatabay. Marketplace implements stringent security measures, including encryption, access controls, and regular vulnerability assessments, to safeguard your data and protect your privacy.
Adjusting primitives for graph : SHORT REPORT / NOTESSubhajit Sahu
Graph algorithms, like PageRank Compressed Sparse Row (CSR) is an adjacency-list based graph representation that is
Multiply with different modes (map)
1. Performance of sequential execution based vs OpenMP based vector multiply.
2. Comparing various launch configs for CUDA based vector multiply.
Sum with different storage types (reduce)
1. Performance of vector element sum using float vs bfloat16 as the storage type.
Sum with different modes (reduce)
1. Performance of sequential execution based vs OpenMP based vector element sum.
2. Performance of memcpy vs in-place based CUDA based vector element sum.
3. Comparing various launch configs for CUDA based vector element sum (memcpy).
4. Comparing various launch configs for CUDA based vector element sum (in-place).
Sum with in-place strategies of CUDA mode (reduce)
1. Comparing various launch configs for CUDA based vector element sum (in-place).
As Europe's leading economic powerhouse and the fourth-largest hashtag#economy globally, Germany stands at the forefront of innovation and industrial might. Renowned for its precision engineering and high-tech sectors, Germany's economic structure is heavily supported by a robust service industry, accounting for approximately 68% of its GDP. This economic clout and strategic geopolitical stance position Germany as a focal point in the global cyber threat landscape.
In the face of escalating global tensions, particularly those emanating from geopolitical disputes with nations like hashtag#Russia and hashtag#China, hashtag#Germany has witnessed a significant uptick in targeted cyber operations. Our analysis indicates a marked increase in hashtag#cyberattack sophistication aimed at critical infrastructure and key industrial sectors. These attacks range from ransomware campaigns to hashtag#AdvancedPersistentThreats (hashtag#APTs), threatening national security and business integrity.
🔑 Key findings include:
🔍 Increased frequency and complexity of cyber threats.
🔍 Escalation of state-sponsored and criminally motivated cyber operations.
🔍 Active dark web exchanges of malicious tools and tactics.
Our comprehensive report delves into these challenges, using a blend of open-source and proprietary data collection techniques. By monitoring activity on critical networks and analyzing attack patterns, our team provides a detailed overview of the threats facing German entities.
This report aims to equip stakeholders across public and private sectors with the knowledge to enhance their defensive strategies, reduce exposure to cyber risks, and reinforce Germany's resilience against cyber threats.
2. SVG
Basic Shapes
Paths
Javascript vs. D3js
Creating a Bar Graph
Scaling
What Next?
3. SVG (ScalableVector Graphics)
Scalable images
Open standard
Files saved as standard XML
Need to have good command of Javascript
D3js is a library written in javascript
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8">
D3js makes it easy to manipulate SVG
graphics
4. D3 = Data Driven Documents
Produce interactive visualizations (web)
Has several libraries to help with creating
graphics
Focus on the visualization part (not the code)
Support for binding data
5. Selections
CSS-style selector to select DOM nodes
Manipulations (append, remove, etc.)
Transitions
“smoothly” interpolate attributes of graphic, creating
an aesthetically pleasing visual
Better than recreating each element
Data-binding
Use a dataset (json, csv, javascript arrays, etc.) to
allow D3 to create an object for each element
6. Based on a coordinate system with (0,0) at
top left
Basic shapes include
Lines, Rectangles, Circles, and Polygons
Paths allow highly customized polygons
Using basic shapes to create interactive
charts like bar charts, area charts, pie charts
More Advanced creations are possible
8. d3.select("body") // select <body> tag
.append("svg") // add <svg> tag
.attr("width", "100") // width of svg, use default for height
.append("rect") // add <rect> element
.attr("width", 50) // set attribute of rect
.attr("height", 150) // set attribute of rect
.attr("x", 25) // move 25 px from left of svg
.attr("y", 25) // move 25 px from top of svg
.style("fill", "blue"); // add some style
9. d3.select("body") // select <body> tag
.append("svg") // add <svg> tag
.attr("width", "100")
.append("circle") // add <circle> element
.attr("cx", 50) // move center of circle 50 px from left of svg
.attr("cy", 50) // move center of circle 50 px from top of svg
.attr("r", 25) // radius of circle
.style("fill", "blue"); // add some style
10. //The data for our line; simply an array of x,y coordinates for each line segment
var lineData = [ { "x": 1, "y": 5}, { "x": 20, "y": 20},
{ "x": 40, "y": 10}, { "x": 60, "y": 40},
{ "x": 80, "y": 5}, { "x": 100, "y": 60}];
//This accessor function will use the x,y coordinates and create a path of points
var lineFunction = d3.svg.line() // we’ll revisit this later
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate("linear"); // we’ll revisit this later
//The SVG Container
var svgContainer = d3.select("body").append("svg")
.attr("width", 200)
.attr("height", 200);
//The line SVG Path we draw
var lineGraph = svgContainer.append("path")
.attr("d", lineFunction(lineData)) // concept of dynamic property; calls the lineFunction
defined above
.attr("stroke", "blue")
.attr("stroke-width", 2)
.attr("fill", "none");
Interpolate(“linear”)
Interpolate(“step-before”)
14. D3.js includes a set of Path Data Generators helper
classes for generating SVG Path instructions.
d3.svg.line - create a new line generator
d3.svg.line.radial - create a new radial line generator
d3.svg.area - create a new area generator
d3.svg.area.radial - create a new radial area generator
d3.svg.arc - create a new arc generator
d3.svg.symbol - create a new symbol generator
d3.svg.chord - create a new chord generator
d3.svg.diagonal - create a new diagonal generator
d3.svg.diagonal.radial - create a new radial diagonal
generator
15. var arc = d3.svg.arc() // What does this do?
.innerRadius(20)
.outerRadius(100)
.startAngle(0)
.endAngle(Math.PI) ;
// Angles are specified in radians;
0 corresponds to 12 o’clock (negative y)
and proceeds clockwise, repeating at 2π
var chart =
d3.select("body").append("svg:svg")
.attr("width", 200)
.attr("height", 250).append("svg:g")
.attr("transform", "translate(50,150)") ;
chart.append("svg:path")
.attr("fill", "green")
.attr("d", arc) ;
endAngle(Math.PI)
endAngle(0.5* Math.PI)
16. Where are we?
We know about SVG shapes
We know a little bit about D3js
We can create different shapes using D3js syntax
What haven’t we done?
No Data examples
No interactive examples (can’t show much in ppt)
18. Greater flexibility with more complex data
Handles binding automatically
Easier transitions
grp.attr("transform", "translate(20,20)");
Moves the entire group 20x20
19. A little tough to understand at first
Makes sense after reviewing examples
General Pattern:
// Update…
var p = d3.select("body").selectAll("p")
.data([4, 8, 15, 16, 23, 42]) // array of numbers
.text(String);
// Enter… this will be called for each data element
p.enter().append("p")
.text(String);
// Exit…
p.exit().remove();
20. // Update…
var p = d3.select("body").selectAll("p")
.data([4, 8, 15, 16, 23, 42])
// join “p” with data items
.text(function(d){
console.log(d);
return (d*d).toString();
});
Notice we can call a function
to get the data element
Since there are no “p” tags in
the body, nothing is displayed
No log information is created
<body>
</body>
html output
21. var p = d3.select("body").selectAll("p")
.data([4, 8, 15, 16, 23, 42])
.text(function(d){
console.log(d);
return d.toString();});
p.enter().append("p")
.text(function(d) {
console.log ("value of d is: " + d.toString());
return (d*2).toString();});
Notice the console output (original
values) and the eventual data that’s
rendered (value doubled)
Essentially, create a “p” tag for each
data element
<body>
<p>8</p><p>16</p><p>30</p>
<p>32</p><p>46</p><p>84</p>
</body>
console.log output
html output
22. This time the html body tag has
some <p> tags defined like this:
<body>
<p>this is p1</p>
<p>this is p2</p>
<p>this is p3</p>
</body>
Here’s the D3 “update” code:
var p = d3.select("body").selectAll("p")
.data([4, 8, 15, 16, 23, 42])
.text(function(d){
console.log("d in update:" + d.toString());
return d.toString();
});
Notice the original <p> text has
been replaced
<body>
<p>4</p>
<p>8</p>
<p>15</p>
</body>
html output
console.log output
23. The html body tag has some
<p> tags defined like this:
<body>
<p>this is p1</p>
<p>this is p2</p>
<p>this is p3</p>
</body>
Here’s the D3 Enter code:
p.enter().append("p")
.text(function(d) {
console.log ("value of d is: " + d.toString());
return (d*2).toString();});
Notice the last three <p> tags
have the doubled value
<body>
<p>4</p>
<p>8</p>
<p>15</p>
<p>32</p>
<p>46</p>
<p>84</p>
</body>
html output
console.log output
24. var data = [4, 8, 15, 16, 23, 42];
function createSomething(){
var p = d3.select("body").selectAll("p")
.data(data)
.text(function(d){
console.log("d in update:" + d.toString());
return d.toString();});
p.enter().append("p")
.text(function(d) {
console.log ("value of d is: " + d.toString());
return (d*2).toString();})
// attach click event to remove an element
.on("click", function(d, i){
console.log(“onclick d, i: “ + d + “, “ + i);
data.splice(d, 1); // let’s remove a value
from data
createSomething();
});
// Exit ...
p.exit().remove();
}
createSomething();
Clicked on 46.What happened
to 32 and 84?
From the
“update”
From the
Enter
selection
The
onclick
removed
an item
from the
array
When data is updated (removed), one
of the <p> is also removed. Notice
that the values are not doubled.
That’s because the update selection
was executed, not Enter. The log
output confirms that.
25. // what would happened if we added an element ???
var data = [4, 8, 15, 16, 23, 42];
function createSomething(){
var p = d3.select("body").selectAll("p")
.data(data)
.text(function(d){
console.log("d in update:" + d.toString());
return d.toString();});
p.enter().append("p")
.text(function(d) {
console.log ("value of d is: " + d.toString());
return (d*2).toString();})
.on("click", function(){
console.log(“addding 10 to data“);
// add the number 10 to the top of array
d.splice(0,0, 10);
createSomething();
});
// Exit ...
p.exit().remove();
}
createSomething();
Notice that the new value was joined
with the first <p>; the first 6 <p> were
updated, and the 7th was inserted
(that’s why it has the double value)Clicked on 46.What happened
to 32?
26. // what would happened if we added an
element ???
var data = [4, 8, 15, 16, 23, 42];
function createSomething(){
var p = d3.select("body").selectAll("p")
.data(data)
.text(function(d){
console.log("d in update:" + d.toString());
return d.toString();});
p.enter().append("p")
.text(function(d) {
console.log ("value of d is: " + d.toString());
return (d*2).toString();})
.on("click", function(){
console.log(“addding 10 to data“);
// add the number 10 to the bottom of array
d.splice(4,0, 10);
createSomething();
});
// Exit ...
p.exit().remove();
}
createSomething();
What will be displayed
when you click on 46?
Look at the log output.
27. Understanding the Update, Enter, Exit
selections is critical
Now we know about SVG graphicsAND
D3 Scripting (a little bit) AND
Selections
So now you are only bound by your
imagination (and a bit of geometry)
28. A Bar chart is simply a set of rectangles
Let’s use D3 to create some rectangles
Here’s something that looks like a bar chart
with 5 rectangles
29. <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script
src="http://d3js.org/d3.v3.min.js"></script>
<script>
<!– on right side -->
</script>
</head>
<body>
</body>
</html>
var w = 300;
var h = 100;
var padding = 2;
var data = [15, 10, 50, 20, 25];
var svg = d3.select("body").append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("rect") // select all rect
.data(data) // our data
.enter() // cross your fingers
.append("rect") // it will append rect
.attr("x", function(d,i) {
return i*(w/dataset.length);
}) // set x … d is data and i is index of data
.attr("y", function(d, i){
return h-(d);
}) // set y … remember y start in top-left corner
.attr("width", w/dataset.length - padding)
.attr("height", function(d) {
return d;
});
30. var w = 300;
var h = 200;
var padding = 2;
var dataset = [15, 10, 45, 20, 25];
var svg = d3.select("body").append("svg")
.attr("width", w)
.attr("height", h);
function getColor(v) {
if (v<=20) {return "#666666"; }
else if(v<40) {return "#FF5010";}
else {return "#FF0000";}
}
svg.selectAll("rect") // select all rect
.data(dataset) // our data
.enter() // will append if doesn't exist
.append("rect") // it will append rect
.attr("x", function(d,i) {
return i*(w/dataset.length);
})
.attr("y", function(d, i){
return h-(d*4);
})
.attr("width", w/dataset.length - padding)
.attr("height", function(d) {
return d*4;
})
.attr("fill", function(d) {return getColor(d);});
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
.text(function(d) {return d;})
.attr({
"text-anchor": "middle",
x: function(d,i){
return i*(w/dataset.length)+(w/dataset.length - padding) /2;
},
y: function(d) {return h-(d*4)+14;}, // drop it inside the bar
"font-family": "sans-serif",
"font-size": 12,
"fill": "#ffffff"
});
31. var w = 300, //width
h = 300, //height
r = 100, //radius
color = d3.scale.category20c(); //builtin range of colors
data = [{
"label": "one",
"value": 20
}, {
"label": "two",
"value": 50
}, {
"label": "three",
"value": 30
}];
var vis = d3.select("body")
.append("svg:svg") //create the SVG element inside the <body>
.data([data]) //associate our data with the document
.attr("width", w) //set the width and height of our visualization (these will be attributes of the <svg> tag
.attr("height", h)
.append("svg:g") //make a group to hold our pie chart
.attr("transform", "translate(" + r + "," + r + ")"); //move the center of the pie chart from 0, 0 to radius,
radius
var arc = d3.svg.arc() //this will create <path> elements for us using arc data
.outerRadius(r);
var pie = d3.layout.pie() //this will create arc data for us given a list of values
.value(function(d) {
return d.value;
}); //we must tell it out to access the value of each element in our data array
var arcs = vis.selectAll("g.slice") //this selects all <g> elements with class slice (there aren't any yet)
.data(pie) //associate the generated pie data (an array of arcs, each having startAngle, endAngle and
value properties)
.enter() //this will create <g> elements for every "extra" data element that should be associated with a
selection. The result is creating a <g> for every object in the data array
.append("svg:g") //create a group to hold each slice (we will have a <path> and a <text> element
associated with each slice)
.attr("class", "slice"); //allow us to style things in the slices (like text)
arcs.append("svg:path")
.attr("fill", function(d, i) {
return color(i);
}) //set the color for each slice to be chosen from the color function defined above
.attr("d", arc); //this creates the actual SVG path using the associated data (pie) with the arc drawing
function
arcs.append("svg:text") //add a label to each slice
.attr("transform", function(d) { //set the label's origin to the center of the arc
//we have to make sure to set these before calling arc.centroid
d.innerRadius = 0;
d.outerRadius = r;
return "translate(" + arc.centroid(d) + ")"; //this gives us a pair of coordinates like [50, 50]
})
.attr("text-anchor", "middle") //center the text on it's origin
.text(function(d, i) {
return data[i].label;
}); //get the label from our original data array
32. Scaling is important for creatingAxis
Can also be used to resize graphics
Use d3.scale.linear() to create scale
var scale = d3.scale.linear()
.domain([130,350]) // min/max
.range([10,100]); // output range;
// now use the scale object to get scaled value
console.log(scale(130)); // 10
console.log(scale(350)); // 100
console.log(scale(300)); // 79.54
console.log(scale(150)); // 18.18
33. Transitions deal with animation; Not possible
to show in a presentation (see demos later)
A little ironic that we can’t show transitions in ppt
Very Powerful feature of D3
A very simply transition:
d3.select("body") .style("color", "green") // make the body green
.transition() .style("color", "red"); // then transition to red
https://www.youtube.com/watch?v=vLk7mlAtEXI
http://bl.ocks.org/mbostock/3943967
36. https://github.com/mbostock/d3/wiki/Gallery
Source code available for all examples
Copy source and play with it in a javascript
environment (jsfiddle.net, jsbin.com, etc.)
Use debugger and console.log liberally to
better understand what’s happening
37. Debugging in javascript
Examples from today
Examples from NYTimes.com
Examples from around the Internet