SVG Axes - zziuni/d3 GitHub Wiki
Wiki โธ API Reference โธ SVG โธ SVG Axes
D3์ axis ์ปดํฌ๋ํธ๋ ์๋์ผ๋ก ์ค์ผ์ผ๋ง ๋๋ ์ฐธ์กฐ ๋ผ์ธ์ ์ถ๋ ฅํ๋ค. axis ์ปดํฌ๋ํธ๊ฐ ์ถ์ ๊ทธ๋ฆฌ๊ณ ์ถ์ ๊ตฌ๋ถ์์ ๋ผ๋ฒจ๋ง์ ํ๋ ์ง๋ฃจํ ์์ ์ ๊ด๋ฆฌํด์ฃผ๋ฏ๋ก ๊ฐ๋ฐ์๋ ๋ฐ์ดํฐ ํํ์๋ง ์ง์คํ ์ ์๋ค.
์ถ(axis) ์ปดํฌ๋ํธ๋ D3์ ๋ชจ๋ quantitative scales์ ํจ๊ป ์ฌ์ฉํ ์ ์๋๋ก ์ค๊ณ๋์๋ค.
# d3.svg.axis()
๊ธฐ๋ณธ ์ถ์ ์๋ก ์์ฑํ๋ค.
# axis(selection)
selection์ด๋ transition์ผ๋ก ์ถ์ ์ ์ฉํ๋ค. selection์ SVG๋ G element๋ฅผ ๊ฐ๊ณ ์์ด์ผ ํ๋ค. ์์ ๋ฅผ ๋ณด์.
d3.select("body").append("svg")
.attr("class", "axis")
.attr("width", 1440)
.attr("height", 30)
.append("g")
.attr("transform", "translate(0,30)")
.call(axis);
# axis.scale([scale])
์ถ๊ณผ ๊ด๋ จ๋ ์ค์ผ์ผ์ get or set. scale์ ์ธ์๋ก ๋๊ธฐ๋ฉด ์ค์ผ์ผ์ ์ง์ ํ๊ณ ์ถ์ ๋ฐํํ๋ค. scale ์ธ์๊ฐ ์์ผ๋ฉด ํ์ฌ ์ค์ผ์ผ์ ๋ฐํํ๋ค. ๊ธฐ๋ณธ๊ฐ์ linear scale.
# axis.orient([orientation])
์ถ ์์น๋ฅผ set, get ํ๋ค. orientation ์ธ์๋ฅผ ๋๊ธฐ๋ฉด ์ถ ์์น๋ฅผ ์ง์ ํ๊ณ ๊ทธ ์ถ์ ๋ฐํํ๋ค. orientation ์ธ์๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด ํ์ฌ ์ถ ์์น๋ฅผ ๋ฐํํ๋ค. ๊ธฐ๋ณธ๊ฐ์ "buttom"์ด๋ค. ์ ํจํ ๊ฐ์ "top", "bottom", "left", "right"์ด๋ค. ์์ง ์ถ์ "left", "right"๋ฅผ ์ง์ ํ๊ณ ์ํ์ถ์ "buttom", "top"์ ์ง์ ํ๋ค.
# axis.ticks([argumentsโฆ])
Get or set the arguments that are passed to the underlying scaleโs tick function. The specified arguments are passed to scale.ticks to compute the tick values. For quantitative scales, specify the desired tick count such as axis.ticks(20)
. For time scales, you can pass in a count or a function, such as axis.ticks(d3.time.minutes, 15)
.
The arguments are also passed to the scaleโs tickFormat method to generate the default tick format. Thus, for log scales, you might specify both a count and a tick format function.
# axis.tickValues([values])
Get or set the explicit tick values. If the array values is specified, the values are used to generate ticks rather than using the scale's tick generator. If values is null, clears any previously-set explicit tick values, reverting back to the scale's tick generator. If values is not specified, returns the currently-set tick values, if any. For example, to generate ticks at specific values:
var xAxis = d3.svg.axis()
.scale(x)
.tickValues([1, 2, 3, 5, 8, 13, 21]);
The explicit tick values take precedent over the tick arguments set by axis.ticks. Note, however, that the tick arguments are still passed to the scale's tickFormat function if tick format is not also set. Thus, it is valid to set both axis.ticks and axis.tickValues.
# axis.tickSubdivide([count])
ํ์ ๊ตฌ๋ถ์์ ๊ฐ์๋ฅผ get or set. count๋ฅผ ์ธ์๋ก ๋๊ธฐ๋ฉด, ์ฃผ ๊ตฌ๋ถ์ ๋งํฌ ์ฌ์ด๋ฅผ ๋ช ๋ฑ๋ถํ ๊ฑด์ง ์ง์ ํ ํ์ ์ถ(axis)๋ฅผ ๋ฐํํ๋ค. count ์ธ์๋ฅผ ๋๊ธฐ์ง ์์ผ๋ฉด ํ์ ๊ตฌ๋ถ์ด ํ์ฌ ๋ช๋ฑ๋ถ ๋์๋์ง ๋ฐํํ๋ค. ๊ธฐ๋ณธ๊ฐ์ 0. ์ง์ ํ count๋ ํ์ ๊ตฌ๋ถ์ ์๋ฅผ ์ค์ ๊ตฌ๋ถ๋ ์ ๋ณด๋ค ํ๋ ์๊ฒ ์ค์ ํ๋ค.(3๋ฑ๋ถํ๋ฉด ๊ตฌ๋ถ์๋ 2๊ฐ๋ผ๋ ๋ป.) ์๋ฅผ ๋ค๋ฉด axis.tickSubdivide( true )
๋ ์ฃผ ๊ตฌ๋ถ์๋น ์ด๋ฑ๋ถ ํ๋ค๋ ๋ป์ด๊ณ , axis.tickSubdivide( 9 )
๋ ์ญ๋ฑ๋ถ ํ๋ค๋ ๋ป์ด๋ค.
# axis.tickSize([major[โ[, minor], end]])
์ฃผ ๊ตฌ๋ถ์, ํ์ ๊ตฌ๋ถ์, ์ข ๋ฃ ๊ตฌ๋ถ์ ํฌ๊ธฐ get or set. ์ข ๋ฃ ๊ตฌ๋ถ์๋ ์ค์ผ์ผ์ ์ ๋ ฅ ๋ฒ์(domain)๋ฅผ ๊ณ ๋ คํด์ ๊ฒฐ์ ๋๋ค. ๊ทธ๋์ ๊ตฌ๋ถ์ ์ด๋ผ๊ธฐ๋ณด๋จ ์์ฑ๋ ์ ๋ ฅ ๋ฒ์ ํจ์ค์ ์ผ๋ถ๋ค. ์ข ๋ฃ ๊ตฌ๋ถ์๋ ์ฒ์๊ณผ ๋ ๊ตฌ๋ถ์์ ๊ณ์ ์๊ฑฐ๋ ๋ฅ์ด์ธ ์๋ ์๋ค. ์ข ๋ฃ ๊ตฌ๋ถ์ ํฌ๊ธฐ๊ฐ 0์ด๋ฉด ์ข ๋ฃ ๊ตฌ๋ถ์๋ ๋ณด์ด์ง ์๋๋ค. ์์ ๋ฅผ ๋ณด์.
axis.tickSize(6); // ์ฃผ, ํ์, ์ข
๋ฃ ๊ตฌ๋ฌธ์ ๋ชจ๋ ํฌ๊ธฐ๊ฐ 6.
axis.tickSize(6, 0); // ์ฃผ, ํ์ ๊ตฌ๋ถ์๋ 6. ์ข
๋ฃ ๊ตฌ๋ถ์๋ 0.
axis.tickSize(6, 3, 0); // ์ฃผ ๊ตฌ๋ถ์๋ 6, ํ์๋ 3. ์ข
๋ฃ๋ 0.
# axis.tickPadding([padding])
Set or get the padding between ticks and tick labels. If padding is specified, sets the padding to the specified value in pixels and returns the axis. If padding is not specified, returns the current padding which defaults to 3 pixels.
# axis.tickFormat([format])
Set or get the tick value formatter for labels. If format is specified, sets the format to the specified function and returns the axis. If format is not specified, returns the current format function, which defaults to null. A null format indicates that the scale's default formatter should be used, which is generated by calling scale.tickFormat. In this case, the arguments specified by ticks are likewise passed to scale.tickFormat.
See d3.format for help creating formatters. For example, axis.tickFormat(d3.format(",.0f"))
will display integers with comma-grouping for thousands.
Note: for log scales, the number of ticks cannot be customized; however, the number of tick labels can be customized via ticks. Likewise, the tick formatter for log scales is typically specified via ticks rather than tickFormat, so as to preserve the default label-hiding behavior.