Skip to content

Commit e5d5db8

Browse files
authored
Merge pull request #1011 from martinRenou/scatter_opacities
Scatter: default_opacities -> opacities
2 parents 260ee26 + e05b9fa commit e5d5db8

12 files changed

Lines changed: 70 additions & 59 deletions

File tree

bqplot/marks.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class _ScatterBase(Mark):
522522
'opacity': {'dimension': 'opacity'},
523523
'rotation': {'dimension': 'rotation'}
524524
}).tag(sync=True)
525-
default_opacities = Array([1.0])\
525+
opacities = Array([1.0])\
526526
.tag(sync=True, display_name='Opacities', **array_serialization)\
527527
.valid(array_squeeze, array_dimension_bounds(1, 1))
528528
hovered_style = Dict().tag(sync=True)
@@ -592,7 +592,7 @@ class Scatter(_ScatterBase):
592592
Stroke color of the marker
593593
stroke_width: Float (default: 1.5)
594594
Stroke width of the marker
595-
default_opacities: list of floats (default: [1.0])
595+
opacities: list of floats (default: [1.0])
596596
Default opacities of the markers. If the list is shorter than
597597
the number
598598
of points, the opacities are reused.
@@ -701,6 +701,16 @@ def default_colors(self, value):
701701
DeprecationWarning)
702702
self.colors = value
703703

704+
@property
705+
def default_opacities(self):
706+
return self.opacities
707+
708+
@default_opacities.setter
709+
def default_opacities(self, value):
710+
warn("default_opacities is deprecated, use opacities instead.",
711+
DeprecationWarning)
712+
self.opacities = value
713+
704714
stroke = Color(None, allow_none=True).tag(sync=True,
705715
display_name='Stroke color')
706716
stroke_width = Float(1.5).tag(sync=True, display_name='Stroke width')

examples/Applications/Feature_Vector_Distribution-Iris-Digits.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
" y=group[1][feature2].values,\n",
135135
" names=names,\n",
136136
" display_names=False,\n",
137-
" default_opacities=[0.5],\n",
137+
" opacities=[0.5],\n",
138138
" default_size=30,\n",
139139
" scales={'x': sc_x, 'y': sc_y}, \n",
140140
" colors=[colors[index]],\n",
@@ -394,7 +394,7 @@
394394
"name": "python",
395395
"nbconvert_exporter": "python",
396396
"pygments_lexer": "ipython3",
397-
"version": "3.7.6"
397+
"version": "3.8.2"
398398
},
399399
"toc": {
400400
"nav_menu": {},

examples/Marks/Object Model/Scatter.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"metadata": {},
121121
"outputs": [],
122122
"source": [
123-
"scatt.default_opacities = [0.3, 0.5, 1.]"
123+
"scatt.opacities = [0.3, 0.5, 1.]"
124124
]
125125
},
126126
{
@@ -343,7 +343,7 @@
343343
"outputs": [],
344344
"source": [
345345
"## Changing the opacity of the scatter\n",
346-
"scatter2.default_opacities = [0.5, 0.3, 0.1]"
346+
"scatter2.opacities = [0.5, 0.3, 0.1]"
347347
]
348348
},
349349
{
@@ -363,7 +363,7 @@
363363
"outputs": [],
364364
"source": [
365365
"## Resetting the opacity and setting the opacity according to the date\n",
366-
"scatter2.default_opacities = [1.0]"
366+
"scatter2.opacities = [1.0]"
367367
]
368368
},
369369
{
@@ -739,7 +739,7 @@
739739
"name": "python",
740740
"nbconvert_exporter": "python",
741741
"pygments_lexer": "ipython3",
742-
"version": "3.7.6"
742+
"version": "3.8.2"
743743
}
744744
},
745745
"nbformat": 4,

examples/Marks/Object Model/ScatterMega.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
"metadata": {},
368368
"outputs": [],
369369
"source": [
370-
"scatt.default_opacities = [0.3, 0.5, 1.]"
370+
"scatt.opacities = [0.3, 0.5, 1.]"
371371
]
372372
},
373373
{
@@ -528,7 +528,7 @@
528528
"outputs": [],
529529
"source": [
530530
"## Changing the opacity of the scatter\n",
531-
"scatter2.default_opacities = [0.5, 0.3, 0.1]"
531+
"scatter2.opacities = [0.5, 0.3, 0.1]"
532532
]
533533
},
534534
{
@@ -538,7 +538,7 @@
538538
"outputs": [],
539539
"source": [
540540
"## Resetting the opacity and setting the opacity according to the date\n",
541-
"scatter2.default_opacities = [1.0]"
541+
"scatter2.opacities = [1.0]"
542542
]
543543
},
544544
{
@@ -612,7 +612,7 @@
612612
"name": "python",
613613
"nbconvert_exporter": "python",
614614
"pygments_lexer": "ipython3",
615-
"version": "3.7.6"
615+
"version": "3.8.2"
616616
}
617617
},
618618
"nbformat": 4,

