Skip to content

Commit 57f6549

Browse files
ryan-williamsclaude
andcommitted
convert scatter/ and bar/ traces to TypeScript
51 files: 33 scatter, 18 bar — the two factory trace modules. Total: 164 .ts / 671 .js remaining (20% converted). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent af2042a commit 57f6549

Some content is hidden

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

52 files changed

+149
-163
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { mergeArray, mergeArrayCastPositive } from '../../lib/index.js';
22

3-
export default function arraysToCalcdata(cd, trace) {
3+
export default function arraysToCalcdata(cd: any[], trace: any): void {
44
for(var i = 0; i < cd.length; i++) cd[i].i = i;
55

66
mergeArray(trace.text, cd, 'tx');
77
mergeArray(trace.hovertext, cd, 'htx');
88

99
var marker = trace.marker;
1010
if(marker) {
11-
mergeArray(marker.opacity, cd, 'mo', true);
11+
(mergeArray as any)(marker.opacity, cd, 'mo', true);
1212
mergeArray(marker.color, cd, 'mc');
1313

1414
var markerLine = marker.line;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ var markerLine = extendFlat(
2525
width: markerLineWidth,
2626
editType: 'calc'
2727
},
28-
colorScaleAttrs('marker.line')
28+
(colorScaleAttrs as any)('marker.line')
2929
);
3030

3131
var marker = extendFlat(
3232
{
3333
line: markerLine,
3434
editType: 'calc'
3535
},
36-
colorScaleAttrs('marker'),
36+
(colorScaleAttrs as any)('marker'),
3737
{
3838
opacity: {
3939
valType: 'number',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import colorscaleCalc from '../../components/colorscale/calc.js';
66
import arraysToCalcdata from './arrays_to_calcdata.js';
77
import calcSelection from '../scatter/calc_selection.js';
88

9-
export default function calc(gd, trace) {
9+
export default function calc(gd: any, trace: any): any[] {
1010
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
1111
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
1212
var size, pos, origPos, pObj, hasPeriod, pLetter;
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Sieve from './sieve.js';
1414
* now doing this one subplot at a time
1515
*/
1616

17-
function crossTraceCalc(gd, plotinfo) {
17+
function crossTraceCalc(gd: any, plotinfo: any): void {
1818
var xa = plotinfo.xaxis;
1919
var ya = plotinfo.yaxis;
2020

@@ -62,7 +62,7 @@ function crossTraceCalc(gd, plotinfo) {
6262
setGroupPositions(gd, ya, xa, calcTracesHorz, opts);
6363
}
6464

65-
function setGroupPositions(gd, pa, sa, calcTraces, opts) {
65+
function setGroupPositions(gd: any, pa: any, sa: any, calcTraces: any[], opts: any): void {
6666
if(!calcTraces.length) return;
6767

6868
var excluded;
@@ -126,7 +126,7 @@ function setGroupPositions(gd, pa, sa, calcTraces, opts) {
126126
}
127127

128128
// Set cornerradiusvalue and cornerradiusform in calcTraces[0].t
129-
function setCornerradius(calcTraces) {
129+
function setCornerradius(calcTraces: any[]): void {
130130
var i, calcTrace, fullTrace, t, cr, crValue, crForm;
131131

132132
for(i = 0; i < calcTraces.length; i++) {
@@ -147,7 +147,7 @@ function setCornerradius(calcTraces) {
147147
}
148148

149149
// Make sure all traces in a stack use the same cornerradius
150-
function standardizeCornerradius(calcTraces) {
150+
function standardizeCornerradius(calcTraces: any[]): void {
151151
if(calcTraces.length < 2) return;
152152
var i, calcTrace, fullTrace, t;
153153
var cr, crValue, crForm;
@@ -172,7 +172,7 @@ function standardizeCornerradius(calcTraces) {
172172
}
173173
}
174174

175-
function initBase(sa, calcTraces) {
175+
function initBase(sa: any, calcTraces: any[]): void {
176176
var i, j;
177177

178178
for(i = 0; i < calcTraces.length; i++) {
@@ -215,7 +215,7 @@ function initBase(sa, calcTraces) {
215215
}
216216
}
217217

218-
function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces, opts) {
218+
function setGroupPositionsInOverlayMode(gd: any, pa: any, sa: any, calcTraces: any[], opts: any): void {
219219
// update position axis and set bar offsets and widths
220220
for(var i = 0; i < calcTraces.length; i++) {
221221
var calcTrace = calcTraces[i];
@@ -243,7 +243,7 @@ function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces, opts) {
243243
}
244244
}
245245

246-
function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces, opts) {
246+
function setGroupPositionsInGroupMode(gd: any, pa: any, sa: any, calcTraces: any[], opts: any): void {
247247
var sieve = new Sieve(calcTraces, {
248248
posAxis: pa,
249249
sepNegVal: false,
@@ -266,7 +266,7 @@ function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces, opts) {
266266
}
267267
}
268268

269-
function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces, opts) {
269+
function setGroupPositionsInStackOrRelativeMode(gd: any, pa: any, sa: any, calcTraces: any[], opts: any): void {
270270
var sieve = new Sieve(calcTraces, {
271271
posAxis: pa,
272272
sepNegVal: opts.mode === 'relative',
@@ -310,7 +310,7 @@ function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces, opts) {
310310
* overlap/stack.
311311
* Angular axes (for barpolar type) don't support group offsets.
312312
*/
313-
function setOffsetAndWidth(gd, pa, sieve, opts) {
313+
function setOffsetAndWidth(gd: any, pa: any, sieve: any, opts: any): void {
314314
var fullLayout = gd._fullLayout;
315315
var positions = sieve.positions;
316316
var distinctPositions = sieve.distinctPositions;
@@ -385,7 +385,7 @@ function setOffsetAndWidth(gd, pa, sieve, opts) {
385385
}
386386
}
387387

388-
function applyAttributes(sieve) {
388+
function applyAttributes(sieve: any): void {
389389
var calcTraces = sieve.traces;
390390
var i, j;
391391

@@ -463,7 +463,7 @@ function applyAttributes(sieve) {
463463
}
464464
}
465465

466-
function setBarCenterAndWidth(pa, sieve) {
466+
function setBarCenterAndWidth(pa: any, sieve: any): void {
467467
var calcTraces = sieve.traces;
468468
var pLetter = getAxisLetter(pa);
469469

@@ -492,7 +492,7 @@ function setBarCenterAndWidth(pa, sieve) {
492492
}
493493
}
494494

495-
function updatePositionAxis(pa, sieve, allowMinDtick) {
495+
function updatePositionAxis(pa: any, sieve: any, allowMinDtick?: boolean): void {
496496
var calcTraces = sieve.traces;
497497
var minDiff = sieve.minDiff;
498498
var vpad = minDiff / 2;
@@ -537,7 +537,7 @@ function updatePositionAxis(pa, sieve, allowMinDtick) {
537537
// store these bar bases and tops in calcdata
538538
// and make sure the size axis includes zero,
539539
// along with the bases and tops of each bar.
540-
function setBaseAndTop(sa, sieve) {
540+
function setBaseAndTop(sa: any, sieve: any): void {
541541
var calcTraces = sieve.traces;
542542
var sLetter = getAxisLetter(sa);
543543

@@ -572,7 +572,7 @@ function setBaseAndTop(sa, sieve) {
572572
}
573573
}
574574

575-
function stackBars(sa, sieve, opts) {
575+
function stackBars(sa: any, sieve: any, opts: any): void {
576576
var sLetter = getAxisLetter(sa);
577577
var calcTraces = sieve.traces;
578578
var calcTrace;
@@ -649,7 +649,7 @@ function stackBars(sa, sieve, opts) {
649649
}
650650
}
651651

652-
function sieveBars(sieve) {
652+
function sieveBars(sieve: any): void {
653653
var calcTraces = sieve.traces;
654654

655655
for(var i = 0; i < calcTraces.length; i++) {
@@ -665,7 +665,7 @@ function sieveBars(sieve) {
665665
}
666666
}
667667

668-
function unhideBarsWithinTrace(sieve, pa) {
668+
function unhideBarsWithinTrace(sieve: any, pa: any): void {
669669
var calcTraces = sieve.traces;
670670

671671
for(var i = 0; i < calcTraces.length; i++) {
@@ -701,7 +701,7 @@ function unhideBarsWithinTrace(sieve, pa) {
701701
//
702702
// normalizeBars requires that either sieveBars or stackBars has been
703703
// previously invoked.
704-
function normalizeBars(sa, sieve, opts) {
704+
function normalizeBars(sa: any, sieve: any, opts: any): void {
705705
var calcTraces = sieve.traces;
706706
var sLetter = getAxisLetter(sa);
707707
var sTop = opts.norm === 'fraction' ? 1 : 100;
@@ -760,7 +760,7 @@ function normalizeBars(sa, sieve, opts) {
760760
// Add an `_sMin` and `_sMax` value for each bar representing the min and max size value
761761
// across all bars sharing the same position as that bar. These values are used for rounded
762762
// bar corners, to carry rounding down to lower bars in the stack as needed.
763-
function setHelperValuesForRoundedCorners(calcTraces, sMinByPos, sMaxByPos, pa) {
763+
function setHelperValuesForRoundedCorners(calcTraces: any[], sMinByPos: any, sMaxByPos: any, pa: any): void {
764764
var pLetter = getAxisLetter(pa);
765765
// Set `_sMin` and `_sMax` value for each bar
766766
for(var i = 0; i < calcTraces.length; i++) {
@@ -779,9 +779,9 @@ function setHelperValuesForRoundedCorners(calcTraces, sMinByPos, sMaxByPos, pa)
779779
// narrower than the space they're in.
780780
// run once per trace group (subplot & direction) and
781781
// the same mapping is attached to all calcdata traces
782-
function collectExtents(calcTraces, pa) {
782+
function collectExtents(calcTraces: any[], pa: any): void {
783783
var pLetter = getAxisLetter(pa);
784-
var extents = {};
784+
var extents: any = {};
785785
var i, j, cd;
786786

787787
var pMin = Infinity;
@@ -858,7 +858,7 @@ function collectExtents(calcTraces, pa) {
858858
}
859859
}
860860

861-
function getAxisLetter(ax) {
861+
function getAxisLetter(ax: any): string {
862862
return ax._id.charAt(0);
863863
}
864864

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import handleGroupingDefaults from '../scatter/grouping_defaults.js';
99
import attributes from './attributes.js';
1010

1111

12-
function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
13-
function coerce(attr, dflt) {
12+
function supplyDefaults(traceIn: any, traceOut: any, defaultColor: any, layout: any): void {
13+
function coerce(attr: string, dflt?: any) {
1414
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
1515
}
1616

@@ -57,10 +57,10 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
5757
coerceSelectionMarkerOpacity(traceOut, coerce);
5858
}
5959

60-
function crossTraceDefaults(fullData, fullLayout) {
60+
function crossTraceDefaults(fullData: any[], fullLayout: any): void {
6161
var traceIn, traceOut;
6262

63-
function coerce(attr, dflt) {
63+
function coerce(attr: string, dflt?: any) {
6464
return Lib.coerce(traceOut._input, traceOut, attributes, attr, dflt);
6565
}
6666

@@ -88,7 +88,7 @@ function crossTraceDefaults(fullData, fullLayout) {
8888
// - a string consisting of a number >= 0 followed by a % sign
8989
// If the given cornerradius value is a numeric string, it will be converted
9090
// to a number.
91-
function validateCornerradius(r) {
91+
function validateCornerradius(r: any): any {
9292
if (isNumeric(r)) {
9393
r = +r;
9494
if (r >= 0) return r;
@@ -102,7 +102,7 @@ function validateCornerradius(r) {
102102
return undefined;
103103
}
104104

105-
function handleText(traceIn, traceOut, layout, coerce, textposition, opts) {
105+
function handleText(traceIn: any, traceOut: any, layout: any, coerce: any, textposition: any, opts?: any): void {
106106
opts = opts || {};
107107
var moduleHasSelected = !(opts.moduleHasSelected === false);
108108
var moduleHasUnselected = !(opts.moduleHasUnselected === false);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function eventData(out, pt, trace) {
1+
export default function eventData(out: any, pt: any, trace: any): any {
22
// standard cartesian event data
33
out.x = 'xVal' in pt ? pt.xVal : pt.x;
44
out.y = 'yVal' in pt ? pt.yVal : pt.y;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import isNumeric from 'fast-isnumeric';
22
import tinycolor from 'tinycolor2';
33
import { isArrayOrTypedArray } from '../../lib/index.js';
44

5-
export var coerceString = function(attributeDefinition, value, defaultValue) {
5+
export var coerceString = function(attributeDefinition: any, value: any, defaultValue?: any): any {
66
if(typeof value === 'string') {
77
if(value || !attributeDefinition.noBlank) return value;
88
} else if(typeof value === 'number' || value === true) {
@@ -14,7 +14,7 @@ export var coerceString = function(attributeDefinition, value, defaultValue) {
1414
attributeDefinition.dflt;
1515
};
1616

17-
export var coerceNumber = function(attributeDefinition, value, defaultValue) {
17+
export var coerceNumber = function(attributeDefinition: any, value: any, defaultValue?: any): number {
1818
if(isNumeric(value)) {
1919
value = +value;
2020

@@ -31,15 +31,15 @@ export var coerceNumber = function(attributeDefinition, value, defaultValue) {
3131
attributeDefinition.dflt;
3232
};
3333

34-
export var coerceColor = function(attributeDefinition, value, defaultValue) {
34+
export var coerceColor = function(attributeDefinition: any, value: any, defaultValue?: any): any {
3535
if(tinycolor(value).isValid()) return value;
3636

3737
return (defaultValue !== undefined) ?
3838
defaultValue :
3939
attributeDefinition.dflt;
4040
};
4141

42-
export var coerceEnumerated = function(attributeDefinition, value, defaultValue) {
42+
export var coerceEnumerated = function(attributeDefinition: any, value: any, defaultValue?: any): any {
4343
if(attributeDefinition.coerceNumber) value = +value;
4444

4545
if(attributeDefinition.values.indexOf(value) !== -1) return value;
@@ -49,14 +49,14 @@ export var coerceEnumerated = function(attributeDefinition, value, defaultValue)
4949
attributeDefinition.dflt;
5050
};
5151

52-
export var getValue = function(arrayOrScalar, index) {
52+
export var getValue = function(arrayOrScalar: any, index: number): any {
5353
var value;
5454
if(!isArrayOrTypedArray(arrayOrScalar)) value = arrayOrScalar;
5555
else if(index < arrayOrScalar.length) value = arrayOrScalar[index];
5656
return value;
5757
};
5858

59-
export var getLineWidth = function(trace, di) {
59+
export var getLineWidth = function(trace: any, di: any): number {
6060
var w =
6161
(0 < di.mlw) ? di.mlw :
6262
!isArrayOrTypedArray(trace.marker.line.width) ? trace.marker.line.width :
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { hoverLabelText } = _axes;
88
import _numerical from '../../constants/numerical.js';
99
const { BADNUM } = _numerical;
1010

11-
function hoverPoints(pointData, xval, yval, hovermode, opts) {
11+
function hoverPoints(pointData: any, xval: number, yval: number, hovermode: any, opts?: any): any[] | undefined {
1212
var barPointData = hoverOnBars(pointData, xval, yval, hovermode, opts);
1313

1414
if(barPointData) {
@@ -23,7 +23,7 @@ function hoverPoints(pointData, xval, yval, hovermode, opts) {
2323
}
2424
}
2525

26-
function hoverOnBars(pointData, xval, yval, hovermode, opts) {
26+
function hoverOnBars(pointData: any, xval: number, yval: number, hovermode: any, opts?: any): any {
2727
var cd = pointData.cd;
2828
var trace = cd[0].trace;
2929
var t = cd[0].t;
@@ -206,7 +206,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
206206
return pointData;
207207
}
208208

209-
function getTraceColor(trace, di) {
209+
function getTraceColor(trace: any, di: any): string | undefined {
210210
var mc = di.mcc || trace.marker.color;
211211
var mlc = di.mlcc || trace.marker.line.color;
212212
var mlw = getLineWidth(trace, di);

0 commit comments

Comments
 (0)