use of org.rstudio.core.client.widget.FixedRatioWidget in project rstudio by rstudio.
the class ChunkConsolePage method init.
private void init(ChunkOutputStream stream) {
preview_ = new ChunkConsolePreview();
preview_.addText(stream.getAllConsoleText());
stream_ = stream;
panel_ = new ScrollPanel();
panel_.add(stream);
if (chunkOutputSize_ != ChunkOutputSize.Full) {
content_ = new FixedRatioWidget(panel_, ChunkOutputUi.OUTPUT_ASPECT, ChunkOutputUi.MAX_PLOT_WIDTH);
} else {
panel_.getElement().getStyle().setWidth(100, Unit.PCT);
content_ = panel_;
}
thumbnail_ = new ChunkOutputThumbnail("R Console", "", preview_, ChunkOutputWidget.getEditorColors());
}
use of org.rstudio.core.client.widget.FixedRatioWidget in project rstudio by rstudio.
the class ChunkOutputStream method onEditorThemeChanged.
@Override
public void onEditorThemeChanged(EditorThemeListener.Colors colors) {
themeColors_ = colors;
// apply the style to any frames in the output
for (Widget w : this) {
if (w instanceof ChunkOutputFrame) {
ChunkOutputFrame frame = (ChunkOutputFrame) w;
frame.runAfterRender(afterRender_);
} else if (w instanceof FixedRatioWidget) {
FixedRatioWidget fixedRatioWidget = (FixedRatioWidget) w;
Widget innerWidget = fixedRatioWidget.getWidget();
if (innerWidget instanceof ChunkOutputFrame) {
ChunkOutputFrame frame = (ChunkOutputFrame) innerWidget;
frame.runAfterRender(afterRender_);
}
} else if (w instanceof EditorThemeListener) {
((EditorThemeListener) w).onEditorThemeChanged(colors);
}
}
}
use of org.rstudio.core.client.widget.FixedRatioWidget in project rstudio by rstudio.
the class ChunkOutputStream method showHtmlOutput.
@Override
public void showHtmlOutput(String url, NotebookHtmlMetadata metadata, int ordinal, final Command onRenderComplete) {
// flush any queued errors
initializeOutput(RmdChunkOutputUnit.TYPE_HTML);
flushQueuedErrors();
// persist metadata
metadata_.put(ordinal, metadata);
final boolean knitrFigure = metadata.getSizingPolicyKnitrFigure();
// sizing policy
if (url.indexOf('?') > 0)
url += "&";
else
url += "?";
if (knitrFigure) {
url += "viewer_pane=1";
}
final ChunkOutputFrame frame = new ChunkOutputFrame();
if (chunkOutputSize_ == ChunkOutputSize.Default) {
if (knitrFigure) {
final FixedRatioWidget fixedFrame = new FixedRatioWidget(frame, ChunkOutputUi.OUTPUT_ASPECT, ChunkOutputUi.MAX_HTMLWIDGET_WIDTH);
addWithOrdinal(fixedFrame, ordinal);
} else {
// reduce size of html widget as much as possible and add scroll,
// once it loads, we will adjust the height appropriately.
frame.getElement().getStyle().setHeight(25, Unit.PX);
frame.getElement().getStyle().setOverflow(Overflow.SCROLL);
frame.getElement().getStyle().setWidth(100, Unit.PCT);
addWithOrdinal(frame, ordinal);
}
} else if (chunkOutputSize_ == ChunkOutputSize.Full) {
frame.getElement().getStyle().setPosition(Position.ABSOLUTE);
frame.getElement().getStyle().setWidth(100, Unit.PCT);
frame.getElement().getStyle().setHeight(100, Unit.PCT);
addWithOrdinal(frame, ordinal);
}
Element body = frame.getDocument().getBody();
Style bodyStyle = body.getStyle();
bodyStyle.setPadding(0, Unit.PX);
bodyStyle.setMargin(0, Unit.PX);
frame.loadUrlDelayed(url, 250, new Command() {
@Override
public void execute() {
onRenderComplete.execute();
if (!knitrFigure) {
int contentHeight = frame.getWindow().getDocument().getBody().getOffsetHeight();
frame.getElement().getStyle().setHeight(contentHeight, Unit.PX);
frame.getElement().getStyle().setOverflow(Overflow.HIDDEN);
frame.getWindow().getDocument().getBody().getStyle().setOverflow(Overflow.HIDDEN);
}
onHeightChanged();
}
;
});
themeColors_ = ChunkOutputWidget.getEditorColors();
afterRender_ = new Command() {
@Override
public void execute() {
if (themeColors_ != null) {
Element body = frame.getDocument().getBody();
Style bodyStyle = body.getStyle();
bodyStyle.setColor(themeColors_.foreground);
}
}
};
frame.runAfterRender(afterRender_);
}
use of org.rstudio.core.client.widget.FixedRatioWidget in project rstudio by rstudio.
the class ChunkOutputStream method extractPages.
public List<ChunkOutputPage> extractPages() {
// flush any errors so they are properly accounted for
flushQueuedErrors();
List<ChunkOutputPage> pages = new ArrayList<ChunkOutputPage>();
List<Widget> removed = new ArrayList<Widget>();
for (Widget w : this) {
// extract ordinal and metadata
JavaScriptObject metadata = null;
String ord = w.getElement().getAttribute(ORDINAL_ATTRIBUTE);
int ordinal = 0;
if (!StringUtil.isNullOrEmpty(ord))
ordinal = StringUtil.parseInt(ord, 0);
if (metadata_.containsKey(ordinal))
metadata = metadata_.get(ordinal);
if (w instanceof ChunkDataWidget) {
ChunkDataWidget widget = (ChunkDataWidget) w;
ChunkDataPage data = new ChunkDataPage(widget, (NotebookFrameMetadata) metadata.cast(), ordinal);
pages.add(data);
removed.add(w);
continue;
} else if (w instanceof ChunkOrdinalWidget) {
pages.add(new ChunkOrdinalPage(ordinal));
removed.add(w);
continue;
}
// extract the inner element if this is a fixed-ratio widget (or just
// use raw if it's not)
Widget inner = w;
if (w instanceof FixedRatioWidget)
inner = ((FixedRatioWidget) w).getWidget();
if (inner instanceof ChunkPlotWidget) {
ChunkPlotWidget plot = (ChunkPlotWidget) inner;
ChunkPlotPage page = new ChunkPlotPage(plot.plotUrl(), plot.getMetadata(), ordinal, null, chunkOutputSize_);
pages.add(page);
removed.add(w);
} else if (inner instanceof ChunkOutputFrame) {
ChunkOutputFrame frame = (ChunkOutputFrame) inner;
ChunkHtmlPage html = new ChunkHtmlPage(frame.getUrl(), (NotebookHtmlMetadata) metadata.cast(), ordinal, null, chunkOutputSize_);
// cancel any pending page load
frame.cancelPendingLoad();
pages.add(html);
removed.add(w);
}
}
for (Widget r : removed) this.remove(r);
return pages;
}
Aggregations