Skip to content

Commit e4a7726

Browse files
committed
fix(toggle_axis): allow to directly hide axes on python command
1 parent 1c74911 commit e4a7726

5 files changed

Lines changed: 36 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [0.23.0]
8+
## [0.24.0]
9+
### Add
10+
- Allow to directly specify if axes are on or off in Python
911

12+
## [0.23.0]
1013
### Feat
1114
- Add events (Subject) to emit shape hovering and clicking
1215
- Highlight shapes when corresponding function is called from wrapper software
1316

17+
## [0.22.4]
1418
### Fix
1519
- Remove offline mode
1620

plot_data/core.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ class Figure(PlotDataObject):
110110

111111
_standalone_in_db = True
112112

113-
def __init__(self, type_: str, width: int = 750, height: int = 400, name: str = '', **kwargs):
113+
def __init__(self, type_: str, width: int = 750, height: int = 400, axis_on: bool = True, name: str = '', **kwargs):
114114
self.width = width
115115
self.height = height
116+
self.axis_on = axis_on
116117
PlotDataObject.__init__(self, type_=type_, name=name, **kwargs)
117118

118119
@property
@@ -879,7 +880,7 @@ class Graph2D(Figure):
879880

880881
def __init__(self, graphs: List[Dataset], x_variable: str, y_variable: str, axis: Axis = None,
881882
log_scale_x: bool = None, log_scale_y: bool = None, width: int = 750, height: int = 400,
882-
name: str = ''):
883+
axis_on: bool = True, name: str = ''):
883884
self.graphs = graphs
884885
self.attribute_names = [x_variable, y_variable]
885886
if axis is None:
@@ -888,7 +889,7 @@ def __init__(self, graphs: List[Dataset], x_variable: str, y_variable: str, axis
888889
self.axis = axis
889890
self.log_scale_x = log_scale_x
890891
self.log_scale_y = log_scale_y
891-
super().__init__(width=width, height=height, type_='graph2d', name=name)
892+
super().__init__(width=width, height=height, type_='graph2d', axis_on=axis_on, name=name)
892893

893894
def mpl_plot(self, ax=None, **kwargs):
894895
""" Plots using matplotlib. """
@@ -1055,7 +1056,7 @@ class Scatter(Figure):
10551056
def __init__(self, x_variable: str = None, y_variable: str = None, tooltip: Tooltip = None,
10561057
point_style: PointStyle = None, elements: List[Sample] = None, points_sets: List[PointFamily] = None,
10571058
axis: Axis = None, log_scale_x: bool = None, log_scale_y: bool = None, heatmap: Heatmap = None,
1058-
heatmap_view: bool = None, width: int = 750, height: int = 400, name: str = ''):
1059+
heatmap_view: bool = None, width: int = 750, height: int = 400, axis_on: bool = True, name: str = ''):
10591060
self.tooltip = tooltip
10601061
self.attribute_names = [x_variable, y_variable]
10611062
self.point_style = point_style
@@ -1082,7 +1083,7 @@ def __init__(self, x_variable: str = None, y_variable: str = None, tooltip: Tool
10821083
self.heatmap = heatmap
10831084
self.heatmap_view = heatmap_view
10841085
self.points_sets = points_sets
1085-
super().__init__(width=width, height=height, type_='scatterplot', name=name)
1086+
super().__init__(width=width, height=height, type_='scatterplot', axis_on=axis_on, name=name)
10861087

10871088

10881089
class ScatterMatrix(Figure):
@@ -1092,7 +1093,8 @@ class ScatterMatrix(Figure):
10921093
_plot_buttons = "MULTIPLOT_BUTTONS"
10931094

10941095
def __init__(self, elements: List[Sample] = None, axes: List[str] = None, point_style: PointStyle = None,
1095-
surface_style: SurfaceStyle = None, width: int = 750, height: int = 400, name: str = ""):
1096+
surface_style: SurfaceStyle = None, width: int = 750, height: int = 400, axis_on: bool = True,
1097+
name: str = ""):
10961098
if elements is None:
10971099
elements = []
10981100
sampled_elements = []
@@ -1112,7 +1114,7 @@ def __init__(self, elements: List[Sample] = None, axes: List[str] = None, point_
11121114
self.surface_style = surface_style
11131115
self.plots = self._build_multiplot()
11141116
self.initial_view_on = True
1115-
super().__init__(width=width, height=height, type_="multiplot", name=name)
1117+
super().__init__(width=width, height=height, type_="multiplot", axis_on=axis_on, name=name)
11161118

11171119
def _build_multiplot(self):
11181120
sample_attributes = self.elements[0].values.keys()
@@ -1299,10 +1301,10 @@ class PrimitiveGroup(Figure):
12991301

13001302
def __init__(self, primitives: List[Union[Contour2D, Arc2D, LineSegment2D, Circle2D,
13011303
Line2D, MultipleLabels, Wire, Point2D]], width: int = 750,
1302-
height: int = 400, attribute_names: List[str] = None, name: str = ''):
1304+
height: int = 400, attribute_names: List[str] = None, axis_on: bool = False, name: str = ''):
13031305
self.primitives = primitives
13041306
self.attribute_names = attribute_names
1305-
super().__init__(width=width, height=height, type_='draw', name=name)
1307+
super().__init__(width=width, height=height, type_='draw', axis_on=axis_on, name=name)
13061308

13071309
def mpl_plot(self, ax=None, equal_aspect=True, **kwargs):
13081310
""" Plots using matplotlib. """
@@ -1360,7 +1362,8 @@ class PrimitiveGroupsContainer(Figure):
13601362

13611363
def __init__(self, primitive_groups: List[PrimitiveGroup], sizes: List[Tuple[float, float]] = None,
13621364
coords: List[Tuple[float, float]] = None, associated_elements: List[int] = None,
1363-
x_variable: str = None, y_variable: str = None, width: int = 750, height: int = 400, name: str = ''):
1365+
x_variable: str = None, y_variable: str = None, width: int = 750, height: int = 400,
1366+
axis_on: bool = True, name: str = ''):
13641367
for i, value in enumerate(primitive_groups):
13651368
if not isinstance(value, PrimitiveGroup):
13661369
primitive_groups[i] = PrimitiveGroup(primitives=value)
@@ -1378,7 +1381,7 @@ def __init__(self, primitive_groups: List[PrimitiveGroup], sizes: List[Tuple[flo
13781381
if y_variable:
13791382
attribute_names.append(y_variable)
13801383
self.association['attribute_names'] = attribute_names
1381-
super().__init__(width=width, height=height, type_='primitivegroupcontainer', name=name)
1384+
super().__init__(width=width, height=height, type_='primitivegroupcontainer', axis_on=axis_on, name=name)
13821385

13831386

13841387
class ParallelPlot(Figure):
@@ -1399,7 +1402,7 @@ class ParallelPlot(Figure):
13991402

14001403
def __init__(self, elements: List[Sample] = None, edge_style: EdgeStyle = None, disposition: str = None,
14011404
axes: List[str] = None, rgbs: List[Tuple[int, int, int]] = None, width: int = 750, height: int = 400,
1402-
name: str = ''):
1405+
axis_on: bool = True, name: str = ''):
14031406
if elements is None:
14041407
elements = []
14051408
sampled_elements = []
@@ -1418,7 +1421,7 @@ def __init__(self, elements: List[Sample] = None, edge_style: EdgeStyle = None,
14181421
self.disposition = disposition
14191422
self.attribute_names = axes
14201423
self.rgbs = rgbs
1421-
super().__init__(width=width, height=height, type_='parallelplot', name=name)
1424+
super().__init__(width=width, height=height, type_='parallelplot', axis_on=axis_on, name=name)
14221425

14231426

14241427
class Histogram(Figure):
@@ -1446,7 +1449,7 @@ class Histogram(Figure):
14461449

14471450
def __init__(self, x_variable: str, elements=None, axis: Axis = None, graduation_nb: float = None,
14481451
edge_style: EdgeStyle = None, surface_style: SurfaceStyle = None, width: int = 750, height: int = 400,
1449-
name: str = ''):
1452+
axis_on: bool = True, name: str = ''):
14501453
if elements is None:
14511454
elements = []
14521455
sampled_elements = []
@@ -1466,7 +1469,7 @@ def __init__(self, x_variable: str, elements=None, axis: Axis = None, graduation
14661469
self.graduation_nb = graduation_nb
14671470
self.edge_style = edge_style
14681471
self.surface_style = surface_style
1469-
super().__init__(width=width, height=height, type_='histogram', name=name)
1472+
super().__init__(width=width, height=height, type_='histogram', axis_on=axis_on, name=name)
14701473

14711474

14721475
class MultiplePlots(Figure):
@@ -1486,7 +1489,8 @@ class MultiplePlots(Figure):
14861489

14871490
def __init__(self, plots: List[PlotDataObject], sizes: List[Window] = None, elements: List[Sample] = None,
14881491
coords: List[Tuple[float, float]] = None, point_families: List[PointFamily] = None,
1489-
initial_view_on: bool = None, width: int = 750, height: int = 400, name: str = ''):
1492+
initial_view_on: bool = None, width: int = 750, height: int = 400, axis_on: bool = True,
1493+
name: str = ''):
14901494
if elements is None:
14911495
elements = []
14921496
sampled_elements = []
@@ -1506,7 +1510,7 @@ def __init__(self, plots: List[PlotDataObject], sizes: List[Window] = None, elem
15061510
self.coords = coords
15071511
self.points_sets = point_families
15081512
self.initial_view_on = initial_view_on
1509-
super().__init__(width=width, height=height, type_='multiplot', name=name)
1513+
super().__init__(width=width, height=height, type_='multiplot', axis_on=axis_on, name=name)
15101514

15111515

15121516
def plot_data_path(local: bool = False, version: str = None):

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export const PG_CONTAINER_PLOT = {
6565
"type_": "text"
6666
}
6767
],
68-
"type_": "primitivegroup"
68+
"type_": "primitivegroup",
69+
"axis_on": false
6970
};
7071

7172
export const EMPTY_MULTIPLOT = {

src/dataInterfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export interface DataInterface {
7474
primitives?: any, //for now, needs a specific interface
7575
tooltip?: any, //for now: tooltip can be Tooltip Object or string,
7676
graduation_nb?: number,
77-
type_?: string
77+
type_?: string,
78+
axis_on?: boolean
7879
}
7980

8081
export interface MultiplotDataInterface {

src/remoteFigure.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class RemoteFigure extends Rect {
7979
this.fixedObjects = new ShapeCollection(this.axes);
8080
this.relativeObjects = new GroupCollection();
8181
this.absoluteObjects = new GroupCollection();
82+
this.setAxisVisibility(data);
8283
}
8384

8485
get scale(): Vertex { return new Vertex(this.relativeMatrix.a, this.relativeMatrix.d)}
@@ -117,6 +118,8 @@ export class RemoteFigure extends Rect {
117118

118119
protected unpackData(data: any): Map<string, any[]> { return RemoteFigure.deserializeData(data) }
119120

121+
protected setAxisVisibility(data: DataInterface): void { if (!data.axis_on) this.toggleAxesVisibility() }
122+
120123
public serializeFeatures(): any {
121124
const elements = [];
122125
for (let i=0; i < this.nSamples; i++) {
@@ -428,8 +431,10 @@ export class RemoteFigure extends Rect {
428431

429432
public togglePoints(): void {}
430433

434+
private toggleAxesVisibility(): void { this.axes.forEach(axis => axis.toggleView()) }
435+
431436
public toggleAxes(): void {
432-
this.axes.forEach(axis => axis.toggleView());
437+
this.toggleAxesVisibility();
433438
this.draw();
434439
}
435440

0 commit comments

Comments
 (0)