fluid plotter synced up with james' max one, helpfile _started_

nix
Ted Moore 4 years ago
parent bf899a100b
commit 372fca134f

@ -1,23 +1,23 @@
FluidPlotterPoint { FluidPlotterPoint {
var id, <x, <y, <>color, <>sizeMultiplier = 1; var id, <x, <y, <>color, <>size = 1;
*new { *new {
arg id, x, y, color, sizeMultiplier = 1; arg id, x, y, color, size = 1;
^super.new.init(id,x,y,color,sizeMultiplier); ^super.new.init(id,x,y,color,size);
} }
init { init {
arg id_, x_, y_, color_, sizeMultiplier_ = 1; arg id_, x_, y_, color_, size_ = 1;
id = id_; id = id_;
x = x_; x = x_;
y = y_; y = y_;
color = color_ ? Color.black; color = color_ ? Color.black;
sizeMultiplier = sizeMultiplier_; size = size_;
} }
} }
FluidPlotter { FluidPlotter {
var <parent, <userView, <xmin, <xmax, <ymin, <ymax, <pointSize = 6, dict_internal, <dict, shape = \circle, catColors, highlightIdentifier; var <parent, <userView, <xmin, <xmax, <ymin, <ymax, <pointSize = 6, pointSizeScale = 1, dict_internal, <dict, shape = \circle, catColors, highlightIdentifier;
*new { *new {
arg parent, bounds, dict, mouseMoveAction,xmin = 0,xmax = 1,ymin = 0,ymax = 1; arg parent, bounds, dict, mouseMoveAction,xmin = 0,xmax = 1,ymin = 0,ymax = 1;
@ -45,7 +45,7 @@ FluidPlotter {
}); });
} }
setCategories_ { categories_ {
arg labelSetDict; arg labelSetDict;
if(dict_internal.notNil,{ if(dict_internal.notNil,{
dict_internal.keysValuesDo({ dict_internal.keysValuesDo({
@ -61,23 +61,33 @@ FluidPlotter {
}); });
} }
setSizeMultiplier_ { pointSize_ {
arg identifier, sizeMultiplier; arg identifier, size;
if(dict_internal.at(identifier).notNil,{ if(dict_internal.at(identifier).notNil,{
dict_internal.at(identifier).sizeMultiplier_(sizeMultiplier); dict_internal.at(identifier).size_(size);
this.refresh; this.refresh;
},{ },{
"FluidPlotter::setSizeMultiplier_ identifier not found".warn; "FluidPlotter::pointSize_ identifier not found".warn;
});
}
// TODO: addPoint_ that checks if the key already exists and throws an error if it does
addPoint_ {
arg identifier, x, y, color, size = 1;
if(dict_internal.at(identifier).notNil,{
"FluidPlotter::addPoint_ There already exists a point with identifier %. Point not added. Use setPoint_ to overwrite existing points.".format(identifier).warn;
},{
this.setPoint_(identifier,x,y,size,color);
}); });
} }
setPoint_ { setPoint_ {
arg identifier, x, y, sizeMultiplier = 1, color; arg identifier, x, y, color, size = 1;
dict_internal.put(identifier,FluidPlotterPoint(identifier,x,y,color ? Color.black,sizeMultiplier)); dict_internal.put(identifier,FluidPlotterPoint(identifier,x,y,color ? Color.black,size));
this.refresh; this.refresh;
} }
setColor_ { pointColor_ {
arg identifier, color; arg identifier, color;
if(dict_internal.at(identifier).notNil,{ if(dict_internal.at(identifier).notNil,{
dict_internal.at(identifier).color_(color); dict_internal.at(identifier).color_(color);
@ -102,9 +112,9 @@ FluidPlotter {
{userView.refresh}.defer; {userView.refresh}.defer;
} }
pointSize_ { pointSizeScale_ {
arg ps; arg ps;
pointSize = ps; pointSizeScale = ps;
this.refresh; this.refresh;
} }
@ -189,11 +199,13 @@ FluidPlotter {
pt.y.postln;*/ pt.y.postln;*/
if(key == highlightIdentifier,{ if(key == highlightIdentifier,{
pointSize_ = pointSize * 2.3 * pt.sizeMultiplier pointSize_ = pointSize * 2.3 * pt.size
},{ },{
pointSize_ = pointSize * pt.sizeMultiplier pointSize_ = pointSize * pt.size
}); });
pointSize_ = pointSize_ * pointSizeScale;
scaledx = pt.x.linlin(xmin,xmax,0,userView.bounds.width,nil) - (pointSize_/2); scaledx = pt.x.linlin(xmin,xmax,0,userView.bounds.width,nil) - (pointSize_/2);
scaledy = pt.y.linlin(ymax,ymin,0,userView.bounds.height,nil) - (pointSize_/2); scaledy = pt.y.linlin(ymax,ymin,0,userView.bounds.height,nil) - (pointSize_/2);

@ -0,0 +1,267 @@
TITLE:: FluidPlotter
summary:: A view for plotting data
categories:: Libraries>FluidCorpusManipulation
related:: Classes/FluidDataSet, Classes/FluidLabelSet, Classes/FluidKDTree, Classes/FluidKMeans
DESCRIPTION::
FluidPlotter is a viewer for plotting data.
CLASSMETHODS::
METHOD:: new
Creates a new instance of FluidPlotter
ARGUMENT:: parent
A parent view to embed the FluidPlotter in. If no parent is passed, FluidPlotter will create a window for itself at the given bounds.
ARGUMENT:: bounds
Where to show the FluidPlotter, either within the parent or on the screen (if no parent is passed).
ARGUMENT:: dict
A link::Classes/Dictionary::
ARGUMENT:: mouseMoveAction
(describe argument here)
ARGUMENT:: xmin
(describe argument here)
ARGUMENT:: xmax
(describe argument here)
ARGUMENT:: ymin
(describe argument here)
ARGUMENT:: ymax
(describe argument here)
returns:: (describe returnvalue here)
INSTANCEMETHODS::
METHOD:: background
(describe method here)
ARGUMENT:: bg
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: xmin
(describe method here)
ARGUMENT:: val
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: pointSize
(describe method here)
ARGUMENT:: identifier
(describe argument here)
ARGUMENT:: size
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: refresh
(describe method here)
returns:: (describe returnvalue here)
METHOD:: ymin
(describe method here)
ARGUMENT:: val
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: userView
(describe method here)
returns:: (describe returnvalue here)
METHOD:: setPoint
(describe method here)
ARGUMENT:: identifier
(describe argument here)
ARGUMENT:: x
(describe argument here)
ARGUMENT:: y
(describe argument here)
ARGUMENT:: color
(describe argument here)
ARGUMENT:: size
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: ymax
(describe method here)
ARGUMENT:: val
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: xmax
(describe method here)
ARGUMENT:: val
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: highlight
(describe method here)
ARGUMENT:: identifier
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: dict
(describe method here)
ARGUMENT:: d
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: createPlotWindow
(describe method here)
ARGUMENT:: bounds
(describe argument here)
ARGUMENT:: parent_
(describe argument here)
ARGUMENT:: mouseMoveAction
(describe argument here)
ARGUMENT:: dict_
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: addPoint
(describe method here)
ARGUMENT:: identifier
(describe argument here)
ARGUMENT:: x
(describe argument here)
ARGUMENT:: y
(describe argument here)
ARGUMENT:: color
(describe argument here)
ARGUMENT:: size
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: shape
(describe method here)
ARGUMENT:: sh
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: globalPointSize
(describe method here)
ARGUMENT:: ps
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: close
(describe method here)
returns:: (describe returnvalue here)
METHOD:: createCatColors
(describe method here)
returns:: (describe returnvalue here)
METHOD:: pointColor
(describe method here)
ARGUMENT:: identifier
(describe argument here)
ARGUMENT:: color
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: dictNotProperlyFormatted
(describe method here)
returns:: (describe returnvalue here)
METHOD:: parent
(describe method here)
returns:: (describe returnvalue here)
METHOD:: categories
(describe method here)
ARGUMENT:: labelSetDict
(describe argument here)
returns:: (describe returnvalue here)
METHOD:: init
(describe method here)
ARGUMENT:: parent_
(describe argument here)
ARGUMENT:: bounds
(describe argument here)
ARGUMENT:: dict_
(describe argument here)
ARGUMENT:: mouseMoveAction
(describe argument here)
ARGUMENT:: xmin_
(describe argument here)
ARGUMENT:: xmax_
(describe argument here)
ARGUMENT:: ymin_
(describe argument here)
ARGUMENT:: ymax_
(describe argument here)
returns:: (describe returnvalue here)
EXAMPLES::
code::
(some example code)
::

@ -28,11 +28,13 @@ d = ~dummy_data.value;
},xmin:20,xmax:20000,ymin:-130,ymax:0); },xmin:20,xmax:20000,ymin:-130,ymax:0);
) )
~fp.pointSize_(10); ~fp.pointSize_("example-5",10);
~fp.pointSize_("example-5",1);
~fp.pointSizeScale_(1);
( (
10.do({ 10.do({
~fp.setColor_("example-%".format(rrand(0,99)),Color.yellow); ~fp.pointColor_("example-%".format(rrand(0,99)),Color.yellow);
}); });
) )
@ -50,13 +52,10 @@ d = ~dummy_data.value;
~fp.shape_(\square); ~fp.shape_(\square);
~fp.setSizeMultiplier_("example-0",10); ~fp.pointColor_("example-7",Color.red);
~fp.setSizeMultiplier_("example-0",1);
~fp.setColor_("example-7",Color.red);
~fp.background_(Color.white)
~fp.background_(Color.red) ~fp.background_(Color.red)
~fp.background_(Color.white)
~fp.close; ~fp.close;
@ -73,7 +72,7 @@ s.waitForBoot{
kmeans.fitPredict(ds,labelset,{ kmeans.fitPredict(ds,labelset,{
labelset.dump({ labelset.dump({
arg lsdict; arg lsdict;
defer{~fp.setCategories_(lsdict)}; defer{~fp.categories_(lsdict)};
"done".postln; "done".postln;
}); });
}); });

Loading…
Cancel
Save