mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
* d3-array: Changed name of import alias in test file for consistency with other test files. Deleted excess line at end of definition. * d3-axis: Enhanced Axis.scale() getter to use generic for refined return type casting. Return type can now be more specific than AxisScale minimal interface compliance. Used `this` as return type for chainable setter methods on Axis. * d3-brush: Use ValueFn type alias from d3-selection for harmonization of callbacks. Use `this` as return type of chainable setter methods. Fixed return type of BrushBehavior.move(...) to be void * d3-chord: Use `this` as return type of chainable setter methods. * d3-collection: Use `this` as return type of chainable setter methods. * d3-color: Use `this` as return type of chainable setter methods. Added helper interface ColorCommonInstance as a fallback to allow extensibility of color spaces e.g. as through d3-hsv * d3-dispatch: Use `this` as return type of chainable setter methods. * d3-drag: Use ValueFn type alias from d3-selection for harmonization of callbacks. Use `this` as return type of chainable setter methods. * d3-ease: Removed excess space. * d3-force: Use `this` as return type of chainable setter methods. Fixed return type of Simulation.tick() to be void. Fixed Force.initialize(...) to be optional when defining a custom force. Enhanced Simulation.force(...) getter to use generic to to cast return type to specific force type, when details are know. Updated related tests. * d3-hsv: New definitions and tests added * d3-interpolate: Use ColorCommonInstance to allow more general color spaces than the color space objects defined in d3-color, e.g. d3-hsv. Added related tests. * d3-quadtree: Use `this` as return type of chainable setter methods. * d3-scale: Fixed missing support of coercible numeric value as input to ScaleSequential. Use `this` as return type of chainable setter methods. * d3-selection: Added type alias ValueFn which is used to harmonize callback functions. Use `this` as return type of chainable setter methods, where no new selection is returned. Removed outdated comments. * d3-selection-multi: Added new definitions with tests. * d3-shape: Use `this` as return type of chainable setter methods. Removed spurious `?` from callback signatures. * d3-time: Use `this` as return type of chainable setter methods. * d3-transition: Added type alias ValueFn which is used to harmonize callback functions. Use `this` as return type of chainable setter methods, where no new transition is returned. * d3-voronoi: Use `this` as return type of chainable setter methods. * d3-zoom: Use `this` as return type of chainable setter methods. Note that ZoomTransform.scale(...) and ZoomTransform.translate(...) return new ZoomTranform objects. Use ValueFn to harmonize callbacks. Updates the prime for the newly developed D3 version 4 definitions on a file-by-file basis.
158 lines
5.3 KiB
TypeScript
158 lines
5.3 KiB
TypeScript
/**
|
|
* Typescript definition tests for d3/d3-axis module
|
|
*
|
|
* Note: These tests are intended to test the definitions only
|
|
* in the sense of typing and call signature consistency. They
|
|
* are not intended as functional tests.
|
|
*/
|
|
|
|
import * as d3Axis from 'd3-axis';
|
|
import {
|
|
scaleLinear,
|
|
ScaleLinear,
|
|
scaleOrdinal,
|
|
ScaleOrdinal,
|
|
scalePow,
|
|
ScalePower,
|
|
scaleTime,
|
|
ScaleTime,
|
|
} from 'd3-scale';
|
|
import { Selection } from 'd3-selection';
|
|
import { Transition } from 'd3-transition';
|
|
import { timeMinute } from 'd3-time';
|
|
import { format } from 'd3-format';
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Preparatory Steps
|
|
// --------------------------------------------------------------------------
|
|
|
|
let num: number;
|
|
|
|
let axisScaleNumber: d3Axis.AxisScale<number>;
|
|
let axisScaleDate: d3Axis.AxisScale<Date>;
|
|
let axisScaleString: d3Axis.AxisScale<string>;
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Test AxisScale Helper Interface
|
|
// --------------------------------------------------------------------------
|
|
|
|
axisScaleNumber = scaleLinear();
|
|
axisScaleDate = scaleTime();
|
|
axisScaleString = scaleOrdinal<number>();
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Test AxisContainerElement
|
|
// --------------------------------------------------------------------------
|
|
|
|
let containerElement: d3Axis.AxisContainerElement;
|
|
let svg: SVGSVGElement,
|
|
g: SVGGElement,
|
|
canvas: HTMLCanvasElement;
|
|
|
|
containerElement = svg;
|
|
containerElement = g;
|
|
// containerElement = canvas; // fails, incompatible type
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Test Axis Generators
|
|
// --------------------------------------------------------------------------
|
|
|
|
let topAxis: d3Axis.Axis<number | { valueOf(): number }> = d3Axis.axisTop(scaleLinear());
|
|
let rightAxis: d3Axis.Axis<Date> = d3Axis.axisRight(scaleTime());
|
|
let bottomAxis: d3Axis.Axis<string> = d3Axis.axisBottom(scaleOrdinal<number>());
|
|
let leftAxis: d3Axis.Axis<number | { valueOf(): number }> = d3Axis.axisLeft(scaleLinear<number>());
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Test Configure Axis
|
|
// --------------------------------------------------------------------------
|
|
|
|
// scale(...) ----------------------------------------------------------------
|
|
|
|
leftAxis = leftAxis.scale(scalePow());
|
|
let powerScale: ScalePower<number, number> = leftAxis.scale<ScalePower<number, number>>();
|
|
// powerScale = leftAxis.scale(); // fails, without casting as AxisScale is purposely generic
|
|
|
|
|
|
|
|
bottomAxis = bottomAxis.scale(scaleOrdinal<number>());
|
|
// bottomAxis = bottomAxis.scale(scalePow()) // fails, domain of scale incompatible with domain of axis
|
|
|
|
let axisScale: d3Axis.AxisScale<string> = bottomAxis.scale();
|
|
let ordinalScale: ScaleOrdinal<string, number> = bottomAxis.scale<ScaleOrdinal<string, number>>();
|
|
// ordinalScale = bottomAxis.scale(); // fails, without casting as AxisScale is purposely generic
|
|
|
|
// ticks(...) ----------------------------------------------------------------
|
|
|
|
topAxis = topAxis.ticks(20, ',f');
|
|
|
|
rightAxis = rightAxis.ticks(timeMinute.every(5));
|
|
|
|
// tickArguments(...) ----------------------------------------------------------------
|
|
|
|
topAxis = topAxis.tickArguments([20, 's']);
|
|
|
|
rightAxis = rightAxis.tickArguments([timeMinute.every(5)]);
|
|
|
|
let tickArguments: Array<any> = leftAxis.tickArguments();
|
|
|
|
// tickValues(...) ----------------------------------------------------------------
|
|
|
|
topAxis = topAxis.tickValues([1, 3, 5, 7]);
|
|
|
|
bottomAxis = bottomAxis.tickValues(['strongly negative', 'strongly positive']);
|
|
|
|
leftAxis = leftAxis.tickValues(null);
|
|
|
|
let tickValues: Array<Date> = rightAxis.tickValues();
|
|
|
|
// tickFormat(...) ----------------------------------------------------------------
|
|
|
|
topAxis = topAxis.tickFormat(format(',.0f'));
|
|
topAxis = topAxis.tickFormat(null);
|
|
|
|
let formatFn: (domainValue: string) => string = bottomAxis.tickFormat();
|
|
|
|
// tickSize(...) ----------------------------------------------------------------
|
|
|
|
rightAxis = rightAxis.tickSize(5);
|
|
num = rightAxis.tickSize();
|
|
|
|
// tickSizeInner(...) ----------------------------------------------------------------
|
|
|
|
rightAxis = rightAxis.tickSizeInner(3);
|
|
num = rightAxis.tickSizeInner();
|
|
|
|
// tickSizeOuter(...) ----------------------------------------------------------------
|
|
|
|
rightAxis = rightAxis.tickSizeOuter(4);
|
|
num = rightAxis.tickSizeOuter();
|
|
|
|
// tickPadding(...) ----------------------------------------------------------------
|
|
|
|
rightAxis = rightAxis.tickPadding(5);
|
|
num = rightAxis.tickPadding();
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Test Apply Axis
|
|
// --------------------------------------------------------------------------
|
|
|
|
let gSelection: Selection<SVGGElement, any, any, any>;
|
|
let gTransition = gSelection.transition();
|
|
|
|
gSelection.call(topAxis);
|
|
gTransition.call(topAxis);
|
|
|
|
let svgSelection: Selection<SVGSVGElement, any, any, any>;
|
|
let svgTransition = svgSelection.transition();
|
|
|
|
svgSelection.call(leftAxis);
|
|
svgTransition.call(leftAxis);
|
|
|
|
let canvasSelection: Selection<HTMLCanvasElement, any, any, any>;
|
|
let canvasTransition = canvasSelection.transition();
|
|
|
|
// canvasSelection.call(rightAxis); // fails, incompatible context container element
|
|
// canvasTransition.call(rightAxis); // fails, incompatible context container element
|