From 8cdc6a7402b4ded74339b14512bcfec159a57aa9 Mon Sep 17 00:00:00 2001 From: Ilfat Galiev Date: Mon, 29 Jun 2020 15:08:20 +0300 Subject: [PATCH] Get computed default sorting for plot segments --- src/core/prototypes/plot_segments/line.ts | 13 ++++++- .../plot_segments/region_2d/cartesian.ts | 39 +++++++++++++++++-- .../plot_segments/region_2d/polar.ts | 28 +++++++++++-- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/core/prototypes/plot_segments/line.ts b/src/core/prototypes/plot_segments/line.ts index c9c048dce1..0442f61e8d 100644 --- a/src/core/prototypes/plot_segments/line.ts +++ b/src/core/prototypes/plot_segments/line.ts @@ -251,6 +251,17 @@ export class LineGuide extends PlotSegmentClass { p = p.concat(buildAxisProperties(this.object, "axis")); } if (this.object.properties.axis) { + const values = (this.object.properties.axis as any).categories; + let defaultValue = "ascending"; + if (values) { + const a = values[0].toString(); + const b = values[(values as any[]).length - 1].toString(); + if (b && a && b.localeCompare(a) > -1) { + defaultValue = "ascending"; + } else { + defaultValue = "descending"; + } + } p.push({ objectID: this.object._id, target: { @@ -260,7 +271,7 @@ export class LineGuide extends PlotSegmentClass { } }, type: Specification.AttributeType.Enum, - default: "ascending" + default: defaultValue }); } return { inferences: r, properties: p }; diff --git a/src/core/prototypes/plot_segments/region_2d/cartesian.ts b/src/core/prototypes/plot_segments/region_2d/cartesian.ts index acbf47a6ef..42af2c4d26 100644 --- a/src/core/prototypes/plot_segments/region_2d/cartesian.ts +++ b/src/core/prototypes/plot_segments/region_2d/cartesian.ts @@ -525,6 +525,17 @@ export class CartesianPlotSegment extends PlotSegmentClass< }); } if (this.object.properties.xData) { + const values = this.object.properties.xData.categories; + let defaultValue = "ascending"; + if (values) { + const a = values[0].toString(); + const b = values[(values as any[]).length - 1].toString(); + if (b && a && b.localeCompare(a) > -1) { + defaultValue = "ascending"; + } else { + defaultValue = "descending"; + } + } p.push({ objectID: this.object._id, target: { @@ -534,10 +545,21 @@ export class CartesianPlotSegment extends PlotSegmentClass< } }, type: Specification.AttributeType.Enum, - default: "ascending" + default: defaultValue }); } if (this.object.properties.yData) { + const values = this.object.properties.yData.categories; + let defaultValue = "ascending"; + if (values) { + const a = values[0].toString(); + const b = values[(values as any[]).length - 1].toString(); + if (b && a && b.localeCompare(a) > -1) { + defaultValue = "ascending"; + } else { + defaultValue = "descending"; + } + } p.push({ objectID: this.object._id, target: { @@ -547,10 +569,21 @@ export class CartesianPlotSegment extends PlotSegmentClass< } }, type: Specification.AttributeType.Enum, - default: "ascending" + default: defaultValue }); } if (this.object.properties.axis) { + const values = (this.object.properties.axis as any).categories; + let defaultValue = "ascending"; + if (values) { + const a = values[0].toString(); + const b = values[(values as any[]).length - 1].toString(); + if (b && a && b.localeCompare(a) > -1) { + defaultValue = "ascending"; + } else { + defaultValue = "descending"; + } + } p.push({ objectID: this.object._id, target: { @@ -560,7 +593,7 @@ export class CartesianPlotSegment extends PlotSegmentClass< } }, type: Specification.AttributeType.Enum, - default: "ascending" + default: defaultValue }); } return { inferences: r, properties: p }; diff --git a/src/core/prototypes/plot_segments/region_2d/polar.ts b/src/core/prototypes/plot_segments/region_2d/polar.ts index a6c5ca5795..868fad8671 100644 --- a/src/core/prototypes/plot_segments/region_2d/polar.ts +++ b/src/core/prototypes/plot_segments/region_2d/polar.ts @@ -86,7 +86,7 @@ export let polarTerminology: Region2DConfiguration["terminology"] = { export class PolarPlotSegment extends PlotSegmentClass< PolarProperties, PolarAttributes - > { +> { public static classID = "plot-segment.polar"; public static type = "plot-segment"; @@ -670,6 +670,17 @@ export class PolarPlotSegment extends PlotSegmentClass< }); } if (this.object.properties.xData) { + const values = (this.object.properties.xData as any).categories; + let defaultValue = "ascending"; + if (values) { + const a = values[0].toString(); + const b = values[(values as any[]).length - 1].toString(); + if (b && a && b.localeCompare(a) > -1) { + defaultValue = "ascending"; + } else { + defaultValue = "descending"; + } + } p.push({ objectID: this.object._id, target: { @@ -679,10 +690,21 @@ export class PolarPlotSegment extends PlotSegmentClass< } }, type: Specification.AttributeType.Enum, - default: "ascending" + default: defaultValue }); } if (this.object.properties.yData) { + const values = (this.object.properties.yData as any).categories; + let defaultValue = "ascending"; + if (values) { + const a = values[0].toString(); + const b = values[(values as any[]).length - 1].toString(); + if (b && a && b.localeCompare(a) > -1) { + defaultValue = "ascending"; + } else { + defaultValue = "descending"; + } + } p.push({ objectID: this.object._id, target: { @@ -692,7 +714,7 @@ export class PolarPlotSegment extends PlotSegmentClass< } }, type: Specification.AttributeType.Enum, - default: "ascending" + default: defaultValue }); } return { inferences: r, properties: p };