1212* limitations under the License.
1313* ==========================================================================
1414*/
15- import { linePlot } from "./plotly/index" ;
15+ import {
16+ linePlot ,
17+ barPlot ,
18+ scatterPlot ,
19+ histPlot ,
20+ piePlot ,
21+ boxPlot ,
22+ violinPlot ,
23+ tablePlot ,
24+ } from "./plotly/index" ;
1625import Series from "../core/series" ;
1726import DataFrame from "../core/frame" ;
1827import { PlotConfigObject } from "../shared/types" ;
28+ import Plotly from "plotly.js-dist-min"
1929
20- class Plotly {
30+
31+ try {
32+ // @ts -ignore
33+ const version = Plotly . version ;
34+ console . info ( `Using Plotly version ${ version } ` ) ;
35+ } catch ( error ) {
36+ console . info ( `Plotly CDN not found. If you need to make Plots, then add the Plotly CDN to your script` ) ;
37+ }
38+
39+ class PlotlyLib {
2140 divId : string ;
2241 ndframe : DataFrame | Series ;
2342
@@ -28,16 +47,114 @@ class Plotly {
2847
2948 /**
3049 * Plot Series or DataFrame as lines.
31- * Uses the Plotly as backend, so supoorts Plotly's configuration parameters
32- * @param plotConfig configuration options for making Plots, supports Plotly.js parameters.
50+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
51+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
3352 */
34- line ( plotConfig : PlotConfigObject ) {
35- linePlot ( this . ndframe , this . divId , plotConfig ) ;
53+ line ( plotConfig ?: PlotConfigObject ) {
54+ const _plotConfig = plotConfig || {
55+ config : { } ,
56+ layout : { }
57+ } ;
58+ linePlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
3659 }
3760
61+ /**
62+ * Plot Series or DataFrame as bars.
63+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
64+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
65+ */
66+ bar ( plotConfig ?: PlotConfigObject ) {
67+ const _plotConfig = plotConfig || {
68+ config : { } ,
69+ layout : { }
70+ } ;
71+ barPlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
72+ }
73+
74+ /**
75+ * Plot Series or DataFrame as scatter.
76+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
77+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
78+ */
79+ scatter ( plotConfig ?: PlotConfigObject ) {
80+ const _plotConfig = plotConfig || {
81+ config : { } ,
82+ layout : { }
83+ } ;
84+ scatterPlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
85+ }
86+
87+ /**
88+ * Plot Series or DataFrame as histogram.
89+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
90+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
91+ */
92+ hist ( plotConfig ?: PlotConfigObject ) {
93+ const _plotConfig = plotConfig || {
94+ config : { } ,
95+ layout : { }
96+ } ;
97+ histPlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
98+ }
99+
100+ /**
101+ * Plot Series or DataFrame as pie.
102+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
103+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
104+ */
105+ pie ( plotConfig ?: PlotConfigObject ) {
106+ const _plotConfig = plotConfig || {
107+ config : { } ,
108+ layout : { }
109+ } ;
110+ piePlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
111+ }
112+
113+ /**
114+ * Plot Series or DataFrame as boxplot.
115+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
116+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
117+ */
118+ box ( plotConfig ?: PlotConfigObject ) {
119+ const _plotConfig = plotConfig || {
120+ config : { } ,
121+ layout : { }
122+ } ;
123+ boxPlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
124+ }
125+
126+ /**
127+ * Plot Series or DataFrame as violinplot.
128+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
129+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
130+ */
131+ violin ( plotConfig ?: PlotConfigObject ) {
132+ const _plotConfig = plotConfig || {
133+ config : { } ,
134+ layout : { }
135+ } ;
136+ violinPlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
137+ }
138+
139+ /**
140+ * Plot Series or DataFrame as table.
141+ * Uses Plotly library as backend, so supports Plotly's configuration parameters
142+ * @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
143+ */
144+ table ( plotConfig ?: PlotConfigObject ) {
145+ const _plotConfig = plotConfig || {
146+ config : { } ,
147+ layout : { }
148+ } ;
149+ tablePlot ( this . ndframe , this . divId , _plotConfig , Plotly ) ;
150+ }
38151
39152}
40153
154+ // class Vega {
155+ // //TODO: Add support for vega library
156+ // }
157+
41158export {
42- Plotly
159+ PlotlyLib
43160}
0 commit comments