Published
Edited
Jan 13, 2022
Fork of 河流图
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
// chart_river
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// color = d3.scaleOrdinal().range(d3.schemeSet1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rawDates = d3.timeDay.range(new Date(2021, 1, 20), new Date(2021, 12, 18)) //此数据中的总日期范围
Insert cell
//Object.keys(rawData[0]).slice(11)
Insert cell
//rawData = d3.csv(
// "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_US.csv"
// )
Insert cell
rawDeathData = d3.csv(
'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_US.csv'
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = Object.assign(d3.csvParse(await FileAttachment("typenum@4.csv").text(), d3.autoType))
Insert cell
datedata = Object.assign(d3.csvParse(await FileAttachment("typenum-4.csv").text(), d3.autoType)).map(d => {d.Date = new Date(d.Date); return d;})
Insert cell
datedata.columns = data.columns
Insert cell
data.columns.slice(1,data.columns.length)
Insert cell
series = d3.stack()
.keys(data.columns.slice(1,data.columns.length)) //关键词(按关键词堆叠
.order(d3.stackOrderDescending) // 将最大的系列放在底部
.offset(d3.stackOffsetSilhouette) //将流图以零为中心
(datedata)
Insert cell
truncatedseries = {
const data = series.map(d => d.slice(dateRange[0], dateRange[1]));
data.forEach((d, i) => (d.key = series[i].key));
return data;
}
//进度条截出来的数据
Insert cell
Insert cell
colorScale = d3.scaleOrdinal()
.domain(keys)
.range(d3.schemeTableau10); //括号里的是10中分类颜色的数组
//根据各关键词来设置河流颜色,一个关键词一个颜色
Insert cell
Insert cell
Insert cell
Insert cell
// viewof newstype = Inputs.select(["Fact Sheet", "Interview", "Media Note", "Notice to the Press", "Press Statement", "Readout", "Remarks", "Remarks to the Press", "Special Briefing", "Speech","ALL"], { label: "选择新闻类型"})
Insert cell
// newstype
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const chartHolder = d3.select(document.createElement("div"));
let myChart = d3Ez.chart.heatMapTable()
.width(370)
.height(700)
.colors(['#ffffe0', '#ffffe0', '#ffffe0', '#ff0000']);
chartHolder
.datum(data_word)
.call(myChart);
return chartHolder.node();
}
Insert cell
textArr = {
let textArr = text
.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()\"]/g,"") // Get rid of any punctuation, special characters etc.
.replace(/[\n\t\s]+/g," ") // Get rid of new lines, tabs, double spaces.
.split(' '); // Split into an array.
return textArr.map(word => {
return word.toLowerCase();
});
}
Insert cell
data_word = {
let shortArrays = [];
let columns = 41;
for (let i = 0, len = textArr.length; i < len; i += columns) {
let sliced = textArr.slice(i, i + columns)
let mapped = sliced.map((word, index) => {
let isLove = (word === searchTerm.toLowerCase());
return {key: index, value: isLove, word: word};
});
shortArrays.push(mapped);
}
return shortArrays.map((words, index) => {
return {key: index, values: words};
});
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more