Skip to content

Commit

Permalink
feat(piechart_in_multiplot): Handle selection of piePart as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanguylo committed Jun 27, 2022
1 parent 3cea6f1 commit 174b386
Show file tree
Hide file tree
Showing 3 changed files with 1,860 additions and 1,831 deletions.
29 changes: 24 additions & 5 deletions src/plot-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { heatmap_color, string_to_hex } from "./color_conversion";
import { Point2D, PrimitiveGroup, Contour2D, Circle2D, Dataset, Graph2D, Scatter, Heatmap, Wire } from "./primitives";
import { Point2D, PrimitiveGroup, Contour2D, Circle2D, Dataset, Graph2D, Scatter, Heatmap, Wire, PieChart } from "./primitives";
import { Attribute, PointFamily, Axis, Tooltip, Sort, permutator } from "./utils";
import { EdgeStyle } from "./style";
import { Shape, List, MyMath } from "./toolbox";
Expand Down Expand Up @@ -169,7 +169,7 @@ export abstract class PlotData {
rubberbands_dep: [string, [number, number]][] = [];

point_families: PointFamily[] = [];
latest_selected_points: Point2D[] = [];
latest_selected_points: any[] = [];
latest_selected_points_index: number[] = [];

// primitive_group_container's attributes
Expand Down Expand Up @@ -1858,18 +1858,29 @@ export abstract class PlotData {
this.clicked_point_index.push([List.get_index_of_element(this.clicked_points[i], this.plotObject.graphs[j].point_list), j]);
}
}
} else if ((this.plotObject instanceof PieChart) && this.clicked_points[i]) {
let true_clicked_points = this.clicked_points[i].points_inside;
for (let j = 0; j < true_clicked_points.length; j++) {
this.clicked_point_index.push(List.get_index_of_element(true_clicked_points[j], this.plotObject.pieParts));
}
}
}
}


refresh_latest_selected_points_index() {
let elements_list: Array<any>;
this.latest_selected_points_index = [];
if (this.plotObject instanceof PieChart) {
elements_list = this.plotObject.pieParts;
} else {
elements_list = this.plotObject.point_list;
}
for (let i = 0; i < this.latest_selected_points.length; i++) {
let selected_point = this.latest_selected_points[i];
if (selected_point != undefined) {
for (let j = 0; j < selected_point.points_inside.length; j++) {
let point_index = List.get_index_of_element(selected_point.points_inside[j], this.plotObject.point_list);
let point_index = List.get_index_of_element(selected_point.points_inside[j], elements_list);
this.latest_selected_points_index.push(point_index);
}
}
Expand Down Expand Up @@ -1914,7 +1925,7 @@ export abstract class PlotData {
// Interactions.reset_permanent_window(this);
// }
this.refresh_clicked_point_index();
if (this.type_ == 'scatterplot') { this.refresh_latest_selected_points_index(); }
if (this.type_ == 'scatterplot' || this.plotObject instanceof PieChart) { this.refresh_latest_selected_points_index(); }
}


Expand Down Expand Up @@ -1954,7 +1965,15 @@ export abstract class PlotData {
this.plotObject.graphs[i].point_list[j].clicked = false;
}
}
}
} else if (this.plotObject instanceof PieChart) {
for (let i = 0; i < this.plotObject.pieParts.length; i++) {
this.plotObject.pieParts[i].selected = false;
if (this.plotObject.pieParts[i]) {
this.plotObject.pieParts[i].selected = false;
if (reset_clicked_points) this.plotObject.pieParts[i].clicked = false;
}
}
}
}


Expand Down
16 changes: 13 additions & 3 deletions src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ export class PiePart {
hidden_color: string = '';
path: Path2D;
clicked: boolean = false;
selected: boolean = false;
points_inside: PiePart[] = [this];
readonly overfliedColor: string = string_to_hex('lightskyblue');
readonly selectedColor: string = string_to_hex("red");
readonly center: [number, number] = [0, 0];
Expand All @@ -992,7 +994,7 @@ export class PiePart {
*/
constructor(
public radius: number,
public initAngle: number, // Warning: canvas' angles are clockwise-oriented. For example: pi/2 rad is below -pi/2 rad.
public initAngle: number, // Warning : X axis is from top to bottom then trigonometric
public endAngle: number,
public color: string = '')
{
Expand Down Expand Up @@ -1031,9 +1033,17 @@ export class PiePart {
assignColor(select_on_mouse: PiePart): string {
let color: string = this.color;
if (this.clicked && select_on_mouse !== this) {
color = this.selectedColor;
if (select_on_mouse != undefined) {
if (select_on_mouse.clicked) {
this.clicked = false
} else {
color = this.selectedColor;
}
} else {
color = this.selectedColor;
}
} else if (this.clicked && select_on_mouse === this) {
color = this.selectedColor;
color = this.overfliedColor;
} else if (!this.clicked && select_on_mouse === this) {
color = this.overfliedColor;
}
Expand Down
Loading

0 comments on commit 174b386

Please sign in to comment.