File size: 1,305 Bytes
494c9e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as d3 from 'd3';

declare module 'd3-selection' {
    export interface Selection<GElement extends d3.BaseType, Datum, PElement extends d3.BaseType, PDatum> {
        attrs(attributes: { [key: string]: any }): this;
        styles(styles: { [key: string]: any }): this;
    }
    export interface Transition<GElement extends d3.BaseType, Datum, PElement extends d3.BaseType, PDatum> {
        attrs(attributes: { [key: string]: any }): this;
        styles(styles: { [key: string]: any }): this;
    }
}

(d3.selection.prototype as any).attrs = function(attrs: any) {
    for (const name in attrs) {
        this.attr(name, attrs[name]);
    }
    return this;
};

(d3.selection.prototype as any).styles = function(styles: any) {
    for (const name in styles) {
        this.style(name, styles[name]);
    }
    return this;
};

// Transition support might be needed too
if ((d3 as any).transition) {
    ((d3 as any).transition.prototype as any).attrs = function(attrs: any) {
        for (const name in attrs) {
            this.attr(name, attrs[name]);
        }
        return this;
    };

    ((d3 as any).transition.prototype as any).styles = function(styles: any) {
        for (const name in styles) {
            this.style(name, styles[name]);
        }
        return this;
    };
}