Vue d'ensemble
Exemples
Captures d'écrans
Comparaisons
Applications
Télécharger
Documentation
Bazaar
État et Feuille de route
Foire aux questions
Auteurs & licence
Forums
Financement de U++
Recherche sur ce site
Langue
français













SourceForge.net Logo



ScatterCtrl Demo

 

Scatter series in GUI applications

 

 

ScatterCtrl_Demo.h

 

#ifndef _ScatterCtrl_Demo_ScatterCtrl_Demo_h

#define _ScatterCtrl_Demo_ScatterCtrl_Demo_h

 

#include <ScatterCtrl/ScatterCtrl.h>

#include <ScatterCtrl/PieCtrl.h>

 

using namespace Upp;

 

#define LAYOUTFILE <ScatterCtrl_Demo/ScatterCtrl_Demo.lay>

#include <CtrlCore/lay.h>

 

#define IMAGECLASS MyImages

#define IMAGEFILE <ScatterCtrl_Demo/ScatterCtrl_Demo.iml>

#include <Draw/iml_header.h>

 

 

struct ScatterDemo : StaticRect {

    virtual void Init() {};

    virtual ScatterCtrl &Scatter() = 0;

};

void RegisterExample(const char *name, ScatterDemo* (*ctrl)(), String fileName);

 

class Tab1 : public WithTab1<ScatterDemo> {

public:

    typedef Tab1 CLASSNAME;

    

    virtual void Init();

    virtual ScatterCtrl &Scatter()    {return scatter;};

 

private:

    Vector<Pointf> s1;

    double s2y[5];

    double s3x[5], s3y[5];

    Vector<double> s4x, s4y;

    VectorMap<double, double> s5;

};

 

class Tab2 : public WithTab2<ScatterDemo> {

public:

    typedef Tab2 CLASSNAME;

    

    void Init();

    virtual ScatterCtrl &Scatter()    {return scatter;};

    

    Callback back1, back2, back3;

};

 

class Tab3 : public WithTab3<ScatterDemo> {

public:

    typedef Tab3 CLASSNAME;

    

    void Init();

    virtual ScatterCtrl &Scatter()    {return scatter;};

};

 

class Tab4 : public WithTab4<ScatterDemo> {

public:

    typedef Tab4 CLASSNAME;

    

    void Init();

    virtual ScatterCtrl &Scatter()    {return scatter;};

    

private:

    Vector<Pointf> s1, s2;

};

 

class Tab5 : public WithTab5<ScatterDemo> {

public:

    typedef Tab5 CLASSNAME;

    

    void Init();

    void Animate();

    void Start();

    void Stop();

    void Reset();

    void PgDown();

    void PgUp();

    void Plus();

    void Minus();

    virtual ScatterCtrl &Scatter()    {return scatter;};

    

private:

    double t;

    Vector<Pointf> s1, s2;

};

 

class Tab6 : public WithTab6<ScatterDemo> {

public:

    typedef Tab6 CLASSNAME;

    

    void Init();

    void FormatX(String& s, int i, double d);    

    virtual ScatterCtrl &Scatter()    {return scatter;};

 

private:

    Vector<Pointf> s1;

};

 

class Tab7 : public WithTab7<ScatterDemo> {

public:

    typedef Tab7 CLASSNAME;

    

    void Init();        

    void AddSeries();

    void RemoveFirstSeries();

    void RemoveLastSeries();

    void RemoveAllSeries();

    virtual ScatterCtrl &Scatter()    {return scatter;};

 

private:

    Array<Vector<Pointf> > series;

};

 

class Tab8 : public WithTab8<ScatterDemo> {

public:

    typedef Tab8 CLASSNAME;

 

    void Init();

    void MyFormat(String& s, int i, double d)

    {

        s = Format("%Mon", fround(d));

        if (!s.IsEmpty())

            s << "\n2011";

    }

    void MyFormatDelta(String& s, int i, double d)

    {

        s = FormatDouble(d, 1) + " " + t_("months");

    }

    virtual ScatterCtrl &Scatter()    {return scatter;};

 

private:

    Vector<Pointf> s1,s2, s3;

};

 

class Tab9 : public WithTab9<ScatterDemo> {

public:

    typedef Tab9 CLASSNAME;

    

    void Init();

    void OnFastView()        {scatter.SetFastViewX(fastView);};

    void OnSequentialX()    {scatter.SetSequentialXAll(sequentialX);};

    virtual ScatterCtrl &Scatter()    {return scatter;};

 

private:

    Vector<Pointf> s1,s2;

};

 

class Tab10 : public WithTab10<ScatterDemo> {

public:

    typedef Tab10 CLASSNAME;

    

    void Init();

    virtual ScatterCtrl &Scatter()    {return scatter;};

 

private:

    double sx[5], sy[5];

};

 

class Tab11 : public WithTab11<ScatterDemo> {

public:

    typedef Tab11 CLASSNAME;

 

    Tab11() {};    

    void Init();

    virtual ScatterCtrl &Scatter()    {return scatter;};

 

private:

    Vector<double> sx, sy;

    LinearEquation linear;

    PolynomialEquation poly2, poly4;

    FourierEquation fourier;

};

 

