mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
feat: Add flowchart, translator examples
This commit is contained in:
parent
247d00f316
commit
a163044d61
9 changed files with 480 additions and 0 deletions
|
|
@ -36,6 +36,8 @@
|
|||
<modules>
|
||||
<module>zeppelin-example-clock</module>
|
||||
<module>zeppelin-example-horizontalbar</module>
|
||||
<module>zeppelin-example-frontend-interpreter-flowchart</module>
|
||||
<module>zeppelin-example-frontend-interpreter-translator</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
|
||||
import {
|
||||
AbstractFrontendInterpreter,
|
||||
FrontendInterpreterResult,
|
||||
DefaultDisplayType,
|
||||
} from 'zeppelin-frontend-interpreter';
|
||||
|
||||
import flowchart from 'flowchart.js';
|
||||
|
||||
export default class FlowchartInterpreter extends AbstractFrontendInterpreter {
|
||||
constructor() {
|
||||
super("%flowchart", DefaultDisplayType.ELEMENT);
|
||||
}
|
||||
|
||||
interpret(paragraphText) {
|
||||
/**
|
||||
* `flowchart` library requires an existing DOM to render.
|
||||
* but the DOM is not created yet when `interpret` is called.
|
||||
* so Zeppelin allows to return callback function which accept a DOM element id.
|
||||
* the callback function will executed when the DOM is ready.
|
||||
*/
|
||||
const callback = (targetElemId) => {
|
||||
let diagram = flowchart.parse(paragraphText);
|
||||
diagram.drawSVG(targetElemId, this.getOption());
|
||||
};
|
||||
|
||||
/**
|
||||
* `interpret` method can return multiple results.
|
||||
* But now, we return just 1 result which is wrapped in an array.
|
||||
*/
|
||||
return [new FrontendInterpreterResult(
|
||||
DefaultDisplayType.ELEMENT,
|
||||
callback
|
||||
)];
|
||||
}
|
||||
|
||||
getOption() {
|
||||
return {
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
'line-width': 3,
|
||||
'line-length': 50,
|
||||
'text-margin': 10,
|
||||
'font-size': 14,
|
||||
'font-color': 'black',
|
||||
'line-color': 'black',
|
||||
'element-color': 'black',
|
||||
'fill': 'white',
|
||||
'yes-text': 'yes',
|
||||
'no-text': 'no',
|
||||
'arrow-end': 'block',
|
||||
'scale': 1,
|
||||
// style symbol types
|
||||
'symbols': {
|
||||
'start': {
|
||||
'font-color': 'red',
|
||||
'element-color': 'green',
|
||||
'fill': 'yellow'
|
||||
},
|
||||
'end':{
|
||||
'class': 'end-element'
|
||||
}
|
||||
},
|
||||
// even flowstate support ;-)
|
||||
'flowstate' : {
|
||||
'past' : { 'fill' : '#CCCCCC', 'font-size' : 12},
|
||||
'current' : {'fill' : 'yellow', 'font-color' : 'red', 'font-weight' : 'bold'},
|
||||
'future' : { 'fill' : '#FFFF99'},
|
||||
'request' : { 'fill' : 'blue'},
|
||||
'invalid': {'fill' : '#444444'},
|
||||
'approved' : { 'fill' : '#58C4A3', 'font-size' : 12, 'yes-text' : 'APPROVED', 'no-text' : 'n/a' },
|
||||
'rejected' : { 'fill' : '#C45879', 'font-size' : 12, 'yes-text' : 'n/a', 'no-text' : 'REJECTED' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "flowchart-frontend-interpreter",
|
||||
"description": "Frontend Flowchart Interpreter (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"raphael": "2.2.0",
|
||||
"flowchart.js": "^1.6.5",
|
||||
"zeppelin-frontend-interpreter": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>zeppelin-examples</artifactId>
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<artifactId>zeppelin-example-frontend-interpreter-flowchart</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
<name>Zeppelin: Example application - Frontend Flowchart Interpreter</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>zeppelin-interpreter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>helium-dev</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<configuration>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>${project.basedir}/../../helium</directory>
|
||||
<includes>
|
||||
<include>${project.artifactId}.json</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<outputDirectory>${project.basedir}/../../helium/</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}</directory>
|
||||
<includes>
|
||||
<include>${project.artifactId}.json</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
{
|
||||
"type" : "FRONTEND_INTERPRETER",
|
||||
"name" : "flowchart-frontend-interpreter",
|
||||
"description" : "with Flowchart.js (example)",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-frontend-interpreter-flowchart",
|
||||
"license" : "Apache-2.0",
|
||||
"icon" : "<i class='fa fa-random'></i>"
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
|
||||
import {
|
||||
AbstractFrontendInterpreter,
|
||||
FrontendInterpreterResult,
|
||||
DefaultDisplayType,
|
||||
} from 'zeppelin-frontend-interpreter';
|
||||
|
||||
import 'whatwg-fetch';
|
||||
|
||||
export default class TranslatorInterpreter extends AbstractFrontendInterpreter {
|
||||
constructor() {
|
||||
super("%translator", DefaultDisplayType.TEXT);
|
||||
}
|
||||
|
||||
interpret(paragraphText) {
|
||||
return [new FrontendInterpreterResult(
|
||||
DefaultDisplayType.TEXT,
|
||||
this.translate(paragraphText)
|
||||
)];
|
||||
}
|
||||
|
||||
translate(text) {
|
||||
return fetch('https://translation.googleapis.com/language/translate/v2', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer YOUR_ACCESS_KEY_HERE',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
'q': text,
|
||||
'source': 'en',
|
||||
'target': 'ko',
|
||||
'format': 'text'
|
||||
})
|
||||
}).then((response) => {
|
||||
if (response.status === 200) {
|
||||
return response.json()
|
||||
}
|
||||
throw new Error(`https://translation.googleapis.com/language/translate/v2 ${response.status} (${response.statusText})`);
|
||||
}).then((json) => {
|
||||
const extracted = json.data.translations.map(t => {
|
||||
return t.translatedText;
|
||||
});
|
||||
return extracted.join('\n');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "translator-frontend-interpreter",
|
||||
"description": "Frontend Translator Interpreter (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"whatwg-fetch": "^2.0.1",
|
||||
"zeppelin-frontend-interpreter": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>zeppelin-examples</artifactId>
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<artifactId>zeppelin-example-frontend-interpreter-translator</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
<name>Zeppelin: Example application - Frontend Translator Interpreter</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>zeppelin-interpreter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>helium-dev</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<configuration>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>${project.basedir}/../../helium</directory>
|
||||
<includes>
|
||||
<include>${project.artifactId}.json</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<outputDirectory>${project.basedir}/../../helium/</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}</directory>
|
||||
<includes>
|
||||
<include>${project.artifactId}.json</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
{
|
||||
"type" : "FRONTEND_INTERPRETER",
|
||||
"name" : "translator-frontend-interpreter",
|
||||
"description" : "with Google Translation API (examaple)",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-frontend-interpreter-translator",
|
||||
"license" : "Apache-2.0",
|
||||
"icon" : "<i class='fa fa-globe '></i>"
|
||||
}
|
||||
Loading…
Reference in a new issue