Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
In order to focus on definitions content, removed 'typings' from the …
Browse files Browse the repository at this point in the history
…toolchain. See deployment related issue #1. As a result, imports are now set to relative paths in the interim to postpone decision regarding deployment and module resolution.

Updates to d3-selection and d3-transition to replace use of type aliases with direct argument typing of function arguments passed into methods or returned. This is done with regard to ease visibility of typing info in editor without need to navigate to alias definition (development is in VS Code). Some updates to naming of generics (e.g. DescElement to generalize beyon immediate  child elements in selections, also use OldDatum in selectAll, where pre-existing data may be selected with the elements.)
  • Loading branch information
tomwanzek committed Jun 25, 2016
1 parent 7b04276 commit 789e549
Show file tree
Hide file tree
Showing 28 changed files with 156 additions and 190 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -40,3 +40,6 @@ typings

# Optional REPL history
.node_repl_history

# Typescript Cache
.tscache
3 changes: 1 addition & 2 deletions Gruntfile.js
Expand Up @@ -15,8 +15,7 @@ module.exports = function (grunt) {
compileService: {
files: [{
src: [
'tests/**/*.ts',
'typings/index.d.ts'
'tests/**/*.ts'
]
}],
options: {
Expand Down
7 changes: 4 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "d3-v4-definitelytyped",
"version": "1.0.0",
"version": "1.0.1",
"description": "Staged and partially experimental typescript definition files related to D3.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -23,6 +23,7 @@
"grunt": "^1.0.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-ts": "^5.5.1",
"typescript": "^1.9.0-dev.20160613-1.0"
}
"typescript": "^1.9.0-dev.20160622-1.0"
},
"dependencies": {}
}
2 changes: 1 addition & 1 deletion src/d3-drag/index.d.ts
Expand Up @@ -5,7 +5,7 @@

// TODO: Clean-up header for proper referencing of new project/module information

import * as d3_selection from 'd3-selection';
import * as d3_selection from '../d3-selection';


// --------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/d3-interpolate/index.d.ts
Expand Up @@ -3,7 +3,7 @@
// Definitions by: Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>, Tom Wanzek <https://github.com/tomwanzek>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import * as d3_color from 'd3-color';
import * as d3_color from '../d3-color';


// --------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/d3-scale/index.d.ts
Expand Up @@ -6,8 +6,8 @@
// TODO: Clean-up header for proper referencing of new project/module information


import * as d3_interpolate from 'd3-interpolate';
import * as d3_time from 'd3-time';
import * as d3_interpolate from '../d3-interpolate';
import * as d3_time from '../d3-time';

// -------------------------------------------------------------------------------
// Shared Types and Interfaces
Expand Down
136 changes: 56 additions & 80 deletions src/d3-selection/index.d.ts

Large diffs are not rendered by default.

107 changes: 58 additions & 49 deletions src/d3-transition/index.d.ts
Expand Up @@ -6,18 +6,20 @@
// TODO: Clean-up header for proper referencing of new project/module information


import * as d3_color from 'd3-color';
import * as d3_dispatch from 'd3-dispatch';
import * as d3_ease from 'd3-ease';
import * as d3_interpolate from 'd3-interpolate';
import * as d3_selection from 'd3-selection';
import * as d3_timer from 'd3-timer';

//import * as d3_color from 'd3-color';
//import * as d3_dispatch from 'd3-dispatch';
//import * as d3_ease from 'd3-ease';
import {BaseType, Primitive, Selection} from '../d3-selection';
//import * as d3_timer from 'd3-timer';

// HACK: ../ to resolve in absence of @types support (including for augmentation below)

