Skip to content

Commit

Permalink
Merge pull request #77 from jonathanBieler/v0.7
Browse files Browse the repository at this point in the history
fixes for v0.7
  • Loading branch information
jonathanBieler authored Nov 13, 2018
2 parents 8032557 + dad60e9 commit d40ff4f
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 97 deletions.
25 changes: 17 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
sudo: true
sudo: required
os:
- linux
julia:
- 0.4
- 0.5
- 0.7
- 1.0
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
addons:
apt:
packages:
- xvfb
- xauth
- libgtk-3-0
before_install:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- libgtk-3-dev
- at-spi2-core
script:
- xvfb-run julia -e 'Pkg.clone(pwd()); Pkg.build("Immerse"); Pkg.test("Immerse"; coverage=true)'
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("Immerse")'
- if [ `uname` = "Linux" ]; then
xvfb-run julia --check-bounds=yes -e 'using Pkg; Pkg.test("Immerse", coverage=true)';
elif [ `uname` = "Darwin" ]; then
julia --check-bounds=yes -e 'using Pkg; Pkg.test("Immerse", coverage=true)';
fi
after_success:
- julia -e 'using Pkg; cd(Pkg.dir("Immerse")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
11 changes: 6 additions & 5 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
julia 0.4
julia 0.7
DataFrames
Gadfly
Compose 0.3.19
Compose
Measures
Colors
Gtk 0.11
GtkUtilities 0.0.8
Reexport
Gtk
GtkUtilities
Reexport
34 changes: 17 additions & 17 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1.0

platform:
#- x86 # 32-bit
- x64 # 64-bit

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - julia_version: latest

branches:
only:
Expand All @@ -19,18 +25,12 @@ notifications:
on_build_status_changed: false

install:
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Immerse\"); Pkg.build(\"Immerse\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"Immerse\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
8 changes: 5 additions & 3 deletions src/Immerse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ __precompile__()

module Immerse

using GtkUtilities, Colors, Reexport, Compat
using GtkUtilities, Colors, Reexport, Compat, REPL
@reexport using Gadfly
import Gtk # because both Gadfly and Gtk define draw
import Gtk: getproperty, setproperty!
import Compose, Measures
using Cairo

@eval Compose begin import Cairo end
Compose.link_cairo()

if VERSION < v"0.4.0-dev"
using Base.Graphics
else
using Graphics
end
using Cairo

export
Figure,
Expand Down
41 changes: 22 additions & 19 deletions src/compose.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# module ImmerseCompose

import Base: start, next, done
#import Base: start, next, done

# import Compose
using Measures: Vec, Measure, AbsoluteBox, resolve
using Compose: Backend
using Compose: Container, Context, Table
using Compose: Form, Line, Circle
using Compose: Property, Stroke, Fill, LineWidth, Visible, SVGClass
using Compose: ListNode
using Compose: List, ListNode, ListNull
using Compose: Transform, IdentityTransform, MatrixTransform, UnitBox
using Compose: absolute_native_units

start(l::List) = l
next(::List, l::List) = (l.head, l.tail)
done(::List, l::List) = typeof(l) <: ListNull
cons(value, l::List{T}) where T = ListNode{T}(value, l)

# using Compat, Colors #, GtkUtilities
# import Gtk

Expand All @@ -27,13 +32,12 @@ using Compose: absolute_native_units
# hitcenter,
# absolute_to_data

typealias ContainersWithChildren Table
typealias Iterables Union{ContainersWithChildren, AbstractArray}
const ContainersWithChildren = Table
const Iterables = Union{ContainersWithChildren, AbstractArray}

iterable(cnt::ContainersWithChildren) = cnt.children
iterable(a::AbstractArray) = a


# Testing utilities
#
# function test_by_drawing(c, obj, transform, units, box)
Expand Down Expand Up @@ -247,7 +251,7 @@ proptype2sym(::Type{Visible}) = :visible

getproperty(ctx::Context, sym::Symbol) = getproperty(ctx, sym2proptype(sym))

function getproperty{P<:Property}(ctx::Context, ::Type{P}, default=nothing)
function getproperty(ctx::Context, ::Type{P}, default=nothing) where {P<:Property}
for c in ctx.property_children
isa(c, P) && return _getvalue(c)
end
Expand All @@ -265,25 +269,25 @@ _getvalue(p::Visible) = [prim.value for prim in p.primitives]

setproperty!(ctx::Context, val, sym::Symbol) = setproperty!(ctx, val, sym2proptype(sym))

setproperty!{P<:Stroke}(ctx::Context, val::Union{Colorant,AbstractString,AbstractArray}, ::Type{P}) =
setproperty!(ctx::Context, val::Union{Colorant,AbstractString,AbstractArray}, ::Type{P}) where {P<:Stroke} =
setproperty!(ctx, Compose.stroke(val))

