Published
Edited
Sep 23, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
<b><i>This is a sentence with bolding and italics</i></b>
Insert cell
** *This is the same sentence in Markdown* **
Insert cell
This is a link to <a href = "https://www.google.ca">Google</a> in HTML
Insert cell
This is a link to [Google](https://www.google.ca) in Markdown
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//Try uncommenting the lines below
//b*b
Insert cell
//b = Math.sqrt(64)
Insert cell
Insert cell
Insert cell
Insert cell
import {ramp} from "@mbostock/color-ramp"
Insert cell
ramp(d3.interpolateViridis, 12)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//this is an expression
Insert cell
//this is a String expression
Insert cell
//this is a block that runs a calculation
//Observable requires {} when running a block or object literal

{
//content here
//Cells in observables require a value to be returned
//for example, if I just want to compute the running sum of a number, I need brackets
}
Insert cell
Insert cell
//foo = 2
Insert cell
Insert cell
//foo = 3
Insert cell
Insert cell
//this is a constructor function
//remember that functions are considered objects in Javascript

function drink(a, b, c){
this.name = a;
this.price = b;
this.flavour = c;

//Below is an anonymous function (function without a name) that is called with the object's sayOrder property. It is only accessible within the scope of the object
this.sayOrder = function(){
return "The "+ this.name + " is " + this.price + " dollars";
}
}
Insert cell
Insert cell
//DEFINE YOUR NEW DRINK OBJECT HERE
//order =
Insert cell
//order.sayOrder()
Insert cell
//order.soldOut = false

//Uncomment the above line, and see how the order object has a new property called soldOut
Insert cell
//This is another function
function listPrice(a, b){
//return `The ${a} is ${b} dollars`; //this is another way of referencing the object's local
}
Insert cell
//listPrice('Mocha', '5')
Insert cell
//This is an object literal. It returns a value, but has no assignment
//Observable requires {} when defining an object literal
//The object literal contains key-value pairs: (name, price, flavour) are keys, and (Single Expresso, 3, floral and light) are values

{
var espresso = {
name: 'Single Espresso',
price: '3',
flavour: 'floral and light'
}
return espresso
}
Insert cell
espresso //espresso is not defined because we did not assign the object literal to a variable
Insert cell
//This is an object literal. We can use object literals to create comma-separated lists of name-value pairs inside curly braces

doubleEspresso = ({
name: 'Double Espresso',
price: '3',
flavour: 'fruity and balanced'
}
)
Insert cell
doubleEspresso.price
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require('d3@7') //7 refers to the version of D3
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

//attach a file here and give it a name to refer to
//Click on the paperclip on the right side of the buttons panel to see all files attached
Insert cell
Insert cell
Insert cell
flavours = ['strawberry', 'cherry', 'grape', 'blueberry']
Insert cell
//get the value 'grape' here
Insert cell
Insert cell
Insert cell
Insert cell
//download titanic
titanic = d3.csv('https://gist.githubusercontent.com/liutianming07/e6ec697e063f8d1a4ba38a9438cc0cf4/raw/946ee21819a4757753864c2c4c3b178b76150ca8/titanic')


Insert cell
Insert cell
Insert cell
import { toc } from "@nebrius/indented-toc" // This component generates the Table of Contents
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more