Skip to content

Add ModeBarButtons enum and extend constructors to support modeBarBut… #16

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
34 changes: 29 additions & 5 deletions lib/plotly.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ import 'dart:html';
import 'dart:js';
import 'dart:async';

/// Mode bar buttons
///
/// According to plotly.js/src/components/modebar/buttons.js
enum ModeBarButtons {
toImage,
sendDataToCloud,
zoom2d,
pan2d,
select2d,
lasso2d,
zoomIn2d,
zoomOut2d,
autoScale2d,
resetScale2d,
hoverClosestCartesian,
hoverCompareCartesian
}

/// Interactive scientific chart.
class Plot {
final JsObject _Plotly;
Expand All @@ -20,7 +38,8 @@ class Plot {
String linkText,
bool displaylogo: false,
bool displayModeBar,
bool scrollZoom})
bool scrollZoom,
List<ModeBarButtons> modeBarButtonsToRemove})
: _Plotly = context['Plotly'],
_container = container,
_proxy = new JsObject.fromBrowserObject(container) {
Expand All @@ -36,6 +55,7 @@ class Plot {
if (displaylogo != null) opts['displaylogo'] = displaylogo;
if (displayModeBar != null) opts['displayModeBar'] = displayModeBar;
if (scrollZoom != null) opts['scrollZoom'] = scrollZoom;
if (modeBarButtonsToRemove != null) opts['modeBarButtonsToRemove'] = modeBarButtonsToRemove.map((button) => button.toString().split('.')[1]);
var _opts = new JsObject.jsify(opts);
_Plotly.callMethod('newPlot', [_container, _data, _layout, _opts]);
}
Expand All @@ -50,15 +70,17 @@ class Plot {
String linkText,
bool displaylogo: false,
bool displayModeBar,
bool scrollZoom}) {
bool scrollZoom,
List<ModeBarButtons> modeBarButtonsToRemove}) {
var elem = document.getElementById(id);
return new Plot(elem, data, layout,
showLink: showLink,
staticPlot: staticPlot,
linkText: linkText,
displaylogo: displaylogo,
displayModeBar: displayModeBar,
scrollZoom: scrollZoom);
scrollZoom: scrollZoom,
modeBarButtonsToRemove: modeBarButtonsToRemove);
}

/// Creates a new plot in an empty `<div>` element with the given [selectors].
Expand All @@ -72,15 +94,17 @@ class Plot {
String linkText,
bool displaylogo: false,
bool displayModeBar,
bool scrollZoom}) {
bool scrollZoom,
List<ModeBarButtons> modeBarButtonsToRemove}) {
var elem = document.querySelector(selectors);
return new Plot(elem, data, layout,
showLink: showLink,
staticPlot: staticPlot,
linkText: linkText,
displaylogo: displaylogo,
displayModeBar: displayModeBar,
scrollZoom: scrollZoom);
scrollZoom: scrollZoom,
modeBarButtonsToRemove: modeBarButtonsToRemove);
}

get data => _proxy['data'];
Expand Down