Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
3762c2ac
Commit
3762c2ac
authored
Mar 17, 2014
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
demo for frontend
parent
91b634b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
119 deletions
+89
-119
Parsec.hs
ihaskell-display/ihaskell-parsec/IHaskell/Display/Parsec.hs
+15
-0
Test.ipynb
notebooks/Test.ipynb
+74
-119
No files found.
ihaskell-display/ihaskell-parsec/IHaskell/Display/Parsec.hs
View file @
3762c2ac
...
...
@@ -19,11 +19,26 @@ instance IHaskellDisplay (Parser a) where
[
i
|
<form><textarea id="${divId}">Hello!</textarea></form>
<script>
// Start the Comm.
var CommManager = IPython.notebook.kernel.comm_manager;
var comm = CommManager.new_comm("parsec", {}, {
iopub : {
output : function () {
console.log("Iopub output init:");
console.log(arguments);
}
}
});
// Create the editor.
var textarea = document.getElementById("${divId}");
var editor = CodeMirror.fromTextArea(textarea);
editor.on("change", function() {
var text = editor.getDoc().getValue();
console.log("New text: " + text);
comm.send({"text": text}, function () {
console.log("Got response!", arguments);
});
});
</script>
|]
notebooks/Test.ipynb
View file @
3762c2ac
...
...
@@ -13,169 +13,124 @@
"cell_type": "code",
"collapsed": false,
"input": [
":ext OverloadedStrings\n",
"import qualified Data.ByteString as B\n",
"import Text.Parsec\n",
"import Text.Parsec.String\n",
"import Text.Parsec.Prim\n",
"import Text.Parsec.Char\n",
"\n",
"import Graphics.Rendering.Chart\n",
"import Data.Default.Class\n",
"import Control.Lens\n",
"import Graphics.Rendering.Chart.Backend.Cairo\n",
"import IHaskell.Display\n",
"\n",
"import Data.Colour\n",
"import Data.Colour.Names\n",
"\n",
"\n",
"xvals = [1.5, 2.5, 5, 8 :: Double ]\n",
"yvals = [0.025, 0.1, 9, 230 :: Double ]\n",
"\n",
"xlvals = map LogValue xvals\n",
"ylvals = map LogValue yvals\n",
"\n",
"-- | Connect the points (xs,ys) with a solid\n",
"-- line using the given color.\n",
"lineXY :: (PlotValue a, PlotValue b) => Colour Double -> [a] -> [b] -> Plot a b\n",
"lineXY col xs ys = toPlot p\n",
" where\n",
" p = plot_lines_style .~ solidLine 1 (opaque col)\n",
" $ plot_lines_values .~ [zip xs ys]\n",
" $ def\n",
"\n",
"-- | Draw symbols at the points (xs,ys).\n",
"--\n",
"symbolXY ::\n",
" (PlotValue a, PlotValue b) =>\n",
" (AlphaColour Double -> PointStyle)\n",
" -> Colour Double \n",
" -> [a] \n",
" -> [b] \n",
" -> Plot a b\n",
"symbolXY sym col xs ys = toPlot p\n",
" where\n",
" p = plot_points_style .~ sym (opaque col)\n",
" $ plot_points_values .~ zip xs ys\n",
" $ def\n",
"\n",
"asCircle = filledCircles 10\n",
"asStar = stars 10 2\n",
"\n",
"-- | This function will plot the given function of x over the list of xs.\n",
"plotIt :: \n",
" (PlotValue a, PlotValue b) =>\n",
" (Colour Double -> [a] -> [b] -> Plot a b)\n",
" -> [a]\n",
" -> [b]\n",
" -> Renderable ()\n",
"\n",
"plotIt plotType xs ys = toRenderable l\n",
" where\n",
" l = layout_title .~ \"Plot\"\n",
" $ layout_plots .~ [ plotType blue xs ys ]\n",
" $ def\n",
"\n",
"r = plotIt (symbolXY asCircle) xvals yvals\n",
"\n",
"rp = do\n",
" printDisplay r\n",
" return 3"
"oneOf \"Hello\"C :: Parser Char"
],
"language": "python",
"metadata": {},
"outputs": [],
"outputs": [
{
"html": [
"\n",
" <form><textarea id=\"text79438521894\">Hello!</textarea></form>\n",
" <script>\n",
" var textarea = document.getElementById(\"text79438521894\");\n",
" var editor = CodeMirror.fromTextArea(textarea);\n",
" editor.on(\"change\", function() {\n",
" var text = editor.getDoc().getValue();\n",
" console.log(\"New text: \" + text);\n",
" });\n",
" </script>\n",
" "
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"-- We can draw diagrams, right in the notebook.\n",
":extension NoMonomorphismRestriction\n",
"import Diagrams.Prelude\n",
"\n",
"-- By Brent Yorgey\n",
"-- Draw a Sierpinski triangle!\n",
"sierpinski 1 = eqTriangle 1\n",
"sierpinski n = s\n",
" ===\n",
" (s ||| s) # centerX\n",
" where s = sierpinski (n-1)\n",
"\n",
"-- The `diagram` function is used to display them in the notebook.\n",
"diagram $ sierpinski 4\n",
" # centerXY\n",
" # fc black\n",
" `atop` square 10\n",
" # fc white"
"x <- display (oneOf \"Hello\" :: Parser Char)"
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
":set -XQuasiQuotes -XTupleSections -XViewPatterns\n",
"import IHaskell.Display -- shouldn't be needed but it turns out that it is essential\n",
"import IHaskell.Display.Rlangqq () -- to check it's installed\n",
"import Data.Monoid\n",
"import Control.Applicative\n",
"import Data.List\n",
"\n",
"sse <- do\n",
" [pun| (sse) |] <- [rDisp|\n",
" m <- lm( log($(xs) / (exp(1)-1)) ~ I(1:length($(xs))))\n",
" plot(m, which=1:2)\n",
" print(predict(m))\n",
" hs_sse <- sum( resid(m)^2 )\n",
" |]\n",
" return (sse :: Double)\n",
"() -- needed to force a display"
"case x of \n",
" Display [DisplayData MimeHtml dat] -> putStrLn $ unpack dat\n",
" _ -> error \"no\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span class='err-msg'>
Exception when trying to run compile-time code:<br/> fd:46: hClose: resource vanished (Broken pipe)<br/> Code: Language.Haskell.TH.Quote.quoteExp<br/> rDisp<br/> \"\\<br/> \\ m <- lm( log(<span>$</span>(xs) / (exp(1)-1)) ~ I(1:length(<span>$</span>(xs))))\\<br/> \\ plot(m, which=1:2)\\<br/> \\ print(predict(m))\\<br/> \\ hs_sse <- sum( resid(m)^2 )\\<br/> \\ \"
</span>"
"<span class='err-msg'>
Not in scope: data constructor `MimeHtml'<br/><br/><br/>Not in scope: `unpack'
</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"Exception when trying to run compile-time code:\n",
" fd:46: hClose: resource vanished (Broken pipe)\n",
" Code: Language.Haskell.TH.Quote.quoteExp\n",
" rDisp\n",
" \"\\\n",
" \\ m <- lm( log($(xs) / (exp(1)-1)) ~ I(1:length($(xs))))\\\n",
" \\ plot(m, which=1:2)\\\n",
" \\ print(predict(m))\\\n",
" \\ hs_sse <- sum( resid(m)^2 )\\\n",
" \\ \""
"Not in scope: data constructor `MimeHtml'\n",
"\n",
"\n",
"Not in scope: `unpack'"
]
}
],
"prompt_number": 2
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import IHaskell.Types"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import ClassyPrelude (unpack)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
":ext OverloadedStrings\n",
"putStrLn \"\u00fc\""
"x"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
" <form><textarea id=\"text33712347157\">Hello!</textarea></form>\n",
" <script>\n",
" var textarea = document.getElementById(\"text33712347157\");\n",
" var editor = CodeMirror.fromTextArea(textarea);\n",
" editor.on(\"change\", function() {\n",
" var text = editor.textContent;\n",
" console.log(\"New text: \" + text);\n",
" });\n",
" </script>\n",
" "
],
"metadata": {},
"output_type": "display_data",
"text": [
"\u00c3\u00bc"
]
"output_type": "display_data"
}
],
"prompt_number":
1
"prompt_number":
4
},
{
"cell_type": "code",
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment