Skip to content

Commit

Permalink
Merge pull request #208 from sglyon/sl/0.7
Browse files Browse the repository at this point in the history
WIP: Sl/0.7
  • Loading branch information
sglyon authored Aug 31, 2018
2 parents ca5a349 + 60002cc commit 2fb2f20
Show file tree
Hide file tree
Showing 26 changed files with 522 additions and 1,115 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ deps/plotly-latest.min.js
deps/plotschema.json
deps/schema.html
deps/*.csv
assets/node_modules/
assets/package-lock.json
deps/build.log
7 changes: 4 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
julia 0.7
JSON 0.7
Blink 0.3.3
DocStringExtensions
Blink 0.8
Requires
PlotlyBase 0.1.2
PlotlyBase
Reexport 0.2.0
Compat 0.69
WebIO
JSExpr
67 changes: 67 additions & 0 deletions assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {contains, filter, has, isNil, type} from 'ramda';


WebIO.CommandSets.Plotly = {
filterEventData: function(gd, eventData, event) {
let filteredEventData;
if (contains(event, ['click', 'hover', 'selected'])) {
const points = [];

if (isNil(eventData)) {
return null;
}

/*
* remove `data`, `layout`, `xaxis`, etc
* objects from the event data since they're so big
* and cause JSON stringify ciricular structure errors.
*
* also, pull down the `customdata` point from the data array
* into the event object
*/
const data = gd.data;

for(let i=0; i < eventData.points.length; i++) {
const fullPoint = eventData.points[i];
const pointData = filter(function(o) {
return !contains(type(o), ['Object', 'Array'])
}, fullPoint);
if (has('curveNumber', fullPoint) &&
has('pointNumber', fullPoint) &&
has('customdata', data[pointData.curveNumber])
) {
pointData['customdata'] = data[
pointData.curveNumber
].customdata[fullPoint.pointNumber];
}

// specific to histogram. see https://github.com/plotly/plotly.js/pull/2113/
if (has('pointNumbers', fullPoint)) {
pointData.pointNumbers = fullPoint.pointNumbers;
}

points[i] = pointData;

}
filteredEventData = {points}
} else if (event === 'relayout') {
/*
* relayout shouldn't include any big objects
* it will usually just contain the ranges of the axes like
* "xaxis.range[0]": 0.7715822247381828,
* "xaxis.range[1]": 3.0095292008680063`
*/
filteredEventData = eventData;
}
if (has('range', eventData)) {
filteredEventData.range = eventData.range;
}
if (has('lassoPoints', eventData)) {
filteredEventData.lassoPoints = eventData.lassoPoints;
}
return {
out: filteredEventData,
isnil: isNil(filteredEventData)
};
}
}
23 changes: 23 additions & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "assets",
"version": "1.0.0",
"description": "WebIO.jl support for plotly",
"main": "index.js",
"dependencies": {
"ramda": "^0.24.1"
},
"devDependencies": {
"clean-webpack-plugin": "^0.1.19",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0",
"webpack-merge": "^4.1.4"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --open --config webpack.dev.js",
"build": "webpack --config webpack.prod.js"
},
"keywords": [],
"author": "Spencer Lyon",
"license": "MIT"
}
1 change: 1 addition & 0 deletions assets/plotly_webio.bundle.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions assets/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
entry: {
app: './index.js'
},
plugins: [
new CleanWebpackPlugin(['dist'])
],
output: {
filename: 'plotly_webio.bundle.js',
path: path.resolve(__dirname)
}
};
10 changes: 10 additions & 0 deletions assets/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const merge = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
contentBase: './dist'
}
});
6 changes: 6 additions & 0 deletions assets/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const merge = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
mode: 'production',
});
2 changes: 1 addition & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const _pkg_assets = joinpath(_pkg_root,"assets")
download("https://api.plot.ly/v2/plot-schema?sha1", joinpath(_pkg_deps,"plotschema.json"))
download("https://cdn.plot.ly/plotly-latest.min.js", joinpath(_pkg_assets,"plotly-latest.min.js"))

include("make_schema_docs.jl")
# include("make_schema_docs.jl")
include("find_attr_groups.jl")
AttrGroups.main()
8 changes: 4 additions & 4 deletions deps/find_attr_groups.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module AttrGroups

using JSON
using Compat: AbstractDict
using DelimitedFiles