setproperty!{P<:Fill}(ctx::Context, val::Union{Colorant,AbstractString,AbstractArray}, ::Type{P}) =
setproperty!(ctx::Context, val::Union{Colorant,AbstractString,AbstractArray}, ::Type{P}) where {P<:Fill} =
setproperty!(ctx, Compose.fill(val))

setproperty!{P<:LineWidth}(ctx::Context, val::Union{Measure,Number}, ::Type{P}) =
setproperty!(ctx::Context, val::Union{Measure,Number}, ::Type{P}) where {P<:LineWidth} =
setproperty!(ctx, Compose.linewidth(val))

setproperty!{P<:Visible}(ctx::Context, val::Bool, ::Type{P}) =
setproperty!(ctx::Context, val::Bool, ::Type{P}) where {P<:Visible} =
setproperty!(ctx, Compose.visible(val))

function setproperty!{P<:Property}(ctx::Context, val::P)
function setproperty!(ctx::Context, val::P) where {P<:Property}
ctx.property_children = _setproperty!(ctx.property_children, val)
ctx
end

# Substitutes or adds a new property node in the list of children
function _setproperty!{P}(iter, val::P, i)
function _setproperty!(iter, val::P, i) where {P}
if done(iter, i)
# add a node
return ListNode{Property}(val, i)
Expand Down Expand Up @@ -318,13 +322,12 @@ function invert_transform(t::MatrixTransform, x, y)
xyt[1], xyt[2]
end


# Iterators/functions that report object specs in native (screen) units
# These are useful for hit-testing

abstract FormIterator
abstract type FormIterator end

immutable FormNativeIterator{F<:Form,B<:Backend,C} <: FormIterator
struct FormNativeIterator{F<:Form,B<:Backend,C} <: FormIterator
form::F
backend::B
coords::C
Expand All @@ -334,7 +337,7 @@ start(iter::FormNativeIterator) = 1 # some will specialize this
done(iter::FormNativeIterator, state::Int) = state > length(iter.form.primitives)
done(iter::FormNativeIterator, state::Tuple{Int,Int}) = state[1] > length(iter.form.primitives)

native{F,B,C}(form::F, backend::B, coords::C) = FormNativeIterator{F,B,C}(form, backend, coords)
native(form::F, backend::B, coords::C) where {F,B,C} = FormNativeIterator{F,B,C}(form, backend, coords)

@inline inc(state::Tuple{Int,Int}, len::Int) =
ifelse(state[2]+1 > len, (state[1]+1, 1), (state[1], state[2]+1))
Expand All @@ -351,13 +354,13 @@ function native(m::Tuple{Measure,Measure}, backend::Backend, coords)
end

# Iteration for specific Forms
start{F<:Line}(::FormNativeIterator{F}) = (1,1)
function next{F<:Line}(iter::FormNativeIterator{F}, state)
start(::FormNativeIterator{F}) where {F<:Line} = (1,1)
function next(iter::FormNativeIterator{F}, state) where {F<:Line}
nxy = native(iter.form.primitives[state[1]].points[state[2]], iter.backend, iter.coords)
nxy, inc(state, length(iter.form.primitives[state[1]].points))
end

@inline function next{F<:Circle}(iter::FormNativeIterator{F}, state)
@inline function next(iter::FormNativeIterator{F}, state) where {F<:Circle}
prim = iter.form.primitives[state]
nx, ny = native(prim.center, iter.backend, iter.coords)
nr = native(prim.radius, iter.backend, iter.coords)
Expand Down
35 changes: 18 additions & 17 deletions src/display_gadfly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# import Gadfly, Compose, Gtk
import Gadfly: Plot, Aesthetics, Coord.Cartesian
import Gtk: GtkCanvas
import Gtk: GtkCanvas, showall
# import ..Immerse
# import ..Immerse: absolute_to_data, find_tagged, setproperty!

Expand All @@ -20,7 +20,7 @@ import Gtk: GtkCanvas

const ppmm = 72/25.4 # pixels per mm FIXME? Get from backend? See dev2data.

immutable PanZoomCallbacks
struct PanZoomCallbacks
idpzk::Culong
end

Expand All @@ -33,7 +33,7 @@ initialized(pzc::PanZoomCallbacks) = pzc.idpzk != 0

# While figures are by default associated with Windows (each with a
# single Canvas), you can have multiple figures per window.
type Figure <: Gtk.GtkBox
mutable struct Figure <: Gtk.GtkBox
handle
canvas::GtkCanvas
tb
Expand Down Expand Up @@ -78,7 +78,7 @@ function setcoord!(fig::Figure, coord)
fig
end

type GadflyDisplay <: Display
mutable struct GadflyDisplay <: AbstractDisplay
figs::Dict{Int,Figure}
fig_order::Vector{Int}
current_fig::Int
Expand Down Expand Up @@ -172,7 +172,7 @@ function setproperty!(figtag::Tuple{Int,Symbol}, val, prop::Symbol)
end

