Introduction to Web Programming for Visualization

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
CSCI 3100 Tutorial 6 Web Development Tools 1 Cuiyun GAO 1.
Cascading Style Sheets
Programming Club IIT Kanpur. Work environment Before you begin coding,always set up your work environment to your needs IDE Notepad++ Sublime Text 2.
Today CSS HTML A project.
Presenter: James Huang Date: Sept. 26,  Introduction  Basics  Lists  Links  Forms  CSS 2.
A really fairly simple guide to: mobile browser-based application development (part 1) Chris Greenhalgh G54UBI / Chris Greenhalgh
Introduction to HTML5 Programming donghao. HTML5 is the New HTML Standard New Elements, Attributes. Full CSS3 Support Video and Audio 2D/3D Graphics Local.
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
Today’s objectives Site performance Padding, Margins, Borders
Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Website Development with Dreamweaver.
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Learning HTML. HTML Attributes HTML elements can have attributes Attributes provide additional information about an element Class – specifies a class.
18 People Surveyed HTML (HyperText Markup Language) HTML “tags” Describes structure Building blocks Headings, paragraphs, lists, links, images, quotes,
Interacting with a Web Page using JavaScript Mat Kelly GTAI Presentation January 10, 2014.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
HTML: Hyptertext Markup Language Doman’s Sections.
Lecture 2 - HTML and CSS Review SFDV3011 – Advanced Web Development 1.
Web Development 101 Presented by John Valance
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
(1) HTML5, CSS, Twitter Bootstrap. (2) HTML5 Will be the new standard New features Drag and Drop and Support for local storage,,,, New input types Removed.
CSCI 3100 Tutorial 2 Web Development Tools 1 HTML 5 & CSS 3 1.
Week 1: Introduction to HTML and Web Design
Working with Cascading Style Sheets
Week-12 (Lecture-1) Cascading Style Sheets (CSS): describe how documents are presented on screens. Types of Style Sheets: External Style Sheet - Define.
DHTML.
Introduction to Information Security
Web Systems & Technologies
Project 1 Introduction to HTML.
Objective % Select and utilize tools to design and develop websites.
Lab 03: Visualization with d3
Internet of the Past.
4.01 Cascading Style Sheets
Tek Raj Chhetri Code for Humans not for machine.
Module: Software Engineering of Web Applications
Chapter 1 Introduction to HTML.
Inserting and Working with Images
>> CSS Rules Selection
Unit 2, Lesson 5 Website Development Tools
Web Programming for Visualization
Objective % Select and utilize tools to design and develop websites.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Unit 2, Lesson 5 Website Development Tools
Revision.
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Introduction to Internet Programming
CSS – Cascading Style Sheet DOM – Document Object Model
Lab 04: Interactive Visualization W/ d3
Introduction to D3.js and Bar Chart in D3.js
DHTML Javascript Internet Technology.
Web Programming A different world! Three main languages/tools No Java
The Canvas.
DHTML Javascript Internet Technology.
Introduction to Programming the WWW I
D3.js Tutorial (Hands on Session)
Input CS 422: UI Design and Programming
Javascript and JQuery SRM DSC.
D3.js Tutorial (Hands on Session)
Understand basic HTML and CSS terminology, concepts, and basic operations. Objective 3.01.
Computer communications
HTML5 - 2 Forms, Frames, Graphics.
4.01 Cascading Style Sheets
Presentation transcript:

Introduction to Web Programming for Visualization 陈思明 北京大学可视化与可视分析实验室 2016.10.19

Visualization

WWW Stuff HTML CSS JavaScript Product Manager Art Designer Programmer Image Source: Pixel4kids.net

HTML Structure Elements <!DOCTYPE html> <html> <head> <title>This is a title</title> <link href="css/index.css" type="text/css" rel="stylesheet" /> </head> <body> <p>Hello world!</p> </body> </html> HTML : HyperText Markup Language the standard markup language used to create web pages. Structure Header Body Embedded assets Elements <div>, <p>, <input>, <span>, etc.

HTML : HyperText Markup Language HTML tags (www.w3schools.com)

HTML Tag Examples

HTML Tag Examples 2 Tables Tr (Row) th/td (Head / Column)

DOM Tree Property Method Event class, text find, insert onclick, onload

CSS CSS : Cascading Style Sheet is a style sheet language used for describing the look and formatting of a document written in a markup language. Inline CSS External CSS

CSS CSS Selector : allow you to select and manipulate HTML element(s). The element Selector The id Selector  keyword “id=…” on html tag The class Selector  keyword “class=…” on html tag

JavaScript Why JavaScript? : JavaScript is one of 3 languages all web developers MUST learn: HTML to define the content of web pages CSS to specify the layout of web pages JavaScript to program the behavior of web pages Example Scenario Web Engine (Server Side) Web Page (Client Side) request response The request format should be verified on the client side thus verification process will not burden the web server

JavaScript In-line Script External Script http://www.w3schools.com/jsref/default.asp

JavaScript <html> <body> <script type=“text/javascript”> document.write(“<h1>这是标题</h1>”); document.write(“<p>这是段落。</p>”); document.write(“<p>这是另一个段落。</p>”); </script> </body> </html>

JSON More compact storage than XML JavaScript compatible More restrict Key must be double quoted {“key1”:”value1”,”key2”:”value2”}

Reference http://www.w3schools.com http://jquery.com http://www.json.org http://d3js.org

Bootstrap Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.

Hands-on Build up a website in 5 minutes http://www.bootcss.com/p/layoutit/

D3.js

