Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@d3fc/d3fc-axis

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@d3fc/d3fc-axis - npm Package Compare versions

Comparing version 2.2.1 to 2.2.2

1244

build/d3fc-axis.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-selection'), require('d3-shape')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-selection', 'd3-shape'], factory) :
(factory((global.fc = global.fc || {}),global.d3,global.d3));
}(this, (function (exports,d3Selection,d3Shape) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-selection'), require('d3-shape')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-selection', 'd3-shape'], factory) :
(global = global || self, factory(global.fc = global.fc || {}, global.d3, global.d3));
}(this, function (exports, d3Selection, d3Shape) { 'use strict';
// "Caution: avoid interpolating to or from the number zero when the interpolator is used to generate
// a string (such as with attr).
// Very small values, when stringified, may be converted to scientific notation and
// cause a temporarily invalid attribute or style property value.
// For example, the number 0.0000001 is converted to the string "1e-7".
// This is particularly noticeable when interpolating opacity values.
// To avoid scientific notation, start or end the transition at 1e-6,
// which is the smallest value that is not stringified in exponential notation."
// - https://github.com/mbostock/d3/wiki/Transitions#d3_interpolateNumber
var effectivelyZero = 1e-6;
// "Caution: avoid interpolating to or from the number zero when the interpolator is used to generate
// a string (such as with attr).
// Very small values, when stringified, may be converted to scientific notation and
// cause a temporarily invalid attribute or style property value.
// For example, the number 0.0000001 is converted to the string "1e-7".
// This is particularly noticeable when interpolating opacity values.
// To avoid scientific notation, start or end the transition at 1e-6,
// which is the smallest value that is not stringified in exponential notation."
// - https://github.com/mbostock/d3/wiki/Transitions#d3_interpolateNumber
var effectivelyZero = 1e-6;
// Wrapper around d3's selectAll/data data-join, which allows decoration of the result.
// This is achieved by appending the element to the enter selection before exposing it.
// A default transition of fade in/out is also implicitly added but can be modified.
var _dataJoin = (function (element, className) {
element = element || 'g';
// Wrapper around d3's selectAll/data data-join, which allows decoration of the result.
// This is achieved by appending the element to the enter selection before exposing it.
// A default transition of fade in/out is also implicitly added but can be modified.
var _dataJoin = (function (element, className) {
element = element || 'g';
var key = function key(_, i) {
return i;
};
var explicitTransition = null;
var dataJoin = function dataJoin(container, data) {
data = data || function (d) {
return d;
var key = function key(_, i) {
return i;
};
var explicitTransition = null;
var implicitTransition = container.selection ? container : null;
if (implicitTransition) {
container = container.selection();
}
var dataJoin = function dataJoin(container, data) {
data = data || function (d) {
return d;
};
var selected = container.selectAll(function (d, i, nodes) {
return Array.from(nodes[i].childNodes).filter(function (node) {
return node.nodeType === 1;
});
}).filter(className == null ? element : element + '.' + className);
var update = selected.data(data, key);
var implicitTransition = container.selection ? container : null;
if (implicitTransition) {
container = container.selection();
}
var enter = update.enter().append(element).attr('class', className);
var selected = container.selectAll(function (d, i, nodes) {
return Array.from(nodes[i].childNodes).filter(function (node) {
return node.nodeType === 1;
});
}).filter(className == null ? element : element + '.' + className);
var update = selected.data(data, key);
var exit = update.exit();
var enter = update.enter().append(element).attr('class', className);
// automatically merge in the enter selection
update = update.merge(enter);
var exit = update.exit();
// if transitions are enabled apply a default fade in/out transition
var transition = implicitTransition || explicitTransition;
if (transition) {
update = update.transition(transition).style('opacity', 1);
enter.style('opacity', effectivelyZero);
exit = exit.transition(transition).style('opacity', effectivelyZero);
}
// automatically merge in the enter selection
update = update.merge(enter);
exit.remove();
// if transitions are enabled apply a default fade in/out transition
var transition = implicitTransition || explicitTransition;
if (transition) {
update = update.transition(transition).style('opacity', 1);
enter.style('opacity', effectivelyZero);
exit = exit.transition(transition).style('opacity', effectivelyZero);
}
update.enter = function () {
return enter;
exit.remove();
update.enter = function () {
return enter;
};
update.exit = function () {
return exit;
};
return update;
};
update.exit = function () {
return exit;
dataJoin.element = function () {
if (!arguments.length) {
return element;
}
element = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
dataJoin.className = function () {
if (!arguments.length) {
return className;
}
className = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
dataJoin.key = function () {
if (!arguments.length) {
return key;
}
key = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
dataJoin.transition = function () {
if (!arguments.length) {
return explicitTransition;
}
explicitTransition = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
return update;
};
dataJoin.element = function () {
if (!arguments.length) {
return element;
}
element = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
dataJoin.className = function () {
if (!arguments.length) {
return className;
}
className = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
dataJoin.key = function () {
if (!arguments.length) {
return key;
}
key = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
dataJoin.transition = function () {
if (!arguments.length) {
return explicitTransition;
}
explicitTransition = arguments.length <= 0 ? undefined : arguments[0];
return dataJoin;
};
});
return dataJoin;
});
var createReboundMethod = (function (target, source, name) {
var method = source[name];
if (typeof method !== 'function') {
throw new Error('Attempt to rebind ' + name + ' which isn\'t a function on the source object');
}
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
var createReboundMethod = (function (target, source, name) {
var method = source[name];
if (typeof method !== 'function') {
throw new Error('Attempt to rebind ' + name + ' which isn\'t a function on the source object');
}
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var value = method.apply(source, args);
return value === source ? target : value;
};
});
var value = method.apply(source, args);
return value === source ? target : value;
};
});
var createTransform = function createTransform(transforms) {
return function (name) {
return transforms.reduce(function (name, fn) {
return name && fn(name);
}, name);
var createTransform = function createTransform(transforms) {
return function (name) {
return transforms.reduce(function (name, fn) {
return name && fn(name);
}, name);
};
};
};
var rebindAll = (function (target, source) {
for (var _len = arguments.length, transforms = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
transforms[_key - 2] = arguments[_key];
}
var rebindAll = (function (target, source) {
for (var _len = arguments.length, transforms = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
transforms[_key - 2] = arguments[_key];
}
var transform = createTransform(transforms);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var transform = createTransform(transforms);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = Object.keys(source)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var name = _step.value;
try {
for (var _iterator = Object.keys(source)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var name = _step.value;
var result = transform(name);
if (result) {
target[result] = createReboundMethod(target, source, name);
var result = transform(name);
if (result) {
target[result] = createReboundMethod(target, source, name);
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
if (_didIteratorError) {
throw _iteratorError;
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return target;
});
return target;
});
var regexify = (function (strsOrRegexes) {
return strsOrRegexes.map(function (strOrRegex) {
return typeof strOrRegex === 'string' ? new RegExp('^' + strOrRegex + '$') : strOrRegex;
var regexify = (function (strsOrRegexes) {
return strsOrRegexes.map(function (strOrRegex) {
return typeof strOrRegex === 'string' ? new RegExp('^' + strOrRegex + '$') : strOrRegex;
});
});
});
var exclude = (function () {
for (var _len = arguments.length, exclusions = Array(_len), _key = 0; _key < _len; _key++) {
exclusions[_key] = arguments[_key];
}
var exclude = (function () {
for (var _len = arguments.length, exclusions = Array(_len), _key = 0; _key < _len; _key++) {
exclusions[_key] = arguments[_key];
}
exclusions = regexify(exclusions);
return function (name) {
return exclusions.every(function (exclusion) {
return !exclusion.test(name);
}) && name;
};
});
exclusions = regexify(exclusions);
return function (name) {
return exclusions.every(function (exclusion) {
return !exclusion.test(name);
}) && name;
};
});
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
};
var identity = function identity(d) {
return d;
};
var axisBase = function axisBase(orient, scale) {
var custom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var tickArguments = [10];
var tickValues = null;
var decorate = function decorate() {};
var tickFormat = null;
var tickSizeOuter = 6;
var tickSizeInner = 6;
var tickPadding = 3;
var svgDomainLine = d3Shape.line();
var dataJoin = _dataJoin('g', 'tick').key(identity);
var domainPathDataJoin = _dataJoin('path', 'domain');
var defaultLabelOffset = function defaultLabelOffset() {
return { offset: [0, tickSizeInner + tickPadding] };
};
var defaultTickPath = function defaultTickPath() {
return { path: [[0, 0], [0, tickSizeInner]] };
};
var labelOffset = custom.labelOffset || defaultLabelOffset;
var tickPath = custom.tickPath || defaultTickPath;
// returns a function that creates a translation based on
// the bound data
var containerTranslate = function containerTranslate(scale, trans) {
var offset = 0;
if (scale.bandwidth) {
offset = scale.bandwidth() / 2;
if (scale.round()) {
offset = Math.round(offset);
}
}
return function (d) {
return trans(scale(d) + offset, 0);
};
};
var translate = function translate(x, y) {
return isVertical() ? 'translate(' + y + ', ' + x + ')' : 'translate(' + x + ', ' + y + ')';
};
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
var pathTranspose = function pathTranspose(arr) {
return isVertical() ? arr.map(function (d) {
return [d[1], d[0]];
}) : arr;
};
return arr2;
} else {
return Array.from(arr);
}
};
var isVertical = function isVertical() {
return orient === 'left' || orient === 'right';
};
var identity = function identity(d) {
return d;
};
var tryApply = function tryApply(fn, args, defaultVal) {
return scale[fn] ? scale[fn].apply(scale, args) : defaultVal;
};
var axisBase = function axisBase(orient, scale) {
var custom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var axis = function axis(selection) {
if (selection.selection) {
dataJoin.transition(selection);
domainPathDataJoin.transition(selection);
}
var tickArguments = [10];
var tickValues = null;
var decorate = function decorate() {};
var tickFormat = null;
var tickSizeOuter = 6;
var tickSizeInner = 6;
var tickPadding = 3;
selection.each(function (data, index, group) {
var svgDomainLine = d3Shape.line();
var element = group[index];
var dataJoin$$1 = _dataJoin('g', 'tick').key(identity);
var container = d3Selection.select(element);
if (!element.__scale__) {
container.attr('fill', 'none').attr('font-size', 10).attr('font-family', 'sans-serif').attr('text-anchor', orient === 'right' ? 'start' : orient === 'left' ? 'end' : 'middle');
}
var domainPathDataJoin = _dataJoin('path', 'domain');
// Stash a snapshot of the new scale, and retrieve the old snapshot.
var scaleOld = element.__scale__ || scale;
element.__scale__ = scale.copy();
var defaultLabelOffset = function defaultLabelOffset() {
return { offset: [0, tickSizeInner + tickPadding] };
};
var defaultTickPath = function defaultTickPath() {
return { path: [[0, 0], [0, tickSizeInner]] };
};
var ticksArray = tickValues == null ? tryApply('ticks', tickArguments, scale.domain()) : tickValues;
var tickFormatter = tickFormat == null ? tryApply('tickFormat', tickArguments, identity) : tickFormat;
var sign = orient === 'bottom' || orient === 'right' ? 1 : -1;
var withSign = function withSign(_ref) {
var _ref2 = slicedToArray(_ref, 2),
x = _ref2[0],
y = _ref2[1];
var labelOffset = custom.labelOffset || defaultLabelOffset;
var tickPath = custom.tickPath || defaultTickPath;
return [x, sign * y];
};
// returns a function that creates a translation based on
// the bound data
var containerTranslate = function containerTranslate(scale, trans) {
var offset = 0;
if (scale.bandwidth) {
offset = scale.bandwidth() / 2;
if (scale.round()) {
offset = Math.round(offset);
}
}
return function (d) {
return trans(scale(d) + offset, 0);
};
};
// add the domain line
var range = scale.range();
var domainPathData = pathTranspose([[range[0], sign * tickSizeOuter], [range[0], 0], [range[1], 0], [range[1], sign * tickSizeOuter]]);
var translate = function translate(x, y) {
return isVertical() ? 'translate(' + y + ', ' + x + ')' : 'translate(' + x + ', ' + y + ')';
};
var domainLine = domainPathDataJoin(container, [data]);
domainLine.attr('d', svgDomainLine(domainPathData)).attr('stroke', '#000');
var pathTranspose = function pathTranspose(arr) {
return isVertical() ? arr.map(function (d) {
return [d[1], d[0]];
}) : arr;
};
var g = dataJoin(container, ticksArray);
var isVertical = function isVertical() {
return orient === 'left' || orient === 'right';
};
var labelOffsets = ticksArray.map(function (d, i) {
return labelOffset(d, i, ticksArray);
});
var tickPaths = ticksArray.map(function (d, i) {
return tickPath(d, i, ticksArray);
});
var tryApply = function tryApply(fn, args, defaultVal) {
return scale[fn] ? scale[fn].apply(scale, args) : defaultVal;
};
// enter
g.enter().attr('transform', containerTranslate(scaleOld, translate)).append('path').attr('stroke', '#000');
var axis = function axis(selection) {
g.enter().append('text').attr('transform', function (d, i) {
return translate.apply(undefined, toConsumableArray(withSign(labelOffsets[i].offset)));
}).attr('fill', '#000');
if (selection.selection) {
dataJoin$$1.transition(selection);
domainPathDataJoin.transition(selection);
}
// exit
g.exit().attr('transform', containerTranslate(scale, translate));
selection.each(function (data, index, group) {
// update
g.select('path').attr('visibility', function (d, i) {
return tickPaths[i].hidden && 'hidden';
}).attr('d', function (d, i) {
return svgDomainLine(pathTranspose(tickPaths[i].path.map(withSign)));
});
var element = group[index];
g.select('text').attr('visibility', function (d, i) {
return labelOffsets[i].hidden && 'hidden';
}).attr('transform', function (d, i) {
return translate.apply(undefined, toConsumableArray(withSign(labelOffsets[i].offset)));
}).attr('dy', function () {
var offset = '0em';
if (isVertical()) {
offset = '0.32em';
} else if (orient === 'bottom') {
offset = '0.71em';
}
return offset;
}).text(tickFormatter);
var container = d3Selection.select(element);
if (!element.__scale__) {
container.attr('fill', 'none').attr('font-size', 10).attr('font-family', 'sans-serif').attr('text-anchor', orient === 'right' ? 'start' : orient === 'left' ? 'end' : 'middle');
}
g.attr('transform', containerTranslate(scale, translate));
// Stash a snapshot of the new scale, and retrieve the old snapshot.
var scaleOld = element.__scale__ || scale;
element.__scale__ = scale.copy();
decorate(g, data, index);
});
};
var ticksArray = tickValues == null ? tryApply('ticks', tickArguments, scale.domain()) : tickValues;
var tickFormatter = tickFormat == null ? tryApply('tickFormat', tickArguments, identity) : tickFormat;
var sign = orient === 'bottom' || orient === 'right' ? 1 : -1;
var withSign = function withSign(_ref) {
var _ref2 = slicedToArray(_ref, 2),
x = _ref2[0],
y = _ref2[1];
axis.tickFormat = function () {
if (!arguments.length) {
return tickFormat;
}
tickFormat = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
return [x, sign * y];
};
axis.tickSize = function () {
if (!arguments.length) {
return tickSizeInner;
}
tickSizeInner = tickSizeOuter = Number(arguments.length <= 0 ? undefined : arguments[0]);
return axis;
};
// add the domain line
var range = scale.range();
var domainPathData = pathTranspose([[range[0], sign * tickSizeOuter], [range[0], 0], [range[1], 0], [range[1], sign * tickSizeOuter]]);
axis.tickSizeInner = function () {
if (!arguments.length) {
return tickSizeInner;
}
tickSizeInner = Number(arguments.length <= 0 ? undefined : arguments[0]);
return axis;
};
var domainLine = domainPathDataJoin(container, [data]);
domainLine.attr('d', svgDomainLine(domainPathData)).attr('stroke', '#000');
axis.tickSizeOuter = function () {
if (!arguments.length) {
return tickSizeOuter;
}
tickSizeOuter = Number(arguments.length <= 0 ? undefined : arguments[0]);
return axis;
};
var g = dataJoin$$1(container, ticksArray);
axis.tickPadding = function () {
if (!arguments.length) {
return tickPadding;
}
tickPadding = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
var labelOffsets = ticksArray.map(function (d, i) {
return labelOffset(d, i, ticksArray);
});
var tickPaths = ticksArray.map(function (d, i) {
return tickPath(d, i, ticksArray);
});
axis.decorate = function () {
if (!arguments.length) {
return decorate;
}
decorate = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
// enter
g.enter().attr('transform', containerTranslate(scaleOld, translate)).append('path').attr('stroke', '#000');
axis.scale = function () {
if (!arguments.length) {
return scale;
}
scale = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
g.enter().append('text').attr('transform', function (d, i) {
return translate.apply(undefined, toConsumableArray(withSign(labelOffsets[i].offset)));
}).attr('fill', '#000');
axis.ticks = function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
// exit
g.exit().attr('transform', containerTranslate(scale, translate));
tickArguments = [].concat(args);
return axis;
};
// update
g.select('path').attr('visibility', function (d, i) {
return tickPaths[i].hidden && 'hidden';
}).attr('d', function (d, i) {
return svgDomainLine(pathTranspose(tickPaths[i].path.map(withSign)));
});
axis.tickArguments = function () {
if (!arguments.length) {
return tickArguments.slice();
}
tickArguments = (arguments.length <= 0 ? undefined : arguments[0]) == null ? [] : [].concat(toConsumableArray(arguments.length <= 0 ? undefined : arguments[0]));
return axis;
};
g.select('text').attr('visibility', function (d, i) {
return labelOffsets[i].hidden && 'hidden';
}).attr('transform', function (d, i) {
return translate.apply(undefined, toConsumableArray(withSign(labelOffsets[i].offset)));
}).attr('dy', function () {
var offset = '0em';
if (isVertical()) {
offset = '0.32em';
} else if (orient === 'bottom') {
offset = '0.71em';
}
return offset;
}).text(tickFormatter);
axis.tickValues = function () {
if (!arguments.length) {
return tickValues.slice();
}
tickValues = (arguments.length <= 0 ? undefined : arguments[0]) == null ? [] : [].concat(toConsumableArray(arguments.length <= 0 ? undefined : arguments[0]));
return axis;
};
g.attr('transform', containerTranslate(scale, translate));
axis.orient = function () {
return orient;
};
decorate(g, data, index);
});
};
axis.tickFormat = function () {
if (!arguments.length) {
return tickFormat;
}
tickFormat = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
axis.tickSize = function () {
if (!arguments.length) {
return tickSizeInner;
}
tickSizeInner = tickSizeOuter = Number(arguments.length <= 0 ? undefined : arguments[0]);
return axis;
};
var axis = function axis(orient, scale) {
var tickCenterLabel = false;
axis.tickSizeInner = function () {
if (!arguments.length) {
return tickSizeInner;
}
tickSizeInner = Number(arguments.length <= 0 ? undefined : arguments[0]);
return axis;
};
var labelOffset = function labelOffset(tick, index, ticksArray) {
var x = 0;
var y = base.tickSizeInner() + base.tickPadding();
var hidden = false;
if (tickCenterLabel) {
var thisPosition = scale(tick);
var nextPosition = index < ticksArray.length - 1 ? scale(ticksArray[index + 1]) : scale.range()[1];
x = (nextPosition - thisPosition) / 2;
axis.tickSizeOuter = function () {
if (!arguments.length) {
return tickSizeOuter;
}
tickSizeOuter = Number(arguments.length <= 0 ? undefined : arguments[0]);
return axis;
};
y = base.tickPadding();
hidden = index === ticksArray.length - 1 && thisPosition === nextPosition;
}
return { offset: [x, y], hidden: hidden };
};
axis.tickPadding = function () {
if (!arguments.length) {
return tickPadding;
}
tickPadding = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
var base = axisBase(orient, scale, { labelOffset: labelOffset });
axis.decorate = function () {
if (!arguments.length) {
return decorate;
}
decorate = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
var axis = function axis(selection) {
return base(selection);
};
axis.scale = function () {
if (!arguments.length) {
return scale;
}
scale = arguments.length <= 0 ? undefined : arguments[0];
axis.tickCenterLabel = function () {
if (!arguments.length) {
return tickCenterLabel;
}
tickCenterLabel = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
rebindAll(axis, base);
return axis;
};
axis.ticks = function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
tickArguments = [].concat(args);
return axis;
var axisTop = function axisTop(scale) {
return axis('top', scale);
};
axis.tickArguments = function () {
if (!arguments.length) {
return tickArguments.slice();
}
tickArguments = (arguments.length <= 0 ? undefined : arguments[0]) == null ? [] : [].concat(toConsumableArray(arguments.length <= 0 ? undefined : arguments[0]));
return axis;
var axisBottom = function axisBottom(scale) {
return axis('bottom', scale);
};
axis.tickValues = function () {
if (!arguments.length) {
return tickValues.slice();
}
tickValues = (arguments.length <= 0 ? undefined : arguments[0]) == null ? [] : [].concat(toConsumableArray(arguments.length <= 0 ? undefined : arguments[0]));
return axis;
var axisLeft = function axisLeft(scale) {
return axis('left', scale);
};
axis.orient = function () {
return orient;
var axisRight = function axisRight(scale) {
return axis('right', scale);
};
return axis;
};
var axisOrdinal = function axisOrdinal(orient, scale) {
var tickOffset = null;
var axis = function axis(orient, scale) {
var tickCenterLabel = false;
var labelOffset = function labelOffset(tick, index, ticksArray) {
var x = 0;
var y = base.tickSizeInner() + base.tickPadding();
var hidden = false;
if (tickCenterLabel) {
var step = function step(tick, index, ticksArray) {
if (scale.step) {
// Use the scale step size
return scale.step();
}
var thisPosition = scale(tick);
var nextPosition = index < ticksArray.length - 1 ? scale(ticksArray[index + 1]) : scale.range()[1];
x = (nextPosition - thisPosition) / 2;
if (index < ticksArray.length - 1) {
// Distance between ticks
return scale(ticksArray[index + 1]) / thisPosition;
} else {
// 2* distance to end
return (scale.range()[1] - thisPosition) * 2;
}
};
y = base.tickPadding();
hidden = index === ticksArray.length - 1 && thisPosition === nextPosition;
}
return { offset: [x, y], hidden: hidden };
};
var tickPath = function tickPath(tick, index, ticksArray) {
var x = 0;
if (tickOffset) {
x = tickOffset(tick, index);
} else {
x = step(tick, index, ticksArray) / 2;
}
return {
path: [[x, 0], [x, base.tickSizeInner()]],
hidden: index === ticksArray.length - 1
};
};
var labelOffset = function labelOffset() {
// Don't include the tickSizeInner in the label positioning
return { offset: [0, base.tickPadding()] };
};
var base = axisBase(orient, scale, { labelOffset: labelOffset });
var base = axisBase(orient, scale, { labelOffset: labelOffset, tickPath: tickPath });
var axis = function axis(selection) {
return base(selection);
};
var axis = function axis(selection) {
base(selection);
};
axis.tickCenterLabel = function () {
if (!arguments.length) {
return tickCenterLabel;
}
tickCenterLabel = arguments.length <= 0 ? undefined : arguments[0];
axis.tickOffset = function () {
if (!arguments.length) {
return tickOffset;
}
tickOffset = arguments.length <= 0 ? undefined : arguments[0];
return axis;
};
rebindAll(axis, base);
return axis;
};
rebindAll(axis, base);
return axis;
};
var axisTop = function axisTop(scale) {
return axis('top', scale);
};
var axisBottom = function axisBottom(scale) {
return axis('bottom', scale);
};
var axisLeft = function axisLeft(scale) {
return axis('left', scale);
};
var axisRight = function axisRight(scale) {
return axis('right', scale);
};
var axisOrdinal = function axisOrdinal(orient, scale) {
var tickOffset = null;
var step = function step(tick, index, ticksArray) {
if (scale.step) {
// Use the scale step size
return scale.step();
}
var thisPosition = scale(tick);
if (index < ticksArray.length - 1) {
// Distance between ticks
return scale(ticksArray[index + 1]) / thisPosition;
} else {
// 2* distance to end
return (scale.range()[1] - thisPosition) * 2;
}
var axisOrdinalTop = function axisOrdinalTop(scale) {
return axisOrdinal('top', scale);
};
var tickPath = function tickPath(tick, index, ticksArray) {
var x = 0;
if (tickOffset) {
x = tickOffset(tick, index);
} else {
x = step(tick, index, ticksArray) / 2;
}
return {
path: [[x, 0], [x, base.tickSizeInner()]],
hidden: index === ticksArray.length - 1
};
var axisOrdinalBottom = function axisOrdinalBottom(scale) {
return axisOrdinal('bottom', scale);
};
var labelOffset = function labelOffset() {
// Don't include the tickSizeInner in the label positioning
return { offset: [0, base.tickPadding()] };
};
var base = axisBase(orient, scale, { labelOffset: labelOffset, tickPath: tickPath });
var axis = function axis(selection) {
base(selection);
var axisOrdinalLeft = function axisOrdinalLeft(scale) {
return axisOrdinal('left', scale);
};
axis.tickOffset = function () {
if (!arguments.length) {
return tickOffset;
}
tickOffset = arguments.length <= 0 ? undefined : arguments[0];
return axis;
var axisOrdinalRight = function axisOrdinalRight(scale) {
return axisOrdinal('right', scale);
};
rebindAll(axis, base);
return axis;
};
var measureLabels = (function (scale) {
var measure = function measure(selection) {
var labels = scale['ticks'] ? scale.ticks() : scale.domain();
var axisOrdinalTop = function axisOrdinalTop(scale) {
return axisOrdinal('top', scale);
};
var tester = selection.append('text');
var boundingBoxes = labels.map(function (l) {
return tester.text(l).node().getBBox();
});
var maxHeight = Math.max.apply(Math, toConsumableArray(boundingBoxes.map(function (b) {
return b.height;
})));
var maxWidth = Math.max.apply(Math, toConsumableArray(boundingBoxes.map(function (b) {
return b.width;
})));
tester.remove();
var axisOrdinalBottom = function axisOrdinalBottom(scale) {
return axisOrdinal('bottom', scale);
};
return {
maxHeight: maxHeight,
maxWidth: maxWidth,
labelCount: labels.length
};
};
var axisOrdinalLeft = function axisOrdinalLeft(scale) {
return axisOrdinal('left', scale);
};
return measure;
});
var axisOrdinalRight = function axisOrdinalRight(scale) {
return axisOrdinal('right', scale);
};
var axisLabelRotate = (function (adaptee) {
var measureLabels = (function (scale) {
var measure = function measure(selection) {
var labels = scale['ticks'] ? scale.ticks() : scale.domain();
var labelRotate = 'auto';
var decorate = function decorate() {};
var tester = selection.append('text');
var boundingBoxes = labels.map(function (l) {
return tester.text(l).node().getBBox();
});
var maxHeight = Math.max.apply(Math, toConsumableArray(boundingBoxes.map(function (b) {
return b.height;
})));
var maxWidth = Math.max.apply(Math, toConsumableArray(boundingBoxes.map(function (b) {
return b.width;
})));
tester.remove();
var isVertical = function isVertical() {
return adaptee.orient() === 'left' || adaptee.orient() === 'right';
};
var sign = function sign() {
return adaptee.orient() === 'top' || adaptee.orient() === 'left' ? -1 : 1;
};
return {
maxHeight: maxHeight,
maxWidth: maxWidth,
labelCount: labels.length
var labelAnchor = function labelAnchor() {
switch (adaptee.orient()) {
case 'top':
case 'right':
return 'start';
default:
return 'end';
}
};
};
return measure;
});
var calculateRotation = function calculateRotation(s) {
var _measureLabels = measureLabels(adaptee.scale())(s),
maxHeight = _measureLabels.maxHeight,
maxWidth = _measureLabels.maxWidth,
labelCount = _measureLabels.labelCount;
var axisLabelRotate = (function (adaptee) {
var measuredSize = labelCount * maxWidth;
var labelRotate = 'auto';
var decorate = function decorate() {};
// The more the overlap, the more we rotate
var rotate = void 0;
if (labelRotate === 'auto') {
var range = adaptee.scale().range()[1];
rotate = range < measuredSize ? 90 * Math.min(1, (measuredSize / range - 0.8) / 2) : 0;
} else {
rotate = labelRotate;
}
var isVertical = function isVertical() {
return adaptee.orient() === 'left' || adaptee.orient() === 'right';
};
var sign = function sign() {
return adaptee.orient() === 'top' || adaptee.orient() === 'left' ? -1 : 1;
};
return {
rotate: isVertical() ? Math.floor(sign() * (90 - rotate)) : Math.floor(-rotate),
maxHeight: maxHeight,
maxWidth: maxWidth,
anchor: rotate ? labelAnchor() : 'middle'
};
};
var labelAnchor = function labelAnchor() {
switch (adaptee.orient()) {
case 'top':
case 'right':
return 'start';
default:
return 'end';
}
};
var decorateRotation = function decorateRotation(sel) {
var _calculateRotation = calculateRotation(sel),
rotate = _calculateRotation.rotate,
maxHeight = _calculateRotation.maxHeight,
anchor = _calculateRotation.anchor;
var calculateRotation = function calculateRotation(s) {
var _measureLabels = measureLabels(adaptee.scale())(s),
maxHeight = _measureLabels.maxHeight,
maxWidth = _measureLabels.maxWidth,
labelCount = _measureLabels.labelCount;
var text = sel.select('text');
var existingTransform = text.attr('transform');
var measuredSize = labelCount * maxWidth;
var offset = sign() * Math.floor(maxHeight / 2);
var offsetTransform = isVertical() ? 'translate(' + offset + ', 0)' : 'translate(0, ' + offset + ')';
// The more the overlap, the more we rotate
var rotate = void 0;
if (labelRotate === 'auto') {
var range = adaptee.scale().range()[1];
rotate = range < measuredSize ? 90 * Math.min(1, (measuredSize / range - 0.8) / 2) : 0;
} else {
rotate = labelRotate;
}
text.style('text-anchor', anchor).attr('transform', existingTransform + ' ' + offsetTransform + ' rotate(' + rotate + ' 0 0)');
};
return {
rotate: isVertical() ? Math.floor(sign() * (90 - rotate)) : Math.floor(-rotate),
maxHeight: maxHeight,
maxWidth: maxWidth,
anchor: rotate ? labelAnchor() : 'middle'
var axisLabelRotate = function axisLabelRotate(arg) {
adaptee(arg);
};
};
var decorateRotation = function decorateRotation(sel) {
var _calculateRotation = calculateRotation(sel),
rotate = _calculateRotation.rotate,
maxHeight = _calculateRotation.maxHeight,
anchor = _calculateRotation.anchor;
adaptee.decorate(function (s) {
decorateRotation(s);
decorate(s);
});
var text = sel.select('text');
var existingTransform = text.attr('transform');
axisLabelRotate.decorate = function () {
if (!arguments.length) {
return decorate;
}
decorate = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelRotate;
};
var offset = sign() * Math.floor(maxHeight / 2);
var offsetTransform = isVertical() ? 'translate(' + offset + ', 0)' : 'translate(0, ' + offset + ')';
axisLabelRotate.labelRotate = function () {
if (!arguments.length) {
return labelRotate;
}
labelRotate = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelRotate;
};
text.style('text-anchor', anchor).attr('transform', existingTransform + ' ' + offsetTransform + ' rotate(' + rotate + ' 0 0)');
};
rebindAll(axisLabelRotate, adaptee, exclude('decorate'));
var axisLabelRotate = function axisLabelRotate(arg) {
adaptee(arg);
};
adaptee.decorate(function (s) {
decorateRotation(s);
decorate(s);
return axisLabelRotate;
});
axisLabelRotate.decorate = function () {
if (!arguments.length) {
return decorate;
}
decorate = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelRotate;
};
var axisLabelOffset = (function (adaptee) {
axisLabelRotate.labelRotate = function () {
if (!arguments.length) {
return labelRotate;
}
labelRotate = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelRotate;
};
var labelOffsetDepth = 'auto';
var decorate = function decorate() {};
rebindAll(axisLabelRotate, adaptee, exclude('decorate'));
var isVertical = function isVertical() {
return adaptee.orient() === 'left' || adaptee.orient() === 'right';
};
return axisLabelRotate;
});
var sign = function sign() {
return adaptee.orient() === 'top' || adaptee.orient() === 'left' ? -1 : 1;
};
var axisLabelOffset = (function (adaptee) {
var decorateOffset = function decorateOffset(sel) {
var _measureLabels = measureLabels(adaptee.scale())(sel),
maxHeight = _measureLabels.maxHeight,
maxWidth = _measureLabels.maxWidth,
labelCount = _measureLabels.labelCount;
var labelOffsetDepth = 'auto';
var decorate = function decorate() {};
var range = adaptee.scale().range()[1];
var isVertical = function isVertical() {
return adaptee.orient() === 'left' || adaptee.orient() === 'right';
};
var offsetLevels = labelOffsetDepth === 'auto' ? Math.floor((isVertical() ? maxHeight : maxWidth) * labelCount / range) + 1 : labelOffsetDepth;
var sign = function sign() {
return adaptee.orient() === 'top' || adaptee.orient() === 'left' ? -1 : 1;
};
var text = sel.select('text');
var existingTransform = text.attr('transform');
var decorateOffset = function decorateOffset(sel) {
var _measureLabels = measureLabels(adaptee.scale())(sel),
maxHeight = _measureLabels.maxHeight,
maxWidth = _measureLabels.maxWidth,
labelCount = _measureLabels.labelCount;
var transform = function transform(i) {
return isVertical() ? 'translate(' + i % offsetLevels * maxWidth * sign() + ', 0)' : 'translate(0, ' + i % offsetLevels * maxHeight * sign() + ')';
};
var range = adaptee.scale().range()[1];
text.attr('transform', function (_, i) {
return existingTransform + ' ' + transform(i);
});
};
var offsetLevels = labelOffsetDepth === 'auto' ? Math.floor((isVertical() ? maxHeight : maxWidth) * labelCount / range) + 1 : labelOffsetDepth;
var text = sel.select('text');
var existingTransform = text.attr('transform');
var transform = function transform(i) {
return isVertical() ? 'translate(' + i % offsetLevels * maxWidth * sign() + ', 0)' : 'translate(0, ' + i % offsetLevels * maxHeight * sign() + ')';
var axisLabelOffset = function axisLabelOffset(arg) {
return adaptee(arg);
};
text.attr('transform', function (_, i) {
return existingTransform + ' ' + transform(i);
adaptee.decorate(function (s) {
decorateOffset(s);
decorate(s);
});
};
var axisLabelOffset = function axisLabelOffset(arg) {
return adaptee(arg);
};
axisLabelOffset.decorate = function () {
if (!arguments.length) {
return decorate;
}
decorate = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelOffset;
};
adaptee.decorate(function (s) {
decorateOffset(s);
decorate(s);
});
axisLabelOffset.labelOffsetDepth = function () {
if (!arguments.length) {
return labelOffsetDepth;
}
labelOffsetDepth = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelOffset;
};
axisLabelOffset.decorate = function () {
if (!arguments.length) {
return decorate;
}
decorate = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelOffset;
};
rebindAll(axisLabelOffset, adaptee, exclude('decorate'));
axisLabelOffset.labelOffsetDepth = function () {
if (!arguments.length) {
return labelOffsetDepth;
}
labelOffsetDepth = arguments.length <= 0 ? undefined : arguments[0];
return axisLabelOffset;
};
});
rebindAll(axisLabelOffset, adaptee, exclude('decorate'));
exports.axisBottom = axisBottom;
exports.axisLabelOffset = axisLabelOffset;
exports.axisLabelRotate = axisLabelRotate;
exports.axisLeft = axisLeft;
exports.axisOrdinalBottom = axisOrdinalBottom;
exports.axisOrdinalLeft = axisOrdinalLeft;
exports.axisOrdinalRight = axisOrdinalRight;
exports.axisOrdinalTop = axisOrdinalTop;
exports.axisRight = axisRight;
exports.axisTop = axisTop;
return axisLabelOffset;
});
Object.defineProperty(exports, '__esModule', { value: true });
exports.axisLabelRotate = axisLabelRotate;
exports.axisLabelOffset = axisLabelOffset;
exports.axisTop = axisTop;
exports.axisBottom = axisBottom;
exports.axisLeft = axisLeft;
exports.axisRight = axisRight;
exports.axisOrdinalTop = axisOrdinalTop;
exports.axisOrdinalBottom = axisOrdinalBottom;
exports.axisOrdinalLeft = axisOrdinalLeft;
exports.axisOrdinalRight = axisOrdinalRight;
Object.defineProperty(exports, '__esModule', { value: true });
})));
}));

@@ -6,2 +6,10 @@ # Change Log

<a name="2.2.2"></a>
## [2.2.2](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-axis@2.2.1...@d3fc/d3fc-axis@2.2.2) (2019-08-12)
**Note:** Version bump only for package @d3fc/d3fc-axis
<a name="2.2.1"></a>

@@ -8,0 +16,0 @@ ## [2.2.1](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-axis@2.2.0...@d3fc/d3fc-axis@2.2.1) (2019-05-28)

{
"extends": "defaults/configurations/eslint",
"env": {

@@ -4,0 +3,0 @@ "browser": true

{
"name": "@d3fc/d3fc-axis",
"version": "2.2.1",
"version": "2.2.2",
"description": "A drop-in replacement for d3 axis, with support for the d3fc decorate pattern",

@@ -19,7 +19,8 @@ "license": "MIT",

"scripts": {
"bundle": "d3fc-scripts bundle",
"test": "d3fc-scripts test"
"bundle": "npx rollup -c ../../scripts/rollup.config.js",
"test": "npx jasmine --config=../../scripts/jasmine.json",
"lint": "npx eslint src/**/*.js",
"screenshots": "node ../../scripts/screenshot.js"
},
"devDependencies": {
"@d3fc/d3fc-scripts": "^2.0.5",
"babel-polyfill": "^6.13.0",

@@ -30,4 +31,4 @@ "d3": "^4.2.5",

"dependencies": {
"@d3fc/d3fc-data-join": "^5.0.8",
"@d3fc/d3fc-rebind": "^5.0.7",
"@d3fc/d3fc-data-join": "^5.0.9",
"@d3fc/d3fc-rebind": "^5.0.8",
"d3-scale": "^1.0.3",

@@ -34,0 +35,0 @@ "d3-selection": "^1.0.2",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc