Public
Edited
Nov 4, 2022
1 fork
Insert cell
Insert cell
viewof csvfile = Inputs.file({label: "CSV file", accept: ".csv", required: true})
Insert cell
Insert cell
Insert cell
data
Insert cell
data[0]
Insert cell
margin = ({ top: 40, right: 110, bottom: 30, left: 20 })
Insert cell
width = 1152
Insert cell
height = 1000
Insert cell
custom_line_chart ={
let svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.style("border", "1px solid black");

const g = svg
.append("g")
.attr("transform", `translate(${width/2},${height/2})`);

let xScale = d3.scaleTime()
.range([margin.left, width - margin.right])
.domain([new Date(2020, 8, 12), new Date(2022, 9, 26)]);
// let yScale =

return svg.node();
}
Insert cell
Tsample = getDatesInRange(new Date('2020-08-12'), new Date('2022-09-26'));
Insert cell
function getDatesInRange(startDate, endDate) {
const date = new Date(startDate.getTime());

const dates = [];

while (date <= endDate) {
dates.push(new Date(date));
date.setDate(date.getDate() + 1);
}

return dates;
}
Insert cell
grouped_by_category = d3.group(data, d=>d.category);
Insert cell
Ysample = Tsample.map((t) => ymapfun(t));
Insert cell
function ymapfun(d){
return d3.sum(d => d.Sentiment_Scores)/d3.count(d => d.Sentiment_Scores)
}
Insert cell
d3.sum(grouped_by_category.get('People & Blogs'), d => d.Sentiment_Scores)/ d3.count(grouped_by_category.get('People & Blogs'), d => d.Sentiment_Scores);
Insert cell
grouped_by_category_keys = Array.from(grouped_by_category.keys())
Insert cell
function get_obj_by_category(grouped_by_category_keys){
let a1 = []
for(let i=0; i< grouped_by_category_keys.length; i++){
a1.push(grouped_by_category.get(grouped_by_category_keys[i]))
}
return a1
}
Insert cell
b1 = get_obj_by_category(grouped_by_category_keys)
Insert cell
b1[0][0]['trending_date']
Insert cell
temp1 = b1[0].map(d=>d.trending_date)
Insert cell
temp2 = b1[0].map(d=>d.Sentiment_Scores)
Insert cell
function c2(a1000, a2000) {
let c1 = new Map();
for(let x1 =0; a1000.length; x1++){
c1.set(a1000[x1], a2000[x1]);
}
return c1
}
Insert cell
// c2(b1[0].map(d=>d.trending_date), b1[0].map(d=>d.Sentiment_Scores))
Insert cell
function get_map_by_category(array1){
let final_map = new Map();
let category_map = new Map();
for(let j=0; j< array1.length; j++){
final_map.set(j, category_map.set(array1[j].map(d=>d.trending_date), array1[j].map(d=>d.Sentiment_Scores)));
}
return final_map
}
Insert cell
a100 = get_map_by_category(b1)
Insert cell
key1 = Array.from(a100.keys());
Insert cell
columns = data.columns.slice(2);
Insert cell
Insert cell
d3.max(data, (d) => d.trending_date)
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