Skip to content

Commit 511541f

Browse files
ryan-williamsclaude
andcommitted
convert all remaining components/ to TypeScript
87 files: annotations (11), annotations3d (5), calendars (2), colorbar (6), grid (1), images (5), modebar (7), rangeselector (6), rangeslider (8), selections (7+2 subdirs), shapes (11+4 subdirs), sliders (5), updatemenus (6+1 scrollbox). Fixed 118 tsc errors: mostly `: any` on object literals that get dynamic properties, `as any` casts, optional params. src/components/ is now 100% TypeScript (136 files, 0 JS). Total: 308 .ts / 527 .js (37% converted). tsc --noEmit: 0 errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7a5d713 commit 511541f

Some content is hidden

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

90 files changed

+579
-579
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cartesianConstants from '../../plots/cartesian/constants.js';
44
import { templatedArray } from '../../plot_api/plot_template.js';
55
import axisPlaceableObjs from '../../constants/axis_placeable_objects.js';
66

7-
function arrowAxisRefDescription(axis) {
7+
function arrowAxisRefDescription(axis: any) {
88
return [
99
'In order for absolute positioning of the arrow to work, *a' + axis +
1010
'ref* must be exactly the same as *' + axis + 'ref*, otherwise *a' + axis +
@@ -19,7 +19,7 @@ function arrowAxisRefDescription(axis) {
1919
].join(' ');
2020
}
2121

22-
function arrowCoordinateDescription(axis, lower, upper) {
22+
function arrowCoordinateDescription(axis: any, lower: any, upper: any) {
2323
return [
2424
'Sets the', axis, 'component of the arrow tail about the arrow head.',
2525
'If `a' + axis + 'ref` is `pixel`, a positive (negative)',

src/components/annotations/calc_autorange.js renamed to src/components/annotations/calc_autorange.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Axes from '../../plots/cartesian/axes.js';
33
import _draw from './draw.js';
44
const { draw } = _draw;
55

6-
export default function calcAutorange(gd) {
6+
export default function calcAutorange(gd: any) {
77
var fullLayout = gd._fullLayout;
88
var annotationList = Lib.filterVisible(fullLayout.annotations);
99

@@ -12,14 +12,14 @@ export default function calcAutorange(gd) {
1212
}
1313
}
1414

15-
function annAutorange(gd) {
15+
function annAutorange(gd: any) {
1616
var fullLayout = gd._fullLayout;
1717

1818
// find the bounding boxes for each of these annotations'
1919
// relative to their anchor points
2020
// use the arrow and the text bg rectangle,
2121
// as the whole anno may include hidden text in its bbox
22-
Lib.filterVisible(fullLayout.annotations).forEach(function(ann) {
22+
Lib.filterVisible(fullLayout.annotations).forEach(function(ann: any) {
2323
var xa = Axes.getFromId(gd, ann.xref);
2424
var ya = Axes.getFromId(gd, ann.yref);
2525
var xRefType = Axes.getRefType(ann.xref);
@@ -31,7 +31,7 @@ function annAutorange(gd) {
3131
});
3232
}
3333

34-
function calcAxisExpansion(ann, ax) {
34+
function calcAxisExpansion(ann: any, ax: any) {
3535
var axId = ax._id;
3636
var letter = axId.charAt(0);
3737
var pos = ann[letter];
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
*
1818
* returns: boolean
1919
*/
20-
function hasClickToShow(gd, hoverData) {
20+
function hasClickToShow(gd: any, hoverData: any) {
2121
var sets = getToggleSets(gd, hoverData);
2222
return sets.on.length > 0 || sets.explicitOff.length > 0;
2323
}
@@ -32,11 +32,11 @@ function hasClickToShow(gd, hoverData) {
3232
*
3333
* returns: Promise that the update is complete
3434
*/
35-
function onClick(gd, hoverData) {
35+
function onClick(gd: any, hoverData: any) {
3636
var toggleSets = getToggleSets(gd, hoverData);
3737
var onSet = toggleSets.on;
3838
var offSet = toggleSets.off.concat(toggleSets.explicitOff);
39-
var update = {};
39+
var update: any = {};
4040
var annotationsOut = gd._fullLayout.annotations;
4141
var i, editHelpers;
4242

@@ -71,7 +71,7 @@ function onClick(gd, hoverData) {
7171
* explicitOff: Array (indices to turn off because you *are* hovering on them)
7272
* }
7373
*/
74-
function getToggleSets(gd, hoverData) {
74+
function getToggleSets(gd: any, hoverData: any) {
7575
var annotations = gd._fullLayout.annotations;
7676
var onSet = [];
7777
var offSet = [];
@@ -121,6 +121,6 @@ function getToggleSets(gd, hoverData) {
121121
}
122122

123123
// to handle log axes until v3
124-
function clickData2r(d, ax) {
124+
function clickData2r(d: any, ax: any) {
125125
return ax.type === 'log' ? ax.l2r(d) : ax.d2r(d);
126126
}

src/components/annotations/common_defaults.js renamed to src/components/annotations/common_defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Lib from '../../lib/index.js';
22
import Color from '../color/index.js';
33

4-
export default function handleAnnotationCommonDefaults(annIn, annOut, fullLayout, coerce) {
4+
export default function handleAnnotationCommonDefaults(annIn: any, annOut: any, fullLayout: any, coerce: any) {
55
coerce('opacity');
66
var bgColor = coerce('bgcolor');
77

src/components/annotations/convert_coords.js renamed to src/components/annotations/convert_coords.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import isNumeric from 'fast-isnumeric';
22
import toLogRange from '../../lib/to_log_range.js';
33

4-
export default function convertCoords(gd, ax, newType, doExtra) {
4+
export default function convertCoords(gd: any, ax: any, newType: any, doExtra: any) {
55
ax = ax || {};
66

77
var toLog = (newType === 'log') && (ax.type === 'linear');
@@ -14,7 +14,7 @@ export default function convertCoords(gd, ax, newType, doExtra) {
1414
var ann;
1515
var attrPrefix;
1616

17-
function convert(attr) {
17+
function convert(attr: any) {
1818
var currentVal = ann[attr];
1919
var newVal = null;
2020

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import handleArrayContainerDefaults from '../../plots/array_container_defaults.j
44
import handleAnnotationCommonDefaults from './common_defaults.js';
55
import attributes from './attributes.js';
66

7-
export default function supplyLayoutDefaults(layoutIn, layoutOut) {
7+
export default function supplyLayoutDefaults(layoutIn: any, layoutOut: any) {
88
handleArrayContainerDefaults(layoutIn, layoutOut, {
99
name: 'annotations',
1010
handleItemDefaults: handleAnnotationDefaults
1111
});
1212
}
1313

14-
function handleAnnotationDefaults(annIn, annOut, fullLayout) {
15-
function coerce(attr, dflt) {
14+
function handleAnnotationDefaults(annIn: any, annOut: any, fullLayout: any) {
15+
function coerce(attr: any, dflt?: any) {
1616
return Lib.coerce(annIn, annOut, attributes, attr, dflt);
1717
}
1818

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
/*
2323
* draw: draw all annotations without any new modifications
2424
*/
25-
function draw(gd) {
25+
function draw(gd: any) {
2626
var fullLayout = gd._fullLayout;
2727

2828
fullLayout._infolayer.selectAll('.annotation').remove();
@@ -41,7 +41,7 @@ function draw(gd) {
4141
*
4242
* index (int): the annotation to draw
4343
*/
44-
function drawOne(gd, index) {
44+
function drawOne(gd: any, index: any) {
4545
var fullLayout = gd._fullLayout;
4646
var options = fullLayout.annotations[index] || {};
4747
var xa = Axes.getFromId(gd, options.xref);
@@ -58,7 +58,7 @@ function drawOne(gd, index) {
5858
// the plot.
5959
// axDomainRef: if true and axa defined, draws relative to axis domain,
6060
// otherwise draws relative to data (if axa defined) or paper (if not).
61-
function shiftPosition(axa, dAx, axLetter, gs, options) {
61+
function shiftPosition(axa: any, dAx: any, axLetter: any, gs: any, options: any) {
6262
var optAx = options[axLetter];
6363
var axRef = options[axLetter + 'ref'];
6464
var vertical = axLetter.indexOf('y') !== -1;
@@ -89,7 +89,7 @@ function shiftPosition(axa, dAx, axLetter, gs, options) {
8989
* @param {object | undefined} xa : full x-axis object to compute subplot pos-to-px
9090
* @param {object | undefined} ya : ... y-axis
9191
*/
92-
function drawRaw(gd, options, index, subplotId, xa, ya) {
92+
function drawRaw(gd: any, options: any, index: any, subplotId: any, xa: any, ya: any) {
9393
var fullLayout = gd._fullLayout;
9494
var gs = gd._fullLayout._size;
9595
var edits = gd._context.edits;
@@ -125,7 +125,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
125125

126126
// calculated pixel positions
127127
// x & y each will get text, head, and tail as appropriate
128-
var annPosPx = {x: {}, y: {}};
128+
var annPosPx: any = {x: {}, y: {}};
129129
var textangle = +options.textangle || 0;
130130

131131
// create the components
@@ -144,8 +144,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
144144
var editTextPosition = edits[options.showarrow ? 'annotationTail' : 'annotationPosition'];
145145
var textEvents = options.captureevents || edits.annotationText || editTextPosition;
146146

147-
function makeEventData(initialEvent) {
148-
var eventData = {
147+
function makeEventData(initialEvent: any) {
148+
var eventData: any = {
149149
index: index,
150150
annotation: options._input,
151151
fullAnnotation: options,
@@ -160,7 +160,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
160160
var annTextGroupInner = annTextGroup.append('g')
161161
.style('pointer-events', textEvents ? 'all' : null)
162162
.call(setCursor, 'pointer')
163-
.on('click', function(event) {
163+
.on('click', function(event: any) {
164164
gd._dragging = false;
165165
gd.emit('plotly_clickannotation', makeEventData(event));
166166
});
@@ -232,7 +232,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
232232
.classed('annotation-text', true)
233233
.text(text);
234234

235-
function textLayout(s) {
235+
function textLayout(s: any) {
236236
s.call(font, font)
237237
.attr({
238238
'text-anchor': {
@@ -269,7 +269,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
269269
var outerWidth = Math.round(annWidth + 2 * borderfull);
270270
var outerHeight = Math.round(annHeight + 2 * borderfull);
271271

272-
function shiftFraction(v, anchor) {
272+
function shiftFraction(v: any, anchor: any) {
273273
if(anchor === 'auto') {
274274
if(v < 1 / 3) anchor = 'left';
275275
else if(v > 2 / 3) anchor = 'right';
@@ -484,7 +484,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
484484
* dx and dy are normally zero, but when you are dragging the textbox
485485
* while the head stays put, dx and dy are the pixel offsets
486486
*/
487-
var drawArrow = function(dx, dy) {
487+
var drawArrow = function(dx: any, dy: any) {
488488
annGroup
489489
.selectAll('.annotation-arrow-g')
490490
.remove();
@@ -520,16 +520,16 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
520520
// casting for rotated boxes: see which edges intersect a
521521
// line from the arrowhead to far away and reduce with xor
522522
// to get the parity of the number of intersections.
523-
if(edges.reduce(function(a, x) {
524-
return a ^
525-
!!Lib.segmentsIntersect(headX, headY, headX + 1e6, headY + 1e6,
526-
x[0], x[1], x[2], x[3]);
523+
if(edges.reduce(function(a: any, x: any) {
524+
return (a as any) ^
525+
(!!Lib.segmentsIntersect(headX, headY, headX + 1e6, headY + 1e6,
526+
x[0], x[1], x[2], x[3]) as any);
527527
}, false)) {
528528
// no line or arrow - so quit drawArrow now
529529
return;
530530
}
531531

532-
edges.forEach(function(x) {
532+
edges.forEach(function(x: any) {
533533
var p = Lib.segmentsIntersect(tailX, tailY, headX, headY,
534534
x[0], x[1], x[2], x[3]);
535535
if(p) {
@@ -594,7 +594,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
594594
modifyBase(ya._name + '.autorange', true);
595595
}
596596
},
597-
moveFn: function(dx, dy) {
597+
moveFn: function(dx: any, dy: any) {
598598
var annxy0 = applyTransform(annx0, anny0);
599599
var xcenter = annxy0[0] + dx;
600600
var ycenter = annxy0[1] + dy;
@@ -625,7 +625,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
625625
doneFn: function() {
626626
Registry.call('_guiRelayout', gd, getUpdateObj());
627627
var notesBox = document.querySelector('.js-notes-box-panel');
628-
if(notesBox) notesBox.redraw(notesBox.selectedObj);
628+
if(notesBox) (notesBox as any).redraw((notesBox as any).selectedObj);
629629
}
630630
});
631631
}
@@ -645,7 +645,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
645645
prepFn: function() {
646646
baseTextTransform = annTextGroup.attr('transform');
647647
},
648-
moveFn: function(dx, dy) {
648+
moveFn: function(dx: any, dy: any) {
649649
var csr = 'pointer';
650650
if(options.showarrow) {
651651
// for these 2 calls to shiftPosition, it is assumed xa, ya are
@@ -706,7 +706,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
706706

707707
setCursor(annTextGroupInner, csr);
708708
},
709-
clickFn: function(_, initialEvent) {
709+
clickFn: function(_: any, initialEvent: any) {
710710
if(options.captureevents) {
711711
gd.emit('plotly_clickannotation', makeEventData(initialEvent));
712712
}
@@ -715,7 +715,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
715715
setCursor(annTextGroupInner);
716716
Registry.call('_guiRelayout', gd, getUpdateObj());
717717
var notesBox = document.querySelector('.js-notes-box-panel');
718-
if(notesBox) notesBox.redraw(notesBox.selectedObj);
718+
if(notesBox) (notesBox as any).redraw((notesBox as any).selectedObj);
719719
}
720720
});
721721
}
@@ -724,7 +724,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
724724
if(edits.annotationText) {
725725
annText.call(svgTextUtils.makeEditable, {delegate: annTextGroupInner, gd: gd})
726726
.call(textLayout)
727-
.on('edit', function(_text) {
727+
.on('edit', function(_text: any) {
728728
options.text = _text;
729729

730730
this.call(textLayout);

src/components/annotations/draw_arrow_head.js renamed to src/components/annotations/draw_arrow_head.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var strScale = Lib.strScale;
66
var strRotate = Lib.strRotate;
77
var strTranslate = Lib.strTranslate;
88

9-
export default function drawArrowHead(el3, ends, options) {
9+
export default function drawArrowHead(el3: any, ends: any, options: any) {
1010
var el = el3.node();
1111
var headStyle = ARROWPATHS[options.arrowhead || 0];
1212
var startHeadStyle = ARROWPATHS[options.startarrowhead || 0];
@@ -95,7 +95,7 @@ export default function drawArrowHead(el3, ends, options) {
9595

9696
function hideLine() { el3.style('stroke-dasharray', '0px,100px'); }
9797

98-
function drawhead(arrowHeadStyle, p, rot, arrowScale) {
98+
function drawhead(arrowHeadStyle: any, p: any, rot: any, arrowScale: any) {
9999
if(!arrowHeadStyle.path) return;
100100
if(arrowHeadStyle.noRotate) rot = 0;
101101

0 commit comments

Comments
 (0)