fabiochiu/medium-articles huggingface dataset:
A Brief Look At Approaches To Red Team Operations
By: Cedric Owens
Tags: Offensive Security, Blue Team, Purple Team, Information Security, Red Team

Approach 2: Linear Operations

I refer to this approach as “linear operations” due to the fact that this approach uses several different operations where a red team simulates an attacker and maintains that same attacker profile across each operation. These operations/exercises are often tightly scoped and shorter in duration (ex: anywhere from 1 week up through 1 month). An example is below:

Op1: Red team does 2FA man in the middle phish (targeting publicly facing login portals) and tries to get access to sensitive systems/data

Op2: Red team keeps the same TTPs from Op1 with a slight modification or introduces a new TTP (ex: adds payload-based phishing).

Op3: Red team continues with the same goal and iterates on the same TTPs with additional modifications.

Using this approach the red team keeps the same “attacker profile” (i.e., continues being the same attacker) across each operation and seeks to demonstrate how an attacker targeting their organization would evolve over time as defenses and detections improve and force them to migrate to new TTPs. As such, the red team may opt to keep some “loot” that they gain in each op and use that data/info/access in the next op. For example, if during Op1 above the red team finds the corporate VPN client and profile then the red team may leverage that in Op2 once they gain access to credentials. This approach is an interesting approach and while it may not make sense to use this approach solely it may be useful to do this across a small handful of red team ops and see how it adds value to the blue team (i.e., hopefully it will help SIRT or threat intel with building and tracking an adversary profile, will help blue become more intimately aware of the attack path being used since the red team essentially keeps using it until they are prevented from doing so by quick response or preventions, etc.)

Considerations: While I think this is an interesting approach to red teaming, I think using this approach solely would limit what the blue team is exposed to in terms of real world attacks that could target the organization. There could be various other attack vectors relevant to the organization but since this method would be limited to the same adversary model and TTPs (which may not include various other vectors), then the red team would likely not use those vectors. So the end result could be that blue team does not get exposed to the breadth of relevant attacks that they should be preparing for. The positive side is that this approach would essentially force improvement in detections/preventions in the attack paths that the red team is using, since essentially red team will continue doing the same thing (with minor modifications) until forced to evolve by rapid response and preventions.
CyberDefenders challenges: Improving malware traffic analysis skills
By: Jacob Stickney
Tags: Information Security, Cybersecurity

Credit goes to cybersecurity professional and YouTube channel Simply Cyber content creator, Gerald Auger, for recommending CyberDefenders. They have a collection of various Blue Team (SOC Analyst, forensics-focused) challenges, including malware traffic analysis challenges using the widely-used packet and protocol analyzer, WireShark. I find it super interesting to utilize Wireshark to investigate network traffic, whether it’s been exploited or not. There’s so much information to sift through. I know that with time, practice, and education, I’ll become more efficient at using it.

Users download the packet capture files and work through a series of investigative questions, given only the slightest of hints, in order to document the indicators of compromise. Being a novice, it’s been a great opportunity to learn my way around WireShark, get more hands-on familiarity with the OSI model, and analyze real malware. If you’re interested in pursuing a career as a SOC Analyst, like I am, this seems to be an important professional skill. I’m grateful for all of the resources that are out there, which show me me how to better hone this particular skill set.
The central learning issue, it seems to me, is that D3.js
By: Douglas Hope
Tags: Data Visualization, D3js, Data Visualisation

The central learning issue, it seems to me, is that D3.js is presented as a general purpose tool capable of tackling more or less any ad-hoc data visualisation challenge (“chaff”), but it’s real strength lies in focussed, progressive and comprehensive data tree traversal and visualisation (the “corn” or “wheat”).

In life, almost everything can be represented as a tree: ranging from data exchange formats, through myriad classification systems, dependent physical properties and modal application patterns. The variety of D3.js methods used in their processing is, however, surprisingly small.

If you want to really master D3.js, then, the most consistent, self-reinforcing approach is through a larger integrative project, mixing and matching multiple data sources to create dependent, time-synchronised visualisations based around a single, real-time, streamed data (exchange) source.

There is, however, a catch: for such larger projects, current, underlying continuous integration/lifecycle management/bundling environments (Webpack etc) tend to block D3.js’s powerful data import methods, forcing the use of clumsy, pseudo-dynamic, pre-compiled substitutes.
Build A Dashboard Application with React + D3
Tags: Visualization, D3js, React

Resource: https://github.com/sdq/react-d3-dashboard

In this demo, we build a dashboard with React+D3 using a fake user dataset.

Data to Dashboard

1. Build Dashboard Layout

