How to use d3-scale - 10 common examples

To help you get started, we’ve selected a few d3-scale 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 DefinitelyTyped / DefinitelyTyped / d3-scale / d3-scale-tests.ts View on Github external
ordinalScaleStringNumber = ordinalScaleStringNumber.domain(['negative', 'neutral', 'positive']);

// range(...) -----------------------------------------------------------------

ordinalScaleStringString = ordinalScaleStringString.range(['crimson', 'midnightblue', 'seagreen']);
rangeStrings = ordinalScaleStringString.range();

ordinalScaleStringNumber = ordinalScaleStringNumber.range([-1, 0, 1]);
rangeNumbers = ordinalScaleStringNumber.range();


// unknown(...) and d3Scale.scaleImplicit --------------------------------------

let implicit: { name: 'implicit' } = d3Scale.scaleImplicit;

ordinalScaleStringString = ordinalScaleStringString.unknown(d3Scale.scaleImplicit);

ordinalScaleStringNumber = ordinalScaleStringNumber.unknown(0);

let unknownValue: string | { name: 'implicit' } = ordinalScaleStringString.unknown();

if (typeof unknownValue === 'string') {
    console.log(unknownValue);
} else {
    console.log(unknownValue.name);
}

// (...) value mapping from domain to output -----------------------------------

outputString = ordinalScaleStringString('neutral');

outputNumber = ordinalScaleStringNumber('negative');
github DefinitelyTyped / DefinitelyTyped / types / d3-scale / d3-scale-tests.ts View on Github external
domainStrings = ordinalScaleStringString.domain();

ordinalScaleStringNumber = ordinalScaleStringNumber.domain(['negative', 'neutral', 'positive']);

// range(...) -----------------------------------------------------------------

ordinalScaleStringString = ordinalScaleStringString.range(['crimson', 'midnightblue', 'seagreen']);
ordinalScaleStringString = ordinalScaleStringString.range(schemePuRd[3]);
rangeStrings = ordinalScaleStringString.range();

ordinalScaleStringNumber = ordinalScaleStringNumber.range([-1, 0, 1]);
rangeNumbers = ordinalScaleStringNumber.range();

// unknown(...) and d3Scale.scaleImplicit --------------------------------------

const implicit: { name: 'implicit' } = d3Scale.scaleImplicit;

ordinalScaleStringString = ordinalScaleStringString.unknown(d3Scale.scaleImplicit);

ordinalScaleStringNumber = ordinalScaleStringNumber.unknown(0);

const unknownValue: string | { name: 'implicit' } = ordinalScaleStringString.unknown();

if (typeof unknownValue === 'string') {
    console.log(unknownValue);
} else {
    console.log(unknownValue.name);
}

// (...) value mapping from domain to output -----------------------------------

outputString = ordinalScaleStringString('neutral');
github DefinitelyTyped / DefinitelyTyped / types / d3-scale / d3-scale-tests.ts View on Github external
ordinalScaleStringNumber = ordinalScaleStringNumber.domain(['negative', 'neutral', 'positive']);

// range(...) -----------------------------------------------------------------

ordinalScaleStringString = ordinalScaleStringString.range(['crimson', 'midnightblue', 'seagreen']);
ordinalScaleStringString = ordinalScaleStringString.range(schemePuRd[3]);
rangeStrings = ordinalScaleStringString.range();

ordinalScaleStringNumber = ordinalScaleStringNumber.range([-1, 0, 1]);
rangeNumbers = ordinalScaleStringNumber.range();

// unknown(...) and d3Scale.scaleImplicit --------------------------------------

const implicit: { name: 'implicit' } = d3Scale.scaleImplicit;

ordinalScaleStringString = ordinalScaleStringString.unknown(d3Scale.scaleImplicit);

ordinalScaleStringNumber = ordinalScaleStringNumber.unknown(0);

const unknownValue: string | { name: 'implicit' } = ordinalScaleStringString.unknown();

if (typeof unknownValue === 'string') {
    console.log(unknownValue);
} else {
    console.log(unknownValue.name);
}

// (...) value mapping from domain to output -----------------------------------

outputString = ordinalScaleStringString('neutral');

outputNumber = ordinalScaleStringNumber('negative');
github DefinitelyTyped / DefinitelyTyped / d3-scale / d3-scale-tests.ts View on Github external
domainStrings = ordinalScaleStringString.domain();

ordinalScaleStringNumber = ordinalScaleStringNumber.domain(['negative', 'neutral', 'positive']);

