Skip to content

Commit 2b83ef4

Browse files
committed
mathjax in graph
1 parent d57bb36 commit 2b83ef4

File tree

7 files changed

+39
-3
lines changed

7 files changed

+39
-3
lines changed

components/dash-core-components/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ venv/
1919
/build
2020
/dash_core_components
2121
dash_core_components_base/plotly.min.js
22+
dash_core_components_base/mathjax.js
2223
/deps
2324
/inst
2425
/man

components/dash-core-components/dash_core_components_base/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"graph",
4949
"highlight",
5050
"markdown",
51+
"mathjax",
5152
"slider",
5253
"upload",
5354
]

components/dash-core-components/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/dash-core-components/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test": "run-s -c lint test:intg test:pyimport",
2424
"test:intg": "pytest --nopercyfinalize --headless tests/integration",
2525
"test:pyimport": "python -m unittest tests/test_dash_import.py",
26-
"prebuild:js": "cp node_modules/plotly.js-dist-min/plotly.min.js dash_core_components_base/plotly.min.js",
26+
"prebuild:js": "cp node_modules/plotly.js-dist-min/plotly.min.js dash_core_components_base/plotly.min.js && cp node_modules/mathjax/es5/tex-svg.js dash_core_components_base/mathjax.js",
2727
"build:js": "webpack --mode production",
2828
"build:backends": "dash-generate-components ./src/components dash_core_components -p package-info.json && cp dash_core_components_base/** dash_core_components/ && dash-generate-components ./src/components dash_core_components -p package-info.json -k RangeSlider,Slider,Dropdown,RadioItems,Checklist,DatePickerSingle,DatePickerRange,Input,Link --r-prefix 'dcc' --r-suggests 'dash,dashHtmlComponents,jsonlite,plotly' --jl-prefix 'dcc' && black dash_core_components",
2929
"build": "run-s prepublishOnly build:js build:backends",
@@ -46,6 +46,7 @@
4646
"fast-isnumeric": "^1.1.4",
4747
"file-saver": "^2.0.5",
4848
"highlight.js": "^11.4.0",
49+
"mathjax": "3.2.0",
4950
"moment": "^2.29.1",
5051
"node-polyfill-webpack-plugin": "^1.1.4",
5152
"plotly.js-dist-min": "file:packages/plotly.js-dist-min-2.9.0.tgz",

components/dash-core-components/src/components/Graph.react.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import {asyncDecorator} from '@plotly/dash-component-plugins';
55
import graph from '../utils/LazyLoader/graph';
66
import plotly from '../utils/LazyLoader/plotly';
7+
import mathjax from '../utils/LazyLoader/mathjax';
78
import {
89
privatePropTypes,
910
privateDefaultProps,
@@ -21,6 +22,10 @@ class PlotlyGraph extends Component {
2122
constructor(props) {
2223
super(props);
2324

25+
if (props.mathjax) {
26+
PlotlyGraph._loadMathjax = true;
27+
}
28+
2429
this.state = {
2530
prependData: [],
2631
extendData: [],
@@ -120,7 +125,11 @@ class PlotlyGraph extends Component {
120125
}
121126

122127
const RealPlotlyGraph = asyncDecorator(PlotlyGraph, () =>
123-
Promise.all([plotly(), graph()]).then(([, graph]) => graph)
128+
Promise.all([
129+
graph(),
130+
plotly(),
131+
PlotlyGraph._loadMathjax ? mathjax() : undefined,
132+
]).then(([graph]) => graph)
124133
);
125134

126135
const ControlledPlotlyGraph = memo(props => {
@@ -266,6 +275,11 @@ PlotlyGraph.propTypes = {
266275
*/
267276
className: PropTypes.string,
268277

278+
/**
279+
* If true, loads mathjax v3 (tex-svg) into the page and use it in the graph
280+
*/
281+
mathjax: PropTypes.bool,
282+
269283
/**
270284
* Beta: If true, animate between updates using
271285
* plotly.js's `animate` function
@@ -574,6 +588,7 @@ PlotlyGraph.defaultProps = {
574588
frames: [],
575589
},
576590
responsive: 'auto',
591+
mathjax: false,
577592
animate: false,
578593
animation_options: {
579594
frame: {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default () => Promise.resolve(window.MathJax ||
2+
import(/* webpackChunkName: "mathjax" */ 'mathjax/es5/tex-svg.js').then(() => {
3+
window.MathJax.config.startup.typeset = false;
4+
5+
return window.MathJax;
6+
})
7+
);

components/dash-core-components/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module.exports = (env, argv) => {
134134
new WebpackDashDynamicImport(),
135135
new webpack.SourceMapDevToolPlugin({
136136
filename: '[file].map',
137-
exclude: ['async-plotlyjs']
137+
exclude: ['async-plotlyjs', 'async-mathjax']
138138
}),
139139
new NodePolyfillPlugin()
140140
]

0 commit comments

Comments
 (0)