It is easy to build a dashboard layout with Ant.Design Layout components. (https://ant.design/components/layout/)

Two useful layouts with ant.design

We can just use Content and Sider to split out dashboard:

Split dashboard with Content and Sider

Now we can use these two component to build our dashboard layout.

Build dashboard layout using Ant Design

Write CSS to make the dashboard look decent.

Dashboard layout with style CSS

2. D3 React Component

D3 is the standard framework to build a visualization chart. However, it is not really compatible with React because D3 operates DOM directly and React uses Virtual DOM. So we need use some methods to combine these two amazing frameworks.

In this tutorial, we package D3 into a React Component. Each chart component is consist of three files: index.js, vis.js, and style.css .

index.js is a React container for D3 chart. The D3 only operate DOMs inside this container, so it will not affect other parts of the React project.

index.js

vis.js is the part for D3 to draw the code using props. We can write D3 code inside the draw function.

style.css is the file for chart style. In our dashboard demo, there are three chart examples (Bar Chart, Line Chart, and Pie Chart).

3. Interface and Interaction

After we finished our chart components, we can now add them to views.

Add components to views

Dashboard with static components

Finally, we can add the interactions to the components. In our demo we store all the state in the Dashboard.js which is the top parent component.

Interactions in the dashboard.

Try yourself!

You can clone the code from https://github.com/sdq/react-d3-dashboard
Global Legislative Review of Child Sexual Abuse Material (CSAM) & Online Grooming for Sexual Purposes
By: Sijuade Oguntayo
Tags: Save The Children, Visualization, Naturallanguageprocessing, Data Science, D3js

Global Legislative Review of Child Sexual Abuse Material (CSAM) & Online Grooming for Sexual Purposes Sijuade Oguntayo Follow Mar 22 · 5 min read

Visualizing Global Legislation with d3.js

Introduction

Some time ago, I participated in an Omdena AI challenge in partnership with Save the Children, a leading humanitarian organization for children with a bold ambition — to create a world where every child has access to quality education and is protected from neglect, exploitation, and abuse.

Photo by Margaret Weir on Unsplash

Over a two-month period, we worked closely with the Technology for Development and Child Protection teams within Save The Children to collect and analyze data from multiple sources including online forums, scientific and newspaper articles for insights.

The Internet — A Dangerous Place

As of January of 2021, there are about 4.6B internet users which roughly is about 60% of the global population. This will continue to increase each year as the internet availability increases and accessibility improves.

A majority of the world’s population can now access the internet. It estimated that there are roughly 875,000 new users every day and young people all over are the most active users of the internet. In the US, the Federal Bureau of Investigations (FBI) estimates there are close to 750,000 offenders online at any given moment.

While child exploitation also happens in the physical world, one of the most significant features of cyberspace is the relative anonymity it provides to its users which makes it especially challenging to track and trace offenders.

While some children(mostly from poorer homes) do not have access to the internet, for a lot of children, internet use is occupying ever more time, and in more locations, and on more personalized devices (mobile phones and tablets).

Online abuse and grooming is an area of growing concern in this modern technological era.

Online sexual predators target young victims with a study showing at least 13% of children reporting to have received negative unwanted attention of a sexual nature on the Internet.

CSAM & Online Grooming

CSAM may come in a variety of mediums including writings, images, videos, and/or drawings.

In 2017, INHOPE, the International Association of Internet Hotlines, reported that of the 1.2M reports received, 18% were sexual abuse images depicting children aged 14–17, 79% were of children aged 3–13, and 3% were of children aged 0–2.

Online Grooming refers to a number of tactics by offenders to befriend children with the intention of sexually exploting them through the internet. Offenders build a trust relationship with the children (sometimes, they themselves posing as one) which they exploit by manipulating and/or pressuring the children into inappropriate activities like sexual conversations and/or creating and transmitting CSAM.

The ultimate goal of online grooming is to sexually abuse a child, either by meeting physically or virtually.
3 Solid Video Tutorials to Get You Started on D3 Data Visualization
By: Annie Liao
Tags: Data Visualization, Web Development, JavaScript, Web Design, D3js

D3.js is a beast. As the JavaScript library for data visualization, its mesmerizingly powerful toolset can seem intimidating even for senior developers.

While not a seasoned developer yet, I have long been interested in D3.js since its initial release in 2011 (wait, it’s been 10 years already?!)

Below are three video tutorials that I found to be very helpful in understanding, utilizing, and appreciating this dataviz giant called D3.

1. D3 Data Visualization by Curran Kelleher

Part of freeCodeCamp’s free resource, this recently-updated (February 2021), 17-hour YouTube tutorial is a course for everyone, ranging from code newbies to JavaScript veterans.

My favorite feature of this course is the ability to pick and choose between sections. There is no need to follow in order. If you expand on the description field, you can see how the course is constructed and simply scrub to the part that works for you:

I took the original 2020 version and truly enjoyed the hands-on experience. It is impressive how Curran makes it quick and easy to build simple D3 data visualizations, especially when you use the 2x playback speed 😉

2. D3 Coding Train ft. Shirley Wu

This is a recorded live interview/demo session between the Coding Train host Daniel Shiffman and D3.js master artist Shirley Wu.

Amidst the fun and lively conversation, Shirley explained the concept of data binding in D3.js, and walked us through her process of building her signature art project.

The 2-part series also inspired me to create my very first D3 project. Nuff said.

3. Fullstack D3 Masterclass by Amelia Wattenberger

To be honest, I was on the fence about this course, as it comes with a hefty price tag and, depending on your learning style, might not be the best bang for your buck.

That being said, Amelia is one of the most admired D3.js developers, so it is definitely worth the effort coding along as she unwraps the intricacy of data visualization — both technically and aesthetically.
How to create D3js v6 Timeline Chart
By: Petr Jahoda
Tags: Programming, D3js, Tutorial, Go, Golang

How to create D3js v6 Timeline Chart

D3js is a Javascript library for doing graphical magic on data. In the year 2020, it was upgraded to version 6.

And this brings us a little problem. Official examples gallery doesn’t use Javascript, instead it uses special Observable Notebook language. It is not easy, nowadays, to find an up-to-date version 6 examples of D3js charts.

This was the reason for this article. I was not able to find out working example of version 6 timeline chart, so I decided to make one.

Please note, that this work stands on shoulders of other people.

In this article, we will use strategy I learnt in Amelia Wattenberger’s book and we will build on those steps:

Access the data Create chart dimensions and scales Draw the canvas Draw data Set up interactions

We will use latest version of D3js, which is version 6.5.0, as of February 8, 2021. We will use Go as a web server to simulate some pseudo-real world backend data sending. And we will use Goland as an IDE.

You can skip Preparing the project, if you only need the D3js information. As always, you’ll find link to Github repository at the end of the article.

Here is a more descriptive tutorial on creating web server in Go.
Experience Learning D3 Javascript Library: Things I picked up on
Tags: JavaScript, D3js

Experience Learning D3 Javascript Library: Things I picked up on Perezchristian Apr 13·3 min read

Photo by Campaign Creators on Unsplash

I came across D3 when I was applying to a position at a media company and was asked in a code challenge to submit a bar chart with data that is within a csv file. Unfortunately I was unable to complete the challenge but it opened my eyes to what I can learn. In my previous projects I created mostly task and list tracking web apps because I’m a stickler when it comes to being organized. So writing code to produce charts was definitely out of my wheel-house. However when trying to teach myself in a limited time frame, I picked up several things that I know I would need to expand on.

Many examples online showed how to create simple bar charts with data that is hardcoded and not from another file. In this case, I had to know how to grab the data that was on the csv file and pass it through my code in order for me to create the visual bar chart.

First within my index.html file, I needed to add the following script to the top of my program in order to have the latest D3 version.

<script src="https://d3js.org/d3.v6.min.js"></script>

Another thing I picked up on was how to call the file within my program in order to get the data objects I needed. To do so I needed to save the csv file within my public folder and within my index.html file I had to reference the following:

d3.csv("program-views.csv", function(d) {

return d

}

This allows my program to pull the data from the csv file and return the data itself. The way the data comes through is an array of objects and for the columns from the csv file, they are also separated out if you so choose to call on them.

As you can imagine in order to create the x and y axis for your chart, you must define both axis with a label and the data you want to show from the csv file. This goes the same with setting up the scale of the chart, the width of the individual bars in the bar chart, and the color to help distinguish one bar from another. In my case, the type of bar chart I had to created would’ve been a grouped bar chart. This is because the employer wanted to show the distinct demographic types from each city based on genre of shows.

The last main thing I picked up on was the importance of svg (scalable vector graphics). This is where the chart would be contained on the page and defining the margin, width, and height.

Although I didn’t succeed in completing my task, I am now more than ever intrigued and excited to learn this new tool at my disposal. I currently just enrolled in a coursera D3 course that will help develop my understanding and skills to be able to create all the charts I can imagine!

P.S If you would like to look learn more about D3, check out the link below:

https://d3js.org/
Moving forward (Samsung summer internship) — Part 3
By: Yash Gugale
Tags: Data Visualization, Funding, Education, D3js, Research

Part three: Enough doors knocked

An international student pays about 3 times the tuition for in-state students. We are aware of this and still enroll to the best US universities because of the quality of education and the opportunities offered. (I feel the need to thank our president Mr. Mitch Daniels for his remarkable decision to freeze Purdue’s tuition since 2012. This is a remarkable step and we owe it to his visionary leadership. As a boilermaker, I will try my best to make Purdue proud). But, I felt the need to take this financial burden off of my parents, though we could afford higher education in the US. I struggled for several weeks trying to get myself funded. I first approached Graduate Assistantship positions since is was told that they were easier to find. Starting right from Fall 2018, I applied to a lot of departments, but was unable to find any openings. Next came the Teaching Assistantship positions. These were filled way early before the fall semester had started. Research positions were also limited in the department and I had no idea where else I could get funding. I figured that I would not be able to fund myself in the fall 2018 semester. I had to get myself some sort of assistantship in the Spring semester. I started applying to GA positions. They were still not available. I applied for TA positions in CGT, CS and other departments. I emailed professors from various departments such as Planetary Sciences, Earth Sciences, Biology, CS, ECE, CGT and even marketing to look for research opportunities. (I might have contacted about 30+ professors) Therein lies the title for this post. Finally I was offered TA, GA and RA positions from various professors and academic personnel. I was interested in a lot of the professors work and looked at how I could apply graphics, VR and Machine learning to solve interesting problems.

During one of the CGT seminars, I came across a research project under Dr. Vetria Byrd in CGT which focused on data visualization. I had never done data visualization in my life, but I was really interested in the project since it was related to Education and Workforce development. (The educational field really interests me) I asked her if there was an opening and after interviews with her and Travis Fuerst (another faculty at CGT), Sascha (IN-MaC Director of Workforce and Education), I was offered an RA position. It was time to call home and tell my father that I no longer needed him to send me money (add dramatic music here). I find myself extremely lucky to get such an opportunity to do research in such an interesting area. I am thankful to Dr. Byrd, Travis and Sascha for giving me such an amazing opportunity.
d3.js, Linearicons and Font Awesome
By: Bryony Miles
Tags: Icons, JavaScript, D3js, Font Awesome

Clients often want to embed icons in d3 which is not a built in feature.

Here’s my solution for 2 great icon providers.

Linear Icons

a) choose your icon

When you go to the website and click on an icon you get the properties page:

You need to store the number in the Entity field (in this case 800).

You will be using this later with the prefix ‘\ue’ instead of ‘’.

b) add a link in your html page:

