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

@zambezi/d3-utils

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zambezi/d3-utils - npm Package Compare versions

Comparing version 3.0.0-1 to 3.0.0-2

Makefile

290

dist/d3-utils.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('underscore')) :
typeof define === 'function' && define.amd ? define(['exports', 'underscore'], factory) :
(factory((global.d3Utils = global.d3Utils || {}),global._));
}(this, function (exports,underscore) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-selection'), require('underscore')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-selection', 'underscore'], factory) :
(factory((global.d3Utils = global.d3Utils || {}),global.d3,global._));
}(this, function (exports,d3Selection,underscore) { 'use strict';
function rebind() {
var objects = [];
function appendFromTemplate(template) {
var div = document.createElement('div');
function rebind(target) {
return objects.reduce(rebindForObject, target);
div.innerHTML = template;
var prototype = div.firstChild;
return function append(d, i) {
return this.appendChild(prototype.cloneNode(true));
};
}
rebind.from = function (source) {
objects.push({ source: source, properties: underscore.rest(arguments) });
function appendIfMissing(tagAndClasses, initAttributes) {
return function append(d, i) {
var target = d3Selection.select(this),
selection = target.select(tagAndClasses);
var elements = void 0,
classes = void 0,
tag = void 0,
element = void 0;
if (!selection.empty()) return selection.node();
elements = tagAndClasses.split('.');
tag = _.first(elements);
classes = _.rest(elements);
element = target.append(tag);
if (initAttributes) element.attr(initAttributes);
if (classes.length) element.classed(classes.join(' '), true);
return element.node();
};
}
function call(component) {
return function call(s) {
return s.call(component);
};
}
function createDispatchCustomEvent() {
var type = void 0,
canBubble = true,
cancelable = true,
detail = void 0;
function dispatchCustomEvent(d, i) {
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(type, canBubble, cancelable, detail);
this.dispatchEvent(evt);
}
dispatchCustomEvent.type = function (value) {
if (!arguments.length) return type;
type = value;
return dispatchCustomEvent;
};
dispatchCustomEvent.canBubble = function (value) {
if (!arguments.length) return canBubble;
canBubble = value;
return dispatchCustomEvent;
};
dispatchCustomEvent.cancelable = function (value) {
if (!arguments.length) return cancelable;
cancelable = value;
return dispatchCustomEvent;
};
dispatchCustomEvent.detail = function (value) {
if (!arguments.length) return detail;
detail = value;
return dispatchCustomEvent;
};
return dispatchCustomEvent;
}
function each(c) {
return function each(s) {
return s.each(then);
function then() {
c.apply(this, arguments);
}
};
}
function emptyIfFormat(predicate, fn, d) {
if (predicate(d)) return '';
return fn.apply(this, underscore.rest(underscore.rest(arguments)));
}
// to be used for wrapping normal formatters:
//
// format = _.wrap(d3.time.format('%x'), empty)
//
// will create a function that returns an empty string if the provided value
// is undefined. Otherwise it'll try to parse it using the d3 formatter.
var emptyIfUndefinedFormat = underscore.partial(emptyIfFormat, underscore.isUndefined);
function fromTarget(fn) {
return function handler() {
d3Selection.select(d3Selection.event.target).each(fn);
};
}
function fromDetail(fn) {
return function handler() {
fn.call(this, d3Selection.event.detail);
};
}
function rebind() {
var objects = [];
function rebind(target) {
return objects.reduce(rebindForObject, target);
}
rebind.from = function (source) {
objects.push({ source: source, properties: underscore.rest(arguments) });
return rebind;
};
return rebind;
function rebindForObject(target, current, index, array) {
var source = current.source;
current.properties.forEach(rebindProperty);
return target;
function rebindProperty(name) {
var i = name.indexOf(':'),
same = !~i,
sourceName = same ? name : name.substring(0, i),
targetName = same ? name : name.substring(i + 1);
target[targetName] = r(target, source, source[sourceName]);
function r(target, source, method) {
return function proxy() {
var value = method.apply(source, arguments);
return value === source ? target : value;
};
}
}
}
}
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);
}
};
return rebind;
function redraw(component) {
return function run(s) {
var args = underscore.rest(arguments),
context = this;
function rebindForObject(target, current, index, array) {
s.on('redraw.component-redraw', draw);
draw();
var source = current.source;
current.properties.forEach(rebindProperty);
function draw() {
component.apply(context, [s].concat(toConsumableArray(args)));
}
};
}
return target;
var dispatchRedraw = createDispatchCustomEvent().type('redraw');
var dispatchSizeDirty = createDispatchCustomEvent().type('size-dirty');
function createResize() {
var type = underscore.uniqueId('resize.resize_'),
w = d3Selection.select(window);
function rebindProperty(name) {
var i = name.indexOf(':'),
same = !~i,
sourceName = same ? name : name.substring(0, i),
targetName = same ? name : name.substring(i + 1);
var wait = 300;
target[targetName] = r(target, source, source[sourceName]);
function resize(s) {
w.on(type, underscore.debounce(onWindowResize, wait));
function r(target, source, method) {
return function proxy() {
var value = method.apply(source, arguments);
return value === source ? target : value;
};
function onWindowResize() {
s.each(dispatchSizeDirty).each(dispatchRedraw);
}
}
resize.wait = function (value) {
if (!arguments.length) return wait;
wait = value;
return resize;
};
return resize;
}
}
exports.rebind = rebind;
function selectionChanged() {
var previousDataKey = underscore.uniqueId('__data-changed-');
var debug = false,
key = void 0;
function changed(d, i) {
if (!key) {
if (debug) console.debug('--(KEY UNDEFINED)--');
return this;
}
var oldKey = this[previousDataKey],
newKey = key.call(this, d, i);
this[previousDataKey] = newKey;
if (debug) console.debug('selection changed?', 'old:', oldKey, 'new:', newKey, newKey === oldKey ? '--(SAME)--' : '++(CHANGED)++');
return oldKey === newKey ? null : this;
}
changed.debug = function (value) {
if (!arguments.length) return debug;
debug = value;
return changed;
};
changed.key = function (value) {
if (!arguments.length) return key;
key = value;
return changed;
};
return changed;
}
function throttle$1(component) {
var wait = arguments.length <= 1 || arguments[1] === undefined ? 150 : arguments[1];
var throttled = underscore.throttle(execute, wait);
return function run(s) {
var args = underscore.rest(arguments),
context = this;
throttled.apply(context, [s].concat(toConsumableArray(args)));
};
function execute() {
component.apply(this, arguments);
}
}
exports.appendFromTemplate = appendFromTemplate;
exports.appendIfMissing = appendIfMissing;
exports.call = call;
exports.createDispatchCustomEvent = createDispatchCustomEvent;
exports.each = each;
exports.emptyIfFormat = emptyIfFormat;
exports.emptyIfUndefinedFormat = emptyIfUndefinedFormat;
exports.fromDetail = fromDetail;
exports.fromTarget = fromTarget;
exports.rebind = rebind;
exports.redraw = redraw;
exports.createResize = createResize;
exports.selectionChanged = selectionChanged;
exports.throttle = throttle$1;
}));
//# sourceMappingURL=d3-utils.js.map

3

package.json
{
"name": "@zambezi/d3-utils",
"version": "3.0.0-1",
"version": "3.0.0-2",
"description": "Common utility functions to use with d3",

@@ -35,4 +35,5 @@ "keywords": [

"dependencies": {
"d3-selection": "^1.0.2",
"underscore": "^1.8.3"
}
}

@@ -9,8 +9,9 @@ import babel from 'rollup-plugin-babel'

moduleName: 'd3Utils',
external: [ 'underscore' ],
external: [ 'd3-selection', 'underscore' ],
sourceMap: true,
plugins: [ babel(babelrc()) ],
globals: {
'underscore': '_'
'underscore': '_',
'd3-selection': 'd3'
}
}

@@ -0,1 +1,13 @@

export { appendFromTemplate } from './append-from-template'
export { appendIfMissing } from './append-if-missing'
export { call } from './call'
export { createDispatchCustomEvent } from './dispatch-custom-event'
export { each } from './each'
export { emptyIfFormat } from './empty-if-format'
export { emptyIfUndefinedFormat } from './empty-if-undefined-format'
export { fromDetail, fromTarget } from './event'
export { rebind } from './rebind'
export { redraw } from './redraw'
export { createResize } from './resize'
export { selectionChanged } from './selection-changed'
export { throttle } from './throttle'

Sorry, the diff of this file is not supported yet

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