# Co-opt the REPL display
Base.display(::Base.REPL.REPLDisplay, ::MIME"text/html", p::Plot) = display(_display, p)
Base.display(::REPL.REPLDisplay, ::MIME"text/html", p::Plot) = display(_display, p)

render_backend(c) = Compose.ImmerseBackend(Gtk.cairo_surface(c))

Expand Down Expand Up @@ -216,7 +216,8 @@ nextfig(d::GadflyDisplay) = d.next_fig
function dropfig(d::GadflyDisplay, i::Int)
haskey(d.figs,i) || return
delete!(d.figs, i)
splice!(d.fig_order, findfirst(d.fig_order,i))
splice!(d.fig_order, something(findfirst(isequal(i), d.fig_order), 0) )

d.next_fig = min(d.next_fig, i)
d.current_fig = isempty(d.fig_order) ? 0 : d.fig_order[end]
end
Expand All @@ -233,9 +234,9 @@ function initialize_toolbar_callbacks(f::Figure)
# Gtk.signal_connect(guidata[c,:fullview], "clicked") do widget
# fullview_cb(f)
# end
Gtk.signal_connect(save_as_wrapper, guidata[c,:save_as], "clicked", Void, (), false, f)
Gtk.signal_connect(panzoom_wrapper, guidata[c,:zoom_button], "clicked", Void, (), false, f)
Gtk.signal_connect(fullview_wrapper, guidata[c,:fullview], "clicked", Void, (), false, f)
Gtk.signal_connect(save_as_wrapper, guidata[c,:save_as], "clicked", Nothing, (), false, f)
Gtk.signal_connect(panzoom_wrapper, guidata[c,:zoom_button], "clicked", Nothing, (), false, f)
Gtk.signal_connect(fullview_wrapper, guidata[c,:fullview], "clicked", Nothing, (), false, f)
Immerse.lasso_initialize(f)
end

Expand All @@ -256,7 +257,7 @@ function figure(;name::String="Figure $(nextfig(_display))",
i = nextfig(_display)
f = Figure()

Gtk.signal_connect(on_figure_destroy, f, "destroy", Void, (), false, (i, _display))
Gtk.signal_connect(on_figure_destroy, f, "destroy", Nothing, (), false, (i, _display))

gtkwindow(name, width, height, f)

Expand Down Expand Up @@ -328,7 +329,7 @@ function createPlotGuiComponents()
Gtk.G_.icon_size(tb,1)#small icon size (16px)

c = Gtk.GtkCanvas()
Gtk.setproperty!(c, :expand, true)
Gtk.set_gtk_property!(c, :expand, true)
push!(box, c)

guidata[c, :save_as] = save_as
Expand All @@ -346,7 +347,7 @@ end

function clear_guidata(c)
gd = guidata[c]
to_delete = Array(Symbol, 0)
to_delete = Symbol[]
for (k,v) in gd
if !(k in [:save_as, :zoom_button, :fullview, :lasso_button])
push!(to_delete, k)
Expand All @@ -361,7 +362,7 @@ function clear_guistate!(f::Figure)
if initialized(f.panzoom_cb)
disconnect(f, f.panzoom_cb)
end
Gtk.setproperty!(guidata[f.canvas, :zoom_button], :active, false)
Gtk.set_gtk_property!(guidata[f.canvas, :zoom_button], :active, false)
f.panzoom_cb = PanZoomCallbacks()
end

Expand All @@ -375,7 +376,7 @@ function render_finish(prep; kwargs...)
p = _plot(prep)
root_context = Gadfly.render_prepared(prep...; kwargs...)

ctx = Compose.pad_inner(root_context, p.theme.plot_padding)
ctx = Compose.pad_inner(root_context, p.theme.plot_padding...)

if p.theme.background_color != nothing
Compose.compose!(ctx, (Compose.context(order=-1000000),
Expand Down Expand Up @@ -433,7 +434,7 @@ function GtkUtilities.panzoom(f::Figure)
aes = _aes(f)
xview = (aes.xviewmin, aes.xviewmax)
yview = (aes.yviewmin, aes.yviewmax)

if xview == (nothing, nothing)
xview = (minimum(aes.x),maximum(aes.x))
end
Expand Down Expand Up @@ -506,13 +507,13 @@ end

function panzoom_cb(f::Figure)
if isempty(f)
Gtk.setproperty!(guidata[f.canvas, :zoom_button], :active, false)
Gtk.set_gtk_property!(guidata[f.canvas, :zoom_button], :active, false)
return nothing
end
if !initialized(f.panzoom_cb)
f.panzoom_cb = PanZoomCallbacks(f)
else
state = Gtk.getproperty(guidata[f.canvas, :zoom_button], :active, Bool)
state = Gtk.get_gtk_property(guidata[f.canvas, :zoom_button], :active, Bool)
if state
unblock(f, f.panzoom_cb)
else
Expand Down
Loading

0 comments on commit d40ff4f

Please sign in to comment.