Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/piechart #168

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e2280d1
Ajout class Pie
Tanguylo Jun 3, 2022
d83ec07
Start with piechart
Tanguylo Jun 7, 2022
d5b2e4b
feat(piechart): first piechart drawing
Tanguylo Jun 7, 2022
b4514ea
feat(piechart): add colors to piechart
Tanguylo Jun 8, 2022
e21e984
feat(piechart):add pie part surface coloring on mouse over
Tanguylo Jun 13, 2022
949df9c
feat(piechart):partial code cleaning
Tanguylo Jun 13, 2022
8427fef
feat(piechart):fix a git mistake with branches
Tanguylo Jun 13, 2022
e21259e
feat(piechart):fixing last diff in core.py
Tanguylo Jun 13, 2022
ad59106
feat(piechart):remove ' /' line 931
Tanguylo Jun 13, 2022
6c494e2
feat(piechart):add parts selection on click
Tanguylo Jun 14, 2022
9c83b56
feat(piechart):manage piepart paths as piepart attribute
Tanguylo Jun 14, 2022
38ebcb3
feat(piechart):initialize pieparts path when instantiating when crea…
Tanguylo Jun 14, 2022
1937904
feat(piechart):some code cleaning
Tanguylo Jun 17, 2022
4675ede
feat(piechart): fix mistakes following the first 6 comments on this p…
Tanguylo Jun 21, 2022
cd1864f
feat(piechart): fix the 5 following remarks of the PR
Tanguylo Jun 21, 2022
1f81acc
feat(piechart): fix the remaining remarks except the drawPieChart method
Tanguylo Jun 21, 2022
e3371ec
feat(piechart): take last PR remarks into account
Tanguylo Jun 21, 2022
84fe419
feat(piechart): change type of color_to_plot_data to map
Tanguylo Jun 22, 2022
8bf219a
feat(piechart): modifications following PR remarks
Tanguylo Jun 22, 2022
006de63
feat(piechart): Changes following the PR review
Tanguylo Jun 24, 2022
3cea6f1
feat(piechart): Put color:string='' in the constructor of PieParts fo…
Tanguylo Jun 24, 2022
174b386
feat(piechart_in_multiplot): Handle selection of piePart as expected
Tanguylo Jun 24, 2022
0413f2f
feat(piechart): add commit to branch and reset latest_selected_points…
Tanguylo Jun 27, 2022
87d5ef6
feat(piechart): Undo color_to_plot_data as a Map
Tanguylo Jun 27, 2022
10772ba
feat(piechart): Changes following second PR
Tanguylo Jun 27, 2022
34cdd69
feat(piechart): DataSample and DataSamples type definition and some c…
Tanguylo Jun 27, 2022
7a5f0e6
feat(piechart): Changes in drawPieChart
Tanguylo Jun 28, 2022
54091b1
feat(piechart): Change multiple_plot.py file
Tanguylo Jun 28, 2022
0ecc993
feat(piechart): Call definePieParts in PieChart constructor and not a…
Tanguylo Jun 28, 2022
5c7c296
feat(piechart): Write PR equivalent in CHANGELOG.md file
Tanguylo Jun 28, 2022
b4bc6e2
Merge branch 'dev' into feat/piechart
Tanguylo Feb 28, 2023
ce09723
merge since 6 months, possible fails
Tanguylo Feb 28, 2023
9896338
Merge branch 'dev' into feat/piechart
Tanguylo Feb 28, 2023
2187adf
feat(piechart): add tests
Tanguylo Feb 28, 2023
f8f4b8a
feat(piechart): pylint
Tanguylo Mar 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions plot_data/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,36 +720,29 @@ class PieChart(PlotDataObject):
"""
A class for drawing pie plots.

:param elements: A list of vectors. Vectors must have the same \
attributes (ie the same keys)
:param elements: [{'name_param_1': any,..., 'name_param_p': any},...,
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
{'name_param_1': any,..., 'name_param_p': any}]
:type elements: List[dict]
:param x_variable: variable that you want to display on x axis
:type x_variable: str
:param trim_variable: variable that you want to use to fill pie parts
:type trim_variable: str
:param tooltip: an object containing all information needed for \
drawing tooltips
:type tooltip: Tooltip
:param point_style: for points' customization
:type point_style: PointStyle
"""

def __init__(self, x_variable: str, elements: List[Any] = None,
def __init__(self, slicing_variable: str, data_samples: List[Any] = None,
tooltip: Tooltip = None,
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
point_style: PointStyle = None,
edge_style: EdgeStyle = None,
axis: Axis = None,
name: str = ''):

self.tooltip = tooltip
self.attribute_names = [x_variable]
self.point_style = point_style
if not elements:
self.elements = []
else:
self.elements = elements
if not axis:
self.axis = Axis()
self.slicing_variable = slicing_variable
if not data_samples:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if data_samples is None: would be the right check

self.data_samples = []
else:
self.axis = axis
self.data_samples = data_samples

PlotDataObject.__init__(self, type_='piechart', name=name)


Expand Down
32 changes: 1 addition & 31 deletions plot_data/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,38 +252,8 @@
);
plot_data.define_canvas($canvas_id.id);
plot_data.draw_initial();
plot_data.mouse_interaction(plot_data.isParallelPlot);
plot_data.mouse_interaction(false);
</script>
</div>
</html>
''')

# piechart_template = Template('''
# <!DOCTYPE html>
# <html lang="en">
# <head>
# <script src=$core_path></script>
# </head>
# <div id="app">
# <canvas id="$canvas_id" width="2000" height="490"
# style="border: 1px solid black;">
# </canvas>

