Skip to content

Commit db65460

Browse files
committed
Add snapshot of the TypeScript Samples
0 parents  commit db65460

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+24134
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TypeScript Samples
2+
3+
Samples for TypeScript

amd/README.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
===== TypeScript Sample: AMD Module =====
2+
3+
=== Overview ===
4+
This sample shows a simple Typescript application using an AMD module.
5+
6+
=== Running ===
7+
tsc --module amd app.ts
8+
start default.htm
9+
10+

amd/app.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
body
2+
{
3+
font-family: 'Segoe UI', sans-serif
4+
}
5+
6+
span {
7+
font-style: italic
8+
}

amd/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import model = require("greeter")
2+
3+
var el = document.getElementById('content');
4+
var greeter = new model.Greeter(el);
5+
greeter.start();

amd/default.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
3+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>TypeScript HTML App</title>
7+
<link rel="stylesheet" href="app.css" type="text/css" />
8+
<script data-main="app" type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.1/require.min.js"></script>
9+
</head>
10+
<body>
11+
<h1>TypeScript HTML App</h1>
12+
13+
<div id="content"></div>
14+
</body>
15+
</html>

amd/greeter.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export class Greeter
2+
{
3+
element: HTMLElement;
4+
span: HTMLElement;
5+
timerToken: number;
6+
7+
constructor (element: HTMLElement)
8+
{
9+
this.element = element;
10+
this.element.innerText += "The time is: ";
11+
this.span = document.createElement('span');
12+
this.element.appendChild(this.span);
13+
this.span.innerText = new Date().toUTCString();
14+
}
15+
16+
start()
17+
{
18+
this.timerToken = setInterval(() => this.span.innerText = new Date().toUTCString(), 500);
19+
}
20+
21+
stop()
22+
{
23+
clearTimeout(this.timerToken);
24+
}
25+
}

d3/README.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
===== TypeScript Sample: D3 =====
2+
3+
=== Overview ===
4+
5+
D3 visualization
6+
- Use of the D3 wrapper
7+
- Use of modules and interfaces
8+
9+
=== Running ===
10+
tsc data.ts
11+
start perf.html

d3/d3.d.ts

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
interface ID3Selectors {
2+
select: (selector: string) => ID3Selection;
3+
selectAll: (selector: string) => ID3Selection;
4+
}
5+
6+
interface ID3Base extends ID3Selectors {
7+
// Array Helpers
8+
ascending: (a: number, b: number) => number;
9+
descending: (a: number, b: number) => number;
10+
min<T, U>(arr: T[], map: (v: T) => U ): U;
11+
min<T>(arr: T[]): T;
12+
max<T, U>(arr: T[], map: (v: T) => U ): U;
13+
max<T>(arr: T[]): T;
14+
extent<T, U>(arr: T[], map: (v: T) => U): U[];
15+
extent<T>(arr: T[]): T[];
16+
quantile: (arr: number[], p: number) => number;
17+
bisectLeft<T>(arr: T[], x: T, low?: number, high?: number): number;
18+
bisect<T>(arr: T[], x: T, low?: number, high?: number): number;
19+
bisectRight<T>(arr: T[], x: T, low?: number, high?: number): number;
20+
21+
// Loading resources
22+
xhr: {
23+
(url: string, callback: (xhr: XMLHttpRequest) => void): void;
24+
(url: string, mime: string, callback: (xhr: XMLHttpRequest) => void): void;
25+
};
26+
text: {
27+
(url: string, callback: (response: string) => void): void;
28+
(url: string, mime: string, callback: (response: string) => void): void;
29+
};
30+
json: (url: string, callback: (response: any) => void) => void;
31+
xml: {
32+
(url: string, callback: (response: Document) => void): void;
33+
(url: string, mime: string, callback: (response: Document) => void): void;
34+
};
35+
html: (url: string, callback: (response: DocumentFragment) => void) => void;
36+
csv: {
37+
(url: string, callback: (response: any[]) => void);
38+
parse(string: string): any[];
39+
parseRows(string: string, accessor: (row: any[], index: number) => any): any;
40+
format(rows: any[]): string;
41+
};
42+
43+
time: ID3Time;
44+
scale: {
45+
linear(): ID3LinearScale;
46+
};
47+
interpolate: ID3BaseInterpolate;
48+
interpolateNumber: ID3BaseInterpolate;
49+
interpolateRound: ID3BaseInterpolate;
50+
interpolateString: ID3BaseInterpolate;
51+
interpolateRgb: ID3BaseInterpolate;
52+
interpolateHsl: ID3BaseInterpolate;
53+
interpolateArray: ID3BaseInterpolate;
54+
interpolateObject: ID3BaseInterpolate;
55+
interpolateTransform: ID3BaseInterpolate;
56+
layout: ID3Layout;
57+
svg: ID3Svg;
58+
random: ID3Random;
59+
}
60+
61+
interface ID3Selection extends ID3Selectors {
62+
attr: {
63+
(name: string): string;
64+
(name: string, value: any): ID3Selection;
65+
(name: string, valueFunction: (data: any, index: number) => any): ID3Selection;
66+
};
67+
68+
classed: {
69+
(name: string): string;
70+
(name: string, value: any): ID3Selection;
71+
(name: string, valueFunction: (data: any, index: number) => any): ID3Selection;
72+
};
73+
74+
style: {
75+
(name: string): string;
76+
(name: string, value: any, priority?: string): ID3Selection;
77+
(name: string, valueFunction: (data: any, index: number) => any, priority?: string): ID3Selection;
78+
};
79+
80+
property: {
81+
(name: string): void;
82+
(name: string, value: any): ID3Selection;
83+
(name: string, valueFunction: (data: any, index: number) => any): ID3Selection;
84+
};
85+
86+
text: {
87+
(): string;
88+
(value: any): ID3Selection;
89+
(valueFunction: (data: any, index: number) => any): ID3Selection;
90+
};
91+
92+
html: {
93+
(): string;
94+
(value: any): ID3Selection;
95+
(valueFunction: (data: any, index: number) => any): ID3Selection;
96+
};
97+
98+
append: (name: string) => ID3Selection;
99+
insert: (name: string, before: string) => ID3Selection;
100+
remove: () => ID3Selection;
101+
102+
data: {
103+
(values: (data: any, index: number) => any) : any;
104+
(values: any[], key?: (data: any, index: number) => any): ID3UpdateSelection;
105+
};
106+
107+
call(callback: (selection: ID3Selection) => void): ID3Selection;
108+
}
109+
110+
interface ID3EnterSelection {
111+
append: (name: string) => ID3Selection;
112+
insert: (name: string, before: string) => ID3Selection;
113+
select: (selector: string) => ID3Selection;
114+
empty: () => boolean;
115+
node: () => Node;
116+
}
117+
118+
interface ID3UpdateSelection extends ID3Selection {
119+
enter: () => ID3EnterSelection;
120+
update: () => ID3Selection;
121+
exit: () => ID3Selection;
122+
}
123+
124+
interface ID3Time {
125+
second: ID3Interval;
126+
minute: ID3Interval;
127+
hour: ID3Interval;
128+
day: ID3Interval;
129+
week: ID3Interval;
130+
sunday: ID3Interval;
131+
monday: ID3Interval;
132+
tuesday: ID3Interval;
133+
wednesday: ID3Interval;
134+
thursday: ID3Interval;
135+
friday: ID3Interval;
136+
saturday: ID3Interval;
137+
month: ID3Interval;
138+
year: ID3Interval;
139+
140+
seconds: ID3Range;
141+
minutes: ID3Range;
142+
hours: ID3Range;
143+
days: ID3Range;
144+
weeks: ID3Range;
145+
months: ID3Range;
146+
years: ID3Range;
147+
148+
sundays: ID3Range;
149+
mondays: ID3Range;
150+
tuesdays: ID3Range;
151+
wednesdays: ID3Range;
152+
thursdays: ID3Range;
153+
fridays: ID3Range;
154+
saturdays: ID3Range;
155+
format: {
156+
157+
(specifier: string): ID3TimeFormat;
158+
utc: (specifier: string) => ID3TimeFormat;
159+
iso: ID3TimeFormat;
160+
};
161+
162+
scale(): ID3TimeScale;
163+
}
164+
165+
interface ID3Range {
166+
(start: Date, end: Date, step?: number): Date[];
167+
}
168+
169+
interface ID3Interval {
170+
(date: Date): Date;
171+
floor: (date: Date) => Date;
172+
round: (date: Date) => Date;
173+
ceil: (date: Date) => Date;
174+
range: ID3Range;
175+
offset: (date: Date, step: number) => Date;
176+
utc: ID3Interval;
177+
}
178+
179+
interface ID3TimeFormat {
180+
(date: Date): string;
181+
parse: (string: string) => Date;
182+
}
183+
184+
interface ID3LinearScale {
185+
(value: number): number;
186+
invert(value: number): number;
187+
domain(numbers: any[]): ID3LinearScale;
188+
range: {
189+
(values: any[]): ID3LinearScale;
190+
(): any[];
191+
};
192+
rangeRound: (values: any[]) => ID3LinearScale;
193+
interpolate: {
194+
(): ID3Interpolate;
195+
(factory: ID3Interpolate): ID3LinearScale;
196+
};
197+
clamp(clamp: boolean): ID3LinearScale;
198+
nice(): ID3LinearScale;
199+
ticks(count: number): any[];
200+
tickFormat(count: number): (n: number) => string;
201+
copy: ID3LinearScale;
202+
}
203+
204+
interface ID3TimeScale {
205+
(value: Date): number;
206+
invert(value: number): Date;
207+
domain(numbers: any[]): ID3TimeScale;
208+
range: {
209+
(values: any[]): ID3TimeScale;
210+
(): any[];
211+
};
212+
rangeRound: (values: any[]) => ID3TimeScale;
213+
interpolate: {
214+
(): ID3Interpolate;
215+
(factory: ID3InterpolateFactory): ID3TimeScale;
216+
};
217+
clamp(clamp: boolean): ID3TimeScale;
218+
ticks: {
219+
(count: number): any[];
220+
(range: ID3Range, count: number): any[];
221+
};
222+
tickFormat(count: number): (n: number) => string;
223+
copy(): ID3TimeScale;
224+
}
225+
226+
interface ID3InterpolateFactory {
227+
(a: any, b: any): ID3BaseInterpolate;
228+
}
229+
interface ID3BaseInterpolate {
230+
(a: any, b: any): ID3Interpolate;
231+
}
232+
233+
interface ID3Interpolate {
234+
(t: number): number;
235+
}
236+
237+
interface ID3Layout {
238+
stack(): ID3StackLayout;
239+
}
240+
241+
interface ID3StackLayout {
242+
(layers: any[], index?: number): any[];
243+
values(accessor?: (d: any) => any): ID3StackLayout;
244+
offset(offset: string): ID3StackLayout;
245+
}
246+
247+
interface ID3Svg {
248+
axis(): ID3SvgAxis;
249+
}
250+
251+
interface ID3SvgAxis {
252+
(selection: ID3Selection): void;
253+
scale: {
254+
(): any;
255+
(scale: any): ID3SvgAxis;
256+
};
257+
258+
orient: {
259+
(): string;
260+
(orientation: string): ID3SvgAxis;
261+
};
262+
263+
ticks: {
264+
(count: number): ID3SvgAxis;
265+
(range: ID3Range, count?: number): ID3SvgAxis;
266+
};
267+
268+
tickSubdivide(count: number): ID3SvgAxis;
269+
tickSize(major?: number, minor?: number, end?: number): ID3SvgAxis;
270+
tickFormat(formatter: (value: any) => string): ID3SvgAxis;
271+
}
272+
273+
interface ID3Random {
274+
normal(mean?: number, deviation?: number): () => number;
275+
}
276+
277+
declare var d3: ID3Base;

0 commit comments

Comments
 (0)