-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
318 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Formatters | ||
#I "../../packages/build/FSharp.Formatting/lib/net40" | ||
#r "FSharp.Markdown.dll" | ||
#r "FSharp.Literate.dll" | ||
|
||
#r "FSharp.CodeFormat.dll" | ||
#r "RazorEngine.dll" | ||
#r "../../packages/build/FAKE/tools/FakeLib.dll" | ||
|
||
//#I "../../bin" | ||
//#r "../../bin/FSharp.Plotly.dll" | ||
#r "../../packages/build/FSharp.Plotly/lib/net40/Fsharp.Plotly.dll" | ||
|
||
open Fake | ||
open System.IO | ||
open FSharp.Literate | ||
open FSharp.Markdown | ||
|
||
open FSharp.Plotly | ||
|
||
// -------------------------------------------------------------------------------------- | ||
// Build FSI evaluator | ||
// -------------------------------------------------------------------------------------- | ||
|
||
/// Builds FSI evaluator that can render System.Image, F# Charts, series & frames | ||
let createFsiEvaluator root output = | ||
|
||
/// Counter for saving files | ||
let imageCounter = | ||
let count = ref 0 | ||
(fun () -> incr count; !count) | ||
|
||
let transformation (value:obj, typ:System.Type) = | ||
match value with | ||
| :? System.Drawing.Image as img -> | ||
// Pretty print image - save the image to the "images" directory | ||
// and return a DirectImage reference to the appropriate location | ||
let id = imageCounter().ToString() | ||
let file = "chart" + id + ".png" | ||
ensureDirectory (output @@ "images") | ||
img.Save(output @@ "images" @@ file, System.Drawing.Imaging.ImageFormat.Png) | ||
Some [ Paragraph [DirectImage ("", (root + "/images/" + file, None))] ] | ||
|
||
| :? GenericChart.GenericChart as ch -> | ||
// Just return the inline HTML for a Plotly chart | ||
let html = GenericChart.toChartHtmlWithSize 700 500 ch | ||
Some [InlineBlock <| html] | ||
|
||
| _ -> None | ||
|
||
// Create FSI evaluator, register transformations & return | ||
let fsiEvaluator = FsiEvaluator() | ||
fsiEvaluator.RegisterTransformation(transformation) | ||
fsiEvaluator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters