Skip to content

Commit 155bf28

Browse files
committed
Convert image trace attributes to TS
1 parent 7bbd311 commit 155bf28

5 files changed

Lines changed: 50 additions & 15 deletions

File tree

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
'use strict';
22

3-
var baseAttrs = require('../../plots/attributes');
4-
var zorder = require('../scatter/attributes').zorder;
3+
import type { AttributeMap, AttrsToType } from '../../types/lib/attributes';
4+
5+
const baseAttrs = require('../../plots/attributes');
6+
const { zorder } = require('../scatter/attributes');
57
const { hovertemplateAttrs, templatefallbackAttrs } = require('../../plots/template_attributes');
6-
var extendFlat = require('../../lib/extend').extendFlat;
7-
var colormodel = require('./constants').colormodel;
8+
const extendFlat = require('../../lib/extend').extendFlat;
9+
const { colormodel } = require('./constants');
810

9-
var cm = ['rgb', 'rgba', 'rgba256', 'hsl', 'hsla'];
10-
var zminDesc = [];
11-
var zmaxDesc = [];
12-
for (var i = 0; i < cm.length; i++) {
13-
var cr = colormodel[cm[i]];
11+
const cm = ['rgb', 'rgba', 'rgba256', 'hsl', 'hsla'] as const;
12+
const zminDesc: string[] = [];
13+
const zmaxDesc: string[] = [];
14+
for (let i = 0; i < cm.length; i++) {
15+
const cr = colormodel[cm[i]];
1416
zminDesc.push('For the `' + cm[i] + '` colormodel, it is [' + (cr.zminDflt || cr.min).join(', ') + '].');
1517
zmaxDesc.push('For the `' + cm[i] + '` colormodel, it is [' + (cr.zmaxDflt || cr.max).join(', ') + '].');
1618
}
1719

18-
module.exports = extendFlat({
20+
/**
21+
* @generates ImageTrace
22+
*/
23+
const attributes = {
1924
source: {
2025
valType: 'string',
2126
editType: 'calc',
@@ -43,7 +48,7 @@ module.exports = extendFlat({
4348
},
4449
zsmooth: {
4550
valType: 'enumerated',
46-
values: ['fast', false],
51+
values: ['fast', false] as const,
4752
dflt: false,
4853
editType: 'plot',
4954
description: [
@@ -133,5 +138,9 @@ module.exports = extendFlat({
133138
hovertemplate: hovertemplateAttrs({}, { keys: ['z', 'color', 'colormodel'] }),
134139
hovertemplatefallback: templatefallbackAttrs(),
135140

136-
zorder: zorder
137-
});
141+
zorder
142+
} as const satisfies AttributeMap;
143+
144+
export type ImageTraceAttributes = AttrsToType<typeof attributes>;
145+
146+
export default attributes;

src/traces/image/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var Lib = require('../../lib');
4-
var attributes = require('./attributes');
4+
var attributes = require('./attributes').default;
55
var constants = require('./constants');
66
var dataUri = require('../../snapshot/helpers').IMAGE_URL_PREFIX;
77

src/traces/image/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
module.exports = {
4-
attributes: require('./attributes'),
4+
attributes: require('./attributes').default,
55
supplyDefaults: require('./defaults'),
66
calc: require('./calc'),
77
plot: require('./plot'),

src/types/generated/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
* Run `npm run gen:types` to regenerate.
44
*/
55

6+
export type { ImageTrace } from './traces/image';
67
export type { ModeBar } from './components/modebar';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Generated from src/traces/image/attributes.ts.
3+
* Do not edit by hand — run `npm run gen:types`.
4+
*/
5+
6+
import type { Datum, TypedArray } from '../../lib/common';
7+
8+
export interface ImageTrace {
9+
source?: string;
10+
z?: Datum[] | TypedArray;
11+
colormodel?: 'rgb' | 'rgba' | 'rgba256' | 'hsl' | 'hsla';
12+
zsmooth?: false | 'fast';
13+
zmin?: unknown[];
14+
zmax?: unknown[];
15+
x0?: any;
16+
y0?: any;
17+
dx?: number;
18+
dy?: number;
19+
text?: Datum[] | TypedArray;
20+
hovertext?: Datum[] | TypedArray;
21+
hoverinfo?: any;
22+
hovertemplate?: any;
23+
hovertemplatefallback?: any;
24+
zorder?: any;
25+
}

0 commit comments

Comments
 (0)