Skip to content

Commit

Permalink
Get computed default sorting for plot segments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilfat Galiev committed Jun 29, 2020
1 parent d22975f commit 8cdc6a7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/core/prototypes/plot_segments/line.ts
Expand Up @@ -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: {
Expand All @@ -260,7 +271,7 @@ export class LineGuide extends PlotSegmentClass {
}
},
type: Specification.AttributeType.Enum,
default: "ascending"
default: defaultValue
});
}
return { inferences: r, properties: p };
Expand Down
39 changes: 36 additions & 3 deletions src/core/prototypes/plot_segments/region_2d/cartesian.ts
Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -560,7 +593,7 @@ export class CartesianPlotSegment extends PlotSegmentClass<
}
},
type: Specification.AttributeType.Enum,
default: "ascending"
default: defaultValue
});
}
return { inferences: r, properties: p };
Expand Down
28 changes: 25 additions & 3 deletions src/core/prototypes/plot_segments/region_2d/polar.ts
Expand Up @@ -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";

Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -692,7 +714,7 @@ export class PolarPlotSegment extends PlotSegmentClass<
}
},
type: Specification.AttributeType.Enum,
default: "ascending"
default: defaultValue
});
}
return { inferences: r, properties: p };
Expand Down

0 comments on commit 8cdc6a7

Please sign in to comment.