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


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)
:type elements: List[dict]
:param x_variable: variable that you want to display on x axis
:type x_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,
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
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()
else:
self.axis = axis
PlotDataObject.__init__(self, type_='piechart', name=name)


class ScatterMatrix(PlotDataObject):
def __init__(self, elements: List[Any] = None, axes: List[str] = None,
point_style: PointStyle = None, surface_style: SurfaceStyle = None,
Expand Down Expand Up @@ -1151,6 +1188,8 @@ def plot_canvas(plot_data_object: Subclass[PlotDataObject],
template = templates.histogram_template
elif plot_type == "scattermatrix":
template = templates.scatter_matrix_template
elif plot_type == "piechart":
template = templates.piechart_template
else:
raise NotImplementedError('Type {} not implemented'.format(plot_type))

Expand Down
62 changes: 62 additions & 0 deletions plot_data/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,65 @@
</body>
</html>
''')

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this template any different than the cypress' one ? Can't they be mutualized ? Should they ?


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();
plot_data.mouse_interaction(plot_data.isParallelPlot);
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
</script>
</div>
</html>
''')

# piechart_template = Template('''
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
# <!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>
# ''')
35 changes: 35 additions & 0 deletions script/pie_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 3 16:18:31 2022

@author: tanguy
"""

import plot_data
import plot_data.colors as colors
import random


elements = []
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),
'length': random.uniform(0, 100),
'shape': random_shape,
'color': random_color
})


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

# piechart = plot_data.PieChart(elements=elements,
xavier-ferry marked this conversation as resolved.
Show resolved Hide resolved
# x_variable='shape', y_variable='length')



plot_data.plot_canvas(plot_data_object=piechart, debug_mode=True)
5 changes: 3 additions & 2 deletions src/multiplots.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PlotData, Interactions} from './plot-data';
import {Point2D} from './primitives';
import { Attribute, PointFamily, check_package_version, Window, TypeOf, equals, Sort, download } from './utils';
import { PlotContour, PlotScatter, ParallelPlot, PrimitiveGroupContainer, Histogram } from './subplots';
import { PlotContour, PlotScatter, ParallelPlot, PrimitiveGroupContainer, Histogram, PlotPieChart } from './subplots';
import { List, Shape, MyObject } from './toolbox';
import { string_to_hex, string_to_rgb, rgb_to_string } from './color_conversion';

Expand Down Expand Up @@ -83,7 +83,7 @@ export class MultiplePlots {
} else if (object_type_ === 'parallelplot') {
this.dataObjects[i]['elements'] = elements;
newObject = new ParallelPlot(this.dataObjects[i], this.sizes[i]['width'], this.sizes[i]['height'], buttons_ON, this.initial_coords[i][0], this.initial_coords[i][1], canvas_id, true);
} else if (object_type_ === 'primitivegroup') {
} else if (object_type_ === 'primitivegroup') {
newObject = new PlotContour(this.dataObjects[i], this.sizes[i]['width'], this.sizes[i]['height'], buttons_ON, this.initial_coords[i][0], this.initial_coords[i][1], canvas_id, true);
} else if (object_type_ === 'primitivegroupcontainer') {
newObject = new PrimitiveGroupContainer(this.dataObjects[i], this.sizes[i]['width'], this.sizes[i]['height'], buttons_ON, this.initial_coords[i][0], this.initial_coords[i][1], canvas_id, true);
Expand All @@ -109,6 +109,7 @@ export class MultiplePlots {
this.display_order.push(i);
this.to_display_plots.push(i);
}

this.mouse_interaction();

if (buttons_ON) {
Expand Down
Loading