_symbol_dict(x) = x
_symbol_dict(d::AbstractDict) =
Expand All @@ -13,8 +13,8 @@ function main()

nms = Set{Symbol}()
function add_to_names!(d::AbstractDict)
map(add_to_names!, keys(d))
map(add_to_names!, values(d))
foreach(add_to_names!, keys(d))
foreach(add_to_names!, values(d))
nothing
end
add_to_names!(s::Symbol) = push!(nms, s)
Expand All @@ -27,7 +27,7 @@ function main()

_UNDERSCORE_ATTRS = collect(
filter(
x-> contains(string(x), "_") && !startswith(string(x), "_"),
x-> occursin(string(x), "_") && !startswith(string(x), "_"),
nms
)
)
Expand Down
1 change: 0 additions & 1 deletion deps/make_schema_docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module PlotlyJSSchemaDocsGenerator
import Markdown
using Markdown: MD
using JSON
using Compat: AbstractDict

# methods to re-construct a plot from JSON
_symbol_dict(x) = x
Expand Down
2 changes: 1 addition & 1 deletion examples/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function table3()
columnwidth=[200, 500, 600, 600, 400, 400, 600, 600, 600],
# columnorder=0:9,
header=attr(
values=map(x-> replace(string(x), '_', '-'), names(df)),
values=map(x-> replace(string(x), '_' => '-'), names(df)),
align="center",
line=attr(width=1, color="rgb(50, 50, 50)"),
fill_color=["rgb(235, 100, 230)"],
Expand Down
34 changes: 0 additions & 34 deletions recession_dates.tsv

This file was deleted.

56 changes: 31 additions & 25 deletions src/PlotlyJS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Reexport
@reexport using PlotlyBase
using JSON
using Base.Iterators
using Compat: AbstractDict
using REPL, Pkg

# need to import some functions because methods are meta-generated
import PlotlyBase:
Expand All @@ -13,10 +13,14 @@ import PlotlyBase:
restyle, relayout, update, addtraces, deletetraces, movetraces, redraw,
extendtraces, prependtraces, prep_kwargs, sizes, savefig, _tovec

using WebIO
using JSExpr
using JSExpr: @var, @new
using Blink
using Blink.JSString
using Requires

export plot

# globals for this package
const _pkg_root = dirname(dirname(@__FILE__))
const _js_path = joinpath(_pkg_root, "assets", "plotly-latest.min.js")
Expand All @@ -33,7 +37,7 @@ abstract type AbstractPlotlyDisplay end
# include the rest of the core parts of the package
include("display.jl")
include("util.jl")
include("savefig.jl")
# include("savefig.jl")

function docs()
schema_path = joinpath(dirname(dirname(@__FILE__)), "deps", "schema.html")
Expand All @@ -54,32 +58,34 @@ function docs()
Blink.content!(w, "html", open(f->read(f, String), schema_path), fade=false)
end

export

# core types
ElectronDisplay, JupyterDisplay, ElectronPlot, JupyterPlot,

# other methods
savefig, svg_data, png_data, jpeg_data, webp_data, autoresize,

# helper methods
plot, fork,

# frontend methods
init_notebook

@require Rsvg include("savefig_cairo.jl")
function PlotlyBase.savefig(p::SyncPlot, args...)
has_orca = haskey(Pkg.installed(), "ORCA")
if has_orca
error("Please call `using ORCA` to save figures")
end

function _savefig_cairo(x...)
msg = """
Rsvg.jl must be loaded in order to save in this format. Please ensure
that Rsvg is installed, then call `using Rsvg` before trying your command
again
"""
if Base.isinteractive()
msg = "Saving figures requires the ORCA package."
msg *= " Would you like to install it? (Y/n) "
print(msg)
answer = readline()
if length(answer) == 0
answer = "y"
end
if lowercase(answer)[1] == 'y'
println("here!!")
println("Ok. Installing ORCA now...")
Pkg.add("ORCA")
info("Please call `using ORCA` and try saving your plot again")
return
end
end
msg = "Please install ORCA separately, then call `using ORCA` and try again"
error(msg)
end

@init begin
function __init__()
@require ORCA="200b8544-ab2f-11e8-2d2a-470a6868b879" include("savefig_orca.jl")
if !isfile(_js_path)
info("plotly.js javascript libary not found -- downloading now")
include(joinpath(_pkg_root, "deps", "build.jl"))
Expand Down
Loading

0 comments on commit 2fb2f20

Please sign in to comment.