// range(...) -----------------------------------------------------------------

ordinalScaleStringString = ordinalScaleStringString.range(['crimson', 'midnightblue', 'seagreen']);
rangeStrings = ordinalScaleStringString.range();

ordinalScaleStringNumber = ordinalScaleStringNumber.range([-1, 0, 1]);
rangeNumbers = ordinalScaleStringNumber.range();


// unknown(...) and d3Scale.scaleImplicit --------------------------------------

let implicit: { name: 'implicit' } = d3Scale.scaleImplicit;

ordinalScaleStringString = ordinalScaleStringString.unknown(d3Scale.scaleImplicit);

ordinalScaleStringNumber = ordinalScaleStringNumber.unknown(0);

let unknownValue: string | { name: 'implicit' } = ordinalScaleStringString.unknown();

if (typeof unknownValue === 'string') {
    console.log(unknownValue);
} else {
    console.log(unknownValue.name);
}

// (...) value mapping from domain to output -----------------------------------

outputString = ordinalScaleStringString('neutral');
github DefinitelyTyped / DefinitelyTyped / d3-axis / d3-axis-tests.ts View on Github external
let containerElement: d3Axis.AxisContainerElement;
const svg: SVGSVGElement = select('svg').node() !; // mock
const g: SVGGElement = select('g').node() !; // mock
const canvas: HTMLCanvasElement = select('canvas').node() !; // mock

containerElement = svg;
containerElement = g;
// containerElement = canvas; // fails, incompatible type

// --------------------------------------------------------------------------
// Test Axis Generators
// --------------------------------------------------------------------------

let topAxis: d3Axis.Axis = d3Axis.axisTop(scaleLinear());
let rightAxis: d3Axis.Axis = d3Axis.axisRight(scaleTime());
let bottomAxis: d3Axis.Axis = d3Axis.axisBottom(scaleOrdinal());
let leftAxis: d3Axis.Axis = d3Axis.axisLeft(scaleLinear());

// --------------------------------------------------------------------------
// Test Configure Axis
// --------------------------------------------------------------------------

// scale(...) ----------------------------------------------------------------

leftAxis = leftAxis.scale(scalePow());
const powerScale: ScalePower = leftAxis.scale>();
// powerScale = leftAxis.scale(); // fails, without casting as AxisScale is purposely  generic

bottomAxis = bottomAxis.scale(scaleOrdinal());
// bottomAxis = bottomAxis.scale(scalePow()) // fails, domain of scale incompatible with domain of axis
github DefinitelyTyped / DefinitelyTyped / types / d3-scale / d3-scale-tests.ts View on Github external
// copy(...) -----------------------------------------------------------------

const copiedPowerScale: d3Scale.ScalePower = powerScaleNumString.copy();

// -------------------------------------------------------------------------------
// Logarithmic Scale Factory
// -------------------------------------------------------------------------------

// scaleLog() ---------------------------------------------------------------------

let logScaleNumber: d3Scale.ScaleLogarithmic;
let logScaleString: d3Scale.ScaleLogarithmic;
let logScaleNumString: d3Scale.ScaleLogarithmic;

logScaleNumber = d3Scale.scaleLog();
logScaleString = d3Scale.scaleLog();
logScaleNumString = d3Scale.scaleLog();

// ScaleLogarithmic Interface ========================================================

// base --------------------------------------------------------------------

const base: number = logScaleNumber.base();

logScaleNumber = logScaleNumber.base(42);

// domain(...) -----------------------------------------------------------------

logScaleNumber = logScaleNumber.domain(domainNumeric);
logScaleNumber = logScaleNumber.domain(domainNumbers);
domainNumbers = logScaleNumber.domain();
github DefinitelyTyped / DefinitelyTyped / d3-scale / d3-scale-tests.ts View on Github external
colorInterpolator = d3Scale.interpolateCool;

colorInterpolator = d3Scale.interpolateCubehelixDefault;


// -------------------------------------------------------------------------------
// Quantize Scale Factory
// -------------------------------------------------------------------------------

// scaleQuantize() -----------------------------------------------------------------

let quantizeScaleNumber: d3Scale.ScaleQuantize;
let quantizeScaleString: d3Scale.ScaleQuantize;

quantizeScaleNumber = d3Scale.scaleQuantize();
quantizeScaleString = d3Scale.scaleQuantize();


// ScaleQuantize Interface ========================================================

// domain(...) -----------------------------------------------------------------