class TabPie : public WithTabPie<StaticRect> {

public:

    typedef TabPie CLASSNAME;

    

    void Init();

};

 

class ScatterCtrl_Demo : public WithScatterCtrl_Demo<TopWindow> {

    typedef ScatterCtrl_Demo CLASSNAME;

    

public:

    ScatterCtrl_Demo();

    TabPie tabPie;

    

private:

    void Preview();

    void SavePNG();

    void SaveJPG();

#ifdef PLATFORM_WIN32

    void SaveEMF();

#endif

    void CopyClipboard();

    void SetMode();

 

    void OnSel();

 

    Vector<StaticRect *> examplesRects;

};

 

#endif

 

 

 

 

main.cpp

 

#include "ScatterCtrl_Demo.h"

 

#include <Report/Report.h>

#include <PdfDraw/PdfDraw.h>

 

#define IMAGECLASS MyImages

#define IMAGEFILE <ScatterCtrl_Demo/ScatterCtrl_Demo.iml>

#include <Draw/iml_source.h>

 

 

struct Example {

    ScatterDemo* (*ctrl)();

    String name;

    int index;

};

 

Array<Example>& Examples()

{

    static Array<Example> x;

    return x;

};

 

void RegisterExample(const char *name, ScatterDemo* (*ctrl)(), String fileName)

{

    Example& x = Examples().Add();

    x.name = name;

    x.ctrl = ctrl;

    x.index = ScanInt(GetFileName(fileName).Mid(3, 2));

}

 

bool CompareExamples(Example &a, Example &b) {return a.index < b.index;}

 

GUI_APP_MAIN

{

    Sort(Examples(), CompareExamples);

    

    ScatterCtrl_Demo().Run();

}

 

ScatterCtrl_Demo::ScatterCtrl_Demo()

{

    CtrlLayout(*this, "Scatter Test");

 

    for (int i = 0; i < Examples().GetCount(); ++i)

        Examples()[i].ctrl()->Init();

            

    examplesList.NoHorzGrid().NoVertGrid();

    examplesList.AddColumn("Example name");

    for (int i = 0; i < Examples().GetCount(); ++i) {

        examplesList.Add(Examples()[i].name);

        Add((*(Examples()[i].ctrl())).HSizePosZ(180, 4).VSizePosZ(4, 8));

        examplesRects.Add(Examples()[i].ctrl());

    }

    examplesList.Add("Pie chart");

//    tabPie.Init();

    Add(tabPie.HSizePosZ(180, 4).VSizePosZ(4, 8));

    examplesRects.Add(&tabPie);

    

    for (int i = 0; i < examplesRects.GetCount(); ++i)

        examplesRects[i]->Hide();

        

    bPreview <<= THISBACK(Preview);

    bSavePNG <<= THISBACK(SavePNG);

    bSaveJPG <<= THISBACK(SaveJPG);

#ifdef PLATFORM_WIN32

    bSaveEMF <<= THISBACK(SaveEMF);

#else

    bSaveEMF.Hide();

#endif

    bCopyClipboard <<= THISBACK(CopyClipboard);

    

    paintMode.Add(ScatterDraw::MD_ANTIALIASED, "Painter Antialiased")

             .Add(ScatterDraw::MD_NOAA,        "Painter No-Antialiased")

             .Add(ScatterDraw::MD_SUBPIXEL,    "Painter Subpixel")

             .Add(ScatterDraw::MD_DRAW,        "Draw");

 

    paintMode <<= THISBACK(SetMode);

    paintMode.SetData(ScatterDraw::MD_ANTIALIASED);

    SetMode();

 

    examplesList.WhenSel = THISBACK(OnSel);

    examplesList.Select(0, false);

    OnSel();

 

    Sizeable().Zoomable().Icon(MyImages::i1());

}

 

void ScatterCtrl_Demo::OnSel()

{

    for (int i = 0; i < examplesRects.GetCount(); ++i)

        examplesRects[i]->Hide();        

    if (examplesList.GetCursor() < 0)

        return;

    examplesRects[examplesList.GetCursor()]->Show();

}

    

void ScatterCtrl_Demo::Preview()

{

    Report r;    

    

    const Drawing &w = Examples()[examplesList.GetCursor()].ctrl()->Scatter().GetDrawing();

    r.Landscape();

    Size pageSize = r.GetPageSize();

    r.DrawDrawing(0, 0, pageSize.cx, pageSize.cy, w);

 

    Perform(r);

}

 

void ScatterCtrl_Demo::SavePNG()

{

    int ntab = examplesList.GetCursor();    

    

    Examples()[ntab].ctrl()->Scatter().SaveToFile(AppendFileName(GetDesktopFolder(), Format("scatter%d.png", ntab)));    

}

 

void ScatterCtrl_Demo::SaveJPG()

{

    int ntab = examplesList.GetCursor();    

    

    Examples()[ntab].ctrl()->Scatter().SaveToFile(AppendFileName(GetDesktopFolder(), Format("scatter%d.jpg", ntab)));                

}

 

#ifdef PLATFORM_WIN32

void ScatterCtrl_Demo::SaveEMF()