examples/Marks/Pyplot/Scatter.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"metadata": {},
113113
"outputs": [],
114114
"source": [
115-
"scatt.default_opacities = [0.3, 0.5, 1.]"
115+
"scatt.opacities = [0.3, 0.5, 1.]"
116116
]
117117
},
118118
{
@@ -315,7 +315,7 @@
315315
"outputs": [],
316316
"source": [
317317
"## Changing the opacity of the scatter\n",
318-
"scatter2.default_opacities = [0.5, 0.3, 0.1]"
318+
"scatter2.opacities = [0.5, 0.3, 0.1]"
319319
]
320320
},
321321
{
@@ -335,7 +335,7 @@
335335
"outputs": [],
336336
"source": [
337337
"## Resetting the opacity and setting the opacity according to the date\n",
338-
"scatter2.default_opacities = [1.0]"
338+
"scatter2.opacities = [1.0]"
339339
]
340340
},
341341
{
@@ -641,7 +641,7 @@
641641
"name": "python",
642642
"nbconvert_exporter": "python",
643643
"pygments_lexer": "ipython3",
644-
"version": "3.7.6"
644+
"version": "3.8.2"
645645
}
646646
},
647647
"nbformat": 4,

js/src/Label.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export class Label extends ScatterBase {
2828
"rotate_angle"], this.update_position, this);
2929
}
3030