quantizeScaleNumber = quantizeScaleNumber.domain([0, 1]);
quantizeScaleNumber = quantizeScaleNumber.domain([new NumCoercible(0), new NumCoercible(100)]);
let domainQuantize: [number, number] = quantizeScaleNumber.domain();

// range(...) -----------------------------------------------------------------

quantizeScaleNumber = quantizeScaleNumber.range(rangeNumbers);
rangeNumbers = quantizeScaleNumber.range();

quantizeScaleString = quantizeScaleString.range(['steelblue', 'brown']);
github DefinitelyTyped / DefinitelyTyped / d3-scale / d3-scale-tests.ts View on Github external
colorInterpolator = d3Scale.interpolateCool;

colorInterpolator = d3Scale.interpolateCubehelixDefault;


// -------------------------------------------------------------------------------
// Quantize Scale Factory
// -------------------------------------------------------------------------------

// scaleQuantize() -----------------------------------------------------------------

let quantizeScaleNumber: d3Scale.ScaleQuantize;
let quantizeScaleString: d3Scale.ScaleQuantize;

quantizeScaleNumber = d3Scale.scaleQuantize();
quantizeScaleString = d3Scale.scaleQuantize();


// ScaleQuantize Interface ========================================================

// domain(...) -----------------------------------------------------------------

quantizeScaleNumber = quantizeScaleNumber.domain([0, 1]);
quantizeScaleNumber = quantizeScaleNumber.domain([new NumCoercible(0), new NumCoercible(100)]);
let domainQuantize: [number, number] = quantizeScaleNumber.domain();

// range(...) -----------------------------------------------------------------

quantizeScaleNumber = quantizeScaleNumber.range(rangeNumbers);
rangeNumbers = quantizeScaleNumber.range();
github DefinitelyTyped / DefinitelyTyped / d3-scale / d3-scale-tests.ts View on Github external
let localTimeScaleNumber: d3Scale.ScaleTime;
let localTimeScaleString: d3Scale.ScaleTime;
let localTimeScaleNumString: d3Scale.ScaleTime;

localTimeScaleNumber = d3Scale.scaleTime();
localTimeScaleString = d3Scale.scaleTime();
localTimeScaleNumString = d3Scale.scaleTime();


let utcScaleNumber: d3Scale.ScaleTime;
let utcScaleString: d3Scale.ScaleTime;
let utcScaleNumString: d3Scale.ScaleTime;

utcScaleNumber = d3Scale.scaleUtc();
utcScaleString = d3Scale.scaleUtc();
utcScaleNumString = d3Scale.scaleUtc();

// domain(...) -----------------------------------------------------------------

localTimeScaleNumber = localTimeScaleNumber.domain(domainDates);

domainDates = localTimeScaleNumber.domain();

localTimeScaleString = localTimeScaleString.domain([new Date(2016, 6, 1), Date.now()]);
domainDates = localTimeScaleString.domain();

localTimeScaleNumString = localTimeScaleNumString.domain(domainDates);
domainDates = localTimeScaleNumString.domain();


// range(...) -----------------------------------------------------------------
github DefinitelyTyped / DefinitelyTyped / types / d3-scale / d3-scale-tests.ts View on Github external
// scaleTime() and scaleUtc() ----------------------------------------------------

let localTimeScaleNumber: d3Scale.ScaleTime;
let localTimeScaleString: d3Scale.ScaleTime;
let localTimeScaleNumString: d3Scale.ScaleTime;

localTimeScaleNumber = d3Scale.scaleTime();
localTimeScaleString = d3Scale.scaleTime();
localTimeScaleNumString = d3Scale.scaleTime();

let utcScaleNumber: d3Scale.ScaleTime;
let utcScaleString: d3Scale.ScaleTime;
let utcScaleNumString: d3Scale.ScaleTime;

utcScaleNumber = d3Scale.scaleUtc();
utcScaleString = d3Scale.scaleUtc();
utcScaleNumString = d3Scale.scaleUtc();

// domain(...) -----------------------------------------------------------------

localTimeScaleNumber = localTimeScaleNumber.domain(domainDates);

domainDates = localTimeScaleNumber.domain();

localTimeScaleString = localTimeScaleString.domain([new Date(2016, 6, 1), Date.now()]);
domainDates = localTimeScaleString.domain();

localTimeScaleNumString = localTimeScaleNumString.domain(domainDates);
domainDates = localTimeScaleNumString.domain();

// range(...) -----------------------------------------------------------------