{

    int ntab = examplesList.GetCursor();    

    

    Examples()[ntab].ctrl()->Scatter().SaveAsMetafile(AppendFileName(GetDesktopFolder(), Format("scatter%d.emf", ntab)));                

}

#endif

 

void ScatterCtrl_Demo::CopyClipboard()

{

    Examples()[examplesList.GetCursor()].ctrl()->Scatter().SaveToClipboard();    

}

 

void ScatterCtrl_Demo::SetMode()

{

    for (int i = 0; i < Examples().GetCount(); ++i)

        Examples()[i].ctrl()->Scatter().SetMode(~paintMode);

}

 

 

 

 

tab10.cpp

 

#include "ScatterCtrl_Demo.h"

 

#define IMAGECLASS Symbol

#define IMAGEFILE <ScatterCtrl_Demo/symbol.iml>

#include <Draw/iml.h>

 

class MyPlot : public SeriesPlot {

private:

    template <class T>

    void DoPaint(T& w, Vector<Point> &p, const int &scale, const double opacity,

                double thick, const Color &color, String pattern, const Color &background,

                const Color &fillColor, int y0) const {

        Vector<Point> t;

        t.SetCount(3);

        for (int i = 0; i < p.GetCount(); ++i) {

            t[0].x = p[i].x + 80;

            t[0].y = y0;

            t[1] = p[i];

            t[2].x = p[i].x - 80;

            t[2].y = y0;

            if (!IsNull(fillColor))

                FillPolylineOpa(w, t, scale, opacity, background, fillColor);

            DrawPolylineOpa(w, t, scale, 1, thick, color, pattern, background);        

        }

    }

    

public:

    void Paint(Draw& w, Vector<Point> &p, const int &scale, const double opacity,

                double thick, const Color &color, String pattern, const Color &background,

                const Color &fillColor, double fx, double fy, int y0) const {

        DoPaint(w, p, scale, opacity, fround(thick), color, pattern, background, fillColor, y0);        

    }

    void Paint(Painter& w, Vector<Point> &p, const int &scale, const double opacity,

                double thick, const Color &color, String pattern, const Color &background,

                const Color &fillColor, double fx, double fy, int y0) const {

        DoPaint(w, p, scale, opacity, fround(thick), color, pattern, background, fillColor, y0);        

    }

};

 

class MyMark : public MarkPlot {

private:

    template <class T>

    void DoPaint(T& w, const int& scale, const Point& cp, const double& size, const Color& markColor) const {

        w.DrawImage(cp.x-8, cp.y-8, Symbol::bug());

    }

 

public:

    void Paint(Draw &p, const int& scale, const Point& cp, const double& size, const Color& markColor) const {

        DoPaint(p, scale, cp, size, markColor);

    }

    void Paint(Painter &p, const int& scale, const Point& cp, const double& size, const Color& markColor) const {

        DoPaint(p, scale, cp, size, markColor);

    }

};

 

void Tab10::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    

    sy[0] = 18; sy[1] = 29; sy[2] = 23; sy[3] = 25; sy[4] = 20;

    sx[0] = 10; sx[1] = 20; sx[2] = 30; sx[3] = 40; sx[4] = 50;

    scatter.AddSeries(sx, sy, 5).Legend("Series").PlotStyle<MyPlot>().MarkStyle<MyMark>().Stroke(3, LtGreen()).Fill(LtGray());

    

    scatter.SetRange(60, 50).SetMajorUnits(10, 10);

    scatter.ShowInfo().ShowContextMenu();

}

 

ScatterDemo *Construct10()

{

    static Tab10 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("User graph", Construct10, __FILE__);

 

    SeriesPlot::Register<MyPlot>("My plot");

    MarkPlot::Register<MyMark>("My mark");

}

 

 

tab3.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

Pointf opara1(double t) {return Pointf(0.5*cos(2*M_PI*t), 0.5*sin(2*M_PI*t));}

 

void para1(Pointf& xy, double t) {xy = Pointf(cos(2*M_PI*t), sin(2*M_PI*t));}

void para2(Pointf& xy, double t) {xy = Pointf(0.5*cos(6*M_PI*t)+3*t-1, 1.5+0.5*sin(6*M_PI*t));}

void para3(Pointf& xy, double t) {xy = Pointf(3+(0.5+t)*cos(6*M_PI*t), (0.5+t)*sin(6*M_PI*t));}

void para4(Pointf& xy, double t) {xy = Pointf(0, -0.25+0.5*t);}

void para5(Pointf& xy, double t) {xy = Pointf(-0.25+0.5*t, 0);}

 

void para1p(Pointf& xy, double t, double a, double b)     {xy = Pointf(a*cos(2*M_PI*t),b*sin(2*M_PI*t));}

void para3p(Pointf& xy, double t, double a)             {xy = Pointf(a+(0.5+t)*cos(6*M_PI*t),(0.5+t)*sin(6*M_PI*t));}

 

