current position：Home>Learning D3 introduction document: Data
Learning D3 introduction document: Data
2021-08-27 05:43:31 【XXHolic】
Following Learn D3: By Example Third articles , Only English translation , The modifiable part of the code replaces... With a static picture , For real-time interaction, please read the original text .
This notebook has a... That contains daily temperature readings CSV file . I use Shift-Command-U ⇧⌘U Keyboard shortcuts Add it ; You can also attach files by dragging and dropping them into the file attachments pane , The file attachments pane can be accessed from the notebook menu or by clicking the paper clip icon above .
FileAttachment Function returns only one handle , This handle allows you to select the desired representation , for example blob 、 buffer or （UTF-8 Coded ） Text . about CSV file , We can call
file.text Get the contents of the file as the desired string .
Of course , A more useful method is to parse the text into a text with
temperature Object of property , We can pass the text to d3.csvParse To achieve .(D3 Load... In the appendix below , Each unit in the notebook is available .）
Click on the array below to view the object .
although Observable Wait implicitly for cross cell promises , But we have to wait
file.text promise , Because we want to access the return value in the same cell .
By default ,D3 No type inference , therefore
temperature Properties are strings . This makes them difficult to get along with . for example , If you try to add two temperatures , Connect them . Oh dear ！
To convert these strings to dates and numbers , Pass a function as the second argument to
d3.csvParse . Each line calls this function , Manipulate the objects of the row as needed . Better yet , adopt d3.autoType Automatically infer types .
If you look at the array above , You will see blue dates and numbers （ Instead of the blue string between double quotes ）, This indicates that the type conversion was successful .
Let's take a look at Observable Unit Syntax . up to now , You only see things that can be named or anonymous expression unit . Both types of units can be checked , However, named cells can only be referenced from other cells .
For code that is more complex than simple expressions , Write a block , The block consists of one or more statements enclosed in braces . Block cells are similar to functions , Only if they return or yield The value is generated only when . Just like expression units , Named block cells can be referenced from other cells .
local variable , For example, above
s , Not visible to the rest of the notebook ; Other cells can only access the return value of the named cell . In this way ,Observable It's like a spreadsheet ： Each cell defines a unique value .
Go back to the task at hand , In a data In the unit of , There is a clearer way to get 、 Parsing and type conversion CSV file . If your data is consistent with d3.autoType Are not compatible , You can use this method ( If you're not sure , Don't rely on automatic type inference or Consult the documentation .）
With convenient data , We can start working now ！ for example , We can calculate the range of dates and temperatures , Get the area value .
As we saw before , We can do it in Example histogram Inject data into , Easy to intuitively perceive the temperature distribution .
A mild climate ！ ah , San Francisco .
stay Observable While processing data , An implicit consideration is whether to put the code in a single unit or separate units . A good rule of thumb is , A unit should define a named value that is referenced by other units （ As above
data ）, Or it should show readers some useful information （ Such as this article 、 The chart above or check the unit data ）.
A key implication of this rule is , You should avoid implicit dependencies between units ： Rely only on what you can name .
Why? ？ Notebook Data flow Is built from its unit reference . If the unit has no name , The unit cannot be referenced , And units that implicitly depend on their effects may run in front of them .( Cells run in topological order , Not from top to bottom .） Implicit dependencies can lead to uncertain behavior in the development process , And possible errors when the notebook is reloaded ！
for example , If a cell defines an array , Another unit modified it , Then other cells may see the array before or after the mutation . To avoid this uncertainty , Need to make dependencies explicit , You can specify a name for the second cell and use array.from or array.map Copy the array . Or merge two units , In this way, other cells can only see the modified array .
Our data is ready , Let's turn to graphics ！
Play with 《 The wizard 3》 In the process of , We often encounter such events and tasks ：
People in conflict , Describing the same thing is a completely different version , But it all makes sense , Finally, you, who have never experienced it, have to make a decision .
After several treatments , I found that sometimes in the game, it is really a torture of human nature , The dilemma , Difficult to decide .
If you encounter such a situation in reality , The alarm is a relatively good way .
author[XXHolic],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Crazy blessing! Tencent boss's "million JVM learning notes", real topic of Huawei Java interview 2020-2021
- How to implement injection in vuex source code?
- JQuery operation select (value, setting, selected)
- An article disassembles the pyramid architecture behind the gamefi outbreak
- BEM - a front-end CSS naming methodology
- [vue3] encapsulate custom global plug-ins
- Error using swiper plug-in in Vue
- Another ruthless character fell by 40000, which was "more beautiful" than Passat and maiteng, and didn't lose BMW
guess what you like
Huang Lei basks in Zhang Yixing's album, and the relationship between teachers and apprentices is no less than that in the past. Netizens envy Huang Lei
He was cheated by Wang Xiaofei and Li Chengxuan successively. Is an Yixuan a blessed daughter and not a blessed home?
Zhou Shen sang the theme song of the film "summer friends and sunny days" in mainland China. Netizen: endless aftertaste
Pink is Wangyuan online! Back to the peak! The new hairstyle is creamy and sassy
Front end interview daily 3 + 1 - day 858
Spring Webflux tutorial: how to build reactive web applications
[golang] walk into go language lesson 24 TCP high-level operation
August 23, 2021 Daily: less than three years after its establishment, Google dissolved the health department
The female doctor of Southeast University is no less beautiful than the female star. She has been married four times, and her personal experience has been controversial
There are many potential safety hazards in Chinese restaurant. The top of the program recording shed collapses, and the artist will fall down if he is careless
- Anti Mafia storm: He Yun's helpless son, Sun Xing, is destined to be caught by his dry son
- Introduction to flex flexible layout in CSS -- learning notes
- CSS learning notes - Flex layout (Ruan Yifeng tutorial summary)
- Today, let's talk about the arrow function of ES6
- Some thoughts on small program development
- Talk about mobile terminal adaptation
- Unwilling to cooperate with Wang Yibo again, Zhao Liying's fans went on a collective strike and made a public apology in less than a day
- JS function scope, closure, let, const
- Zheng Shuang's 30th birthday is deserted. Chen Jia has been sending blessings for ten years. Is it really just forgetting to make friends?
- Unveil the mystery of ascension
- Asynchronous solution async await
- Analysis and expansion of Vue infinite scroll source code
- Compression webpack plugin first screen loading optimization
- Specific usage of vue3 video play plug-in
- "The story of huiyeji" -- people are always greedy, and fairies should be spotless!
- Installing Vue devtool for chrome and Firefox
- Basic usage of JS object
- Two easy-to-use animation JS that make the page move
- Front end Engineering - scaffold
- Java SQL Server intelligent fixed asset management, back end + front end + mobile end
- Array de duplication problem solution - Nan recognition problem
- New choice for app development: building mobile applications using Vue native
- New gs8 Chengdu auto show announces interior Toyota technology blessing
- Vieira officially terminated his contract and left the team. The national security club sent blessings to him
- Less than 200000 to buy a Ford RV? 2.0T gasoline / diesel power, horizontal bed / longitudinal bed layout can be selected
- How does "heart 4" come to an end? Pinhole was boycotted by the brand, Ma Dong deleted the bad comments, and no one blessed him
- We are fearless in epidemic prevention and control -- pay tribute to the front-line workers of epidemic prevention!
- Front end, netty framework tutorial
- Xiaomi 11 | miui12.5 | android11 solves the problem that the httpcanary certificate cannot be installed
- The wireless charging of SAIC Roewe rx5 plus is so easy to use!
-  typescript
- CSS transform Complete Guide (Second Edition) flight.archives 007
- Ajax foundation - HTTP foundation of interview essential knowledge
- Cloud lesson | explain in detail how Huawei cloud exclusive load balancing charges
- [JS] 10. Closure application (loop processing)
- Left hand IRR, right hand NPV, master the password of getting rich