31-
update_default_opacities(animate) {
31+
update_opacities(animate) {
3232
if (!this.model.dirty) {
3333
const animation_duration = animate === true ? this.parent.model.get("animation_duration") : 0;
3434

3535
// update opacity scale range?
3636
const that = this;
3737
this.d3el.selectAll(".label")
38-
.transition("update_default_opacities")
38+
.transition("update_opacities")
3939
.duration(animation_duration)
4040
.style("opacity", function(d, i) {
4141
return that.get_element_opacity(d, i);
@@ -69,7 +69,7 @@ export class Label extends ScatterBase {
6969

7070
this.update_text();
7171
this.update_style();
72-
this.update_default_opacities(true);
72+
this.update_opacities(true);
7373
}
7474

7575
update_text() {

js/src/Scatter.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Scatter extends ScatterBase {
3737
this.listenTo(this.model, "change:colors", this.update_colors);
3838
this.listenTo(this.model, "change:stroke", this.update_stroke);
3939
this.listenTo(this.model, "change:stroke_width", this.update_stroke_width);
40-
this.listenTo(this.model, "change:default_opacities", this.update_default_opacities);
40+
this.listenTo(this.model, "change:opacities", this.update_opacities);
4141
this.listenTo(this.model, "change:default_skew", this.update_default_skew);
4242
this.listenTo(this.model, "change:marker", this.update_marker);
4343
this.listenTo(this.model, "change:default_size", this.update_default_size);
@@ -108,26 +108,26 @@ export class Scatter extends ScatterBase {
108108
}
109109
}
110110

111-
update_default_opacities(animate) {
111+
update_opacities(animate) {
112112
if (!this.model.dirty) {
113-
const default_opacities = this.model.get("default_opacities");
113+
const opacities = this.model.get("opacities");
114114
const colors = this.model.get("colors");
115115
const len = colors.length;
116-
const len_opac = default_opacities.length;
116+
const len_opac = opacities.length;
117117
const animation_duration = animate === true ? this.parent.model.get("animation_duration") : 0;
118118

119119
// update opacity scale range?
120120
const that = this;
121121
this.d3el.selectAll(".dot")
122-
.transition("update_default_opacities")
122+
.transition("update_opacities")
123123
.duration(animation_duration)
124124
.style("opacity", function(d, i) {
125125
return that.get_element_opacity(d, i);
126126
});
127127
if (this.legend_el) {
128128
this.legend_el.select("path")
129129
.style("opacity", function(d, i) {
130-
return default_opacities[i % len_opac];
130+
return opacities[i % len_opac];
131131
})
132132
.style("fill", function(d, i) {
133133
return colors[i % len];
@@ -271,7 +271,8 @@ export class Scatter extends ScatterBase {
271271
that = this;
272272
elements
273273
.style("fill", fill ? this.get_mark_color.bind(this) : "none")
274-
.style("stroke", stroke ? stroke: this.get_mark_color.bind(this)).style("opacity", function(d, i) {
274+
.style("stroke", stroke ? stroke: this.get_mark_color.bind(this))
275+
.style("opacity", function(d, i) {
275276
return that.get_element_opacity(d, i);
276277
}).style("stroke-width", stroke_width);
277278
}

js/src/ScatterBase.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export abstract class ScatterBase extends Mark {
156156
if (opacity_scale) {
157157
this.listenTo(opacity_scale, "domain_changed", () => {
158158
const animate = true;
159-
this.update_default_opacities(animate);
159+
this.update_opacities(animate);
160160
});
161161
}
162162
if (skew_scale) {
@@ -212,12 +212,12 @@ export abstract class ScatterBase extends Mark {
212212

213213
get_element_opacity(data, index) {
214214
const opacity_scale = this.scales.opacity;
215-
const default_opacities = this.model.get("default_opacities");
216-
const len = default_opacities.length;
215+
const opacities = this.model.get("opacities");
216+
const len = opacities.length;
217217
if(opacity_scale && data.opacity !== undefined) {
218218
return opacity_scale.scale(data.opacity);
219219
}
220-
return default_opacities[index % len];
220+
return opacities[index % len];
221221
}
222222

223223
get_element_skew(data) {
@@ -682,7 +682,7 @@ export abstract class ScatterBase extends Mark {
682682
}
683683

684684
abstract color_scale_updated(animate?);
685-
abstract update_default_opacities(animate?);
685+
abstract update_opacities(animate?);
686686
abstract update_default_skew(animate?);
687687
abstract update_default_size(animate?);
688688

js/src/ScatterBaseModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ScatterBaseModel extends MarkModel {
4343
hovered_style: {},
4444
unhovered_style: {},
4545
colors: ['steelblue'],
46-
default_opacities: [1.0],
46+
opacities: [1.0],
4747
enable_move: false,
4848
enable_delete: false,
4949
restrict_x: false,
@@ -140,6 +140,6 @@ export class ScatterBaseModel extends MarkModel {
140140
opacity: serialize.array_or_json,
141141
size: serialize.array_or_json,
142142
rotation: serialize.array_or_json,
143-
default_opacities: serialize.array_or_json
143+
opacities: serialize.array_or_json
144144
}
145145
}

js/src/ScatterGL.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ export class ScatterGL extends Mark {
319319
}
320320

321321
get_opacity_attribute_parameters() {
322-
let default_opacities = this.model.get('default_opacities') || [1.];
322+
let opacities = this.model.get('opacities') || [1.];
323323

324-
if (default_opacities.length == 0) default_opacities = [1.];
324+
if (opacities.length == 0) opacities = [1.];
325325

326326
if (this.model.get('opacity')) {
327327
const opacity = this.model.get('opacity');
@@ -333,7 +333,7 @@ export class ScatterGL extends Mark {
333333

334334
_.each(_.range(this.markers_number - opacity.length), (i) => {
335335
i = i + opacity.length;
336-
array[i] = default_opacities[i % default_opacities.length];
336+
array[i] = opacities[i % opacities.length];
337337
});
338338
}
339339
else {
@@ -344,14 +344,14 @@ export class ScatterGL extends Mark {
344344
} else {
345345
let array: Float32Array;
346346
let mesh_per_attribute: number;
347-
if (default_opacities.length == 1) {
348-
array = to_float_array(default_opacities);
347+
if (opacities.length == 1) {
348+
array = to_float_array(opacities);
349349
mesh_per_attribute = this.markers_number;
350350
} else {
351351
array = to_float_array(this.markers_number);
352352
mesh_per_attribute = 1;
353353
_.each(_.range(this.markers_number), (i) => {
354-
array[i] = default_opacities[i % default_opacities.length];
354+
array[i] = opacities[i % opacities.length];
355355
});
356356
}
357357

@@ -497,7 +497,7 @@ export class ScatterGL extends Mark {
497497
this.listenTo(this.model, "change:y", this.update_y);
498498

499499
this.listenTo(this.model, "change:color change:colors change:unselected_style", this.update_color);
500-
this.listenTo(this.model, "change:opacity change:default_opacities", this.update_opacity);
500+
this.listenTo(this.model, "change:opacity change:opacities", this.update_opacity);
501501
this.listenTo(this.model, "change:size change:default_size", this.update_size);
502502
this.listenTo(this.model, "change:rotation", this.update_rotation);
503503
this.listenTo(this.model, "change:selected", this.update_selected);

0 commit comments

Comments
 (0)