void Tab3::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(7, 4);

    scatter.SetMajorUnits(0.5, 0.5);

    scatter.SetXYMin(-2, -2);

    

    scatter.AddSeries(&opara1, 20).Legend("Circle 1");//.NoMark();

    scatter.AddSeries(STDBACK(para1), 100).Legend("Circle 2").NoMark();

    scatter.AddSeries(STDBACK(para2), 100).Legend("Coil").NoMark();

    scatter.AddSeries(STDBACK(para3), 150).Legend("Spiral 1").NoMark();

    scatter.AddSeries(STDBACK1(para3p, 2.5), 150, 0, 1).Legend("Spiral 2").NoMark();

    scatter.AddSeries(STDBACK(para4), 2).Legend("VLine").NoMark();

    scatter.AddSeries(STDBACK(para5), 2).Legend("HLine").NoMark();

    scatter.AddSeries(STDBACK2(para1p, 4.0, 0.25), 50, 0, 1).Legend("Ellipse 1").NoMark();

    scatter.AddSeries(STDBACK2(para1p, 2.0, 0.5), 50, 0, 1).Legend("Ellipse 2").NoMark();

}

 

ScatterDemo *Construct3()

{

    static Tab3 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Parametric Functions", Construct3, __FILE__);

}

 

 

tab4.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

void Tab4::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(13, 50)

           .SetMajorUnits(1, 10)

           .SetXYMin(0, -20);

    scatter.SetMouseHandling(true).ShowContextMenu();

    

    s1 <<Pointf(1,-6)<<Pointf(2,-4)<<Pointf(3,2)<<Pointf(4,8)<<Pointf(5,8)<<Pointf(6,15)<<Pointf(7,20)<<Pointf(8,25)<<Pointf(9,14)<<Pointf(10,10)<<Pointf(11,3)<<Pointf(12,-11);

    scatter.AddSeries(s1).Legend("2005");

    

    s2 <<Pointf(1,-12)<<Pointf(2,-7)<<Pointf(3,0)<<Pointf(4,2)<<Pointf(5,10)<<Pointf(6,18)<<Pointf(7,25)<<Pointf(8,26)<<Pointf(9,15)<<Pointf(10,12)<<Pointf(11,7)<<Pointf(12,-6);

    scatter.AddSeries(s2).Legend("2006").MarkStyle<CircleMarkPlot>();

    

    scatter.Graduation_FormatX(ScatterCtrl::MON)

           .SetLabelY("Temperature [176 C]")

           .SetMarkWidth(1, 4);

}

 

ScatterDemo *Construct4()

{

    static Tab4 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Formatting", Construct4, __FILE__);

}

 

 

tab9.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

void Tab9::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(100000,40).SetXYMin(0, -20);

    scatter.SetMouseHandling(true).SetMaxZoom(500000).SetMinZoom(2);

    for (int t = 0; t < 100000; ++t) {

        s1 <<Pointf(t,20*sin(2*M_PI*t/100000));

        s2 <<Pointf(t,15*cos(2*M_PI*t/100000));

    }

    scatter.AddSeries(s1).Legend("series1");

    scatter.AddSeries(s2).Legend("series2");

    scatter.ShowInfo();    

    fastView.WhenAction = THISBACK(OnFastView);

    sequentialX.WhenAction = THISBACK(OnSequentialX);

    fastView = true;

    sequentialX = true;

    OnFastView();

    OnSequentialX();

}

 

ScatterDemo *Construct9()

{

    static Tab9 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Big dataset", Construct9, __FILE__);

}

 

 

tab6.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

void Tab6::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(6,100);

    scatter.SetMajorUnits(1,20);

    scatter.ShowInfo();

    

    s1 <<Pointf(log10(10.0),14)<<Pointf(log10(1e2),25)<<Pointf(log10(1e3),39)<<Pointf(log10(1e4),44)<<Pointf(log10(1e5),76);

    scatter.AddSeries(s1).Legend("series1");

    scatter.cbModifFormatX = THISBACK(FormatX);

}

 

void Tab6::FormatX(String& s, int i, double d)

{

    s = FormatDoubleExp(pow(10., d), 1);

}

 

ScatterDemo *Construct6()

{

    static Tab6 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Log", Construct6, __FILE__);

}

 

 

tab1.cpp

 

#include "ScatterCtrl_Demo.h"

 

enum {

    SERIE2

};

 

void Tab1::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    

    s1 << Pointf(10, 26) << Pointf(20, 37) << Pointf(30, 31) << Pointf(40, 33) << Pointf(50, 28);

    scatter.AddSeries(s1).Legend("Series 1").Opacity(0.3).Fill();

    

    s2y[0] = 22; s2y[1] = 33; s2y[2] = 27; s2y[3] = 29; s2y[4] = 24;

    scatter.AddSeries(s2y, 5, 10, 10).Legend("Series 2").Id(SERIE2).PlotStyle<LineSeriesPlot>()

                    .Dash("").MarkColor(Red()).Fill().Opacity(0.5);

    

    s3y[0] = 18; s3y[1] = 29; s3y[2] = 23; s3y[3] = 25; s3y[4] = 20;

    s3x[0] = 10; s3x[1] = 20; s3x[2] = 30; s3x[3] = 40; s3x[4] = 50;

    scatter.AddSeries(s3x, s3y, 5).Legend("Series 3");

    

    s4y << 14 << 25 << 19 << 21 << 16;

    s4x << 10 << 20 << 30 << 40 << 50;

    scatter.AddSeries(s4x, s4y).Legend("Series 4").PlotStyle<StaggeredSeriesPlot>().Dash("").NoMark().Fill().Stroke(3, LtRed());

    

    s5.Add(10, 10);

    s5.Add(20, 21);

    s5.Add(30, 15);

    s5.Add(40, 16);

    s5.Add(50, 12);

    int barWidth = 4;

    scatter.AddSeries(s5).Legend("Series 5").PlotStyle<BarSeriesPlot>(barWidth).Dash("").NoMark().Fill();

    

    scatter.SetRange(60, 50).SetMajorUnits(10, 10);

    scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().SetPopText("h", "v", "v2").SetMouseHandling(true, true);

}

 

