primers

Following Learn D3: Scales 5, only translated into English, the modifiable parts of the code were replaced with static images. For real-time interaction, please read the original text.

The body of the

SVG and Canvas allow graphics of any type to be intentionally generic; In contrast, D3 is for visualization and therefore provides a specialized vocabulary of shapes that are functions for generating path data.

Paths can be circles, rectangles, straight lines, curves, dives, tigers 🐅, and just about anything you can imagine. The shape of the path is specified by the SVG Path Data Language (or equivalent Canvas path method), which is similar to the old plotter’s commands. Such as:

  • Mx,y – Move to specified point [x,y]
  • Lx,y – Draw a line to the specified point [x,y]
  • Hx – Draw a horizontal line of length x
  • Vy – Draw a vertical line of length y
  • Z – Closes the current subpath

For example, we want to think of Apple’s stock price over the years as a line chart. This is a data set containing date and close (” close “refers to the stock price at the end of the market), and the corresponding scale.

To draw this line, we need path data, start moving to the first point with Mx,y, and then repeat Lx,y to draw a line to each subsequent point. We can do this by looping through points.

But d3.line is more convenient. Calling d3.line returns a default line generator. By calling line.x and line.y, we can configure the line using functions to return the x and Y positions of a given data point D. These functions retrieve the desired abstract value (date or count) and convert it to a visual location (by applying scale).

With the line generator, the data returns the corresponding SVG path data string, which can be used to set the D attribute of the path element.

To avoid duplication, I define reusable axes in the appendix below. Each axis is a function that selects the G element to fill.

The path above is a blue line with no padding. To avoid misleading spikes from mitts between line segments, I set the mitt limit to 100% of the line width (1 x). I can also use rounded wire to join and seal.

For area diagrams, there is a similar d3.area. The shape of the region is specified as two lines with shared x values: area.y0 is the baseline and Area.y1 is the top line. For the area graph with a constant baseline along the bottom edge of the graph, we set area.y0 to y(0).

If you want an area with variable baselines such as stacked Area Chart, Streamgraph or the Bollinger bands below, pass a function to area.y0. As with area.x and area.y1, this function is called for each data point to calculate the corresponding y value.

To complete the presentation of Bollinger Bands by displaying central moving averages and daily closing prices, we can overlay lines at the top. Because each path element can have only one style, we use multiple colors for multiple paths.

When lines and regions work together: You can call area.lineY0 or area.lineY1, respectively, to get the line corresponding to the baseline or top line of the region. This is useful for decorating areas with top or bottom lines.

Lines and regions have more functions, and we won’t cover them all here, but there are a few hints: radial lines and regions are useful for periodic data, such as seasonal temperatures; Curves provide configurable interpolation methods, such as maintaining a single curve; You can show gaps in missing data.

Of course, visualization is more than just bars, lines, and areas.

Another common shape, D3, is called an arc (arc), but mathematicians call it a circular sector. Its features are used around Pie Charts, Donut Charts, Sunsurge (but, confusingly, not Arc Diagrams).

In the same way that lines and regions are configured by X and Y, arcs are configured by innerRadius, outerRadius, startAngle, endAngle (angles expressed in radians). The arc generator above is configured to accept an array [startAngle, endAngle].

For PIE charts or Donut charts, calculating arc angles as described above can be tedious, so D3 provides D3.pie for ease of use. Think back to the delicious fruit data set.

By configuring the value accessor for the count property of the PIE layout, we can calculate the Angle of the arc so that the Angle span of each arc is proportional to its value, and the total span of the arc increases continuously from 0 to 2π.

These per-data objects can be passed to an arc generator with a fixed radius to generate a circle graph (since I can’t resist showing off, I’ll use fill and rounded radius).

Now that we’ve covered some common data graphics, let’s see how to get them moving!

Next

The appendix

The attached

According to the source code, the platform dependence was removed and the main code was extracted, with the following examples:

  • Example 1
  • Example 2
  • Example 3
  • Example 4
  • Example 5
  • Example 6
  • Example 7

The resources

The Witcher 3 is almost halfway through the main line, and it’s getting better and better, and then it’s always thinking “Push the story, clear the mission”.

Once I suddenly realized that I seemed to fall into a state of “addiction”, just want to blindly find a goal to promote, and then produce a sense of self-satisfaction.

Sometimes I feel bored after a long time, and it is necessary to reflect on how I should play a game:

  • The world view and setting of the game understand and think and imagine.
  • The operation and combat of the game, the experience of the basic system Settings such as empowerment, consciously thinking and exploring, and discovering different combinations of gameplay.
  • Focus on the design and telling of branching stories.
  • If you have played the same type of game, comparing yourself to others will help reduce the number of mistakes you have made.