@zambezi/d3-utils
Advanced tools
Comparing version 3.0.0-4 to 3.0.0-5
@@ -65,2 +65,38 @@ (function (global, factory) { | ||
// Reconfigurable higher-level component, it receives a D3 component, not a | ||
// selection, and will return a new component that will dispatch 'size-dirty' | ||
// and 'data-dirty' every time it's run, just before running the original, | ||
// provided component. | ||
function createAutoDirty() { | ||
var autoSizeDirty = true, | ||
autoDataDirty = true; | ||
function autoDirty(component) { | ||
console.debug('autoDirty', component); | ||
return function run(s) { | ||
if (autoSizeDirty) s.dispatch('size-dirty', { bubbles: true }); | ||
if (autoDataDirty) s.dispatch('data-dirty', { bubbles: true }); | ||
return s.call(component); | ||
}; | ||
} | ||
autoDirty.autoSizeDirty = function (value) { | ||
if (!arguments.length) return autoSizeDirty; | ||
autoSizeDirty = value; | ||
return autoDirty; | ||
}; | ||
autoDirty.autoDataDirty = function (value) { | ||
if (!arguments.length) return autoDataDirty; | ||
autoDataDirty = value; | ||
return autoDirty; | ||
}; | ||
return autoDirty; | ||
} | ||
function createDispatchCustomEvent() { | ||
@@ -105,2 +141,25 @@ var type = void 0, | ||
function createResize() { | ||
var type = underscore.uniqueId('resize.resize_'), | ||
w = d3Selection.select(window); | ||
var wait = 300; | ||
function resize(s) { | ||
w.on(type, underscore.debounce(onWindowResize, wait)); | ||
function onWindowResize() { | ||
s.dispatch('redraw').dispatch('size-dirty'); | ||
} | ||
} | ||
resize.wait = function (value) { | ||
if (!arguments.length) return wait; | ||
wait = value; | ||
return resize; | ||
}; | ||
return resize; | ||
} | ||
function each(c) { | ||
@@ -193,27 +252,2 @@ return function each(s) { | ||
var dispatchRedraw = createDispatchCustomEvent().type('redraw'); | ||
var dispatchSizeDirty = createDispatchCustomEvent().type('size-dirty'); | ||
function createResize() { | ||
var type = underscore.uniqueId('resize.resize_'), | ||
w = d3Selection.select(window); | ||
var wait = 300; | ||
function resize(s) { | ||
w.on(type, underscore.debounce(onWindowResize, wait)); | ||
function onWindowResize() { | ||
s.each(dispatchSizeDirty).each(dispatchRedraw); | ||
} | ||
} | ||
resize.wait = function (value) { | ||
if (!arguments.length) return wait; | ||
wait = value; | ||
return resize; | ||
}; | ||
return resize; | ||
} | ||
function selectionChanged() { | ||
@@ -277,3 +311,5 @@ | ||
exports.call = call; | ||
exports.createAutoDirty = createAutoDirty; | ||
exports.createDispatchCustomEvent = createDispatchCustomEvent; | ||
exports.createResize = createResize; | ||
exports.each = each; | ||
@@ -286,3 +322,2 @@ exports.emptyIfFormat = emptyIfFormat; | ||
exports.redraw = redraw; | ||
exports.createResize = createResize; | ||
exports.selectionChanged = selectionChanged; | ||
@@ -289,0 +324,0 @@ exports.throttle = throttle$1; |
{ | ||
"name": "@zambezi/d3-utils", | ||
"version": "3.0.0-4", | ||
"version": "3.0.0-5", | ||
"description": "Common utility functions to use with d3", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
export { appendFromTemplate } from './append-from-template' | ||
export { appendIfMissing } from './append-if-missing' | ||
export { call } from './call' | ||
export { createAutoDirty } from './auto-dirty' | ||
export { createDispatchCustomEvent } from './dispatch-custom-event' | ||
export { createResize } from './resize' | ||
export { each } from './each' | ||
@@ -11,4 +13,3 @@ export { emptyIfFormat } from './empty-if-format' | ||
export { redraw } from './redraw' | ||
export { createResize } from './resize' | ||
export { selectionChanged } from './selection-changed' | ||
export { throttle } from './throttle' |
import { rest } from 'underscore' | ||
import { select } from 'd3-selection' | ||
import { uniqueId, debounce } from 'underscore' | ||
import { createDispatchCustomEvent } from './dispatch-custom-event' | ||
const dispatchRedraw = createDispatchCustomEvent().type('redraw') | ||
, dispatchSizeDirty = createDispatchCustomEvent().type('size-dirty') | ||
export function createResize() { | ||
@@ -19,4 +15,3 @@ const type = uniqueId('resize.resize_') | ||
function onWindowResize() { | ||
s.each(dispatchSizeDirty) | ||
.each(dispatchRedraw) | ||
s.dispatch('redraw').dispatch('size-dirty') | ||
} | ||
@@ -23,0 +18,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35579
24
515