ScatterDemo *Construct1()

{

    static Tab1 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Basic", Construct1, __FILE__);

}

 

 

 

tab7.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

void Tab7::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    

    bAddSeries             <<= THISBACK(AddSeries);

    bRemoveLastSeries     <<= THISBACK(RemoveLastSeries);

    bRemoveFirstSeries     <<= THISBACK(RemoveFirstSeries);

    bRemoveAllSeries     <<= THISBACK(RemoveAllSeries);

}

 

void Tab7::AddSeries()

{

    int num = scatter.GetCount();

    double f = 1 + num*1.1;    

    

    Vector<Pointf> &s = series.Add();

    s << Pointf(10, 3*f) << Pointf(30, 7*f) << Pointf(50, 12*f) << Pointf(70, 10*f);

    scatter.AddSeries(s).Legend(String("series") + AsString(num));    

}

 

void Tab7::RemoveFirstSeries()    

{

    if (scatter.IsEmpty())

        return;

    scatter.RemoveSeries(0);

    series.Remove(0);

}

 

void Tab7::RemoveLastSeries()        

{

    if (scatter.IsEmpty())

        return;

    int topIndex = scatter.GetCount()-1;

    scatter.RemoveSeries(topIndex);

    series.Remove(topIndex);

}

 

void Tab7::RemoveAllSeries()        

{

    scatter.RemoveAllSeries();

    series.Clear();

}

 

ScatterDemo *Construct7()

{

    static Tab7 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Operations", Construct7, __FILE__);    

}

 

 

tabPie.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

void TabPie::Init()

{

    CtrlLayout(*this);    

    

    chart.ShowPercent();

    chart.AddCategory("Sunny",  8, ::Color(90, 150, 255));

    chart.AddCategory("Cloudy", 4, ::Color(90, 255, 150));    

    chart.AddCategory("Rainy",  2, ::Color(250, 150, 90));    

}

 

 

 

tab5.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

void Tab5::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(10, 100);

    scatter.AddSeries(s1).Legend("U-t").NoMark();

    scatter.AddSeries(s2).Legend("I-t").NoMark();

    bStart <<=(THISBACK(Start));

    bStop <<=(THISBACK(Stop));

    bReset <<=(THISBACK(Reset));

    bPgDown <<=(THISBACK(PgDown));

    bPgUp <<=(THISBACK(PgUp));

    bPlus <<=(THISBACK(Plus));

    bMinus <<=(THISBACK(Minus));

    t = 0;

    bStop.Disable();    

}

 

void Tab5::Animate()

{

    s1 << Pointf(t, 50+20*sin(t));

    s2 << Pointf(t, 50+30*cos(t));

    scatter.Refresh();

    t += 0.1;

    if((t-scatter.GetXMin()) >= scatter.GetXRange())

        scatter.SetXYMin(scatter.GetXMin() + 0.1, 0);

}

 

void Tab5::Start()

{

    SetTimeCallback(-5, THISBACK(Animate));

    bStart.Disable();

    bStop.Enable();

}

 

void Tab5::Stop()

{

    KillTimeCallback();

    bStart.Enable();

    bStop.Disable();

}

 

void Tab5::Reset()

{

    t = 0;

    s1.Clear();

    s2.Clear();

    scatter.SetXYMin(0, 0);    

    scatter.Refresh();

}

 

void Tab5::PgDown()

{

    scatter.SetXYMin(scatter.GetXMin()-5, 0);

    scatter.Refresh();

}

 

void Tab5::PgUp()

{

    scatter.SetXYMin(scatter.GetXMin()+5, 0);

    scatter.Refresh();

}

 

void Tab5::Plus()

{

    scatter.SetRange(scatter.GetXRange()/2, 100);

    scatter.Refresh();

}

 

void Tab5::Minus()

{

    scatter.SetRange(scatter.GetXRange()*2, 100);

    scatter.Refresh();

}

 

ScatterDemo *Construct5()

{

    static Tab5 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Dynamic", Construct5, __FILE__);

}

 

 

tab11.cpp

 

#include "ScatterCtrl_Demo.h"

 