<link rel="stylesheet" href="https://cdn.linearicons.com/free/1.0.0/icon-font.min.css">

c) the code (use can clearly use CSS for styling if you wish)

svg.append('text')

.style('font-family', 'Linearicons-Free')

.attr('font-size', '20px' )

.text('\ue800')

.attr('x',40)

.attr('y',40)

.attr("fill","pink");

This adds a pink 20px x 20px home icon to your svg at position (40,40).

Font Awesome

a) choose your icon

When you go to the website and click on an icon you get the properties page:

You need to store the number in the Entity which is the number/letter combo starting with f (in this case 2b9).

You will be using this later with the prefix ‘\uf’ instead of ‘f’.

b) add a link in your html page:

<script src="https://kit.fontawesome.com/type-your-personal-kitcode-here.js"></script>

You’ll need to visit this link to get your personal kit code.

c) the code

d3.select("svg").append("text")

.attr("class","fa")

.attr("x",20)

.attr("y",20)

.attr("font-size","20px")

.attr("fill","pink")

.text('\uf2b9')

NB: you need to give your text element a class of “fa” otherwise it won’t render properly.

Hope that’s helpful..
Replacing Text with SVG paths in JavaScript.
By: Fanzhong Zeng
Tags: JavaScript, D3js, Scalable Vector Graphics

