1- import { assert } from "chai" ;
21const opn = require ( "opn" ) ;
32import * as path from "path" ;
4- import * as Sugar from "sugar" ;
53import { ISerializedDataFrame } from "@data-forge/serialization" ;
64import { exportTemplate , IExportOptions } from "inflate-template" ;
75import { captureImage , ICaptureOptions } from "capture-template" ;
86import { ChartType , IChartDef , AxisType , HorizontalLabelPosition , VerticalLabelPosition , IPlotConfig as IExpandedPlotConfig , IAxisMap as IExpandedAxisMap , ISingleYAxisMap as IExpandedSingleYAxisMap } from "@data-forge-plot/chart-def" ;
97import { ISingleAxisMap , ISingleYAxisMap , IPlotConfig , IAxisMap , IAxisConfig } from "./chart-def" ;
8+ import { isObject , isString , isArray } from "./utils" ;
109
1110const DEFAULT_CHART_PACKAGE = "@data-forge-plot/apex" ;
1211
@@ -22,7 +21,7 @@ async function findChartTemplatePath(): Promise<string> {
2221 return chartTemplatesPath ;
2322}
2423
25- export async function startPlot ( ) : Promise < void > {
24+ export async function startPlot ( ) : Promise < void > {
2625 /*TODO:
2726 globalChartRenderer = new ChartRenderer();
2827
@@ -270,7 +269,15 @@ export abstract class AbstractPlotAPI implements IPlotAPI {
270269 * Configure the default x axis.
271270 */
272271 x ( seriesName : string ) : IXAxisConfigAPI {
273- this . globalAxisMap . x . series = seriesName ;
272+ if ( ! this . globalAxisMap . x ) {
273+ this . globalAxisMap . x = {
274+ series : seriesName ,
275+ } ;
276+ }
277+ else {
278+ this . globalAxisMap . x . series = seriesName ;
279+ }
280+
274281 return new XAxisConfigAPI (
275282 "x" ,
276283 seriesName ,
@@ -379,7 +386,7 @@ export abstract class AbstractPlotAPI implements IPlotAPI {
379386 if ( defaultedGlobalAxis . y . length === 0 ) {
380387 // Default the primary Y axis.
381388 defaultedGlobalAxis . y = this . data . columnOrder
382- . filter ( columnName => columnName !== defaultedGlobalAxis . x . series )
389+ . filter ( columnName => defaultedGlobalAxis . x === undefined || columnName !== defaultedGlobalAxis . x . series )
383390 . map ( columnName => ( {
384391 series : columnName ,
385392 } ) ) ;
@@ -414,7 +421,9 @@ export class PlotAPI extends AbstractPlotAPI {
414421 }
415422
416423 constructor ( data : ISerializedDataFrame , plotConfig : IPlotConfig , showLegendDefault : boolean , globalAxisMap ?: IAxisMap ) {
417- assert . isObject ( data , "Expected 'data' parameter to PlotAPI constructor to be a serialized dataframe." ) ;
424+ if ( ! isObject ( data ) ) {
425+ throw new Error ( "Expected 'data' parameter to PlotAPI constructor to be a serialized dataframe." ) ;
426+ }
418427
419428 // Clone the def and plot map so they can be updated by the fluent API.
420429 const expandedPlotConfig : IExpandedPlotConfig = Object . assign ( { } , plotConfig ) as IExpandedPlotConfig ;
@@ -505,7 +514,7 @@ export class PlotAPI extends AbstractPlotAPI {
505514
506515 if ( globalAxisMap ) {
507516 if ( globalAxisMap . x ) {
508- if ( Sugar . Object . isString ( globalAxisMap . x ) ) {
517+ if ( isString ( globalAxisMap . x ) ) {
509518 expandedGlobalAxisMap . x = {
510519 series : globalAxisMap . x ,
511520 } ;
@@ -516,16 +525,16 @@ export class PlotAPI extends AbstractPlotAPI {
516525 }
517526
518527 if ( globalAxisMap . y ) {
519- if ( Sugar . Object . isString ( globalAxisMap . y ) ) {
528+ if ( isString ( globalAxisMap . y ) ) {
520529 expandedGlobalAxisMap . y = [
521530 {
522531 series : globalAxisMap . y ,
523532 } ,
524533 ] ;
525534 }
526- else if ( Sugar . Object . isArray ( globalAxisMap . y ) ) {
535+ else if ( isArray ( globalAxisMap . y ) ) {
527536 expandedGlobalAxisMap . y = ( globalAxisMap . y as any [ ] ) . map ( series => {
528- if ( Sugar . Object . isString ( series ) ) {
537+ if ( isString ( series ) ) {
529538 return {
530539 series,
531540 } ;
@@ -546,16 +555,16 @@ export class PlotAPI extends AbstractPlotAPI {
546555 }
547556
548557 if ( globalAxisMap . y2 ) {
549- if ( Sugar . Object . isString ( globalAxisMap . y2 ) ) {
558+ if ( isString ( globalAxisMap . y2 ) ) {
550559 expandedGlobalAxisMap . y2 = [
551560 {
552561 series : globalAxisMap . y2 ,
553562 } ,
554563 ] ;
555564 }
556- else if ( Sugar . Object . isArray ( globalAxisMap . y2 ) ) {
565+ else if ( isArray ( globalAxisMap . y2 ) ) {
557566 expandedGlobalAxisMap . y2 = ( globalAxisMap . y2 as any [ ] ) . map ( series => {
558- if ( Sugar . Object . isString ( series ) ) {
567+ if ( isString ( series ) ) {
559568 return {
560569 series,
561570 } ;
@@ -737,7 +746,7 @@ class YAxisConfigAPI extends AxisConfigAPI<IYAxisConfigAPI, ISingleYAxisMap> imp
737746 if ( ! this . singleAxisMap . x ) {
738747 this . singleAxisMap . x = { series : seriesName } ;
739748 }
740- else if ( Sugar . Object . isString ( this . singleAxisMap . x ) ) {
749+ else if ( isString ( this . singleAxisMap . x ) ) {
741750 this . singleAxisMap . x = { series : seriesName } ;
742751 }
743752 else {
0 commit comments