void Tab11::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(5, 1500).SetMajorUnits(1, 250).SetXYMin(-3, 0);

    scatter.SetMouseHandling(true, true).ShowContextMenu().SetLegendWidth(160);

    

    sx << -3.067E0 << -2.981E0 << -2.921E0 << -2.912E0 << -2.840E0 << -2.797E0 << -2.702E0 << -2.699E0 << -2.633E0 << -2.481E0 << -2.363E0 << -2.322E0 << -1.501E0 << -1.460E0 << -1.274E0 << -1.212E0 << -1.100E0 << -1.046E0 << -0.915E0 << -0.714E0 << -0.566E0 << -0.545E0 << -0.400E0 << -0.309E0 << -0.109E0 << -0.103E0 << 0.010E0 << 0.119E0 << 0.377E0 << 0.790E0 << 0.963E0 << 1.006E0 << 1.115E0 << 1.572E0 << 1.841E0 << 2.047E0 << 2.200E0;

    sy << 80.574E0 << 84.248E0 << 87.264E0 << 87.195E0 << 89.076E0 << 89.608E0 << 89.868E0 << 90.101E0 << 92.405E0 << 95.854E0 << 100.696E0 << 101.060E0 << 401.672E0 << 390.724E0 << 567.534E0 << 635.316E0 << 733.054E0 << 759.087E0 << 894.206E0 << 990.785E0 << 1090.109E0 << 1080.914E0 << 1122.643E0 << 1178.351E0 << 1260.531E0 << 1273.514E0 << 1288.339E0 << 1327.543E0 << 1353.863E0 << 1414.509E0 << 1425.208E0 << 1421.384E0 << 1442.962E0 << 1464.350E0 << 1468.705E0 << 1447.894E0 << 1457.628E0;        

        

    VectorDouble vs1(sy, sx);

    double l_r2, p2_r2, p4_r2, f_r2;

    

    linear.Fit(vs1, l_r2);

    poly2.SetDegree(2);

    poly2.Fit(vs1, p2_r2);

    poly4.SetDegree(4);

    poly4.Fit(vs1, p4_r2);

    fourier.SetDegree(3);

    fourier.Fit(vs1, f_r2);

    

    scatter.AddSeries(sx, sy).Legend("Series").MarkStyle<RhombMarkPlot>().MarkWidth(10).NoPlot();

    scatter.AddSeries(linear).Legend(linear.GetFullName()).NoMark().Stroke(2);

    scatter.AddSeries(poly2).Legend(poly2.GetFullName()).NoMark().Stroke(2);

    scatter.AddSeries(poly4).Legend(poly4.GetFullName()).NoMark().Stroke(2);

    scatter.AddSeries(fourier).Legend(fourier.GetFullName()).NoMark().Stroke(2);

    

    grid.AddColumn("Type", 10);

    grid.AddColumn("Equation", 40);

    grid.AddColumn("R2", 5);

    

    grid.Add(linear.GetFullName(),     linear.GetEquation(),  FormatDoubleFix(l_r2, 5));

    grid.Add(poly2.GetFullName(),     poly2.GetEquation(),   FormatDoubleFix(p2_r2, 5));

    grid.Add(poly4.GetFullName(),     poly4.GetEquation(),   FormatDoubleFix(p4_r2, 5));

    grid.Add(fourier.GetFullName(), fourier.GetEquation(), FormatDoubleFix(f_r2, 5));

}

 

ScatterDemo *Construct11()

{

    static Tab11 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample(t_("Trend Lines"), Construct11, __FILE__);

}

 

 

tab2.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

double funct1(double x)    {return 3;}

double funct2(double x)    {return (x*x-5);}

double funct3(double x)    {return (-x*x-5);}

 

void   vfunct1(double& y, double x) {y = 0;}

void   vfunct2(double& y, double x) {y = x*x;}

void   vfunct3(double& y, double x) {y = -x*x;}

 

void Tab2::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(12, 60).SetXYMin(-6, -30).SetMajorUnits(2, 10);

    scatter.SetMouseHandling(true);

 

    scatter.AddSeries(&funct1).Legend("y = 3").NoMark();

    scatter.AddSeries(&funct2).Legend("y = x^2-5").NoMark();

    scatter.AddSeries(&funct3).Legend("y = -x^2-5").NoMark();

    

    scatter.AddSeries(&vfunct1).Legend("y = 0").NoMark();

    scatter.AddSeries(&vfunct2).Legend("y = x^2").NoMark();

    scatter.AddSeries(&vfunct3).Legend("y = -x^2").NoMark();

}

 

ScatterDemo *Construct2()

{

    static Tab2 tab;

    return &tab;

}

 

INITBLOCK {    

    RegisterExample("Explicit Functions", Construct2, __FILE__);

}

 

 

tab8.cpp

 

#include "ScatterCtrl_Demo.h"

 

 

void Tab8::Init()