Appending Text to the Screen

Before we start, I’ll like to mention that I am using the D3 JavaScript Library. So if anyone plans on using my code, please take a look at that library and import the library in your own project.

I am also using a mono space font, which is a type of font that the letters/characters each occupy the same amount of horizontal space.

Let’s take a look at the parameters of the function first.

In the parameters we have g, which is the html element we are appending the image to. The text, being the words or paragraph we are displaying on the screen. The id, is the name of this html element’s id we are creating. X and Y being the start position of the text. Fill color is the color of the text, and scale is the size of the text.

There are two optional parameters, first is the horizontal_letter_spacing, this is how width each of my letters are. It is used to figure out how far away each letter should be from each other. The other one being stroke_width, which is the number that tells how wide the line is in units, which I default to 2.

The rest is simple, we simply select the g and for each letter or character in the string, we append a path to it, giving it the necessary attributes while updating the new X position by the horizontal spacing, and the scale (size) of each letter.

Note: character_array is a hash of all the possible characters on the keyboard as an SVG path of an mono space font . Scroll all the way down to get the hash.

However there is one issue, this will continue forever even going off the screen, since this doesn’t know when to stop, and restart in the next line.
Explanatory Model Analysis with modelStudio
By: Przemyslaw Biecek
Tags: Machine Learning, Model Visualisation, D3js, Model Exploration, Xai

Version 0.2.1 of the modelStudio package reached CRAN this week. Let me shortly overview coolest new features (list of all changes).

Short reminder: The modelStudio package creates an interactive serverless D3.js dashboard for exploration of predictive models, which is based on principles of Explanatory Model Analysis. With modelStudio interface, one can juxtapose instance-level model explanations (Break Down, Shapley values and Ceteris Paribus profiles), dataset-level model explanations (Partial Dependence Plots, Feature Importance, Accumulated Local Effects Plot) and data exploration plots (histogram and scatterplots). Examples below use a GBM model trained on the kaggle FIFA 19 dataset to predict player’s value based on selected 40 player’s characteristics. Play with the live demo here.

New plots for EDA

There are two new plots in modelStudio for exploratory data analysis: Target vs Feature and Average Target vs Feature (useful for classification problems). They are especially helpful when examining Partial Dependence profiles. Both show the relation between target and a selected feature, but first shows the raw relation in the data, while the latter shows a relationship learned by a model.

Better defaults

Some defaults changed in version v0.2.1 to improve the general usability.

If no new instances are provided for local explanations, then by default, a small sample is taken at random from the training data.

When modelStudio is plotted, by default the first panel is set to a Break Down plot while the second panel is clicked. This saves 3 clicks!

All plots for categorical variables now have the same order of levels.

Verbose and stable calculations

modelStudio is serverless, so all computations need to be done in advance, which may take some time. By default, the whole process is more verbose, shows a progress bar and information about the current calculations.

The try-catch blocks reassure that even if some parts fail, the rest will finish and plots will show up in the dashboard.

Feature importance plots now have boxplots that show how stable are calculations for individual variables.

Easy to create

The code chunk below creates a random forest model for the apartments dataset and then creates a modelStudio dashboard.

library(DALEX)

library(randomForest)

model <- randomForest(m2.price ~., data = apartments)

explainer <- explain(model, data = apartments[,-1], y = apartments[,1]) library(modelStudio)

modelStudio(explainer)

Learn more

Find more information in the modelStudio GitHub repo.
增強 D3.js 的視覺化功能
By: Kjh, Kuan-Jung
Tags: Visualization, D3js, Interaction Design

增強 D3.js 的視覺化功能

在這篇會討論的內容有增加篩選資料功能、增加動畫效果，使你的資料看起來和緩自然，最後，我們增加一些 tooltips，讓使用者 hover 到某個地方時，會顯示該資料的內容。

在 D3.js 基礎繪圖中，有提到我為 scatter plot 製作了一個特殊的功能：只顯示 min/max 的點，我今天打算為他來製作新功能：使用者可以透過下拉選單選擇顯示全部點的數字、只顯示 min/max、以及不顯示。

為了完成這個目的，我們要先做到兩件事：調整 showMinMax 函式(這個命名不是很好)

還有在下拉選單的挑選時，讓 js 知道前端 select 元素更改的事件。

雖然我們有 jQuery 可以使用，但為了這次的練習，使用 d3 的 select 函式來做處理：

