1212* limitations under the License.
1313* ==========================================================================
1414*/
15- import { ArrayType1D , BaseDataOptionType , SeriesInterface } from "../shared/types" ;
15+ import {
16+ ArrayType1D ,
17+ BaseDataOptionType ,
18+ SeriesInterface ,
19+ CsvOutputOptionsBrowser ,
20+ ExcelOutputOptionsBrowser ,
21+ JsonOutputOptionsBrowser ,
22+ CsvOutputOptionsNode ,
23+ ExcelOutputOptionsNode ,
24+ JsonOutputOptionsNode
25+ } from "../shared/types" ;
1626import { variance , std , median , mode } from 'mathjs' ;
1727import { _genericMathOp } from "./math.ops" ;
1828import { DATA_TYPES } from '../shared/defaults'
@@ -26,6 +36,9 @@ import Dt from './datetime';
2636import dummyEncode from "../transformers/encoders/dummy.encoder" ;
2737import DataFrame from "./frame" ;
2838import tensorflow from '../shared/tensorflowlib'
39+ import { PlotlyLib } from "../plotting" ;
40+ import { toCSVBrowser , toExcelBrowser , toJSONBrowser } from "../io/browser" ;
41+ import { toCSVNode , toExcelNode , toJSONNode } from "../io/node" ;
2942
3043const utils = new Utils ( ) ;
3144
@@ -1358,4 +1371,78 @@ export default class Series extends NDframe implements SeriesInterface {
13581371 } ) : DataFrame {
13591372 return dummyEncode ( this , options )
13601373 }
1374+
1375+
1376+ /**
1377+ * Make plots of Series or DataFrame.
1378+ * Uses the Plotly as backend, so supports Plotly's configuration parameters
1379+ * @param divId Name of the div to show the plot
1380+ * @returns Plotly class that expoese different plot type
1381+ */
1382+ plot ( divId : string ) {
1383+ //TODO: Add support for check plot library to use
1384+ // So we can support other plot library like d3, vega, etc
1385+ if ( utils . isBrowserEnv ( ) ) {
1386+ const plt = new PlotlyLib ( this , divId ) ;
1387+ return plt ;
1388+ } else {
1389+ throw new Error ( "Not supported in NodeJS" ) ;
1390+ }
1391+ }
1392+
1393+ /**
1394+ * Converts a DataFrame or Series to CSV.
1395+ * @param options Configuration object. Supports the following options:
1396+ * - `filePath`: Local file path to write the CSV file. If not specified, the CSV will be returned as a string.
1397+ * - `header`: Boolean indicating whether to include a header row in the CSV file.
1398+ * - `sep`: Character to be used as a separator in the CSV file.
1399+ */
1400+ toCSV ( options ?: CsvOutputOptionsBrowser | CsvOutputOptionsNode ) : string
1401+ toCSV ( options ?: CsvOutputOptionsBrowser | CsvOutputOptionsNode ) : string | void {
1402+ if ( utils . isBrowserEnv ( ) ) {
1403+ return toCSVBrowser ( this , options as CsvOutputOptionsBrowser )
1404+ } else {
1405+ return toCSVNode ( this , options as CsvOutputOptionsNode )
1406+ }
1407+ }
1408+
1409+ /**
1410+ * Converts a DataFrame or Series to JSON.
1411+ * @param options Configuration object. Supported options:
1412+ * - `filePath`: The file path to write the JSON to. If not specified, the JSON object is returned.
1413+ * - `format`: The format of the JSON. Defaults to `'column'`. E.g for using `column` format:
1414+ * ```
1415+ * [{ "a": 1, "b": 2, "c": 3, "d": 4 },
1416+ * { "a": 5, "b": 6, "c": 7, "d": 8 }]
1417+ * ```
1418+ * and `row` format:
1419+ * ```
1420+ * { "a": [1, 5, 9],
1421+ * "b": [2, 6, 10]
1422+ * }
1423+ * ```
1424+ */
1425+ toJSON ( options ?: JsonOutputOptionsBrowser | JsonOutputOptionsNode ) : object
1426+ toJSON ( options ?: JsonOutputOptionsBrowser | JsonOutputOptionsNode ) : object | void {
1427+ if ( utils . isBrowserEnv ( ) ) {
1428+ return toJSONBrowser ( this , options as JsonOutputOptionsBrowser )
1429+ } else {
1430+ return toJSONNode ( this , options as JsonOutputOptionsNode )
1431+ }
1432+ }
1433+
1434+
1435+ /**
1436+ * Converts a DataFrame or Series to Excel Sheet.
1437+ * @param options Configuration object. Supported options:
1438+ * - `sheetName`: The sheet name to be written to. Defaults to `'Sheet1'`.
1439+ * - `filePath`: The filePath to be written to. Defaults to `'./output.xlsx'`.
1440+ */
1441+ toExcel ( options ?: ExcelOutputOptionsBrowser | ExcelOutputOptionsNode ) : void {
1442+ if ( utils . isBrowserEnv ( ) ) {
1443+ toExcelBrowser ( this , options as ExcelOutputOptionsBrowser )
1444+ } else {
1445+ return toExcelNode ( this , options as ExcelOutputOptionsNode )
1446+ }
1447+ }
13611448}
0 commit comments