提纲 Data Driven Documents – D3 D3 Concept D3 Important Features D3 Hands-on

Trend of Visualization Programming Tools Framework Platform Url OpenGL with glut C/C++ http://nehe.gamedev.net/tutorial/lessons_01__05/22004/ OpenFramework http://www.openframeworks.cc/ Java2D with Swing Java http://download.oracle.com/javase/tutorial/2d/index.html Prefuse http://prefuse.org Processing Processing (based on Java) http://processing.org ProtoVis JavaScript http://protovis.org Our recommendations in 2011 But now We recommend Web Programming and D3js Library

Why Web Programing? Users – Everyone can touch it Flexibility – JS code is far less than C++ Library and sharing – Don’t need to build wheels for the cars But Please have graphical programming basic in mind High performance visualization, please turn right for C++

D3.js http://d3js.org One sentence illustration -- Binding data to HTML elements

SVG <svg> <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" /> </svg>

Learning from the ‘Three Little Circle’ – Step 1: Relationship between SVG and D3 http://bost.ocks.org/mike/circles/

Learning from the ‘Three Little Circle’ – Step 2: Selection http://bost.ocks.org/mike/circles/

Learning from the ‘Three Little Circle’ – Step 3: Binding Data http://bost.ocks.org/mike/circles/

D3 Core: Enter – Update - Exit

D3 Core: Enter – Update – Exit Take-home code First to ‘enter’ – when new data coming Remember to ‘update’ – when existing data change values Don’t forget to ‘exit’ – remove what we don’t want

6 Steps to write a visualization

Deconstruct the visualization into primitives X-axis Y-axis X, Y mapping Color encoding Labeling Any interactions

Step 1: Loading the data Loading Data Preprocessing related attributes d3.tsv("data.tsv", function(error, data) { if (error) throw error; data.forEach(function(d) { d.sepalLength = +d.sepalLength; d.sepalWidth = +d.sepalWidth; });

Step 2: Mapping the data Mapping the data Defining the boundary Defining the ‘d3.scale’ Choosing the mapping mechanism – linear, log, etc. Setting the ‘domain’ and ‘range’ var margin = {top: 20, right: 20, bottom: 30, left: 40}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var x = d3.scale.linear() .range([0, width]); var y = d3.scale.linear() .range([height, 0]); x.domain(d3.extent(data, function(d) { return d.sepalWidth; })).nice(); y.domain(d3.extent(data, function(d) { return d.sepalLength; })).nice();

Step 3: Preparing for drawing var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var xAxis = d3.svg.axis() .scale(x) .orient("bottom"); var yAxis = d3.svg.axis() .scale(y) .orient("left"); SVG is the main canvas for drawing X-axis and Y-axis is mapping with the x and y scale

Step 4: Drawing the primitives Drawing the xAxis Drawing the labels Drawing the yAxis and lables svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(xAxis) .append("text") .attr("class", "label") .attr("x", width) .attr("y", -6) .style("text-anchor", "end") .text("Sepal Width (cm)"); .attr("class", "y axis") .call(yAxis) .attr("transform", "rotate(-90)") .attr("y", 6) .attr("dy", ".71em") .text("Sepal Length (cm)")

Step 5: Drawing the Dot Main parts of the drawing Data binding Data entering Data updating svg.selectAll(".dot") .data(data) .enter().append("circle") .attr("class", "dot") .attr("r", 3.5) .attr("cx", function(d) { return x(d.sepalWidth); }) .attr("cy", function(d) { return y(d.sepalLength); }) .style("fill", function(d) { return color(d.species); });

Step 6: Drawing the Legends Labels are the data of categories, in this data is 3 categories Adding the rect and text Setting the contents var legend = svg.selectAll(".legend") .data(color.domain()) .enter().append("g") .attr("class", "legend") .attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; }); legend.append("rect") .attr("x", width - 18) .attr("width", 18) .attr("height", 18) .style("fill", color); legend.append("text") .attr("x", width - 24) .attr("y", 9) .attr("dy", ".35em") .style("text-anchor", "end") .text(function(d) { return d; });

JavaScript Closure var counter = 0; function add() { counter += 1; } var add = (function () { var counter = 0; return function () {return counter += 1;} })(); add();

JavaScript var f=function(){return this.a} var a=12 The invocation context var f=function(){return this.a} var a=12 f() // this=window, 12 var o={a:23, f:f} o.f() // this=o, 23 var p={a:34, f:f.bind(o)} p.f() // this=o, 23 o.f.call(p) // this=p, 34 p.f.call(p) // this=o, 23

JavaScript $( "#button" ).on( "click", function( event ) { Callback Single thread Message polling and callback registration $( "#button" ).on( "click", function( event ) { hiddenBox.show(); }); $.ajax({url: "test.html”}).done(function() { $( this ).addClass( "done" );

Graphics Canvas SVG WebGL Runtime generation Complex and high performance SVG Vector graphics XML format

Canvas <canvas id="canvas" width="200" height="100"></canvas> var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); context.beginPath(); context.moveTo(100, 100); context.lineTo(100, 200); context.strokeStyle = "black"; context.stroke(); context.fillStyle = "#FF0000"; context.fillRect(0,0,150,75);

Networking $.ajax({url: ”test", success: function(result){ $("#div1").html(result); }}); $.get(”test", function(data, status){ alert("Data: " + data + "\nStatus: " + status); }); $.ajax({ method: "POST", url: "some.php", data: { name: "John", location: "Boston" } }).done(function( msg ) { alert( "Data Saved: " + msg );});

SVG <svg> <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" /> </svg>