其中，select(“#kpi”).node().value 是回傳當前選擇的元素 value，意思是如果我在前端選 None，則 s 會得到 none。

執行結果如下：

上述是第一種常用的 filter。

我們還有另外一種 filter 方式，例如我為前面練習的天氣資料做擷取，我只只想看某個特定區段的時間，但是礙於篇幅，會於另外一篇中做討論。

這篇會討論一些動畫以及 Transition，主要目的是讓使用者看起來更有互動的感覺。

我們一樣以更改 scatter plot 為基礎進行練習。

首先我們在產生圓點的地方加入 transition()，這樣可以讓圖形呈現的方式變得較為動態，接著我們可以利用一個叫 duration() 的函式，接在 transition() 後面，來延遲圖形呈現。

我們也可以選擇呈現的方式，我們可以使用一個函式叫 ease()，傳入一參數 d3.easeBounce 來讓他呈現圖形時會有躍動的視覺效果。

練習的程式碼如下：

我們很常看到 tool tips，當我們的鼠標移到某個地方的時候，他會跳出一個小格子，裡面會有相對應的數字或提示。

在這邊我們要探討兩種加入 tool tips 方式，第一種是利用 HTML5 的 title attritube ，直接對圖形加 title，另一種則是透過 mousehover 事件來顯示 tool tips 。

首先，我們看第一種的做法，我們直接在前面製作的 bar chart 圖形後面直接加入以下兩行程式碼：

這樣的意思是，我在每個 rect 裡面再 append 一個 title 元素，然後該 title 內容就是數字內容。執行結果如下：

第二種比較複雜，我們預計直接讓這些 bar chart 在滑鼠指標指到的時候，在該長條的頂部顯示數字。

我們首先在長條圖中加入數字：

接著，我要撰寫當這個 rect 被鼠標 hover 時，才顯示數字，所以我要把產生 text 的 function 稍作修改。

我們利用 on(“mouseover”) 時顯示數字，on(“mouseout”) 達到讓數字消失之功效，所以我先在加這幾段 svg.selectAll(“rect”) 這段宣告長條的定義後面補上這樣的內容：

我們在 mouseover 事件時，直接在 svg 底下放入 text，並且當 mouseout 事件時，刪除這個文字，不過問題來了，因為直接在 svg 底下放text，文字不會跑到 rect 裡面，所以我們要對文字的 x、y 軸以及顯示的顏色做設定：

大家看到這段程式碼，應該會疑惑兩件事：parseFloat(d3.select(this).attr(“x”)) 這是甚麼？然後怎麼有魔術數字(-11 +20 之類特定的數字)，魔術數字主要是調整文字視覺上的排版，這並不是很好的示範，但因為時間有限，所以我就沒用 scale 等方法讓他根據螢幕大小來縮放。如果你要做到 RWD，建議使用 scale 來處理等比例縮放問題。在來，我們討論 d3.select(this).attr(“x”) 這幾個出現在上述程式碼， d3.select(this) 表示抓取當前我 mouseover 的元素資料，我要抓取這個長條的起始 x 座標，並且計算出長條的寬度，使我的文字可以顯示在長條的中間，那 parseFloat(d3.select(this).attr(“y”)) 一樣是要抓取長條的高度，好讓我的文字顯示在上面。

所以，根據上面的邏輯，我們來執行這段程式碼：

文字都有出來，排版也還可以，但是文字並沒有在 mouseout 事件發生時消失。

所以，我們要做最後一件事：指定被 mouseover 的長條有個獨立的 ID，並且在 mouseout 時， d3 去移除他原本選取的 id，對於 d3 的 selector 運作模式，我會在附錄中講解。

所以，我對產生的 text 指定其 id 元素為 tooltip，並且在 mouseout 時，透過 d3 的 selector 去移除 tooltip 。

最後執行結果如下：

在這個文章中，我們探討了幾個常見的互動方式，第一種是透過 filter 來撈取範圍資料，加強整個圖形重點，第二個是研究 Transition，讓產生圖表的方式有看起來更有「產生圖形的動作」，最後我們建立了簡單的 tool tip，讓讀者可以看到數字或事該筆資料的某些訊息提示 。

2. 關於 D3.select(selector) 的運作模式

我們在前面有看到

他到底怎麼找到正確的 text#tooltip 並刪除呢？我們可以從 d3 的官方文件看到以下 d3 selector 的運作模式

Selects the first element that matches the specified selector string. If no elements match the selector, returns an empty selection. If multiple elements match the selector, only the first matching element (in document order) will be selected.
Converting D3.js to PDF to PowerPoint
By: Gregor Hesse
Tags: JavaScript, Pdf, PowerPoint, Emf, D3js

Converting D3.js to PDF to PowerPoint

After creating a beautiful visualization in D3.js I often get the same question from my colleagues in marketing: «Could you send me a PowerPoint of this?». I usually explain that this a programmed chart, similar to a website, and that it is unfortunately not possible to put this on a PowerPoint slide. So far my best recommendation was to use the Microsoft snipping tool. But I recently found a solution that does a surprisingly good job.

So before we start, we need of course a D3.js visualization. For this I created a sunburst chart showing the annual net revenue of Mondēlez in 2018. It’s a pretty interesting chart. As we can see, 43.1% of their net revenue alone came from biscuits like e.g. Oreos. And North America alone accounts for 50% of these sales. That’s really a lot of biscuits.

So let’s convert this visualization into something we can use in a PowerPoint slide. First thing we want to do is to convert the html file with our D3.js visualization into a PDF. For this, we just need PhantomJS, a bit of JavaScript and a batch file with one line. This will take only three minutes. First, we download PhantomJS and extract the ZIP file into a folder of our preference, e.g. C:/PhantomJS/. No installation needed. Second, we download the rasterize.js script and put it into the folder where our sunburst.html file is located. Now, we open the Editor and type

C:/PhantomJS/bin/phantomjs rasterize.js sunburst.html sunburst.pdf

We save this file as a batch file, e.g. convert.bat. When running the batch file, we can see that a new file, called sunburst.pdf will pop up in our folder. We might want to fine tune the page width and height as well as the margins at the very beginning of the rasterize.js script. For our sunburst chart, we chose:

This is already pretty convenient. Our colleagues can already do so much more with a PDF than an HTML file that relies on several JavaScript packages and JSON files.
10 things I learned from Covid-19 with D3.js
By: Stacy Cho
Tags: Technology, Programming, Web Development, JavaScript, D3js

10 things I learned from Covid-19 with D3.js

Global Timeline of Covid19 by Stacy S. Cho

Overview

Global Covid19 Timeline has earned a lot of 💌 👏 😍from many people. I really appreciate for everyone’s support

As of now April 16, 2020, Global Covid19 Timeline has earned - 9K+ User Traffic - 58 Likes & 15 Comments from LinkedIn Post - 100+ Visits & 25+ Clone from Github repository

Photo by Priscilla Du Preez on Unsplash

Douglas Noel Adams, an author of The Hitchhiker’s Guide to the Galaxy once said,

Programming gets things done

I was actively looking for software engineer jobs in NYC before the Corona Virus swept New York & New Jersey. I had many interviews scheduled and I was very hopeful and motivated to start my career as a software engineer.

The virus swept the U.S., especially New York and I received many emails and messages about interview process being pended and rejected due to the the virus. New Yorkers were asked to Stay at Home and my job hunting period stopped until further notice.

For the first few days of my status being changed from Job seeker to the unemployed, John Hopkins’s Covid Website & Google’s Coronavirus (COVID-19) map became my Netflix. I was checking the graphs and the world map every hours hoping that the trend goes down and everything comes back to the normal, but the trend goes an opposite of what I hope so.
d3.csv(): Reading in Data via D3
By: Tim Lafferty
Tags: Beginner, D3js, JavaScript

Loading and accessing the data

Download the data set to follow along.

If you’re not familiar with asynchronous programming, these next parts might feel a bit confusing to you. We’re going to have to work on the honor system though, as I’m not about to explain it in this post.

Alright — so first thing is first: we need to access the data. Here’s a simple script (and common pattern) to do so:

// Load Data

d3.csv("datasources/Sample-Superstore.csv")

.then(res => {

console.log(res)

})

In an oversimplified explanation, we’re waiting for the data source to be read (as the “res” variable) and then calling our next function(s). This prevents the functions from trying to execute before the data is available. If you’re wondering what the arrow-looking thing is, don’t worry — I’ll cover that in a bit.

Now, look at your console. You should see an array of objects. By expanding one of those objects, you will find all of the properties associated. Looks correct, right?

However, notice that every value was ingested as a string. This obviously will make any further math virtually impossible (or at least a major pain in your ass).

Let’s create a function called “type” that converts all of the necessary fields into numeric values.

// 1. Helper functions

const dateParser = d3.timeParse(“%m/%d/%Y”); // 2. Type Conversion

function type(d) {

return {

RowId: +d[“Row ID”],

OrderId: d[“Order ID”],

CustomerId: d[“Customer ID”],

ProductId: d[“Product ID”],

CustomerName: d[“Customer Name”],

City: d.City,

State: d.State,

PostalCode: +d[“Postal Code”],

Region: d.Region,

Category: d.Category,

SubCategory: d[“Sub-Category”],

Product: d[“Product Name”],

Sales: +d.Sales,

Quantity: d.Quantity,

Profit: +d.Profit,

Discount: +d.Discount,

OrderDate: dateParser(d[“Order Date”]),

ShipDate: dateParser(d[“Ship Date”])

}

} // 3. Load Data

d3.csv(“datasources/Sample — Superstore.csv”, type)

.then(res => {

console.log(res)

})

Let’s break this code into three chunks:

Helper functions: This is where you place functions that will help you do small tasks, such as parse dates, format numbers, remove characters, etc. Type Conversion: To the main point, this function explicitly casts the data point of interest to their respective type. Columns not specified will not be returned. Loading Data: Notice right next to the file directory, we’re invoking the type function we’ve just created.

Now, look at your console. You should see an array of objects. By expanding one of those objects, you will find all of the properties associated. Looks correct, right?

Awesome! Now we’re ready to start playing with our data.
Bring Data to Life on Mobile: D3.js & React Native
By: Tyler Murphy
Tags: Tutorial, Graph, D3js, React Native

X Axis & D3 Scaleband

Let’s take a moment to talk about the xAxis.js , and specifically, scaleBand which we have imported from d3-scale here.

The main concept around constructing graphs with D3 is the idea of drawing an SVG. We need a way to take a set of data and determine its x,y position on the SVG. The way to do this is to use a scale function, like scaleBand .

For this specific use case, we want to plot the 7 days of the week, ending in todays date. We know that each day is no greater or less than any other day, aka will be evenly spaced out, and so we can use the scaleBand function to achieve this.

First, lets write a function that will generate an object containing 2 arrays for days and their corresponding dates:

Here we are looping 7 times (without using one of those nasty for loops), using moment to get and format each day and date, and pushing to their respective arrays. We return this as an object, which looks like this:

Let’s add this function to our Axis component, place these values inside an ART grouping, and map over them.

Okay let’s unpack some of this new code. After we generated our values for days and dates, we map over them in order to plot them on the graph. We are doing this for both days, and dates. The reason is because, if you look at the very top image in this tutorial, the day of the week is above the day number, and therefore they have a different Y position.

I’ve included a handful of attributes with Text, such as alignment, font, and fill. An important attribute to look at here is opacity. Basically I am saying “If this is the last item being mapped, set to opacity 1, else set to 0.6”. This is what gives us that highlighted effect on today’s date.

Now, if you save and/or reload the app, you’re UI should look like this:

X-Axis with no x-plotting function

In the bottom left we have our X Axis values, but they are all stacked on top of each other. This is because we have not yet computed X positions for them. Lets write a function, using scaleband , that will take in the index, values being assessed, and width, and return the x position for each value individually as they are being mapped:

Above we are creating a scaleBand that uses a function called rangeRound to shorten the width of the scale. Then we apply each value to x.domain and return the position generated for this specific index.

Now we will call this function for x to accurately plot our xAxis:

Your XAxis component should now be complete and look like this:

… And you will now see an XAxis in the UI, showing the past week of dates, highlighting today:

X-Axis finished

Wow. That was a lot of work. And we have only covered the X Axis! Maybe I should have split this article into multiple parts. 🤔

Oh well, is what it is. Let’s move on to creating the YAxis and the gridlines.
An Alternative to Choropleth: Contour Density Maps in D3.js
By: Ellie Frymire
Tags: Data Visualization, JavaScript, Maps, Visualization, D3js

by Ellie Frymire, Data Visualization Developer, Two-N

Note: In this article, we present an argument for using contour maps to represent graphically continuous data, and follow up with a technical how-to on implementation using d3.js. Although the first section is written towards for all audiences as a discussion of visual theory, the development section is written towards developers, specifically those well versed in d3.js.

Choropleth maps have historically been the default visual representation for data associated with a geographic area. They can be most helpful to expose three valuable data types for region-based data: (1) the location and geography of each feature, (2) area or size, and (3) the associated data values. Because of the clear relationship between region and data value, it is often the first choice for geographic data:

In the choropleth example on the left, the poverty data included is a percent by state — thus a map with each state colored by its value makes sense.

But what if the data itself isn’t constrained to a delineated region, like temperature, or precipitation? Weather events are continuous; rain or temperature doesn’t stop at a border. Often, this data is managed on a regional level, such as climate divisions, but it shouldn’t be visualized as such. In these instances, choropleth maps are much less effective.

The state, county, climate division, or other borders that are inherent in choropleths create artificial boundaries that are not applicable to geographically continuous data. We propose using contour maps to visualize continuous data measured by geographic region.

Contour maps blend the border lines between regions, maintaining the continuity of the data itself. Let’s consider this direction with rate of temperature change data from the US climate divisions, reported by the EPA. Here’s a sample of the data:

Climate Division,Temperature Change

101,-0.294037192

102,-0.234474868

103,-0.661866435

104,-0.220764618

105,-0.242089482

106,-0.432744154

107,-0.521121018

108,0.075600358

201,2.096787133

202,1.463899629

203,2.291893527

204,2.023514559

205,2.793129751

206,2.685887319

207,1.544004314

...

Each climate division represents a geographical area, and the associated value is representative for the entire region. This data translates to the below choropleth (figure 3), also from the EPA:

The choropleth map is still illustrative, but region borders are insignificant in this context. The varying temperatures in neighboring divisions show the spread of temperature over the entire country, but the regions themselves aren’t relevant. The same data, visualized in a contour map, can appear much more effective:

The region borders are no longer limits for the data. This visual, rather, focuses on the geographically continuous data itself, illustrating the varying temperature changes throughout the country.
Map visualization in D3.js with GeoJSON/TopoJSON cartography
By: Anirudh K Mahant
Tags: Cartography, Geojson, Datamap, D3js, Topojson

With the fluent syntactic sugar, it can be combined in one liner. Now D3.js can draw SVG paths for all US counties using the GeoJSON features collection.

D3.js teams up rather well with TopoJSON to simplify Map visualizations. All the data magic happens by calling topojson.feature(us, us.objects.counties).features() function which returns US counties as GoeJSON FeatureCollection . With one change you can draw US states instead, the only required change is topojson.feature(us, us.objects.states).features() because the TopoJSON file has both US counties and states defined as geometry collection.

What’s GeoJSON and TopoJSON?

GeoJSON is an open standards format to store and interchange geographic data in JSON format, along with non-spatial attributes. The format gained traction with advent of GIS (Geographic Information System) systems and devices. Due to its high precision a GeoJSON format is not streamlined for web or bandwidth friendly.

Working as an extension on top of GeoJSON, TopoJSON format compensates these cons by using several algorithms to eliminate redundant and duplicate data. Concisely, simplifying paths as arcs and combining boundaries between topologies that might produce two-folds.

TopoJSON comes bundled with a set of useful CLI tools to make it easier. You can install them using NPM package manager. Some notable CLI tools:

They come in very handy for advanced CLI cartography, which is the aim. If it felt like cakewalk by now, the same cannot be said when manipulating maps, like choropleth maps, 3D maps, map interactions, or, combining/merging topologies.

Anatomy of GeoJSON/TopoJSON

Addressing the theme around this article, let’s understand how GeoJSON/TopoJSON store geographic topologies. GeoJSON uses FeatureCollection and Feature objects, to test it let’s take a Feature object for Delaware (notice no arcs):

Look closely at co-ordinates object, they’re longitudes and latitudes (reverse them in Google Maps) defining the boundary of Delaware. Now let’s see the same map object in TopoJSON format (click view raw):

Pay attention to bbox or bounding box and arcs object, also there are no geometry objects. That’s how TopoJSON overcomes the exhausting payload size of GeoJSON, by encoding GeoJSON feature collection into arcs , optionally quantize and simplify geometry, resulting in much simpler and smaller format with somewhat precision trade-off.

Advanced cartography with CLI

Merging US states into regions — starting with northwest, midwest, southwest, southeast and northeast. Several ideas pumped in from Observable HQ out of which two of them really stood out. Explore more on Observable HQ, there’s abundant information on D3.js with matching examples.

There are two methods to do it, one is using topomerge CLI, and the other is using topojson.merge() in Browser. I went with the Browser approach first, quick and dirty, but proves effective!
Vue + D3.js -專案發想實作
By: Jacy Chu
Tags: Firebase, Vuejs, JavaScript, Frontend, D3js

實作學習筆記

在實作過程中，遇到大大小小的困難。有的稍微上網查一下便迎刃而解，有的嘗試了好幾個小時只有一點進展。不論問題點是大是小，都從中獲得許多，以下將依開發的順序，記錄這些學習。

(1) 引用 Tailwind CSS 至專案

最初參考這支 Youtube 教學影片 Set up a New Project with Vue.js and tailwind.css。後來發現只要在創建好專案時，加上： vue add tailwind 指令，即自動配置好原本需手動修改的部分。

(2) 季度切換之樣式改變

若在一般 js 檔案開發，會使用querySelectAll 將所有按鈕做選取，先將所有 button 的 active 取消，再把選中的加上 active class，類似下方程式碼的寫法：

然而在 Vue 中寫法不同，在 Q1->Q4 的 buttons 上，各自綁定 {active:quarter === 'QX'} ，下方 methods 設定被選中的 e.target.dataset.quarter 。

(3) Send Form 檢查

表單檢查，先用 isNaN() 檢查 amount 是不是數字，還有檢查是否有空值情況就按送出，若有以上情況會出現錯誤訊息。檢查的 methods 綁定在 button 上的 click 事件，若這邊用 <form> 去包的話，不論檢查有沒有過都會送出！要特別小心。

(4) 資料庫連動

Firebase 提供 onSnapshot 監聽功能，如果資料有改變會自動觸發。由於繪製表格部分與季度 & 填寫表單是分開的。本來想說要用變數從 props 父傳子去觸發改動，後來發現不需要做這件事。Send Form 動作改動到 Firebase 資料，設定好的情況下，會自動觸發。

(5) Q1->Q4 四張圖表切割

一開始寫的時候，只有 source 與 amount 兩個欄位。因為要切換季度所以多加上 quarter 欄位。update function 會接收到所有的資料，先過濾只留下選中的季度： data = data.filter(item => item.quarter == this.quarter) 。後續操作即切分開來！

(6) Hover 環圈圖

游標移動到環圈圖上面，出現客製化的 tooltip，顯示項目詳細資訊，點按一下即會刪除該項目。實作過程中，發現 mouseover 與 click 事件，操作上有點問題。處於 hover 狀態，被切換成 click，還沒有完成刪除動作又 hover 在新的區塊上。為了解決這樣的問題，在 mouseover 觸發加上 setTimeout 0.2秒的時間。

(7) 計算 Total & Annual Income

此專案沒有使用 Vuex，所以採用 $emit 將子元件傳送計算好的數字，傳給父元件呈現。使用 new.Intl.NumberFormat().format 將數字採用千進位。

(8) 自製重組 Ｑ1->Q4 資料

Firebase 只有每一筆資料，在畫面下方，四個季度整理的長條圖資料需要自行後製。每個季度整理形式如下：

將季度的金額加總，重新組合繪製在畫布上。

(9) Source 相同 數字加上去

一開始寫法，使用 db.collection("incometracker").add() ，即便輸入的 source 已經存在仍會產生新的區塊(不會覆蓋掉原本的，若要覆蓋使用 update )。以上都不是此實作想採用的作法，會希望使用者輸入同項目時，直接加到存在的項目上，由於此操作在寫進 Firebase 之前，故在加到 Firebase 前做下列檢查：
First steps with SvelteKit and Tailwind CSS JIT
By: Benjamin Preiss
Tags: Sveltekit, Data Visualization, Tailwind Css, D3js, Svelte

Let’s build a simple page with SvelteKit! Just recently I stumbled across slate and its design system while reading about filecoin. Today I will use their design system and Tailwind CSS JIT to create a little page in SvelteKit.

Step 1 — Setup Project

Setting up the project I basically followed the “Getting Started” section in the SvelteKit docs: https://kit.svelte.dev/docs#introduction-getting-started

mkdir my-app

cd my-app

npm init svelte@next

npm install

npm run dev

At the init step I chose the following settings: SvelteKit skeleton project, no typescript, add ESLint and add Prettier.

The last command starts the development server on localhost:3000. We are ready to go!

Step 2 — Setup Tailwind CSS Jit

Again, following a guide. Credits to Matt Lehrer!

Installation and Initialization (from the Tailwind CSS “Getting Started” Guide)

npm install -D tailwindcss@latest postcss@latest autoprefixer@latest

npx tailwindcss init

2. Setup CSS purging in production + JIT (taken from Matt Lehrer and Tailwind Blog)

// tailwind.config.js

module.exports = {

mode: 'jit',

purge: ['src/app.html', 'src/**/*.svelte'],

...

}

3. Include Tailwind in CSS. Create style.css (taken from Matt Lehrer)

/* ./src/style.css */

@tailwind base;

@tailwind components;

@tailwind utilities;

Step 3 — Final adjustments to project

intended src folder file structure

Remember, we used a SvelteKit skeleton to setup our project. Now we have to make some small adjustments before we can start. The intended src/ file structure is depicted on the left.

Create src/$layout.svelte

Create a file src/$layout.svelte. It will import style.css on every route (taken from Matt Lehrer):

Remove unused files

Delete src/global.d.ts.

Now we are ready to go!

Step 4— Create simple page using slate design system

Now let’s start creating our a simple page using slate design system! For the beginning I want to add a h1 heading and a “Radial Tidy Tree” using d3 (link)

Create h1 heading

Here is an excerpt from the sds source code for h1 headings:

Translated to Tailwind styles:

font-normal font-inter text-sds-h1 break-words no-underline

Change tailwind.config.cjs :

Resulting code for index.svelte :

Gives us at localhost:3000 :

Create radial tidy tree from d3.js

We will now adapt this d3.js “Radial Tidy Tree” example to work in Svelte. We will only apply necessary changes to get it to work, not using Svelte + d3.js to its full potential.

Every line I changed is commented with single line JS comments. The according explanation can be found above in a multi line JS comment:

/* Explanation

*/ // Wrong code

Correct code

Which results in:

Credits

As already mentioned above, credits go to

This article is just about putting together the knowledge they so kindly shared!