source: node_modules/d3-axis/dist/d3-axis.js

Last change on this file was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[e4c61dd]1// https://d3js.org/d3-axis/ v3.0.0 Copyright 2010-2021 Mike Bostock
2(function (global, factory) {
3typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4typeof define === 'function' && define.amd ? define(['exports'], factory) :
5(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
6}(this, (function (exports) { 'use strict';
7
8function identity(x) {
9 return x;
10}
11
12var top = 1,
13 right = 2,
14 bottom = 3,
15 left = 4,
16 epsilon = 1e-6;
17
18function translateX(x) {
19 return "translate(" + x + ",0)";
20}
21
22function translateY(y) {
23 return "translate(0," + y + ")";
24}
25
26function number(scale) {
27 return d => +scale(d);
28}
29
30function center(scale, offset) {
31 offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
32 if (scale.round()) offset = Math.round(offset);
33 return d => +scale(d) + offset;
34}
35
36function entering() {
37 return !this.__axis;
38}
39
40function axis(orient, scale) {
41 var tickArguments = [],
42 tickValues = null,
43 tickFormat = null,
44 tickSizeInner = 6,
45 tickSizeOuter = 6,
46 tickPadding = 3,
47 offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
48 k = orient === top || orient === left ? -1 : 1,
49 x = orient === left || orient === right ? "x" : "y",
50 transform = orient === top || orient === bottom ? translateX : translateY;
51
52 function axis(context) {
53 var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
54 format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity) : tickFormat,
55 spacing = Math.max(tickSizeInner, 0) + tickPadding,
56 range = scale.range(),
57 range0 = +range[0] + offset,
58 range1 = +range[range.length - 1] + offset,
59 position = (scale.bandwidth ? center : number)(scale.copy(), offset),
60 selection = context.selection ? context.selection() : context,
61 path = selection.selectAll(".domain").data([null]),
62 tick = selection.selectAll(".tick").data(values, scale).order(),
63 tickExit = tick.exit(),
64 tickEnter = tick.enter().append("g").attr("class", "tick"),
65 line = tick.select("line"),
66 text = tick.select("text");
67
68 path = path.merge(path.enter().insert("path", ".tick")
69 .attr("class", "domain")
70 .attr("stroke", "currentColor"));
71
72 tick = tick.merge(tickEnter);
73
74 line = line.merge(tickEnter.append("line")
75 .attr("stroke", "currentColor")
76 .attr(x + "2", k * tickSizeInner));
77
78 text = text.merge(tickEnter.append("text")
79 .attr("fill", "currentColor")
80 .attr(x, k * spacing)
81 .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
82
83 if (context !== selection) {
84 path = path.transition(context);
85 tick = tick.transition(context);
86 line = line.transition(context);
87 text = text.transition(context);
88
89 tickExit = tickExit.transition(context)
90 .attr("opacity", epsilon)
91 .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
92
93 tickEnter
94 .attr("opacity", epsilon)
95 .attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
96 }
97
98 tickExit.remove();
99
100 path
101 .attr("d", orient === left || orient === right
102 ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
103 : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
104
105 tick
106 .attr("opacity", 1)
107 .attr("transform", function(d) { return transform(position(d) + offset); });
108
109 line
110 .attr(x + "2", k * tickSizeInner);
111
112 text
113 .attr(x, k * spacing)
114 .text(format);
115
116 selection.filter(entering)
117 .attr("fill", "none")
118 .attr("font-size", 10)
119 .attr("font-family", "sans-serif")
120 .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
121
122 selection
123 .each(function() { this.__axis = position; });
124 }
125
126 axis.scale = function(_) {
127 return arguments.length ? (scale = _, axis) : scale;
128 };
129
130 axis.ticks = function() {
131 return tickArguments = Array.from(arguments), axis;
132 };
133
134 axis.tickArguments = function(_) {
135 return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
136 };
137
138 axis.tickValues = function(_) {
139 return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
140 };
141
142 axis.tickFormat = function(_) {
143 return arguments.length ? (tickFormat = _, axis) : tickFormat;
144 };
145
146 axis.tickSize = function(_) {
147 return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
148 };
149
150 axis.tickSizeInner = function(_) {
151 return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
152 };
153
154 axis.tickSizeOuter = function(_) {
155 return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
156 };
157
158 axis.tickPadding = function(_) {
159 return arguments.length ? (tickPadding = +_, axis) : tickPadding;
160 };
161
162 axis.offset = function(_) {
163 return arguments.length ? (offset = +_, axis) : offset;
164 };
165
166 return axis;
167}
168
169function axisTop(scale) {
170 return axis(top, scale);
171}
172
173function axisRight(scale) {
174 return axis(right, scale);
175}
176
177function axisBottom(scale) {
178 return axis(bottom, scale);
179}
180
181function axisLeft(scale) {
182 return axis(left, scale);
183}
184
185exports.axisBottom = axisBottom;
186exports.axisLeft = axisLeft;
187exports.axisRight = axisRight;
188exports.axisTop = axisTop;
189
190Object.defineProperty(exports, '__esModule', { value: true });
191
192})));
Note: See TracBrowser for help on using the repository browser.