Table of Contents
- Overview
- Properties
- Methods
- .createElement (tag)
- .viewElement (html, [context])
- .domEvent()
- .fetch (url, [options])
- .fetchText (url, [options])
- .json (url, [options])
- .logDebug (msg)
- .logInfo (msg)
- .logWarn (msg)
- .logError (err)
- .on (el, typenames, listener)
- .renderFromUrl (url, [context], [asElement])
- .renderFromDist (name, path, [context], [asElement])
- .select(HTMLElement)
- .selectAll(HTMLElement)
- .selectChildren ([HTMLElement])
- .transition ([sel])
- .transitionDuration ([sel])
The viewBase
object is the base prototype for both view/component and directives
prototypes and therefore it is at the core of the extendibility for the framework.
import {viewBase} from 'd3-view';
viewBase.myMethod = function () {
}
Component name, for a view this is view
, for any other component/directive it is the name
the component has been registered with. For directives, this is always prefixed with d3-
.
The HTMLElement of the component.
Same as viewProviders
Equivalent to d3.select(vm.el)
, d3 selection of the component element.
Unique identifier
Create a new HTML Element with the given tag. Return a d3.selection of the new element.
Render an html
string into an HTML Element. This method returns a d3.selection.
If the optional context
object is provided, it renders the html string using
handlebars template engine (requires handlebars to be available).
Return the current dom event. Equivalent to d3.selection.event
.
Fetch a resource from a url
. This is a convenient method which uses the
fetch
provider.
Fetch a resource from a url
and return the text value
Fetch a resource from a url
and return the object obtained after parsing text as JSON.
Convenience method for logging a debug message (only when debug is turned on).
Uses the viewProvider.logger
instance with the .name prefix.
Convenience method for logging a info message.
Uses the viewProvider.logger
instance with the .name prefix.
Convenience method for logging a warning message.
Uses the viewProvider.logger
instance with the .name prefix.
Convenience method for logging an error message or a stack trace in case err
is an exception.
Uses the viewProvider.logger
instance with the .name prefix.
Adds or removes a listener to each selected element el
for the specified event typenames
. The input el
can be a W3c selector string, an HTML element or a d3 selection.
The typenames
is a string event type, such as click, mouseover, or submit; any
DOM event type supported by your browser may be used.
This method is a proxy for d3-selection.on with the only difference in the listener
signature:
function listener (event) {
...
}
where event
is the d3.event
fired.
Fetch a template from a url
(or the cache if already loaded) and return a Promise which resolve into a d3.selection if asElement
is true
(by default it is true).
If the optional context
object is provided, it renders the remote html string using
the compileHtml
function in viewProviders
(provided this functin is available).
The compileHtml
function is not available in the standard d3-view
distribution.
One could use handlebars compile function for example:
import Handlebars from 'handlebars';
import {viewProviders} from 'd3-view';
viewProviders.compileHtml = Handlebars.compile;
The asElement
parameter can be set to false
if the the template is not a valid html and therefore no conversion to d3-selection is required. This is useful for any other template such as text, json and so forth.
Similar to the previous function, but fetches the template/file form a distribution.
Return a d3.selection of the HTMLElement
.
Equivalent to d3.selectAll(HTMLElement)
.
Select all children of a given HTMLElement, if the HTMLElement is not given select all children of the .el element.
Return a d3.transition object if possible. It requires the d3-transition module to be loaded in the bundle.
If a selection sel
is not provided, return a transition on .sel.
If d3-transition is not loaded or a transition duration is not specified or equal to 0, this method returns nothing.
Fetch a transition duration for the selection sel
. If sel
is not provided,
fetch a transition duration from .sel.
A transition duration is specified in the data-transition-duration
attribute.
<div ... data-transition-duration=250></div>
If d3-transition is not loaded this method always returns 0.