mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
pass bundled visualization to result.controller.js
This commit is contained in:
parent
f5ce99e2e8
commit
0c4da2ead0
15 changed files with 120 additions and 24 deletions
|
|
@ -46,13 +46,15 @@ public class HeliumPackage {
|
|||
String description,
|
||||
String artifact,
|
||||
String className,
|
||||
String[][] resources) {
|
||||
String[][] resources,
|
||||
String icon) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.artifact = artifact;
|
||||
this.className = className;
|
||||
this.resources = resources;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@ public class ApplicationLoaderTest {
|
|||
"desc1",
|
||||
artifact,
|
||||
className,
|
||||
new String[][]{{}});
|
||||
new String[][]{{}},
|
||||
"icon");
|
||||
return app1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.zeppelin.rest;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.zeppelin.helium.Helium;
|
||||
import org.apache.zeppelin.helium.HeliumApplicationFactory;
|
||||
import org.apache.zeppelin.helium.HeliumPackage;
|
||||
|
|
@ -31,6 +32,8 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Helium Rest Api
|
||||
|
|
@ -113,7 +116,13 @@ public class HeliumRestApi {
|
|||
@Path("visualizations/load")
|
||||
@Produces("text/javascript")
|
||||
public Response visualizationLoad() {
|
||||
try {
|
||||
String visBundle = FileUtils.readFileToString(new File("/tmp/npm/vis.bundle.js"));
|
||||
return Response.ok(visBundle).build();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return Response.serverError().build();
|
||||
}
|
||||
|
||||
return Response.ok("console.log(' -- vis bundle -- ');").build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').controller('HeliumCtrl', HeliumCtrl);
|
||||
|
|
|
|||
|
|
@ -40,12 +40,13 @@ import ScatterchartVisualization from '../../../visualization/builtins/visualiza
|
|||
'baseUrlSrv',
|
||||
'ngToast',
|
||||
'saveAsService',
|
||||
'noteVarShareService'
|
||||
'noteVarShareService',
|
||||
'heliumService'
|
||||
];
|
||||
|
||||
function ResultCtrl($scope, $rootScope, $route, $window, $routeParams, $location,
|
||||
$timeout, $compile, $http, $q, $templateRequest, websocketMsgSrv,
|
||||
baseUrlSrv, ngToast, saveAsService, noteVarShareService) {
|
||||
baseUrlSrv, ngToast, saveAsService, noteVarShareService, heliumService) {
|
||||
|
||||
/**
|
||||
* Built-in visualizations
|
||||
|
|
@ -152,6 +153,21 @@ import ScatterchartVisualization from '../../../visualization/builtins/visualiza
|
|||
|
||||
$scope.init = function(result, config, paragraph, index) {
|
||||
console.log('result controller init %o %o %o', result, config, index);
|
||||
|
||||
// register helium plugin vis
|
||||
var heliumVis = heliumService.get();
|
||||
console.log('Helium visualizations %o', heliumVis);
|
||||
heliumVis.forEach(function(vis) {
|
||||
$scope.builtInTableDataVisualizationList.push({
|
||||
id: vis.id,
|
||||
name: vis.name,
|
||||
icon: vis.icon
|
||||
});
|
||||
builtInVisualizations[vis.id] = {
|
||||
class: vis.class
|
||||
};
|
||||
});
|
||||
|
||||
updateData(result, config, paragraph, index);
|
||||
renderResult($scope.type);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
"name": "zeppelin-tabledata",
|
||||
"description": "tabledata api",
|
||||
"version": "0.7.0-SNAPSHOT",
|
||||
"main": "tabledata",
|
||||
"dependencies": {
|
||||
"json3": "~3.3.1",
|
||||
"lodash": "~3.9.3"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
"name": "zeppelin-vis",
|
||||
"description": "Visualization API",
|
||||
"version": "0.7.0-SNAPSHOT",
|
||||
"main": "visualization",
|
||||
"dependencies": {
|
||||
"json3": "~3.3.1",
|
||||
"nvd3": "~1.7.1",
|
||||
|
|
|
|||
35
zeppelin-web/src/components/helium/helium.service.js
Normal file
35
zeppelin-web/src/components/helium/helium.service.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
angular.module('zeppelinWebApp').service('heliumService', heliumService);
|
||||
|
||||
heliumService.$inject = ['$http', 'baseUrlSrv'];
|
||||
|
||||
function heliumService($http, baseUrlSrv) {
|
||||
|
||||
var url = baseUrlSrv.getRestApiBase() + '/helium/visualizations/load';
|
||||
var visualizations = [];
|
||||
|
||||
// load should be promise
|
||||
this.load = $http.get(url).success(function(response) {
|
||||
eval(response);
|
||||
});
|
||||
|
||||
this.get = function() {
|
||||
return visualizations;
|
||||
};
|
||||
};
|
||||
})();
|
||||
|
|
@ -109,18 +109,26 @@ public class HeliumVisualizationFactory {
|
|||
String webpackConfig = Resources.toString(webpackConfigUrl, Charsets.UTF_8);
|
||||
|
||||
// generate load.js
|
||||
StringBuilder loadJs = new StringBuilder();
|
||||
StringBuilder loadJsImport = new StringBuilder();
|
||||
StringBuilder loadJsRegister = new StringBuilder();
|
||||
for (HeliumPackage pkg : pkgs) {
|
||||
String [] moduleNameVersion = getNpmModuleNameAndVersion(pkg);
|
||||
if (moduleNameVersion == null) {
|
||||
continue;
|
||||
}
|
||||
loadJs.append("import " + moduleNameVersion[0] + " from \"" + moduleNameVersion[0] + "\"\n");
|
||||
loadJsImport.append(
|
||||
"import " + moduleNameVersion[0] + " from \"" + moduleNameVersion[0] + "\"\n");
|
||||
loadJsRegister.append("visualizations.push({" +
|
||||
"id: '" + moduleNameVersion[0] + "'," +
|
||||
"name: '" + pkg.getName() + "'," +
|
||||
"icon: '" + pkg.getIcon() + "'," +
|
||||
"class: " + moduleNameVersion[0] +
|
||||
"})\n");
|
||||
}
|
||||
|
||||
FileUtils.write(new File(workingDirectory, "package.json"), pkgJson);
|
||||
FileUtils.write(new File(workingDirectory, "webpack.config.js"), webpackConfig);
|
||||
FileUtils.write(new File(workingDirectory, "load.js"), loadJs.toString());
|
||||
FileUtils.write(new File(workingDirectory, "load.js"), loadJsImport.append(loadJsRegister).toString());
|
||||
|
||||
// install tabledata module
|
||||
File tabledataModuleInstallPath = new File(workingDirectory,
|
||||
|
|
|
|||
|
|
@ -134,7 +134,8 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
"desc1",
|
||||
"",
|
||||
HeliumTestApplication.class.getName(),
|
||||
new String[][]{});
|
||||
new String[][]{},
|
||||
"");
|
||||
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
factory.setInterpreters("user", note1.getId(),factory.getDefaultInterpreterSettingList());
|
||||
|
|
@ -179,7 +180,8 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
"desc1",
|
||||
"",
|
||||
HeliumTestApplication.class.getName(),
|
||||
new String[][]{});
|
||||
new String[][]{},
|
||||
"");
|
||||
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
factory.setInterpreters("user", note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
|
@ -218,7 +220,8 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
"desc1",
|
||||
"",
|
||||
HeliumTestApplication.class.getName(),
|
||||
new String[][]{});
|
||||
new String[][]{},
|
||||
"");
|
||||
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
notebook.bindInterpretersToNote("user", note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
|
@ -278,7 +281,8 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
"desc1",
|
||||
"",
|
||||
HeliumTestApplication.class.getName(),
|
||||
new String[][]{});
|
||||
new String[][]{},
|
||||
"");
|
||||
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
notebook.bindInterpretersToNote("user", note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ public class HeliumLocalRegistryTest {
|
|||
"desc1",
|
||||
"artifact1",
|
||||
"classname1",
|
||||
new String[][]{});
|
||||
new String[][]{},
|
||||
"");
|
||||
FileUtils.writeStringToFile(new File(r1Path, "pkg1.json"), gson.toJson(pkg1));
|
||||
|
||||
// then
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ public class HeliumTest {
|
|||
"desc1",
|
||||
"artifact1",
|
||||
"className1",
|
||||
new String[][]{}));
|
||||
new String[][]{},
|
||||
""));
|
||||
|
||||
registry2.add(new HeliumPackage(
|
||||
HeliumPackage.Type.APPLICATION,
|
||||
|
|
@ -93,7 +94,8 @@ public class HeliumTest {
|
|||
"desc2",
|
||||
"artifact2",
|
||||
"className2",
|
||||
new String[][]{}));
|
||||
new String[][]{},
|
||||
""));
|
||||
|
||||
// then
|
||||
assertEquals(2, helium.getAllPackageInfo().size());
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ public class HeliumVisualizationFactoryTest {
|
|||
"lodash",
|
||||
"lodash^3.9.3",
|
||||
"",
|
||||
null
|
||||
null,
|
||||
"icon"
|
||||
);
|
||||
hvf.install(pkg);
|
||||
assertTrue(new File(tmpDir, "node_modules/lodash").isDirectory());
|
||||
|
|
@ -85,7 +86,8 @@ public class HeliumVisualizationFactoryTest {
|
|||
"lodash",
|
||||
"lodash^3.9.3",
|
||||
"",
|
||||
null
|
||||
null,
|
||||
"icon"
|
||||
);
|
||||
List<HeliumPackage> pkgs = new LinkedList<>();
|
||||
pkgs.add(pkg);
|
||||
|
|
@ -107,7 +109,8 @@ public class HeliumVisualizationFactoryTest {
|
|||
"vis1",
|
||||
localPkg,
|
||||
"",
|
||||
null
|
||||
null,
|
||||
"fa fa-coffee"
|
||||
);
|
||||
List<HeliumPackage> pkgs = new LinkedList<>();
|
||||
pkgs.add(pkg);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"description": "",
|
||||
"main": "vis1",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"zeppelin-tabledata": "0.7.0-SNAPSHOT",
|
||||
"zeppelin-vis": "0.7.0-SNAPSHOT"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,21 @@
|
|||
|
||||
var zeppelin = zeppelin || {};
|
||||
import Visualization from 'zeppelin-vis'
|
||||
import PassthroughTransformation from 'zeppelin-tabledata/passthrough'
|
||||
|
||||
/**
|
||||
* Base class for visualization
|
||||
*/
|
||||
zeppelin.MyVisualization = function(targetEl, config) {
|
||||
this.targetEl = targetEl;
|
||||
export default class vis1 extends Visualization {
|
||||
constructor(targetEl, config) {
|
||||
super(targetEl, config)
|
||||
this.passthrough = new PassthroughTransformation(config);
|
||||
console.log('passthrough %o', this.passthrough);
|
||||
}
|
||||
|
||||
render(tableData) {
|
||||
this.targetEl.html('Vis1')
|
||||
}
|
||||
|
||||
getTransformation() {
|
||||
return this.passthrough
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue