I am working with an SVG file that includes both rectangular elements and text elements.
index.html
<svg id="timeline" width="300" height="100">
<g transform="translate(10,10)" class="container" width="280" height="96">
<rect x="10" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day1"></rect>
<rect x="58" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day2"></rect>
<rect x="106" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day3"></rect>
<rect x="154" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day4"></rect>
<text class="textnumbers" id="day1" x="22.8" y="50">1</text>
<text class="textnumbers" id="day2" x="70.8" y="50">1</text>
<text class="textnumbers" id="day3" x="118.8" y="50">1</text>
<text class="textnumbers" id="day4" x="116.8" y="50">1</text>
</g>
</svg>
By using D3Service from d3-ng2-service
, I have the following code:
let day = 1;
let rect_id = "rect#day" + day;
let ele = D3.select<SVGRectElement>(rect_id).node();
let label_id = rect_id.replace("rect", ".textnumbers");
let numberEle = D3.select<TextElement>(label_id);
Problem arises as I encounter a TS2346 error with the select:
error TS2346: Supplied parameters do not match any signature of call target.
The index.d.ts
for D3Service is :
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/d3-selection/index.d.ts#L155
Looking at line 162 of the file:
select<DescElement extends BaseType>(selector: string): Selection<DescElement, Datum, PElement, PDatum>;
It seems like I might be using incorrect element types such as SVGRectElement
and TextElement
. How can I correctly interpret the index.d.ts
file to identify the right element types? Any help would be appreciated. Thanks!