How to use the d3fc.util function in d3fc

To help you get started, we’ve selected a few d3fc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / chart / multiChart.js View on Github external
export default function() {
    var charts = [];
    var dispatch = d3.dispatch(event.viewChange);

    function key(d) { return d.option.id; }

    var secDataJoin = fc.util.dataJoin()
        .children(true)
        .selector('.secondary-container')
        .element('svg')
        .attr('class', function(d) {
            return 'secondary-container secondary-' + d.valueString;
        })
        // Issue with elements being regenerated due to data being overwritten. See:
        // https://github.com/ScottLogic/d3fc/blob/0327890d48c9de73a41d901df02bac88dc83e398/src/series/multi.js#L26-L36
        .key(function(d) {
            return key(this.__secondaryChart__ || d);
        });

    function multiChart(selection) {
        selection.each(function(model) {
            var secondaries = secDataJoin(this, charts);
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / chart / primary.js View on Github external
function primary(selection) {
        var model = selection.datum();

        if (model.selectorsChanged) {
            selectorsChanged(model);
        }

        primaryChart.xDomain(model.viewDomain);

        xScale.discontinuityProvider(model.discontinuityProvider);

        crosshair.snap(fc.util.seriesPointSnapXOnly(currentSeries.option, model.visibleData));
        updateCrosshairDecorate(model.visibleData);

        movingAverage(model.data);
        bollingerAlgorithm(model.data);

        // Scale y axis
        // Add percentage padding either side of extreme high/lows
        var extentAccessors = getExtentAccessors(multi.series());
        var paddedYExtent = fc.util.extent()
            .fields(extentAccessors)
            .pad(0.08)(model.visibleData);
        primaryChart.yDomain(paddedYExtent);

        // Find current tick values and add close price to this list, then set it explicitly below
        var latestPrice = currentYValueAccessor(model.data[model.data.length - 1]);
        var tickValuesWithAnnotations = produceAnnotatedTickValues(yScale, [latestPrice]);
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / chart / secondary / macd.js View on Github external
function macd(selection) {
        var model = selection.datum();
        algorithm(model.data);

        var paddedYExtent = fc.util.extent()
            .fields(['macd'])
            .symmetricalAbout(0)
            .pad(0.08)(model.data.map(function(d) { return d.macd; }));
        chart.trackingLatest(model.trackingLatest)
            .xDomain(model.viewDomain)
            .yDomain(paddedYExtent);

        selection.call(chart);
    }
github ScottLogic / StockFlux / stockflux-bitflux / src / assets / js / app.js View on Github external
.on(event.newTrade, function(data) {
                updateModelData(data);
                if (model.charts.primary.trackingLatest) {
                    var newDomain = util.domain.moveToLatest(
                        model.charts.primary.discontinuityProvider,
                        model.charts.primary.viewDomain,
                        fc.util.extent().fields(['date'])(model.charts.primary.data));
                    onViewChange(newDomain);
                }
            })
            .on(event.historicDataLoaded, function(data) {
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / series / candlestick.js View on Github external
export default function() {
    var xScale = fc.scale.dateTime();
    var yScale = d3.scale.linear();
    var barWidth = fc.util.fractionalBarWidth(0.75);
    var xValue = function(d) { return d.date; };
    var xValueScaled = function(d, i) { return xScale(xValue(d, i)); };
    var yLowValue = function(d) { return d.low; };
    var yHighValue = function(d) { return d.high; };
    var yCloseValue = function(d) { return d.close; };

    var candlestickSvg = fc.svg.candlestick()
      .x(function(d) { return xScale(d.date); })
      .open(function(d) { return yScale(d.open); })
      .high(function(d) { return yScale(yHighValue(d)); })
      .low(function(d) { return yScale(yLowValue(d)); })
      .close(function(d) { return yScale(d.close); });

    var upDataJoin = fc.util.dataJoin()
      .selector('path.up')
      .element('path')
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / series / candlestick.js View on Github external
var yScale = d3.scale.linear();
    var barWidth = fc.util.fractionalBarWidth(0.75);
    var xValue = function(d) { return d.date; };
    var xValueScaled = function(d, i) { return xScale(xValue(d, i)); };
    var yLowValue = function(d) { return d.low; };
    var yHighValue = function(d) { return d.high; };
    var yCloseValue = function(d) { return d.close; };

    var candlestickSvg = fc.svg.candlestick()
      .x(function(d) { return xScale(d.date); })
      .open(function(d) { return yScale(d.open); })
      .high(function(d) { return yScale(yHighValue(d)); })
      .low(function(d) { return yScale(yLowValue(d)); })
      .close(function(d) { return yScale(d.close); });

    var upDataJoin = fc.util.dataJoin()
      .selector('path.up')
      .element('path')
      .attr('class', 'up');

    var downDataJoin = fc.util.dataJoin()
      .selector('path.down')
      .element('path')
      .attr('class', 'down');

    var candlestick = function(selection) {
        selection.each(function(data) {
            candlestickSvg.width(barWidth(data.map(xValueScaled)));

            var upData = data.filter(function(d) { return d.open < d.close; });
            var downData = data.filter(function(d) { return d.open >= d.close; });
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / util / domain / centerOnDate.js View on Github external
export default function(discontinuityProvider, domain, data, centerDate) {
    var dataExtent = fc.util.extent()
        .fields(['date'])(data);

    var domainExtent = fc.util.extent()
        .fields([fc.util.fn.identity])(domain);

    var domainTimeDifference = discontinuityProvider.distance(domainExtent[0], domainExtent[1]);

    if (centerDate.getTime() < dataExtent[0] || centerDate.getTime() > dataExtent[1]) {
        return domainExtent;
    }

    var centeredDataDomain = [
        discontinuityProvider.offset(centerDate, -domainTimeDifference / 2),
        discontinuityProvider.offset(centerDate, domainTimeDifference / 2)
    ];
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / util / domain / centerOnDate.js View on Github external
export default function(discontinuityProvider, domain, data, centerDate) {
    var dataExtent = fc.util.extent()
        .fields(['date'])(data);

    var domainExtent = fc.util.extent()
        .fields([fc.util.fn.identity])(domain);

    var domainTimeDifference = discontinuityProvider.distance(domainExtent[0], domainExtent[1]);

    if (centerDate.getTime() < dataExtent[0] || centerDate.getTime() > dataExtent[1]) {
        return domainExtent;
    }

    var centeredDataDomain = [
        discontinuityProvider.offset(centerDate, -domainTimeDifference / 2),
        discontinuityProvider.offset(centerDate, domainTimeDifference / 2)
    ];

    var timeShift = 0;
    if (centeredDataDomain[1].getTime() > dataExtent[1].getTime()) {
        timeShift = -discontinuityProvider.distance(dataExtent[1], centeredDataDomain[1]);
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / menu / generator / dropdown.js View on Github external
export default function() {
    var dispatch = d3.dispatch('optionChange');

    var buttonDataJoin = fc.util.dataJoin()
        .selector('button')
        .element('button')
        .attr({
            'class': 'dropdown-toggle',
            'type': 'button',
            'data-toggle': 'dropdown'
        });

    var caretDataJoin = fc.util.dataJoin()
        .selector('.caret')
        .element('span')
        .attr('class', 'caret');

    var listDataJoin = fc.util.dataJoin()
        .selector('ul')
        .element('ul')
github ScottLogic / StockFlux / packages / stockflux-bitflux / src / assets / js / menu / generator / dropdown.js View on Github external
export default function() {
    var dispatch = d3.dispatch('optionChange');

    var buttonDataJoin = fc.util.dataJoin()
        .selector('button')
        .element('button')
        .attr({
            'class': 'dropdown-toggle',
            'type': 'button',
            'data-toggle': 'dropdown'
        });

    var caretDataJoin = fc.util.dataJoin()
        .selector('.caret')
        .element('span')
        .attr('class', 'caret');

    var listDataJoin = fc.util.dataJoin()
        .selector('ul')
        .element('ul')
        .attr('class', 'dropdown-menu');

    var listItemsDataJoin = fc.util.dataJoin()
        .selector('li')
        .element('li')
        .key(function(d) { return d.displayString; });

    function dropdown(selection) {
        var model = selection.datum();