{

    CtrlLayout(*this);    

    HSizePos().VSizePos();

    scatter.SetRange(13, 50, 20).SetMajorUnits(1, 10).SetXYMin(0,-20, 1000);

    scatter.SetMouseHandling(true, true);

 

    s3 <<Pointf(1,-12)<<Pointf(2,-17)<<Pointf(3,-13)<<Pointf(4,15)<<Pointf(5,18)<<Pointf(6,25)<<Pointf(7,27)<<Pointf(8,20)<<Pointf(9,5)<<Pointf(10,-10)<<Pointf(11,24)<<Pointf(12,17);

    double barWidth = 0.4;

    scatter.AddSeries(s3).Legend("Device 1").PlotStyle<BarSeriesPlot>(barWidth).NoMark().Stroke(2, Gray()).Dash(LINE_SOLID).Fill(LtGray());

    

    s1<<Pointf(1,-6)<<Pointf(2,-4)<<Pointf(3,2)<<Pointf(4,8)<<Pointf(5,8)<<Pointf(6,15)<<Pointf(7,20)<<Pointf(8,30)<<Pointf(9,14)<<Pointf(10,10)<<Pointf(11,3)<<Pointf(12,-11);

    scatter.AddSeries(s1).Legend("Temperature").Stroke(3, Null).Dash(LINE_DASHED).MarkStyle<SquareMarkPlot>();

    

    s2 <<Pointf(1,1008)<<Pointf(2,1012)<<Pointf(3,1016)<<Pointf(4,1012)<<Pointf(5,1008)<<Pointf(6,1016)<<Pointf(7,1012)<<Pointf(8,1004)<<Pointf(9,1000)<<Pointf(10,1001)<<Pointf(11,1000)<<Pointf(12,1002);

    scatter.AddSeries(s2).Legend("Pressure").Stroke(3, Null).Dash("15 6 6 6 3 6 6 6").SetDataPrimaryY(false);

    scatter.SetDrawY2Reticle();

    

    scatter.cbModifFormatX = THISBACK(MyFormat);

    scatter.cbModifFormatDeltaX = THISBACK(MyFormatDelta);

    scatter.SetMaxZoom(40).SetMinZoom(2, 20)

           .SetLabelY("Temperature [C]")

           .SetLabelY2("Pressure [mBar]")

           .SetMarkWidth(1, 4);

    scatter.ShowInfo()

           .ShowContextMenu();    

}

 

ScatterDemo *Construct8()

{

    static Tab8 tab;

    return &tab;

}

 

INITBLOCK {

    RegisterExample("Secondary Y", Construct8, __FILE__);

}

 

 

ScatterCtrl_Demo.lay

 

LAYOUT(ScatterCtrl_Demo, 624, 352)

    ITEM(Button, bPreview, SetLabel(t_("Print Preview")).LeftPosZ(4, 88).BottomPosZ(4, 20))

    ITEM(Button, bSavePNG, SetLabel(t_("Save as PNG")).LeftPosZ(4, 88).BottomPosZ(28, 20))

    ITEM(Button, bSaveJPG, SetLabel(t_("Save as JPEG")).LeftPosZ(96, 80).BottomPosZ(28, 20))

    ITEM(Button, bSaveEMF, SetLabel(t_("Save as EMF")).LeftPosZ(108, 68).BottomPosZ(52, 20))

    ITEM(Button, bCopyClipboard, SetLabel(t_("Copy to Clipboard")).LeftPosZ(4, 100).BottomPosZ(52, 20))

    ITEM(DropList, paintMode, LeftPosZ(4, 172).BottomPosZ(77, 19))

    ITEM(Label, dv___6, SetLabel(t_("Painting Mode")).LeftPosZ(4, 172).BottomPosZ(97, 19))

    ITEM(ArrayCtrl, examplesList, LeftPosZ(4, 168).VSizePosZ(28, 124))

    ITEM(Label, dv___8, SetLabel(t_("Choose example")).LeftPosZ(4, 168).TopPosZ(4, 21))

END_LAYOUT

 

LAYOUT(Tab1, 380, 292)

    ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("Basic Test")).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(16, 12).VSizePosZ(16, 16))

END_LAYOUT

 

LAYOUT(Tab2, 380, 292)

    ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("Functions")).SetTitleFont(SansSerifZ(14).Bold()).SetGridWidth(2).HSizePosZ(16, 12).VSizePosZ(16, 16))

END_LAYOUT

 

LAYOUT(Tab3, 384, 284)

    ITEM(ScatterCtrl, scatter, SetTitle(t_("Parametric functions demo")).SetTitleFont(SansSerifZ(14).Bold()).SetTitleColor(White).SetPlotAreaColor(Color(229, 229, 229)).SetColor(Color(198, 212, 255)).SetLabelsColor(White).SetAxisColor(Color(28, 212, 0)).SetAxisWidth(12).SetGridColor(Color(28, 127, 0)).HSizePosZ(16, 16).VSizePosZ(16, 16))

END_LAYOUT

 

