test_charts.anubis 5.89 KB
read widgets4/widget.anubis
read widgets4/host_window.anubis
read widgets4/image.anubis

read tools/basis.anubis
read graphism/geometrical_figures.anubis
read charts.anubis
   

define Float
   opp
     (
       Float f
     ) =
   if (0-f) is 
     {
       failure   then f,
       success(s) then s
     }.
   
define List(HG_Data)
   data
     =
   [
     hg_data("1",[2.0,0.0]),
     hg_data("2",[4.0,5.0]),
     hg_data("3",[0.0,0.0]),
     hg_data("4",[1.0,3.0]),
     //hg_data("5",[1.0,opp(2.0)]),
     hg_data("5",[1.0,2.0]),
     hg_data("6",[1.0,1.1]),
     hg_data("7",[2.0,6.0]),
     hg_data("8",[1.0,1.0]),
     hg_data("9",[1.0,2.0]),
     hg_data("10",[0.0,0.0]),
   ].
   
  
define Chart_Settings
   chart_sets
     =
   chart_sets
     (rgba(255,255,180,255),         // bg_color
      rgba(0,0,0,255),
      rgba(0,100,195,255),
      "helvetica_medium_r_8",
      true).
   
define Image_Settings
   img_sets 
     =
   img_sets(500,500,rgba(255,255,255,0)).
   
   
define One
   make_histogram_H
     =
   with histo = 
   histogram("Histogramme_H",
             rgba(255,0,0,255),
             data,
             [rgba(200,75,75,255),rgba(70,175,60,255)],
             ["N1","N2"],
             chart_sets,
             img_sets,
             horizontal,
             ysets(0.0,1,1,sub_axis(dotted(4,2)),true),
             4),

   if create_histogram_r(histo,"histogram_h.jpeg") is 
     {
       error(e) then print("ERROR ="+e+"\n"),
       ok(rh)   then 
   
   if x_int(rh) is (nxi,lxi) then
   if y_int(rh) is (nyi,lyi) then
   print("xh = "+x_length(rh)+"\n");
   print("yh = "+y_length(rh)+"\n");
   print(if left_top(rh) is (l,t) then "l="+l+" t="+t+"\n");
   print(if right_bottom(rh) is (r,b) then "r="+r+" b="+b+"\n");
   print("nxi="+nxi+" lxi="+lxi+"\n");
   print("nyi="+nyi+" lyi="+lyi+"\n");
   
   if left_top(rh) is (hl,ht) then
   if right_bottom(rh) is (hr,hb) then 
   if read_image_from_JPEG_file("histogram.jpeg") is 
     {
       cannot_open_file then print("COF\n"),
       decompress_error then print("DE \n"),
       ok(j)            then 
         print("W="+width(j)+" H="+height(j)+"\n");
         with rgbai = to_RGBA(j,1),
         draw_rectangle(rgbai,rect(hl,ht,300,300),rgba(238,196,249,130));
         if write_image_to_JPEG_file(to_JPEG(rgbai),"surimpress.jpg",100) is 
           {
             cannot_create_file then print("CCF\n"),
             compression_error then print("CE \n"),
             ok             then print("OK \n")
           }
     }}.
   
   create_histogram(histo).
   
   
   
   
   *** Histo V
   
define List(HG_Data)
   data_V
     =
   [
     hg_data("1111111",[2.0,0.0]),
     hg_data("2222222",[4.0,5.0]),
     hg_data("3333333",[0.0,0.0]),
     hg_data("44444",[1.0,3.0]),
     //hg_data("5",[1.0,opp(2.0)]),
     hg_data("5555555",[1.0,2.0]),
     hg_data("66666",[1.0,1.1]),
     hg_data("77777",[2.0,6.0]),
     hg_data("8888888",[1.0,1.0]),
     hg_data("999999",[1.0,2.0]),
     hg_data("100000",[0.0,0.0]),
   ].


define One
   make_histogram_V
     =
   with histo = 
   histogram("Histogramme_V",
             rgba(255,0,0,255),
             data_V,
             [rgba(200,75,75,255),rgba(70,175,60,255)],
             ["NV1","NV2"],
             chart_sets,
             img_sets,
             vertical,
             ysets(0.0,1,1,sub_axis(dotted(4,2)),true),
             4),

   if create_histogram_r(histo,"histogram_v.jpeg") is 
     {
       error(e) then print("ERROR ="+e+"\n"),
       ok(rh)   then 
   
   if x_int(rh) is (nxi,lxi) then
   if y_int(rh) is (nyi,lyi) then
   print("xh = "+x_length(rh)+"\n");
   print("yh = "+y_length(rh)+"\n");
   print(if left_top(rh) is (l,t) then "l="+l+" t="+t+"\n");
   print(if right_bottom(rh) is (r,b) then "r="+r+" b="+b+"\n");
   print("nxi="+nxi+" lxi="+lxi+"\n");
   print("nyi="+nyi+" lyi="+lyi+"\n");
   
   if left_top(rh) is (hl,ht) then
   if right_bottom(rh) is (hr,hb) then 
   if read_image_from_JPEG_file("histogram.jpeg") is 
     {
       cannot_open_file then print("COF\n"),
       decompress_error then print("DE \n"),
       ok(j)            then 
         print("W="+width(j)+" H="+height(j)+"\n");
         with rgbai = to_RGBA(j,1),
         draw_rectangle(rgbai,rect(hl,ht,300,300),rgba(238,196,249,130));
         if write_image_to_JPEG_file(to_JPEG(rgbai),"surimpress.jpg",100) is 
           {
             cannot_create_file then print("CCF\n"),
             compression_error then print("CE \n"),
             ok             then print("OK \n")
           }
     }}.

   
   *** CurveQualify
   
define List(Curve_Data_XY)
   cd_true
     =
   [dataxy(1.2,3.0),
    dataxy(2.5,5.0),
    dataxy(2.7,8.0),
    dataxy(3.5,9.0),
    dataxy(4.7,3.5)].
   
define List(Curve_Data_XY)
   cd_false
     =
   [dataxy(2.0,4.0),
    dataxy(1.0,7.0)].
   
define One
   make_curves
      =
   with curve = 
   curve("Curve",
          rgba(255,0,0,255),
          [cdata(rgba(200,55,100,255),dotted(3,3),disk(medium,rgba(200,55,100,255)),"BON",cd_true),
            cdata(rgba(100,100,255,255),filled,fsquare(medium,rgba(100,100,255,255),),
                  "MAUVAIS",cd_false)],
           chart_sets,
           img_sets,
           xsets(0.5,0.0,2,horizontal),
           ysets(0.0,1,0,sub_axis(dotted(4,2)),true)),

   create_curve(curve,"curve.jpeg").
   create_curve(curve).


define One
   test_charts 
     =
   print("    Histogram (X horizontal) : ..... 1\n");
   print("    Histogram (X vertical) : ....... 2\n");
   print("    Curves : ....................... 3\n");
   with c = prompt("   choice : "),
   if c="1" then make_histogram_H else 
   if c="2" then make_histogram_V   else 
   if c="3" then make_curves    else
   test_charts.
   
global define One
   test_charts (List(String) ls) =
   
   if ls is 
     {
       []      then test_charts,
       [c . t] then 
         if c="1" then make_histogram_H else 
         if c="2" then make_histogram_V else 
         if c="3" then make_curves      else
         test_charts
     }.