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

Forward port #1523 Fix pWidget accessor in the case of ipywidgets 7 #1524

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions js/src/Figure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Scale, ScaleModel } from 'bqscales';

import * as popperreference from './PopperReference';
import popper from 'popper.js';
import { applyAttrs, applyStyles } from './utils';
import { applyAttrs, applyStyles, getLuminoWidget } from './utils';
import { AxisModel } from './AxisModel';
import { Mark } from './Mark';
import { MarkModel } from './MarkModel';
Expand Down Expand Up @@ -735,6 +735,7 @@ export class Figure extends DOMWidgetView {
this.trigger('margin_updated');
}

// Phosphor shims
update_plotarea_dimensions() {
this.plotarea_width = this.width - this.margin.left - this.margin.right;
this.plotarea_height = this.height - this.margin.top - this.margin.bottom;
Expand All @@ -756,7 +757,7 @@ export class Figure extends DOMWidgetView {
case 'resize':
case 'after-show':
case 'after-attach':
if (this.luminoWidget.isVisible) {
if (getLuminoWidget(this).isVisible) {
this.debouncedRelayout();
}
break;
Expand Down
8 changes: 4 additions & 4 deletions js/src/Mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { MessageLoop } from '@lumino/messaging';

import { Widget } from '@lumino/widgets';

import { d3GetEvent } from './utils';
import { d3GetEvent, getLuminoWidget } from './utils';
import * as _ from 'underscore';
import { MarkModel } from './MarkModel';
import { Figure } from './Figure';
Expand Down Expand Up @@ -342,7 +342,7 @@ export abstract class Mark extends widgets.WidgetView {
null
);
MessageLoop.sendMessage(
this.tooltip_view.luminoWidget,
getLuminoWidget(this.tooltip_view),
Widget.Msg.AfterShow
);
this.parent.popper.enableEventListeners();
Expand Down Expand Up @@ -392,9 +392,9 @@ export abstract class Mark extends widgets.WidgetView {
this.create_child_view(tooltip_model).then((view) => {
this.tooltip_view = view;

MessageLoop.sendMessage(view.luminoWidget, Widget.Msg.BeforeAttach);
MessageLoop.sendMessage(getLuminoWidget(view), Widget.Msg.BeforeAttach);
this.tooltip_div.node().appendChild(view.el);
MessageLoop.sendMessage(view.luminoWidget, Widget.Msg.AfterAttach);
MessageLoop.sendMessage(getLuminoWidget(view), Widget.Msg.AfterAttach);
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions js/src/MarketMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { MarketMapModel } from './MarketMapModel';
import { Tooltip } from './Tooltip';
import * as popperreference from './PopperReference';
import popper from 'popper.js';
import { applyAttrs, applyStyles } from './utils';
import { applyAttrs, applyStyles, getLuminoWidget } from './utils';

export class MarketMap extends Figure {
protected renderImpl() {
Expand Down Expand Up @@ -841,9 +841,9 @@ export class MarketMap extends Figure {
tooltip_widget_creation_promise.then((view) => {
that.tooltip_view = view as Tooltip;

MessageLoop.sendMessage(view.luminoWidget, Widget.Msg.BeforeAttach);
MessageLoop.sendMessage(getLuminoWidget(view), Widget.Msg.BeforeAttach);
that.tooltip_div.node().appendChild(view.el);
MessageLoop.sendMessage(view.luminoWidget, Widget.Msg.AfterAttach);
MessageLoop.sendMessage(getLuminoWidget(view), Widget.Msg.AfterAttach);
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

import { DOMWidgetView } from '@jupyter-widgets/base';
import * as d3 from 'd3';
// var d3 =Object.assign({}, require("d3-array"), require("d3-scale"));
import isTypedArray from 'is-typedarray';
Expand Down Expand Up @@ -118,3 +119,8 @@ export function d3GetEvent() {
// leading to a null event, for now we can use window.event as fallback.
return require('d3-selection').event || window.event;
}

// Phosphor shim for ipywidgets 7 support
export function getLuminoWidget(ipywidget: DOMWidgetView) {
return ipywidget.pWidget ? ipywidget.pWidget : ipywidget.luminoWidget;
}