/**
* Extend interface 'Selection' by declaration merging with 'd3-selection'
*/
declare module 'd3-selection' {
export interface Selection<GElement extends d3_selection.BaseType, Datum, PElement extends d3_selection.BaseType, PDatum> {
declare module '../d3-selection' {
export interface Selection<GElement extends BaseType, Datum, PElement extends BaseType, PDatum> {
interrupt(name?: string): Transition<GElement, Datum, PElement, PDatum>;
transition(name?: string): Transition<GElement, Datum, PElement, PDatum>;
transition(transition: Transition<GElement, Datum, PElement, PDatum>): Transition<GElement, Datum, PElement, PDatum>;
Expand All @@ -29,48 +31,53 @@ declare module 'd3-selection' {
// Shared Type Definitions and Interfaces
// --------------------------------------------------------------------------

export interface TweenFn<T extends d3_selection.BaseType, U, V> extends Function {
(this: T, datum?: U, i?: number, group?: T[] | NodeListOf<T> ): d3_interpolate.InterpolationFn<V>;
export interface TweenFn<T extends BaseType, U, V> extends Function {
(this: T, datum?: U, i?: number, group?: T[] | NodeListOf<T>): ((t: number) => V);
}


export function active<GElement extends d3_selection.BaseType, Datum, PElement extends d3_selection.BaseType, PDatum>(node: GElement, name?: string): Transition<GElement, Datum, PElement, PDatum> | null;
export function active<GElement extends BaseType, Datum, PElement extends BaseType, PDatum>(node: GElement, name?: string): Transition<GElement, Datum, PElement, PDatum> | null;

export function interrupt(node: d3_selection.BaseType, name?: string): void;
export function interrupt(node: BaseType, name?: string): void;

export interface Transition<GElement extends d3_selection.BaseType, Datum, PElement extends d3_selection.BaseType, PDatum> {
export interface Transition<GElement extends BaseType, Datum, PElement extends BaseType, PDatum> {

// Sub-selection -------------------------

select<ChildElement extends d3_selection.BaseType>(selector: string): Transition<ChildElement, Datum, PElement, PDatum>;
select<ChildElement extends d3_selection.BaseType>(selector: d3_selection.SelectorFn<GElement, Datum, ChildElement>): Transition<ChildElement, Datum, PElement, PDatum>;
select<DescElement extends BaseType>(selector: string): Transition<DescElement, Datum, PElement, PDatum>;
select<DescElement extends BaseType>(selector: (this: GElement, datum?: Datum, index?: number, group?: Array<GElement> | NodeListOf<GElement>) => DescElement): Transition<DescElement, Datum, PElement, PDatum>;

selectAll<ChildElement extends d3_selection.BaseType, NewDatum>(selector: string): Transition<ChildElement, NewDatum, GElement, Datum>;
selectAll<ChildElement extends d3_selection.BaseType, NewDatum>(selector: d3_selection.SelectorAllFn<GElement, Datum, ChildElement>): Transition<ChildElement, NewDatum, GElement, Datum>;
// TODO: while the empty selections (null or undefined selector) are defined on the underlying object, they should not be exposed in the type definition API
// as they are meaningless on transitions.)
// selectAll(): Transition<undefined, undefined, GElement, Datum>; // _groups are set to empty array, first generic type is set to undefined by convention
// selectAll(selector: null): Transition<undefined, undefined, GElement, Datum>; // _groups are set to empty array, first generic type is set to undefined by convention
selectAll<DescElement extends BaseType, OldDatum>(selector: string): Transition<DescElement, OldDatum, GElement, Datum>;
selectAll<DescElement extends BaseType, OldDatum>(selector: (this: GElement, datum?: Datum, index?: number, group?: Array<GElement> | NodeListOf<GElement>) => (Array<DescElement> | NodeListOf<DescElement>)): Transition<DescElement, OldDatum, GElement, Datum>;

selection(): d3_selection.Selection<GElement, Datum, PElement, PDatum>;
selection(): Selection<GElement, Datum, PElement, PDatum>;
transition(): Transition<GElement, Datum, PElement, PDatum>;

// Modifying -------------------------------

attr(name: string, value: d3_selection.Primitive | null): Transition<GElement, Datum, PElement, PDatum>;
attr(name: string, value: d3_selection.ValueFn<GElement, Datum, d3_selection.Primitive>): Transition<GElement, Datum, PElement, PDatum>;
attr(name: string, value: Primitive | null): Transition<GElement, Datum, PElement, PDatum>;
attr(name: string, value: (this: GElement, datum?: Datum, index?: number, group?: Array<GElement> | NodeListOf<GElement>) => Primitive): Transition<GElement, Datum, PElement, PDatum>;
// TODO: Review tweenFn
attrTween(name: string, tweenFn: TweenFn<GElement, Datum, d3_selection.Primitive>): Transition<GElement, Datum, PElement, PDatum>;
style(name: string, value: d3_selection.Primitive | null, priority?: string): Transition<GElement, Datum, PElement, PDatum>;
style(name: string, value: d3_selection.ValueFn<GElement, Datum, d3_selection.Primitive>, priority?: string): Transition<GElement, Datum, PElement, PDatum>;
attrTween(name: string, tweenFn: TweenFn<GElement, Datum, Primitive>): Transition<GElement, Datum, PElement, PDatum>;

style(name: string, value: Primitive | null, priority?: string): Transition<GElement, Datum, PElement, PDatum>;
style(name: string, value: (this: GElement, datum?: Datum, index?: number, group?: Array<GElement> | NodeListOf<GElement>) => Primitive, priority?: string): Transition<GElement, Datum, PElement, PDatum>;
// TODO: Review tweenFn
styleTween(name: string, tweenFn: TweenFn<GElement, Datum, d3_selection.Primitive>): Transition<GElement, Datum, PElement, PDatum>;
text(value: d3_selection.Primitive | null): Transition<GElement, Datum, PElement, PDatum>;
text(value: d3_selection.ValueFn<GElement, Datum, d3_selection.Primitive>): Transition<GElement, Datum, PElement, PDatum>;
styleTween(name: string, tweenFn: TweenFn<GElement, Datum, Primitive>): Transition<GElement, Datum, PElement, PDatum>;

text(value: Primitive | null): Transition<GElement, Datum, PElement, PDatum>;
text(value: (this: GElement, datum?: Datum, index?: number, group?: Array<GElement> | NodeListOf<GElement>) => Primitive): Transition<GElement, Datum, PElement, PDatum>;
// TODO: Review tweenFn
text(tweenFn: TweenFn<GElement, Datum, d3_selection.Primitive>): Transition<GElement, Datum, PElement, PDatum>;
text(tweenFn: TweenFn<GElement, Datum, Primitive>): Transition<GElement, Datum, PElement, PDatum>;

// TODO: Check return type of TweenFn
tween(name: string): TweenFn<GElement, Datum, d3_selection.Primitive | void>;
tween(name: string, tweenFn: TweenFn<GElement, Datum, d3_selection.Primitive> | void): Transition<GElement, Datum, PElement, PDatum>;
tween(name: string): TweenFn<GElement, Datum, void> | null;
tween(name: string, tweenFn: null): Transition<GElement, Datum, PElement, PDatum>;
tween(name: string, tweenFn: TweenFn<GElement, Datum, void>): Transition<GElement, Datum, PElement, PDatum>;

remove(): Transition<GElement, Datum, PElement, PDatum>;

Expand All @@ -80,45 +87,47 @@ export interface Transition<GElement extends d3_selection.BaseType, Datum, PElem
//merge<TJoinGElement extends BaseType, JointDatum>(other: Transition<TJoinGElement, JointDatum>): Transition<TJoinGElement, JointDatum>;

filter(selector: string): Transition<GElement, Datum, PElement, PDatum>;
filter(selector: d3_selection.ValueFn<GElement, Datum, boolean>): Transition<GElement, Datum, PElement, PDatum>;
filter(selector: (this: GElement, datum?: Datum, index?: number, group?: Array<GElement> | NodeListOf<GElement>) => boolean): Transition<GElement, Datum, PElement, PDatum>;

// Event Handling -------------------

// TODO: Check return type of on(type) (i.e. 'this' typing as 'any', given that functionis not bound when returned?)
on(type: string): d3_selection.ListenerFn<any, Datum>;
on(type: string, listener: d3_selection.ListenerFn<GElement, Datum>): Transition<GElement, Datum, PElement, PDatum>;

on(type: string): (this: GElement, datum: Datum, index: number, group: Array<GElement> | NodeListOf<GElement>) => any;
on(type: string, listener: null): Transition<GElement, Datum, PElement, PDatum>;
on(type: string, listener: (this: GElement, datum: Datum, index: number, group: Array<GElement> | NodeListOf<GElement>) => any): Transition<GElement, Datum, PElement, PDatum>;

// Control Flow ----------------------

each(valueFn: d3_selection.ValueFn<GElement, Datum, void>): Transition<GElement, Datum, PElement, PDatum>;
each(valueFn: (this: GElement, datum?: Datum, index?: number, group?: Array<GElement> | NodeListOf<GElement>) => void): Transition<GElement, Datum, PElement, PDatum>;

call(func: (transition: Transition<GElement, Datum, PElement, PDatum>, ...args: any[]) => any, ...args: any[]): Transition<GElement, Datum, PElement, PDatum>;

empty(): boolean;

node(): GElement;
node(): GElement;
nodes(): Array<GElement>;

size(): number;

// Transition Configuration ----------------------

delay(): number;
delay(milliseconds: number): Transition<GElement, Datum, PElement, PDatum>;

duration(): number;
duration(milliseconds: number): Transition<GElement, Datum, PElement, PDatum>;

ease(): d3_ease.EasingFn;
ease(easingFn: d3_ease.EasingFn): Transition<GElement, Datum, PElement, PDatum>;
ease(): (normalizedTime: number) => number;
ease(easingFn: (normalizedTime: number) => number): Transition<GElement, Datum, PElement, PDatum>;
}


export function transition(name: string): Transition<HTMLElement, any, null, undefined>;
export function transition<GElement extends d3_selection.BaseType, Datum, PElement extends d3_selection.BaseType, PDatum>(transition: Transition<GElement, Datum, PElement, PDatum>): Transition<GElement, Datum, PElement, PDatum>;
export function transition<GElement extends BaseType, Datum, PElement extends BaseType, PDatum>(transition: Transition<GElement, Datum, PElement, PDatum>): Transition<GElement, Datum, PElement, PDatum>;

// export namespace transition {
// // HACK: declaration merging with function signatures with different generic templates.
// // TODO: Review prototype typing, given the two different invocation signatures
// // var prototype: Transition<d3_selection.BaseType, any, d3_selection.BaseType | null, any>;
// }

export namespace transition {
// HACK: declaration merging with function signatures with different generic templates.
// TODO: Review prototype typing, given the two different invocation signatures
var prototype: Transition<d3_selection.BaseType, any, d3_selection.BaseType | null, any>;
}
4 changes: 3 additions & 1 deletion src/d3-voronoi/index.d.ts
Expand Up @@ -79,5 +79,7 @@ export interface VoronoiDiagram<T> {
// voronoi Export
// --------------------------------------------------------------------------


// TODO: Review, whether to specify T = [number, number] as separate signature
// or simply comment on it:
// export function voronoi(): VoronoiLayout<[number, number]>;
export function voronoi<T>(): VoronoiLayout<T>;
10 changes: 7 additions & 3 deletions src/d3-zoom/index.d.ts
Expand Up @@ -5,11 +5,15 @@

// TODO: Clean-up header for proper referencing of new project/module information

import * as d3_selection from 'd3-selection';
import * as d3_transition from 'd3-transition';
import * as d3_selection from '../d3-selection';
import * as d3_transition from '../d3-transition';

// Note: This dependency is driven by Definitions, not D3 itself
import {ScaleIdentity, ScaleLinear, ScaleLogarithmic, ScalePower} from 'd3-scale';
import {ScaleIdentity, ScaleLinear, ScaleLogarithmic, ScalePower} from '../d3-scale';

// TODO: consider defining a minimal scale interface, which can be used with
// rescaleX and rescaleY instead of the import of the defined contiuous scales
// from d3-scale

// --------------------------------------------------------------------------
// Shared Type Definitions and Interfaces
Expand Down
2 changes: 1 addition & 1 deletion tests/d3-array/d3-array-test.ts
Expand Up @@ -6,6 +6,6 @@
* are not intended as functional tests.
*/

import * as d3Array from 'd3-array';
import * as d3Array from '../../src/d3-array';

// TODO: Add definitions tests
2 changes: 1 addition & 1 deletion tests/d3-color/d3-color-test.ts
Expand Up @@ -6,7 +6,7 @@
* are not intended as functional tests.
*/

import * as d3Color from 'd3-color';
import * as d3Color from '../../src/d3-color';

// RGB and HSL Typeguards

Expand Down
2 changes: 1 addition & 1 deletion tests/d3-dispatch/d3-dispatch-test.ts
Expand Up @@ -6,7 +6,7 @@
* are not intended as functional tests.
*/

import * as d3Dispatch from 'd3-dispatch';
import * as d3Dispatch from '../../src/d3-dispatch';

// Preparation --------------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions tests/d3-drag/d3-drag-test.ts
Expand Up @@ -6,5 +6,4 @@
* are not intended as functional tests.
*/

import * as d3Drag from 'd3-drag';

import * as d3Drag from '../../src/d3-drag';
2 changes: 1 addition & 1 deletion tests/d3-ease/d3-ease-test.ts
Expand Up @@ -6,6 +6,6 @@
* are not intended as functional tests.
*/

import * as d3Ease from 'd3-ease';
import * as d3Ease from '../../src/d3-ease';

// TODO: Add definitions tests
2 changes: 1 addition & 1 deletion tests/d3-format/d3-format-test.ts
Expand Up @@ -6,6 +6,6 @@
* are not intended as functional tests.
*/

import * as d3Format from 'd3-format';
import * as d3Format from '../../src/d3-format';

// TODO: Add definitions tests
4 changes: 2 additions & 2 deletions tests/d3-interpolate/d3-interpolate-test.ts
Expand Up @@ -6,8 +6,8 @@
* are not intended as functional tests.
*/

import * as d3Color from 'd3-color';
import * as d3Interpolate from 'd3-interpolate';
import * as d3Color from '../../src/d3-color';
import * as d3Interpolate from '../../src/d3-interpolate';

// Preparatory steps -------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/d3-path/d3-path-test.ts
Expand Up @@ -6,6 +6,6 @@
* are not intended as functional tests.
*/

import * as d3Path from 'd3-path';
import * as d3Path from '../../src/d3-path';

// TODO: Add definitions tests
2 changes: 1 addition & 1 deletion tests/d3-polygon/d3-polygon-test.ts
Expand Up @@ -6,6 +6,6 @@
* are not intended as functional tests.
*/

import * as d3Polygon from 'd3-polygon';
import * as d3Polygon from '../../src/d3-polygon';

// TODO: Add definitions tests
2 changes: 1 addition & 1 deletion tests/d3-random/d3-random-test.ts
Expand Up @@ -6,6 +6,6 @@
* are not intended as functional tests.
*/

import * as d3Random from 'd3-random';
import * as d3Random from '../../src/d3-random';

// TODO: Add definitions tests
2 changes: 1 addition & 1 deletion tests/d3-scale/d3-scale-test.ts
Expand Up @@ -6,5 +6,5 @@
* are not intended as functional tests.
*/

import * as d3Scale from 'd3-scale';
import * as d3Scale from '../../src/d3-scale';

4 changes: 3 additions & 1 deletion tests/d3-time-format/d3-time-format-test.ts
Expand Up @@ -4,4 +4,6 @@
* 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 d3TimeFormat from '../../src/d3-time-format';
2 changes: 1 addition & 1 deletion tests/d3-time/d3-time-test.ts
Expand Up @@ -6,7 +6,7 @@
* are not intended as functional tests.
*/

import * as d3Time from 'd3-time';
import * as d3Time from '../../src/d3-time';


let countableI: d3Time.CountableTimeInterval;
Expand Down
2 changes: 1 addition & 1 deletion tests/d3-timer/d3-timer-test.ts
Expand Up @@ -6,7 +6,7 @@
* are not intended as functional tests.
*/

import * as d3Timer from 'd3-timer';
import * as d3Timer from '../../src/d3-timer';

// Test now definition
let now: number = d3Timer.now();
Expand Down

1 comment on commit 789e549

@wz2b
Copy link

@wz2b wz2b commented on 789e549 Aug 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit changed the imports to relative, which I think fixes problems importing things due to transitive imports. I'm waiting for this change to appear in npm. In the meantime, I'm concerned that the commit message says:

imports are now set to relative paths in the interim

because it seems like a good (permanent) idea to me.

Please sign in to comment.