LAYOUT(Tab4, 400, 316)

    ITEM(ScatterCtrl, scatter, SetLabelsFont(SansSerifZ(11)).SetTitle(t_("Temperature Average. X Axis mouse zoom + scroll")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaLeftMargin(40).SetLabelX(t_("Month")).SetLegendWidth(200).HSizePosZ(16, 16).VSizePosZ(16, 16))

END_LAYOUT

 

LAYOUT(Tab5, 400, 288)

    ITEM(ScatterCtrl, scatter, SetTitle(t_("Dynamic")).SetTitleFont(StdFontZ(14).Bold()).SetLabelX(t_("time[s]")).HSizePosZ(16, 12).VSizePosZ(12, 36))

    ITEM(Button, bStart, SetLabel(t_("Start")).LeftPosZ(16, 42).BottomPosZ(5, 23))

    ITEM(Button, bStop, SetLabel(t_("Stop")).LeftPosZ(64, 42).BottomPosZ(5, 23))

    ITEM(Button, bReset, SetLabel(t_("Reset")).LeftPosZ(112, 42).BottomPosZ(5, 23))

    ITEM(Button, bPgDown, SetLabel(t_("<<")).RightPosZ(122, 30).BottomPosZ(5, 23))

    ITEM(Button, bPgUp, SetLabel(t_(">>")).RightPosZ(86, 30).BottomPosZ(5, 23))

    ITEM(Button, bPlus, SetLabel(t_("+")).RightPosZ(50, 30).BottomPosZ(5, 23))

    ITEM(Button, bMinus, SetLabel(t_("-")).RightPosZ(14, 30).BottomPosZ(5, 23))

END_LAYOUT

 

LAYOUT(Tab6, 400, 280)

    ITEM(ScatterCtrl, scatter, SetTitle(t_("Logarithmic Scale")).SetTitleFont(StdFontZ(14).Bold()).HSizePosZ(12, 12).VSizePosZ(16, 16))

END_LAYOUT

 

LAYOUT(Tab7, 388, 300)

    ITEM(ScatterCtrl, scatter, SetTitle(t_("Operations")).SetTitleFont(MonospaceZ(16).Bold()).SetPlotAreaLeftMargin(45).SetLabelX(t_("[x]")).SetLabelY(t_("[y]")).HSizePosZ(12, 12).VSizePosZ(12, 36))

    ITEM(Button, bAddSeries, SetLabel(t_("AddSeries")).LeftPosZ(12, 60).BottomPosZ(4, 20))

    ITEM(Button, bRemoveLastSeries, SetLabel(t_("RemoveLastSeries")).LeftPosZ(76, 104).BottomPosZ(4, 20))

    ITEM(Button, bRemoveFirstSeries, SetLabel(t_("RemoveFirstSeries")).LeftPosZ(184, 100).BottomPosZ(4, 20))

    ITEM(Button, bRemoveAllSeries, SetLabel(t_("RemoveAllSeries")).LeftPosZ(288, 88).BottomPosZ(4, 20))

END_LAYOUT

 

LAYOUT(Tab8, 400, 316)

    ITEM(ScatterCtrl, scatter, SetLabelsFont(SansSerifZ(11)).SetTitle(t_("Temperature & Pressure Averages. X-Y Axis mouse zoom + scroll")).SetTitleFont(SansSerifZ(15).Bold()).SetPlotAreaLeftMargin(40).SetPlotAreaRightMargin(70).SetPlotAreaTopMargin(50).SetPlotAreaBottomMargin(50).SetLabelX(t_("Month")).SetLabelY(t_("Legend Y")).SetLabelY2(t_("Legend Y2")).SetLegendWidth(200).HSizePosZ(16, 16).VSizePosZ(16, 16))

END_LAYOUT

 

LAYOUT(Tab9, 380, 348)

    ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("Big dataset")).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(16, 12).VSizePosZ(16, 76))

    ITEM(Option, sequentialX, SetLabel(t_("SetSequentialX")).LeftPosZ(112, 92).BottomPosZ(8, 16))

    ITEM(Option, fastView, SetLabel(t_("SetFastView")).LeftPosZ(16, 84).BottomPosZ(8, 16))

    ITEM(Label, dv___3, SetLabel(t_("It includes two series with 100000 points.\nTo work with Painter it requires SetFastView and SetSequentialX to be true. \nIf not the program could get stuck.")).HSizePosZ(16, 4).BottomPosZ(28, 44))

END_LAYOUT

 

LAYOUT(Tab10, 380, 292)

    ITEM(ScatterCtrl, scatter, SetLabelsFont(StdFontZ(11)).SetTitle(t_("User graph")).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(16, 12).VSizePosZ(16, 16))

END_LAYOUT

 

LAYOUT(Tab11, 504, 468)

    ITEM(ScatterCtrl, scatter, SetTitle(t_("Trend Line demo")).SetTitleFont(SansSerifZ(14).Bold()).SetPlotAreaColor(Color(229, 229, 229)).SetAxisWidth(12).HSizePosZ(8, 8).VSizePosZ(8, 108))

    ITEM(ArrayCtrl, grid, HSizePosZ(112, 8).BottomPosZ(4, 100))

    ITEM(Label, dv___2, SetLabel(t_("Trend Lines Details:")).LeftPosZ(8, 100).BottomPosZ(83, 21))

END_LAYOUT

 

LAYOUT(TabPie, 536, 440)

    ITEM(PieCtrl, chart, SetLegendBackColor(Color(229, 229, 229)).SetLegendHeight(80).SetTitle(t_("Average Weather")).SetFrame(ThinInsetFrame()).HSizePosZ(8, 12).VSizePosZ(40, 12))

    ITEM(Label, dv___1, SetLabel(t_(" EXPERIMENTAL")).SetFrame(ThinInsetFrame()).LeftPosZ(8, 84).TopPosZ(8, 24))

END_LAYOUT

 

 

 

 

 

Cette page est aussi en english, català, čeština, deutsch, español, euskara, română, русский, 中文(简体) et 中文(繁體). Vous voulez nous aider ?