1- // //perform plotting
2- // // import {newPlot} from 'plotly.js/dist/plotly'
3- // import { Utils } from "../core/utils"
4- // const utils = new Utils()
5-
6-
7-
8- // /**
9- // * Plotting methods and Functions performed on Series and DataFrames
10- // */
11- // export class Plot {
12- // constructor() {}
13-
14- // plot(ndframe, div, config) {
15- // let params = Object.keys(config)
16- // let this_config = {}
17-
18- // if (!utils.__key_in_object(config, "layout")){
19- // this_config['layout'] = {}
20- // }
21-
22- // params.forEach(param => {
23- // this_config[param] = config[param]
24- // })
25-
26- // if (ndframe.series) {
27- // let x = ndframe.values
28- // let trace = {
29- // x: x,
30- // type: this_config["kind"],
31- // mode: this_config["mode"]
32- // }
33- // newPlot(div, [trace], this_config['layout']);
34-
35- // } else {
36- // //DataFrame
37- // if (utils.__key_in_object(this_config, 'x') && utils.__key_in_object(this_config, 'y')) {
38- // let x = ndframe[this_config['x']].values
39- // let y = ndframe[this_config['y']].values
40-
41- // let trace = {
42- // x: x,
43- // y: y,
44- // type: config["kind"],
45- // mode: config["mode"],
46- // }
47-
48- // let xaxis = {}; let yaxis = {}
49- // xaxis['title'] = this_config['x']
50- // yaxis['title'] = this_config['y']
51-
52- // this_config['layout']['xaxis'] = xaxis
53- // this_config['layout']['yaxis'] = yaxis
54-
55-
56- // newPlot(div, [trace], this_config['layout']);
57-
58- // } else {
59- // //plot all
60- // let y = ndframe.index
61- // let data = []
62- // ndframe.column_names.forEach(c_name => {
63- // let trace = {
64- // x: ndframe[c_name].values,
65- // y: y,
66- // type: this_config["kind"],
67- // mode: this_config["mode"],
68- // name: c_name
69- // };
70- // data.push(trace)
71-
72- // })
73- // newPlot(div, data, this_config['layout']);
74- // }
75-
76-
77- // }
78- // }
79-
80- // }
1+ //perform plotting
2+ import { newPlot } from 'plotly.js/dist/plotly'
3+ import { Utils } from "../core/utils"
4+ const utils = new Utils ( )
5+
6+
7+
8+ /**
9+ * Plotting methods and Functions performed on Series and DataFrames
10+ */
11+ export class Plot {
12+ constructor ( ) { }
13+
14+ plot ( ndframe , div , config ) {
15+ let params = Object . keys ( config )
16+ let this_config = { }
17+
18+ if ( ! utils . __key_in_object ( config , "layout" ) ) {
19+ this_config [ 'layout' ] = { }
20+ }
21+
22+ params . forEach ( param => {
23+ this_config [ param ] = config [ param ]
24+ } )
25+
26+ if ( ndframe . series ) {
27+ let x = ndframe . values
28+ let trace = { }
29+ trace [ "x" ] = x
30+
31+ params . forEach ( param => {
32+ if ( ! param == 'layout' ) {
33+ trace [ param ] = config [ param ]
34+ }
35+ } )
36+
37+
38+ newPlot ( div , [ trace ] , this_config [ 'layout' ] ) ;
39+
40+ } else {
41+ //DataFrame
42+ if ( utils . __key_in_object ( this_config , 'x' ) && utils . __key_in_object ( this_config , 'y' ) ) {
43+ let x = ndframe [ this_config [ 'x' ] ] . values
44+ let y = ndframe [ this_config [ 'y' ] ] . values
45+
46+ let trace = {
47+ x : x ,
48+ y : y ,
49+ type : config [ "type" ] ,
50+ mode : config [ "mode" ] ,
51+ }
52+
53+ let xaxis = { } ; let yaxis = { }
54+ xaxis [ 'title' ] = this_config [ 'x' ]
55+ yaxis [ 'title' ] = this_config [ 'y' ]
56+
57+ this_config [ 'layout' ] [ 'xaxis' ] = xaxis
58+ this_config [ 'layout' ] [ 'yaxis' ] = yaxis
59+
60+
61+ newPlot ( div , [ trace ] , this_config [ 'layout' ] ) ;
62+
63+ } else {
64+ //plot all
65+ let y = ndframe . index
66+ let data = [ ]
67+ ndframe . column_names . forEach ( c_name => {
68+ let trace = {
69+ x : ndframe [ c_name ] . values ,
70+ y : y ,
71+ type : this_config [ "type" ] ,
72+ mode : this_config [ "mode" ] ,
73+ name : c_name
74+ } ;
75+ data . push ( trace )
76+
77+ } )
78+ newPlot ( div , data , this_config [ 'layout' ] ) ;
79+ }
80+
81+
82+ }
83+ }
84+
85+ }
0 commit comments