Skip to content

Commit ee93342

Browse files
committed
Update plot config
1 parent b0b8e9b commit ee93342

File tree

15 files changed

+51
-69
lines changed

15 files changed

+51
-69
lines changed

src/danfojs-base/core/generic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ export default class NDframe implements NDframeInterface {
161161
*/
162162
get tensor() {
163163
if (this.$isSeries) {
164-
return tensorflow.tensor1d(this.$data)
164+
return tensorflow.tensor1d(this.$data, this.$dtypes[0]);
165165
} else {
166-
return tensorflow.tensor2d(this.$data)
166+
return tensorflow.tensor2d(this.$data, this.shape, "float32")
167167
}
168168
}
169169

src/danfojs-base/plotting/index.ts

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ class PlotlyLib implements IPlotlyLib {
4343
this.divId = divId;
4444
}
4545

46+
private getPlotConfig(plotConfig?: PlotConfigObject) {
47+
const _plotConfig = {
48+
config: plotConfig && plotConfig.config ? plotConfig.config : {},
49+
layout: plotConfig && plotConfig.layout ? plotConfig.layout : {}
50+
};
51+
return _plotConfig;
52+
}
4653
/**
4754
* Plot Series or DataFrame as lines.
4855
* Uses Plotly library as backend, so supports Plotly's configuration parameters
4956
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
5057
*/
5158
line(plotConfig?: PlotConfigObject) {
52-
const _plotConfig = plotConfig || {
53-
config: {},
54-
layout: {}
55-
};
59+
const _plotConfig = this.getPlotConfig(plotConfig);
5660
linePlot(this.ndframe, this.divId, _plotConfig, Plotly);
5761
}
5862

@@ -62,10 +66,7 @@ class PlotlyLib implements IPlotlyLib {
6266
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
6367
*/
6468
bar(plotConfig?: PlotConfigObject) {
65-
const _plotConfig = plotConfig || {
66-
config: {},
67-
layout: {}
68-
};
69+
const _plotConfig = this.getPlotConfig(plotConfig);
6970
barPlot(this.ndframe, this.divId, _plotConfig, Plotly);
7071
}
7172

@@ -75,10 +76,7 @@ class PlotlyLib implements IPlotlyLib {
7576
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
7677
*/
7778
scatter(plotConfig?: PlotConfigObject) {
78-
const _plotConfig = plotConfig || {
79-
config: {},
80-
layout: {}
81-
};
79+
const _plotConfig = this.getPlotConfig(plotConfig);
8280
scatterPlot(this.ndframe, this.divId, _plotConfig, Plotly);
8381
}
8482

@@ -88,10 +86,7 @@ class PlotlyLib implements IPlotlyLib {
8886
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
8987
*/
9088
hist(plotConfig?: PlotConfigObject) {
91-
const _plotConfig = plotConfig || {
92-
config: {},
93-
layout: {}
94-
};
89+
const _plotConfig = this.getPlotConfig(plotConfig);
9590
histPlot(this.ndframe, this.divId, _plotConfig, Plotly);
9691
}
9792

@@ -101,10 +96,7 @@ class PlotlyLib implements IPlotlyLib {
10196
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
10297
*/
10398
pie(plotConfig?: PlotConfigObject) {
104-
const _plotConfig = plotConfig || {
105-
config: {},
106-
layout: {}
107-
};
99+
const _plotConfig = this.getPlotConfig(plotConfig);
108100
piePlot(this.ndframe, this.divId, _plotConfig, Plotly);
109101
}
110102

@@ -114,10 +106,7 @@ class PlotlyLib implements IPlotlyLib {
114106
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
115107
*/
116108
box(plotConfig?: PlotConfigObject) {
117-
const _plotConfig = plotConfig || {
118-
config: {},
119-
layout: {}
120-
};
109+
const _plotConfig = this.getPlotConfig(plotConfig);
121110
boxPlot(this.ndframe, this.divId, _plotConfig, Plotly);
122111
}
123112

@@ -127,10 +116,7 @@ class PlotlyLib implements IPlotlyLib {
127116
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
128117
*/
129118
violin(plotConfig?: PlotConfigObject) {
130-
const _plotConfig = plotConfig || {
131-
config: {},
132-
layout: {}
133-
};
119+
const _plotConfig = this.getPlotConfig(plotConfig);
134120
violinPlot(this.ndframe, this.divId, _plotConfig, Plotly);
135121
}
136122

@@ -140,18 +126,12 @@ class PlotlyLib implements IPlotlyLib {
140126
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
141127
*/
142128
table(plotConfig?: PlotConfigObject) {
143-
const _plotConfig = plotConfig || {
144-
config: {},
145-
layout: {}
146-
};
129+
const _plotConfig = this.getPlotConfig(plotConfig);
147130
tablePlot(this.ndframe, this.divId, _plotConfig, Plotly);
148131
}
149132

150133
}
151134

152-
// class Vega {
153-
// //TODO: Add support for vega library
154-
// }
155135

156136
export {
157137
PlotlyLib

src/danfojs-base/plotting/plotly/bar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Series from "../../core/series";
1616
import DataFrame from "../../core/frame";
1717
import { Data } from "plotly.js-dist-min"
18-
import { PlotConfigObject } from "../../shared/types"
18+
import { InternalPlotConfigObject } from "../../shared/types"
1919
import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2020

2121

@@ -28,7 +28,7 @@ import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2828
* @param divId HTML div id to plot in.
2929
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
3030
*/
31-
export const barPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
31+
export const barPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
3232
const config = plotConfig["config"]
3333
const layout = plotConfig["layout"]
3434

@@ -126,8 +126,8 @@ export const barPlot = (ndframe: DataFrame | Series, divId: string, plotConfig:
126126

127127
const traces: Data[] = [];
128128
cols.forEach((col) => {
129-
const y = ndframe.index;
130-
const x = (ndframe as DataFrame)[col].values;
129+
const x = ndframe.index;
130+
const y = (ndframe as DataFrame)[col].values;
131131

132132
const trace: Data = { x, y, name: col, type: 'bar' };
133133
traces.push(trace);

src/danfojs-base/plotting/plotly/box.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Series from "../../core/series";
1616
import DataFrame from "../../core/frame";
1717
import { Data } from "plotly.js-dist-min"
18-
import { PlotConfigObject } from "../../shared/types"
18+
import { InternalPlotConfigObject } from "../../shared/types"
1919
import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2020

2121

@@ -28,7 +28,7 @@ import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2828
* @param divId HTML div id to plot in.
2929
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
3030
*/
31-
export const boxPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
31+
export const boxPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
3232
const config = plotConfig["config"]
3333
const layout = plotConfig["layout"]
3434

src/danfojs-base/plotting/plotly/hist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Series from "../../core/series";
1616
import DataFrame from "../../core/frame";
1717
import { Data } from "plotly.js-dist-min"
18-
import { PlotConfigObject } from "../../shared/types"
18+
import { InternalPlotConfigObject } from "../../shared/types"
1919
import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2020

2121

@@ -28,7 +28,7 @@ import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2828
* @param divId HTML div id to plot in.
2929
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
3030
*/
31-
export const histPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
31+
export const histPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
3232
const config = plotConfig["config"]
3333
const layout = plotConfig["layout"]
3434

src/danfojs-base/plotting/plotly/line.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Series from "../../core/series";
1616
import DataFrame from "../../core/frame";
1717
import { Data } from "plotly.js-dist-min"
18-
import { PlotConfigObject } from "../../shared/types"
18+
import { InternalPlotConfigObject } from "../../shared/types"
1919
import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2020

2121

@@ -29,7 +29,7 @@ import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2929
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
3030
* @param Plotly Plotly package passed from the class.
3131
*/
32-
export const linePlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
32+
export const linePlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
3333
const config = plotConfig["config"]
3434
const layout = plotConfig["layout"]
3535

src/danfojs-base/plotting/plotly/pie.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import Series from "../../core/series";
1818
import DataFrame from "../../core/frame";
1919
import { Data } from "plotly.js-dist-min"
20-
import { PlotConfigObject } from "../../shared/types"
21-
import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
20+
import { InternalPlotConfigObject } from "../../shared/types"
21+
import { checkIfColsExist } from "./utils"
2222

2323

2424
/**
@@ -29,7 +29,7 @@ import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2929
* @param divId HTML div id to plot in.
3030
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
3131
*/
32-
export const piePlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
32+
export const piePlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
3333
const config = plotConfig["config"]
3434
const layout = plotConfig["layout"]
3535

@@ -74,7 +74,7 @@ export const piePlot = (ndframe: DataFrame | Series, divId: string, plotConfig:
7474
const cols = config["columns"] ? checkIfColsExist(ndframe, config['columns']) : ndframe.columns;
7575

7676
if (config['rowPositions']) {
77-
if (config['rowPositions'].length != cols.length - 1) {
77+
if (config['rowPositions'].length != cols.length) {
7878
throw Error(`Lenght of rowPositions array must be equal to number of columns. Got ${config['rowPositions'].length}, expected ${cols.length - 1}`);
7979
}
8080
} else {
@@ -87,7 +87,7 @@ export const piePlot = (ndframe: DataFrame | Series, divId: string, plotConfig:
8787
}
8888

8989
if (config['columnPositions']) {
90-
if (config['columnPositions'].length != cols.length - 1) {
90+
if (config['columnPositions'].length != cols.length) {
9191
throw Error(`Lenght of columnPositions array must be equal to number of columns. Got ${config['columnPositions'].length}, expected ${cols.length - 1}`);
9292
}
9393
} else {

src/danfojs-base/plotting/plotly/scatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Series from "../../core/series";
1616
import DataFrame from "../../core/frame";
1717
import { Data } from "plotly.js-dist-min"
18-
import { PlotConfigObject } from "../../shared/types"
18+
import { InternalPlotConfigObject } from "../../shared/types"
1919
import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2020

2121
/**
@@ -27,7 +27,7 @@ import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2727
* @param divId HTML div id to plot in.
2828
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
2929
*/
30-
export const scatterPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
30+
export const scatterPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
3131
const config = plotConfig["config"]
3232
const layout = plotConfig["layout"]
3333

src/danfojs-base/plotting/plotly/table.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
import Series from "../../core/series";
1616
import DataFrame from "../../core/frame";
17-
import { PlotConfigObject } from "../../shared/types"
17+
import { InternalPlotConfigObject } from "../../shared/types"
1818

1919

2020
/**
@@ -24,7 +24,7 @@ import { PlotConfigObject } from "../../shared/types"
2424
* @param divId HTML div id to plot in.
2525
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
2626
*/
27-
export const tablePlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
27+
export const tablePlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
2828
const config = plotConfig["config"]
2929
const layout = plotConfig["layout"]
3030
let header: any = {};
@@ -65,6 +65,7 @@ export const tablePlot = (ndframe: DataFrame | Series, divId: string, plotConfig
6565
cells[param] = config['tableCellStyle'][param];
6666
});
6767
}
68+
6869
const trace = {
6970
type: 'table',
7071
header,

src/danfojs-base/plotting/plotly/violin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Series from "../../core/series";
1616
import DataFrame from "../../core/frame";
1717
import { Data } from "plotly.js-dist-min"
18-
import { PlotConfigObject } from "../../shared/types"
18+
import { InternalPlotConfigObject } from "../../shared/types"
1919
import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2020

2121

@@ -28,7 +28,7 @@ import { checkIfColsExist, throwErrorOnWrongColName } from "./utils"
2828
* @param divId HTML div id to plot in.
2929
* @param plotConfig configuration options for making Plots, supports Plotly.js Config and Layout parameters.
3030
*/
31-
export const violinPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: PlotConfigObject, Plotly: any) => {
31+
export const violinPlot = (ndframe: DataFrame | Series, divId: string, plotConfig: InternalPlotConfigObject, Plotly: any) => {
3232
const config = plotConfig["config"]
3333
const layout = plotConfig["layout"]
3434

0 commit comments

Comments
 (0)