added some error checks and warnings

nix
Ted Moore 4 years ago
parent 656ff21b71
commit f96f5d7000

@ -33,14 +33,8 @@ FluidPlotter {
ymin = ymin_; ymin = ymin_;
ymax = ymax_; ymax = ymax_;
if(dict_.isNil,{this.dictNotProperlyFormatted});
if(dict_.size != 2,{this.dictNotProperlyFormatted});
if(dict_.at("data").isNil,{this.dictNotProperlyFormatted});
if(dict_.at("cols").isNil,{this.dictNotProperlyFormatted});
if(dict_.at("cols") != 2,{this.dictNotProperlyFormatted});
this.createCatColors; this.createCatColors;
this.dict_(dict_); if(dict_.notNil,{this.dict_(dict_)});
this.createPlotWindow(bounds,parent_,mouseMoveAction,dict_); this.createPlotWindow(bounds,parent_,mouseMoveAction,dict_);
this.background_(Color.white); this.background_(Color.white);
} }
@ -54,6 +48,7 @@ FluidPlotter {
setCategories_ { setCategories_ {
arg labelSetDict; arg labelSetDict;
if(dict_internal.notNil,{
dict_internal.keysValuesDo({ dict_internal.keysValuesDo({
arg id, pt; arg id, pt;
var col, cat = labelSetDict.at("data").at(id)[0].interpret; var col, cat = labelSetDict.at("data").at(id)[0].interpret;
@ -62,6 +57,9 @@ FluidPlotter {
pt.color_(col); pt.color_(col);
}); });
this.refresh; this.refresh;
},{
"FluidPlotter::setCategories_ FluidPlotter cannot receive setCategories. It has no data. First set a dictionary.".warn;
});
} }
setSizeMultiplier_ { setSizeMultiplier_ {
@ -113,6 +111,13 @@ FluidPlotter {
dict_ { dict_ {
arg d; arg d;
if(d.isNil,{^this.dictNotProperlyFormatted});
if(d.size != 2,{^this.dictNotProperlyFormatted});
if(d.at("data").isNil,{^this.dictNotProperlyFormatted});
if(d.at("cols").isNil,{^this.dictNotProperlyFormatted});
if(d.at("cols") != 2,{^this.dictNotProperlyFormatted});
dict = d; dict = d;
dict_internal = Dictionary.new; dict_internal = Dictionary.new;
dict.at("data").keysValuesDo({ dict.at("data").keysValuesDo({
@ -170,6 +175,7 @@ FluidPlotter {
userView = UserView(parent,Rect(xpos,ypos,bounds.width,bounds.height)); userView = UserView(parent,Rect(xpos,ypos,bounds.width,bounds.height));
userView.drawFunc_({ userView.drawFunc_({
if(dict_internal.notNil,{
dict_internal.keysValuesDo({ dict_internal.keysValuesDo({
arg key, pt; arg key, pt;
var pointSize_, scaledx, scaledy, color; var pointSize_, scaledx, scaledy, color;
@ -197,6 +203,7 @@ FluidPlotter {
Pen.draw; Pen.draw;
}); });
}); });
});
userView.mouseMoveAction_({ userView.mouseMoveAction_({
arg view, x, y, modifiers; arg view, x, y, modifiers;

@ -1,5 +1,6 @@
( (
~dummy_data = { ~dummy_data = {
arg xmin = 20, xmax = 20000, ymin = -130, ymax = 0;
Dictionary.newFrom([ Dictionary.newFrom([
"cols",2, "cols",2,
"data",Dictionary.newFrom(Array.fill(200,{ "data",Dictionary.newFrom(Array.fill(200,{
@ -8,7 +9,7 @@
if((i % 2) == 0,{ if((i % 2) == 0,{
return = "example-%".format((i/2).asInteger); return = "example-%".format((i/2).asInteger);
},{ },{
return = [exprand(20,20000),rrand(-130,0)]; return = [rrand(xmin,xmax),rrand(ymin,ymax)];
}); });
// return.postln; // return.postln;
return; return;
@ -54,6 +55,7 @@ d = ~dummy_data.value;
~fp.setColor_("example-7",Color.red); ~fp.setColor_("example-7",Color.red);
~fp.background_(Color.white)
~fp.background_(Color.red) ~fp.background_(Color.red)
~fp.close; ~fp.close;
@ -67,7 +69,7 @@ s.waitForBoot{
s.sync; s.sync;
ds.load(~fp.dict,{ ds.load(~dummy_data.(),{
kmeans.fitPredict(ds,labelset,{ kmeans.fitPredict(ds,labelset,{
labelset.dump({ labelset.dump({
arg lsdict; arg lsdict;
@ -104,3 +106,10 @@ w = Window("test",Rect(50,50,800,600)).front;
"".postln; "".postln;
},xmin:20,xmax:20000,ymin:-130,ymax:0); },xmin:20,xmax:20000,ymin:-130,ymax:0);
) )
(
Window.closeAll;
~fp = FluidPlotter(bounds:Rect(100,100,500,500))
)
~fp.dict_(~dummy_data.(0.01,1,0.0,1.0).postln);
Loading…
Cancel
Save