# <!-- Sets the basepath for the library if not in same directory -->

# <script>
# var width = 0.95*window.innerWidth;
# var height = Math.max(0.95*window.innerHeight, 350);

# var data = $data;
# var number_plot_data = data.length;

# var plot_data = new PlotData.PlotPieChart(
# data, width, height, true, 0, 0, $canvas_id.id
# );
# plot_data.define_canvas($canvas_id.id);
# plot_data.draw_initial();
# </script>
# </div>
# </html>
# ''')
16 changes: 8 additions & 8 deletions script/pie_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
import random


elements = []
data_samples = []
SHAPES = ['round', 'square', 'triangle', 'ellipse']
COLORS = [colors.RED, colors.BLUE, colors.GREEN, colors.YELLOW, colors.ORANGE, colors.VIOLET]
for i in range(50):
random_shape = SHAPES[random.randint(0, len(SHAPES) - 1)]
random_color = COLORS[random.randint(0, len(SHAPES) - 1)]
elements.append({'mass': random.uniform(0, 50),
data_samples.append({'mass': random.uniform(0, 50),
'length': random.uniform(0, 100),
'shape': random_shape,
'color': random_color
})


piechart = plot_data.PieChart(elements=elements,
x_variable='mass')
piechart1 = plot_data.PieChart(data_samples=data_samples,
slicing_variable='mass')

# piechart = plot_data.PieChart(elements=elements,
# x_variable='shape', y_variable='length')
piechart2 = plot_data.PieChart(data_samples=data_samples,
slicing_variable='length')



plot_data.plot_canvas(plot_data_object=piechart, debug_mode=True)
plot_data.plot_canvas(plot_data_object=piechart1, debug_mode=True)
plot_data.plot_canvas(plot_data_object=piechart2, debug_mode=True)
77 changes: 34 additions & 43 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, PieChart, PiePart } 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 @@ -291,6 +291,7 @@ export abstract class PlotData {
this.init_scale = 0.95 * (this.width - this.decalage_axis_x) / (this['max_abs'] - this['min_abs']);
this.scale = this.init_scale;
this.originX = this.decalage_axis_x - this.scale * this['min_abs'];

} else { // only rescale
this.scaleX = this.init_scale;
this.scaleY = this.init_scale;
Expand Down Expand Up @@ -776,53 +777,43 @@ export abstract class PlotData {


drawPiechart(d: PieChart, hidden: boolean, mvx: number, mvy: number): void {
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
this.interaction_ON = true;
if (d['type_'] == 'piechart') {
const radius: number = this.height / this.init_scaleY * 0.45;
const center: Array<number> = [this.width / this.init_scaleX / 1.9, this.height / this.init_scaleY / 2];
let colorRadius: number = 0;
let colorRatio: number = 360 / d.pieParts.length;
this.context.lineWidth = 0.5;

for (let part of d.pieParts) {
part.centerX = center[0];
part.centerY = center[1];
part.radius = radius;
colorRadius += colorRatio;

this.color_to_plot_data[part.hidden_color] = part;

if (hidden) {
this.context.strokeStyle = part.hidden_color;
this.context.fillStyle = part.hidden_color;
} else {
if (part.clicked){
d.pieParts.forEach(piepart => piepart.clicked = false);
part.clicked = true;
}
if (part.clicked && this.select_on_mouse !== part) {
this.context.fillStyle = this.color_surface_on_click;
this.context.strokeStyle = this.color_surface_on_click;
} else if (part.clicked && this.select_on_mouse === part) {
this.context.fillStyle = this.color_surface_on_mouse;
this.context.strokeStyle = this.color_surface_on_mouse;
} else if (!part.clicked && this.select_on_mouse === part) {
this.context.fillStyle = this.color_surface_on_mouse;
this.context.strokeStyle = this.color_surface_on_mouse;
} else {
this.context.fillStyle = 'hsl('+ colorRadius +', 50%, 50%, 90%)';
this.context.strokeStyle = 'hsl('+ colorRadius +', 50%, 50%, 90%)';
}
this.context.fillStyle = part.color;
this.context.strokeStyle = part.color;
const radius: number = this.height;
const center: [number, number] = [this.width / this.init_scaleX / 2, this.height / this.init_scaleY / 2];
const colorRatio: number = 360 / d.pieParts.length;
let colorRadius: number = 0;
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
this.context.lineWidth = 0.5;

for (let part of d.pieParts) {
part.centerX = center[0];
part.centerY = center[1];
part.radius = radius;
colorRadius += colorRatio;

if (hidden) {
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
this.context.strokeStyle = part.hidden_color;
this.context.fillStyle = part.hidden_color;
} else {
if (part.clicked){
d.pieParts.forEach(piepart => piepart.clicked = false);
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
part.clicked = true;
}
part.draw(this.context, mvx, mvy, this.scaleX, this.X, this.Y);
if (part.clicked && this.select_on_mouse !== part) {
part.color = this.color_surface_on_click;

} else if (this.select_on_mouse === part) {
part.color = this.color_surface_on_mouse;

} else {
part.color = 'hsl('+ colorRadius +', 50%, 50%, 90%)';
}
this.context.fillStyle = part.color;
this.context.strokeStyle = part.color;
}
this.draw_tooltip(d.tooltip, mvx, mvy, this.scatter_points, d.point_list, d.elements, this.mergeON,
d.attribute_names);
part.draw(this.context, mvx, mvy, this.scaleX, this.X, this.Y);
}
}


get_point_order() {
var point_order = [];
for (let i = 0; i < this.point_families.length; i++) {
Expand Down
Loading