update plotly.js typing (#27355)

* update typing
- add missing event handlers from https://github.com/plotly/react-plotly.js/#event-handler-props
- add addFrames / deleteFrames functions
- use Font interface in ScatterMarker.colorbar
- change Font.color type from string to Color
- fix 'common mistakes': tabs to spaces

* fix linting errors

* use tab indentation and require in tslint
This commit is contained in:
Jon Freedman
2018-07-21 01:42:18 +01:00
committed by Wesley Wigham
parent ce73aaf4ab
commit a9394b8436
4 changed files with 892 additions and 424 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -127,7 +127,7 @@ const graphDiv = '#test';
const update = {
title: 'some new title', // updates the title
'xaxis.range': [0, 5], // updates the xaxis range
'yaxis.range[1]': 15 // updates the end of the yaxis range
'yaxis.range[1]': 15 // updates the end of the yaxis range
} as Layout;
Plotly.relayout(graphDiv, update);
})();
@@ -251,6 +251,37 @@ function rand() {
})();
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Plotly.addFrames + Plotly.deleteFrames as per https://plot.ly/javascript/animations/
(() => {
const n = 100;
const frames = [
{name: 'sine', data: [{x: new Array<number>(100), y: new Array<number>(n)}]},
{name: 'cosine', data: [{x: new Array<number>(100), y: new Array<number>(n)}]},
{name: 'circle', data: [{x: new Array<number>(100), y: new Array<number>(n)}]},
];
for (let i = 0; i < n; i++) {
const t = i / (n - 1) * 2 - 1;
// A sine wave:
frames[0].data[0].x[i] = t * Math.PI;
frames[0].data[0].y[i] = Math.sin(t * Math.PI);
// A cosine wave:
frames[1].data[0].x[i] = t * Math.PI;
frames[1].data[0].y[i] = Math.cos(t * Math.PI);
// A circle:
frames[2].data[0].x[i] = Math.sin(t * Math.PI);
frames[2].data[0].y[i] = Math.cos(t * Math.PI);
}
Plotly.addFrames(graphDiv, frames);
Plotly.deleteFrames(graphDiv, [2]);
})();
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Using events
(async () => {
@@ -340,8 +371,70 @@ function rand() {
Plotly.restyle('myDiv', update);
});
myPlot.on('plotly_beforeplot', (event) => {
console.log('plotting');
const okToPlot = true;
return okToPlot;
});
myPlot.on('plotly_afterplot', () => {
console.log('done plotting');
});
myPlot.on('plotly_animatingframe', (event) => {
console.log(`animating ${event.frame.name} with ${event.animation.transition.easing}`);
});
myPlot.on('plotly_legendclick', (event) => {
console.log('clicked on legend');
const clickVal = true;
return clickVal;
});
myPlot.on('plotly_legenddoubleclick', (event) => {
console.log('dbl clicked on legend');
const dblClickVal = true;
return dblClickVal;
});
myPlot.on('plotly_sliderchange', (event) => {
console.log(`Slider at [${event.slider.x},${event.slider.y} with ${event.step.method}`);
});
myPlot.on('plotly_sliderstart', (event) => {
console.log(`Slider at [${event.slider.x},${event.slider.y}`);
});
myPlot.on('plotly_sliderend', (event) => {
console.log(`Slider at [${event.slider.x},${event.slider.y} with ${event.step.method}`);
});
myPlot.on('plotly_beforeexport', () => {
console.log('starting export');
});
myPlot.on('plotly_afterexport', () => {
console.log('done exporting');
});
myPlot.on('plotly_animated', () => {
console.log('done animation');
});
myPlot.on('plotly_animationinterrupted', () => {
console.log('animation interrupted');
});
myPlot.on('plotly_framework', () => {
console.log('framework');
});
myPlot.on('plotly_transitioning', () => {
console.log('starting transition');
});
myPlot.on('plotly_transitioninterrupted', () => {
console.log('transition interrupted');
});
})();
//////////////////////////////////////////////////////////////////////

View File

@@ -127,7 +127,7 @@ const graphDiv = '#test';
const update = {
title: 'some new title', // updates the title
'xaxis.range': [0, 5], // updates the xaxis range
'yaxis.range[1]': 15 // updates the end of the yaxis range
'yaxis.range[1]': 15 // updates the end of the yaxis range
} as Layout;
Plotly.relayout(graphDiv, update);
})();
@@ -251,6 +251,37 @@ function rand() {
})();
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Plotly.addFrames + Plotly.deleteFrames as per https://plot.ly/javascript/animations/
(() => {
const n = 100;
const frames = [
{name: 'sine', data: [{x: new Array<number>(100), y: new Array<number>(n)}]},
{name: 'cosine', data: [{x: new Array<number>(100), y: new Array<number>(n)}]},
{name: 'circle', data: [{x: new Array<number>(100), y: new Array<number>(n)}]},
];
for (let i = 0; i < n; i++) {
const t = i / (n - 1) * 2 - 1;
// A sine wave:
frames[0].data[0].x[i] = t * Math.PI;
frames[0].data[0].y[i] = Math.sin(t * Math.PI);
// A cosine wave:
frames[1].data[0].x[i] = t * Math.PI;
frames[1].data[0].y[i] = Math.cos(t * Math.PI);
// A circle:
frames[2].data[0].x[i] = Math.sin(t * Math.PI);
frames[2].data[0].y[i] = Math.cos(t * Math.PI);
}
Plotly.addFrames(graphDiv, frames);
Plotly.deleteFrames(graphDiv, [2]);
})();
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Using events
(async () => {
@@ -340,8 +371,70 @@ function rand() {
Plotly.restyle('myDiv', update);
});
myPlot.on('plotly_beforeplot', (event) => {
console.log('plotting');
const okToPlot = true;
return okToPlot;
});
myPlot.on('plotly_afterplot', () => {
console.log('done plotting');
});
myPlot.on('plotly_animatingframe', (event) => {
console.log(`animating ${event.frame.name} with ${event.animation.transition.easing}`);
});
myPlot.on('plotly_legendclick', (event) => {
console.log('clicked on legend');
const clickVal = true;
return clickVal;
});
myPlot.on('plotly_legenddoubleclick', (event) => {
console.log('dbl clicked on legend');
const dblClickVal = true;
return dblClickVal;
});
myPlot.on('plotly_sliderchange', (event) => {
console.log(`Slider at [${event.slider.x},${event.slider.y} with ${event.step.method}`);
});
myPlot.on('plotly_sliderstart', (event) => {
console.log(`Slider at [${event.slider.x},${event.slider.y}`);
});
myPlot.on('plotly_sliderend', (event) => {
console.log(`Slider at [${event.slider.x},${event.slider.y} with ${event.step.method}`);
});
myPlot.on('plotly_beforeexport', () => {
console.log('starting export');
});
myPlot.on('plotly_afterexport', () => {
console.log('done exporting');
});
myPlot.on('plotly_animated', () => {
console.log('done animation');
});
myPlot.on('plotly_animationinterrupted', () => {
console.log('animation interrupted');
});
myPlot.on('plotly_framework', () => {
console.log('framework');
});
myPlot.on('plotly_transitioning', () => {
console.log('starting transition');
});
myPlot.on('plotly_transitioninterrupted', () => {
console.log('transition interrupted');
});
})();
//////////////////////////////////////////////////////////////////////

View File

@@ -3,6 +3,7 @@
"rules": {
// TODOs
"no-duplicate-imports": false,
"no-object-literal-type-assertion": false
"no-object-literal-type-assertion": false,
"indent": [true, "tabs", 1]
}
}