GithubHelp home page GithubHelp logo

dynamicobjects's Introduction

DynamicObjects

Mini framework helping to scale Dynamics up.

There are many features and enhancements in the pipeline.

Installation

Manual

Go to 'releases' tab and download appropriate .paclet file.

Run PacletInstall @ path/to/the.paclet file

Via MPM`

If you don't have MPM` yet, run:

Import["https://raw.githubusercontent.com/kubapod/mpm/master/install.m"]

and then:

Needs @ "MPM`"    
MPM`MPMInstall["kubapod", "dynamicobjects"]

Background

The problem with scaling of Dynamic is as explained here: Allow multiple GUI elements to react dynamically to interaction with a single element.

The solution to linked problem is not readable / approachable unless you are a power user:

n = 120;
names = Range[n];
pts = AssociationThread[names -> N@CirclePoints[n]];
edges = RandomSample[Subsets[names, {2}], 250];
DynamicModule[{}
, Graphics[
    {
      (
        ToExpression[
          "{sA:=state" <> ToString[#] <> ", sB:=state" <> ToString[#2] <> "}"
        , StandardForm
        , Hold
        ] /. Hold[spec_] :> With[
          spec, {  Dynamic @ If[TrueQ[sA || sB], Red, Black], Line[{pts[#1], pts[#2]}] }
        ]
      ) & @@@ edges
    , PointSize[0.025]
    , (
        ToExpression[
          "{sA:=state" <> ToString[#] <> "}"
        , StandardForm
        , Hold
        ] /. Hold[spec_] :> With[
          spec
        , { Dynamic @ If[TrueQ[sA], Red, Black]
          , EventHandler[ Point @ pts[#], {"MouseEntered" :> (sA = True), "MouseExited" :> (sA = False)}  ]
          }
        ]
      ) & /@ names
    }
  , ImageSize -> Large
  ]
]

Using this package it is way more handy, additionally it scopes all generated symbols unlike the code above (that would make it even worse):

FrontEndModule[ 
  Graphics[
    { 
      { 
        Dynamic @ If[ TrueQ[ FrontEndSymbol["state",#1] || FrontEndSymbol["state", #2] ], Red, Black]
      , Line[{pts[#1],pts[#2]}]
      }& @@@ edges    
    , {
        AbsolutePointSize@7
      , Dynamic @ If[ TrueQ[FrontEndSymbol["state",#1]], Red, Black]
      , EventHandler[Point@pts[#],{"MouseEntered":>(FrontEndSymbol["state",#1]=True),"MouseExited":>(FrontEndSymbol["state",#1]=False)}]
      }& /@ names
    }
  , ImageSize -> Medium
  ]
]

Bonus

If you know what you are doing you can even create a completely FrontEnd side interaction:

<< DynamicObjects`

n = 150;
names = Range[n];
pts = AssociationThread[names -> N@CirclePoints[n]];
edges = RandomSample[Subsets[names, {2}], 2000];

FrontEndModule[
 Graphics[
  { 
    { DynamicBox[
        FEPrivate`If[
          FEPrivate`SameQ[ FEPrivate`Or[ FrontEndSymbol["state",#1], FrontEndSymbol["state", #2]], True ]
        , RGBColor[1,0,1]
        , RGBColor[0. ,0. ,0. , .1]
        
        ]
      ]
    , Line[{pts[#1],pts[#2]}]
    }& @@@ edges
  , PointSize[0.025]
  , { 
      DynamicBox[
        FEPrivate`If[ 
          SameQ[FrontEndSymbol["state",#1],True]
        , RGBColor[1,0,1]
        , RGBColor[0,0,0]
        ]
      ]
    , EventHandler[Point@pts[#]
      , { "MouseEntered" :> FEPrivate`Set[FrontEndSymbol["state",#1],True]
        , "MouseExited":>FEPrivate`Set[FrontEndSymbol["state",#1],False]
        }
      ]
    }& /@ names
  }
, ImageSize->Large
],
Initialization :> ( Set[FrontEndSymbol["state", #],False] & /@ Range[n])
]

Alt text

dynamicobjects's People

Contributors

kubapod avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dynamicobjects's Issues

No License file?

I just noticed that the repository does not seem to have a license file. Is this code free to use?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.