Skip to content

Commit c2067ce

Browse files
committed
Refactor Plotting class to support different plotting libraries and complete Plotly line plot
1 parent 1e7f997 commit c2067ce

9 files changed

Lines changed: 285 additions & 186 deletions

File tree

src/danfojs-base/core/frame.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import NDframe from "./generic";
2525
import { table } from "table";
2626
import Series from './series';
2727
import Groupby from '../aggregators/groupby'
28+
import { Plotly } from "../plotting";
29+
2830
const utils = new Utils();
2931

3032
/**
@@ -2435,8 +2437,21 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
24352437
this.values as ArrayType2D,
24362438
columns,
24372439
colDtype,
2438-
colIndex
2440+
colIndex
24392441
).group()
2440-
2442+
2443+
}
2444+
2445+
/**
2446+
* Make plots of Series or DataFrame.
2447+
* Uses the Plotly as backend, so supports Plotly's configuration parameters
2448+
* @param divId Name of the div to show the plot
2449+
* @returns Plotly class that expoese different plot type
2450+
*/
2451+
plot(divId: string) {
2452+
//TODO: Add support for check plot library to use
2453+
// So we can support other plot library like d3, vega, etc
2454+
const plt = new Plotly(this, divId);
2455+
return plt;
24412456
}
24422457
}

src/danfojs-base/core/series.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Dt from './datetime';
2626
import dummyEncode from "../transformers/encoders/dummy.encoder";
2727
import DataFrame from "./frame";
2828
import tensorflow from '../shared/tensorflowlib'
29-
import Plot from "../plotting/plotly";
29+
import { Plotly } from "../plotting";
3030

3131
const utils = new Utils();
3232

@@ -1368,7 +1368,9 @@ export default class Series extends NDframe implements SeriesInterface {
13681368
* @returns Plotly class that expoese different plot type
13691369
*/
13701370
plot(divId: string) {
1371-
const plt = new Plot(this, divId);
1371+
//TODO: Add support for check plot library to use
1372+
// So we can support other plot library like d3, vega, etc
1373+
const plt = new Plotly(this, divId);
13721374
return plt;
13731375
}
13741376
}

src/danfojs-base/plotting/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license
3+
* Copyright 2021, JsData. All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
* ==========================================================================
14+
*/
15+
import { linePlot } from "./plotly/index";
16+
import Series from "../core/series";
17+
import DataFrame from "../core/frame";
18+
import { PlotConfigObject } from "../shared/types";
19+
20+
class Plotly {
21+
divId: string;
22+
ndframe: DataFrame | Series;
23+
24+
constructor(ndframe: DataFrame | Series, divId: string) {
25+
this.ndframe = ndframe;
26+
this.divId = divId;
27+
}
28+
29+
/**
30+
* 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.
33+
*/
34+
line(plotConfig: PlotConfigObject) {
35+
linePlot(this.ndframe, this.divId, plotConfig);
36+
}
37+
38+
39+
}
40+
41+
export {
42+
Plotly
43+
}

src/danfojs-base/plotting/plotly.ts

Lines changed: 0 additions & 179 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright 2021, JsData. All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
* ==========================================================================
14+
*/
15+
16+
export { linePlot } from "./line";

0 commit comments

Comments
 (0)