blob: feecc518b87bf99081a7c7903cc7a0c37e0a1b3d [file] [log] [blame]
/**
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*
* This copyright notice shows up in the generated Java code
*/
package org.eclipse.osbp.xtext.chart.jvmmodel;
import com.vaadin.data.Property;
import com.vaadin.server.FileDownloader;
import com.vaadin.server.Page;
import com.vaadin.server.StreamResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.JavaScriptFunction;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.UI;
import elemental.json.JsonArray;
import elemental.json.JsonException;
import elemental.json.JsonObject;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.UUID;
import java.util.concurrent.Executors;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import mondrian.olap.Member;
import org.dussan.vaadin.dcharts.DCharts;
import org.dussan.vaadin.dcharts.DownloadButtonLocation;
import org.dussan.vaadin.dcharts.base.elements.Trendline;
import org.dussan.vaadin.dcharts.base.elements.XYaxis;
import org.dussan.vaadin.dcharts.base.elements.XYseries;
import org.dussan.vaadin.dcharts.data.DataSeries;
import org.dussan.vaadin.dcharts.data.Ticks;
import org.dussan.vaadin.dcharts.metadata.LegendPlacements;
import org.dussan.vaadin.dcharts.metadata.PyramidSides;
import org.dussan.vaadin.dcharts.metadata.SeriesToggles;
import org.dussan.vaadin.dcharts.metadata.TooltipAxes;
import org.dussan.vaadin.dcharts.metadata.XYaxes;
import org.dussan.vaadin.dcharts.metadata.Xaxes;
import org.dussan.vaadin.dcharts.metadata.Yaxes;
import org.dussan.vaadin.dcharts.metadata.directions.BarDirections;
import org.dussan.vaadin.dcharts.metadata.locations.TooltipLocations;
import org.dussan.vaadin.dcharts.metadata.renderers.AxisRenderers;
import org.dussan.vaadin.dcharts.metadata.renderers.SeriesRenderers;
import org.dussan.vaadin.dcharts.options.Axes;
import org.dussan.vaadin.dcharts.options.AxesDefaults;
import org.dussan.vaadin.dcharts.options.Cursor;
import org.dussan.vaadin.dcharts.options.Highlighter;
import org.dussan.vaadin.dcharts.options.Legend;
import org.dussan.vaadin.dcharts.options.Options;
import org.dussan.vaadin.dcharts.options.Series;
import org.dussan.vaadin.dcharts.options.SeriesDefaults;
import org.dussan.vaadin.dcharts.options.Title;
import org.dussan.vaadin.dcharts.renderers.axis.LinearAxisRenderer;
import org.dussan.vaadin.dcharts.renderers.legend.EnhancedLegendRenderer;
import org.dussan.vaadin.dcharts.renderers.series.BarRenderer;
import org.dussan.vaadin.dcharts.renderers.series.BubbleRenderer;
import org.dussan.vaadin.dcharts.renderers.series.DonutRenderer;
import org.dussan.vaadin.dcharts.renderers.series.MeterGaugeRenderer;
import org.dussan.vaadin.dcharts.renderers.series.PieRenderer;
import org.dussan.vaadin.dcharts.renderers.series.PyramidRenderer;
import org.dussan.vaadin.dcharts.renderers.tick.AxisTickRenderer;
import org.dussan.vaadin.dcharts.renderers.tick.CanvasAxisTickRenderer;
import org.eclipse.e4.core.di.extensions.EventUtils;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.impl.UIElementImpl;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.osbp.eventbroker.EventBrokerMsg;
import org.eclipse.osbp.runtime.common.event.EventDispatcherEvent;
import org.eclipse.osbp.ui.api.datamart.DatamartFilter;
import org.eclipse.osbp.ui.api.datamart.IDatamartFilterGenerator;
import org.eclipse.osbp.utils.vaadin.ViewLayoutManager;
import org.eclipse.osbp.xtext.action.ChartActionEnum;
import org.eclipse.osbp.xtext.basic.generator.BasicDslGeneratorUtils;
import org.eclipse.osbp.xtext.chart.Chart;
import org.eclipse.osbp.xtext.chart.ChartModel;
import org.eclipse.osbp.xtext.chart.ChartOption;
import org.eclipse.osbp.xtext.chart.ChartPackage;
import org.eclipse.osbp.xtext.chart.ChartTree;
import org.eclipse.osbp.xtext.chart.jvmmodel.D3JsJavaUtil;
import org.eclipse.osbp.xtext.datamart.common.DatamartFilterGenerator;
import org.eclipse.osbp.xtext.datamart.common.olap.CellSetToD3JsonConverter;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedAxis;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedCell;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedHierarchy;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedLevel;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedMember;
import org.eclipse.osbp.xtext.datamart.common.olap.DerivedPosition;
import org.eclipse.osbp.xtext.i18n.I18NModelGenerator;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.common.types.JvmDeclaredType;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.xbase.compiler.GeneratorConfig;
import org.eclipse.xtext.xbase.compiler.ImportManager;
import org.eclipse.xtext.xbase.compiler.output.TreeAppendable;
import org.eclipse.xtext.xbase.lib.Extension;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
@SuppressWarnings("all")
public class ChartModelGenerator extends I18NModelGenerator {
@Inject
@Extension
private IQualifiedNameProvider _iQualifiedNameProvider;
@Inject
@Extension
private D3JsJavaUtil _d3JsJavaUtil;
@Inject
@Extension
private BasicDslGeneratorUtils _basicDslGeneratorUtils;
@Override
public TreeAppendable createAppendable(final EObject context, final ImportManager importManager, final GeneratorConfig config) {
TreeAppendable _xblockexpression = null;
{
this.setBuilder(context.eResource());
importManager.addImportFor(this._typeReferenceBuilder.typeRef(HashMap.class, this._typeReferenceBuilder.typeRef(String.class), this._typeReferenceBuilder.typeRef(String.class)).getType());
importManager.addImportFor(this._typeReferenceBuilder.typeRef(Map.class, this._typeReferenceBuilder.typeRef(String.class), this._typeReferenceBuilder.typeRef(String.class)).getType());
importManager.addImportFor(this._typeReferenceBuilder.typeRef(Collection.class, this._typeReferenceBuilder.typeRef(String.class)).getType());
this._basicDslGeneratorUtils.addImportFor(this, importManager, this._typeReferenceBuilder, Property.ValueChangeListener.class, DCharts.class, Label.class, List.class, ArrayList.class, Page.class, Page.Styles.class, DerivedAxis.class, DerivedCell.class, DerivedPosition.class, DerivedMember.class, HorizontalLayout.class, TabSheet.class, Series.class, XYseries.class, Ticks.class, DataSeries.class, SeriesDefaults.class, SeriesRenderers.class, CanvasAxisTickRenderer.class, DonutRenderer.class, PieRenderer.class, BubbleRenderer.class, BarRenderer.class, BarDirections.class, MeterGaugeRenderer.class, PyramidRenderer.class, PyramidSides.class, Trendline.class, Cursor.class, Legend.class, LegendPlacements.class, EnhancedLegendRenderer.class, SeriesToggles.class, Highlighter.class, Title.class, TooltipLocations.class, TooltipAxes.class, Axes.class, XYaxes.class, XYaxis.class, Xaxes.class, Yaxes.class, AxisTickRenderer.class, AxisRenderers.class, LinearAxisRenderer.class, AxesDefaults.class, DownloadButtonLocation.class, Options.class, DerivedHierarchy.class, DerivedLevel.class, CellSetToD3JsonConverter.class, Date.class, JavaScriptFunction.class, JsonArray.class, JsonObject.class, JsonException.class, EventHandler.class, Event.class, EventUtils.class, EventBrokerMsg.class, Executors.class, Notification.class, EObject.class, UIElementImpl.class, UiPackageImpl.class, MUIElement.class, MPartStack.class, UI.class, ResourceBundle.class, Locale.class, DatamartFilterGenerator.class, ViewLayoutManager.class, IDatamartFilterGenerator.FilterChangeListener.class, EventDispatcherEvent.class, EventDispatcherEvent.EventDispatcherDataTag.class, EventDispatcherEvent.EventDispatcherCommand.class, DatamartFilter.class, Member.MemberType.class, Panel.class, MPerspective.class, ChartActionEnum.class, UUID.class, StreamResource.class, MToolBarElement.class, Button.class, FileDownloader.class, StreamResource.StreamSource.class, ByteArrayOutputStream.class, ImageIO.class, ByteArrayInputStream.class, InputStream.class);
_xblockexpression = super.createAppendable(context, importManager, config);
}
return _xblockexpression;
}
@Override
public void doGenerate(final Resource input, final IFileSystemAccess fsa) {
super.addTranslatables("download");
super.doGenerate(input, fsa);
EList<EObject> _contents = input.getContents();
for (final EObject obj : _contents) {
this.internalDoGenerate(obj, fsa);
}
}
protected void _internalDoGenerate(final ChartModel chartModel, final IFileSystemAccess fsa) {
EList<ChartPackage> _packages = chartModel.getPackages();
for (final ChartPackage pkg : _packages) {
EList<Chart> _charts = pkg.getCharts();
for (final Chart chart : _charts) {
ChartOption _charttype = chart.getCharttype();
if ((_charttype instanceof ChartTree)) {
String pckgName = this._iQualifiedNameProvider.getFullyQualifiedName(pkg).toString();
StringBuilder strBuilder = new StringBuilder();
String pckgNamePath = pckgName.replaceAll("\\.", "/");
StringConcatenation _builder = new StringConcatenation();
_builder.append(pckgNamePath);
_builder.append("/");
String _createChartJsFilename = this._d3JsJavaUtil.createChartJsFilename(chart);
_builder.append(_createChartJsFilename);
String propOutputFile = _builder.toString();
this.generateJsFile(chart, strBuilder);
int _length = strBuilder.length();
boolean _greaterThan = (_length > 0);
if (_greaterThan) {
fsa.generateFile(propOutputFile, strBuilder);
}
}
}
}
}
public void generateJsFile(final Chart chart, final StringBuilder strBuilder) {
String chartFilePath = this._d3JsJavaUtil.createfullyQualifiedChartFilename(chart).replaceAll("\\.", "_");
ChartOption _charttype = chart.getCharttype();
if ((_charttype instanceof ChartTree)) {
ChartOption _charttype_1 = chart.getCharttype();
ChartTree chartTree = ((ChartTree) _charttype_1);
boolean _isMap = chartTree.isMap();
if (_isMap) {
this.generateTreeMapJsFile(strBuilder, chartFilePath);
} else {
boolean _isCollapsible = chartTree.isCollapsible();
if (_isCollapsible) {
this.generateCollTreeJsFile(strBuilder, chartFilePath);
}
}
}
}
public void generateTreeMapJsFile(final StringBuilder strBuilder, final String chartJavaFileName) {
StringConcatenation _builder = new StringConcatenation();
_builder.append(chartJavaFileName);
_builder.append(" = function() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("var margin = {");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("top: 40,");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("right: 10,");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("bottom: 10,");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("left: 10");
_builder.newLine();
_builder.append("\t\t");
_builder.append("},");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("width = 960 - margin.left - margin.right,");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("height = 500 - margin.top - margin.bottom;");
_builder.newLine();
_builder.newLine();
_builder.append("\t\t");
_builder.append("var color = d3.scale.category20c();");
_builder.newLine();
_builder.newLine();
_builder.append("\t\t");
_builder.append("function position() {");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("this.style(\"left\", function (d) {");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("return d.x + \"px\";");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("})");
_builder.newLine();
_builder.append("\t\t ");
_builder.append(".style(\"top\", function (d) {");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("return d.y + \"px\";");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("})");
_builder.newLine();
_builder.append("\t\t ");
_builder.append(".style(\"width\", function (d) {");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("return Math.max(0, d.dx - 1) + \"px\";");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("})");
_builder.newLine();
_builder.append("\t\t ");
_builder.append(".style(\"height\", function (d) {");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("return Math.max(0, d.dy - 1) + \"px\";");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("});");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t\t");
_builder.append("var cxD3TreeMapJsHTMLRootComponent = this.getElement();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("var cxD3TreeMapJsComponentHtmlTagId = this.getState().htmlTagId;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("var checked = \"\";");
_builder.newLine();
_builder.append("\t\t");
_builder.append("var connector = this;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("var dataColumn = \"\";");
_builder.newLine();
_builder.newLine();
_builder.append("\t\t");
_builder.append("var preValueLabel = \"\";");
_builder.newLine();
_builder.newLine();
_builder.append("\t\t");
_builder.append("for (var i=0;i < this.getState().dataColumnList.length;i++) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("if (i == 0){");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("checked = \" checked\";");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("preValueLabel = this.getState().dataColumnList[0];");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("} else {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("checked = \"\";");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("dataColumn = dataColumn + \"\\t<label><input id=\\\"\"+this.getState().htmlTagId+\"_input\\\" type=\\\"radio\\\" name=\\\"mode\\\" value=\\\"\"+ this.getState().dataColumnList[i] + \"\\\"\" + checked + \"> \"+ this.getState().dataColumnList[i] + \"</label>\\n\";");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("var treemap = d3.layout.treemap()");
_builder.newLine();
_builder.append("\t\t");
_builder.append(".size([width, height])");
_builder.newLine();
_builder.append("\t\t");
_builder.append(".sticky(true)");
_builder.newLine();
_builder.append("\t\t");
_builder.append(".value(function (d) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return eval(\"d.\" + preValueLabel);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("});");
_builder.newLine();
_builder.append("//\t\talert(\"dataColumn: \" + dataColumn);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cxD3TreeMapJsHTMLRootComponent.innerHTML = \t\"<form>\\n\" +");
_builder.newLine();
_builder.append("\t\t\t\t\t\t");
_builder.append("dataColumn +");
_builder.newLine();
_builder.append("\t\t\t\t\t\t");
_builder.append("\"</form>\\n\" +");
_builder.newLine();
_builder.append("\t\t\t\t\t\t");
_builder.append("\"<div id=\\\"\"+this.getState().htmlTagId+\"_div\\\">\" + \"</div>\";");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("var cxD3TreeMapJsHTMLRootComponentSelection = d3.select(cxD3TreeMapJsHTMLRootComponent).select(\"#\"+this.getState().htmlTagId+\"_div\");");
_builder.newLine();
_builder.append("//\t\t\talert(\"selection: \" + selection);");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("var cxD3TreeMapJsHTMLRootComponentDiv = cxD3TreeMapJsHTMLRootComponentSelection.append(\"div\")");
_builder.newLine();
_builder.append("\t\t\t\t\t\t\t ");
_builder.append(".style(\"position\", \"relative\")");
_builder.newLine();
_builder.append("\t\t\t\t\t\t\t\t");
_builder.append(".style(\"width\", (width + margin.left + margin.right) + \"px\")");
_builder.newLine();
_builder.append("\t\t\t\t\t\t\t\t");
_builder.append(".style(\"height\", (height + margin.top + margin.bottom) + \"px\")");
_builder.newLine();
_builder.append("\t\t\t\t\t\t\t ");
_builder.append(".style(\"left\", margin.left + \"px\")");
_builder.newLine();
_builder.append("\t\t\t\t\t\t\t ");
_builder.append(".style(\"top\", margin.top + \"px\");");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("jsonTreeMapFunction = function(jsonObj) {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("var node = cxD3TreeMapJsHTMLRootComponentDiv.datum(jsonObj).selectAll(\".node\")");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append(".data(treemap.nodes)");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append(".enter().append(\"div\")");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append(".attr(\"class\", \"node\")");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append(".attr(\"title\", function(d) { return d.children ? \"\" : d.tooltipName + \"\\n\" + preValueLabel + \": \" + eval(\"d.\" + preValueLabel); })");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append(".call(position)");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append(".style(\"background\", function(d) { return d.children ? color(d.name) : null; })");
_builder.newLine();
_builder.append("//\t\t\t\t\t .style(\"background\", function(d) { return d.children ? d3.rgb(\"red\") : null; })");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append(".text(function(d) { return d.children ? null : d.name; });");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("d3.select(cxD3TreeMapJsHTMLRootComponent).selectAll(\"#\"+cxD3TreeMapJsComponentHtmlTagId+\"_input\").on(\"change\", function change() {");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("var valueLabel = this.value;");
_builder.newLine();
_builder.append("//\t\t\t\t alert(\"valueOut: \" + valueOut);");
_builder.newLine();
_builder.append("\t\t\t\t ");
_builder.append("var value = this.value === \"count\"");
_builder.newLine();
_builder.append("\t\t\t\t ");
_builder.append("? function() { return 1; }");
_builder.newLine();
_builder.append("\t\t\t\t ");
_builder.append(": function (d) { return eval(\"d.\" + valueLabel); };");
_builder.newLine();
_builder.append("\t\t");
_builder.append("//\t\t\t\t : function (d) { return d.size; };");
_builder.newLine();
_builder.append("\t\t\t\t\t ");
_builder.newLine();
_builder.append("\t\t\t\t\t ");
_builder.append("node.data(treemap.value(value).nodes)");
_builder.newLine();
_builder.append("\t\t\t\t\t \t");
_builder.append(".attr(\"title\", function(d) { return d.children ? \"\" : d.tooltipName + \"\\n\" + valueLabel + \": \" + eval(\"d.\" + valueLabel); })");
_builder.newLine();
_builder.append("\t\t\t\t\t \t");
_builder.append(".transition()");
_builder.newLine();
_builder.append("\t\t\t\t\t ");
_builder.append(".duration(1500)");
_builder.newLine();
_builder.append("\t\t\t\t\t ");
_builder.append(".call(position);");
_builder.newLine();
_builder.append("\t\t\t\t\t ");
_builder.append("});");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("var jsonString = this.getState().jsonData;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("jsonTreeMapFunction(JSON.parse(jsonString));");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
strBuilder.append(_builder);
}
public void generateCollTreeJsFile(final StringBuilder strBuilder, final String chartJavaFileName) {
StringConcatenation _builder = new StringConcatenation();
_builder.append(chartJavaFileName);
_builder.append(" = function() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("var margin = {top: 20, right: 120, bottom: 20, left: 120},");
_builder.newLine();
_builder.append(" ");
_builder.append("width = 1460 - margin.right - margin.left,");
_builder.newLine();
_builder.append(" ");
_builder.append("height = 1000 - margin.top - margin.bottom;");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append("\t");
_builder.append("var i = 0,");
_builder.newLine();
_builder.append("\t ");
_builder.append("duration = 750,");
_builder.newLine();
_builder.append("\t ");
_builder.append("cxD3TreeJsComponent_jsonRoot;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("var tree = d3.layout.tree()");
_builder.newLine();
_builder.append("\t ");
_builder.append(".size([height, width]);");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("var diagonal = d3.svg.diagonal()");
_builder.newLine();
_builder.append("\t ");
_builder.append(".projection(function(d) { return [d.y, d.x]; });");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("var cxD3TreeJsHTMLRootComponent = this.getElement();");
_builder.newLine();
_builder.append("\t");
_builder.append("cxD3TreeJsHTMLRootComponent.innerHTML = \t");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("\"<label><input id=\\\"\"+this.getState().htmlTagId+\"_input\\\" type=\\\"radio\\\" name=\\\"mode\\\" value=\\\"expand\\\">Expand</label>\\n\" +");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("\"<label><input id=\\\"\"+this.getState().htmlTagId+\"_input\\\" type=\\\"radio\\\" name=\\\"mode\\\" value=\\\"collapse\\\" checked>Collapse</label>\\n\" +");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("\"<div id=\\\"\"+this.getState().htmlTagId+\"_div\\\">\" + \"</div>\";\t");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("var cxD3TreeJsHTMLRootComponentSelection = d3.select(cxD3TreeJsHTMLRootComponent).select(\"#\"+this.getState().htmlTagId+\"_div\");");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("var cxD3TreeJsHTMLRootComponentSvg = cxD3TreeJsHTMLRootComponentSelection.append(\"svg\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"width\", width + margin.right + margin.left)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"height\", height + margin.top + margin.bottom)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".append(\"g\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("function collapse(d) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (d.children) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("d._children = d.children;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("d._children.forEach(collapse);");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("d.children = null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("function expand(d) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (d._children) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("d.children = d._children;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("d.children.forEach(expand);");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("d._children = null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("jsonTreeFunction = function(jsonData) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cxD3TreeJsComponent_jsonRoot = jsonData;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cxD3TreeJsComponent_jsonRoot.x0 = height / 2;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("cxD3TreeJsComponent_jsonRoot.y0 = 0;");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("cxD3TreeJsComponent_jsonRoot.children.forEach(collapse);");
_builder.newLine();
_builder.append("\t\t ");
_builder.append("update(cxD3TreeJsComponent_jsonRoot);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("jsonTreeFunction(JSON.parse(this.getState().jsonData));");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("d3.select(cxD3TreeJsHTMLRootComponent).select(self.frameElement).style(\"height\", \"800px\");");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("d3.select(cxD3TreeJsHTMLRootComponent).selectAll(\"#\"+this.getState().htmlTagId+\"_input\").on(\"change\", function change() {");
_builder.newLine();
_builder.append("//\t\talert(\"this.value = \" + this.value);");
_builder.newLine();
_builder.append("\t ");
_builder.append("if (this.value === \"expand\"){");
_builder.newLine();
_builder.append("\t \t");
_builder.append("cxD3TreeJsComponent_jsonRoot.children.forEach(expand);");
_builder.newLine();
_builder.append("\t ");
_builder.append("} else {");
_builder.newLine();
_builder.append("\t \t");
_builder.append("cxD3TreeJsComponent_jsonRoot.children.forEach(collapse);");
_builder.newLine();
_builder.append("\t ");
_builder.append("}");
_builder.newLine();
_builder.append("\t ");
_builder.append("update(cxD3TreeJsComponent_jsonRoot);");
_builder.newLine();
_builder.append("\t");
_builder.append("});");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("function update(source) {");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Compute the new tree layout.");
_builder.newLine();
_builder.append("\t ");
_builder.append("var nodes = tree.nodes(cxD3TreeJsComponent_jsonRoot).reverse(),");
_builder.newLine();
_builder.append("\t ");
_builder.append("links = tree.links(nodes);");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Normalize for fixed-depth.");
_builder.newLine();
_builder.append("\t ");
_builder.append("nodes.forEach(function(d) { d.y = d.depth * 180; });");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Update the nodes€¦");
_builder.newLine();
_builder.append("\t ");
_builder.append("var node = cxD3TreeJsHTMLRootComponentSvg.selectAll(\"g.node\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".data(nodes, function(d) { return d.id || (d.id = ++i); });");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Enter any new nodes at the parent\'s previous position.");
_builder.newLine();
_builder.append("\t ");
_builder.append("var nodeEnter = node.enter().append(\"g\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"class\", \"node\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"transform\", function(d) { return \"translate(\" + source.y0 + \",\" + source.x0 + \")\"; })");
_builder.newLine();
_builder.append("\t ");
_builder.append(".on(\"click\", click);");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("nodeEnter.append(\"circle\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"r\", 1e-6)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".style(\"fill\", function(d) { return d._children ? \"lightsteelblue\" : \"#fff\"; });");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("nodeEnter.append(\"text\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"x\", function(d) { return d.children || d._children ? -10 : 10; })");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"dy\", \".35em\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"text-anchor\", function(d) { return d.children || d._children ? \"end\" : \"start\"; })");
_builder.newLine();
_builder.append("\t ");
_builder.append(".text(function(d) { return d.name; })");
_builder.newLine();
_builder.append("\t ");
_builder.append(".style(\"fill-opacity\", 1e-6);");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Transition nodes to their new position.");
_builder.newLine();
_builder.append("\t ");
_builder.append("var nodeUpdate = node.transition()");
_builder.newLine();
_builder.append("\t ");
_builder.append(".duration(duration)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"transform\", function(d) { return \"translate(\" + d.y + \",\" + d.x + \")\"; });");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("nodeUpdate.select(\"circle\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"r\", 4.5)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".style(\"fill\", function(d) { return d._children ? \"lightsteelblue\" : \"#fff\"; });");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("nodeUpdate.select(\"text\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".style(\"fill-opacity\", 1);");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Transition exiting nodes to the parent\'s new position.");
_builder.newLine();
_builder.append("\t ");
_builder.append("var nodeExit = node.exit().transition()");
_builder.newLine();
_builder.append("\t ");
_builder.append(".duration(duration)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"transform\", function(d) { return \"translate(\" + source.y + \",\" + source.x + \")\"; })");
_builder.newLine();
_builder.append("\t ");
_builder.append(".remove();");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("nodeExit.select(\"circle\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"r\", 1e-6);");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("nodeExit.select(\"text\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".style(\"fill-opacity\", 1e-6);");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Update the links€¦");
_builder.newLine();
_builder.append("\t ");
_builder.append("var link = cxD3TreeJsHTMLRootComponentSvg.selectAll(\"path.link\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".data(links, function(d) { return d.target.id; });");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Enter any new links at the parent\'s previous position.");
_builder.newLine();
_builder.append("\t ");
_builder.append("link.enter().insert(\"path\", \"g\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"class\", \"link\")");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"d\", function(d) {");
_builder.newLine();
_builder.append("\t ");
_builder.append("var o = {x: source.x0, y: source.y0};");
_builder.newLine();
_builder.append("\t ");
_builder.append("return diagonal({source: o, target: o});");
_builder.newLine();
_builder.append("\t ");
_builder.append("});");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Transition links to their new position.");
_builder.newLine();
_builder.append("\t ");
_builder.append("link.transition()");
_builder.newLine();
_builder.append("\t ");
_builder.append(".duration(duration)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"d\", diagonal);");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Transition exiting nodes to the parent\'s new position.");
_builder.newLine();
_builder.append("\t ");
_builder.append("link.exit().transition()");
_builder.newLine();
_builder.append("\t ");
_builder.append(".duration(duration)");
_builder.newLine();
_builder.append("\t ");
_builder.append(".attr(\"d\", function(d) {");
_builder.newLine();
_builder.append("\t ");
_builder.append("var o = {x: source.x, y: source.y};");
_builder.newLine();
_builder.append("\t ");
_builder.append("return diagonal({source: o, target: o});");
_builder.newLine();
_builder.append("\t ");
_builder.append("})");
_builder.newLine();
_builder.append("\t ");
_builder.append(".remove();");
_builder.newLine();
_builder.newLine();
_builder.append("\t ");
_builder.append("// Stash the old positions for transition.");
_builder.newLine();
_builder.append("\t ");
_builder.append("nodes.forEach(function(d) {");
_builder.newLine();
_builder.append("\t ");
_builder.append("d.x0 = d.x;");
_builder.newLine();
_builder.append("\t ");
_builder.append("d.y0 = d.y;");
_builder.newLine();
_builder.append("\t ");
_builder.append("});");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("// Toggle children on click.");
_builder.newLine();
_builder.append("\t");
_builder.append("function click(d) {");
_builder.newLine();
_builder.append("\t ");
_builder.append("if (d.children) {");
_builder.newLine();
_builder.append("\t ");
_builder.append("d._children = d.children;");
_builder.newLine();
_builder.append("\t ");
_builder.append("d.children = null;");
_builder.newLine();
_builder.append("\t ");
_builder.append("} else {");
_builder.newLine();
_builder.append("\t ");
_builder.append("d.children = d._children;");
_builder.newLine();
_builder.append("\t ");
_builder.append("d._children = null;");
_builder.newLine();
_builder.append("\t ");
_builder.append("}");
_builder.newLine();
_builder.append("\t ");
_builder.append("update(d);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
strBuilder.append(_builder);
}
public void internalDoGenerate(final EObject chartModel, final IFileSystemAccess fsa) {
if (chartModel instanceof JvmDeclaredType) {
_internalDoGenerate((JvmDeclaredType)chartModel, fsa);
return;
} else if (chartModel instanceof ChartModel) {
_internalDoGenerate((ChartModel)chartModel, fsa);
return;
} else if (chartModel != null) {
_internalDoGenerate(chartModel, fsa);
return;
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(chartModel, fsa).toString());
}
}
}