Advertisement
Guest User

graph.lua

a guest
Mar 3rd, 2023
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.13 KB | None | 0 0
  1. --[[ GRAPH widget v1.1 by wlourf (07.01.2011)
  2.     this widget draws some graphs with some effects
  3.     http://u-scripts.blogspot.com/2010/10/graph-widget.html
  4.    
  5. To call the script in a conky, use, before TEXT
  6.     lua_load /path/to/the/script/graph.lua
  7.     lua_draw_hook_pre main_graph
  8. and add one line (blank or not) after TEXT
  9.  
  10.  
  11. Parameters are :
  12. 3 parameters are mandatory
  13. name        - the name of the conky variable to display,
  14.               for example for {$cpu cpu0}, just write name="cpu"
  15. arg         - the argument of the above variable,
  16.               for example for {$cpu cpu1}, just write arg="cpu1"
  17.               arg can be a numerical value if name=""
  18. max         - the maximum value the above variable can reach,
  19.               for example for {$cpu cpu1}, just write max=100 or less or more
  20.    
  21. Optional parameters:
  22. x,y         - coordinates of the bottom-left corner of the graph,
  23.               relative to the top-left corner of the conky window
  24.               default =  bottom-left corner of the conky window
  25. width       - width of the graph, default = 100 pixels
  26. height      - height of the graph, default = 20 pixels
  27. nb_values   - number of values to display in the graph, default=width
  28.               i.e. 1 pixel for 1 value
  29. autoscale   - if set to true, calculate the max valeu of the y axis and
  30.               doesn't use the max parameter above, default=false
  31. skew_x      - skew graph around x axis, défaut = 0
  32. skew_y      - skew graph around y axis, défaut = 0
  33. angle       - angle of rotation of the graph in degress, default = 0
  34.               i.e. a horizontal graph)
  35. inverse     - if set to true, graph are draw from right to left, default=false
  36. background  - if set to false, background is not drawn, default=true
  37. foreground  - if set to false, foreground is not drawn, default=true
  38.               foreground = plain graph
  39. bg_bd_size  - size of the border of the background, default=0=no border
  40. fg_bd_size  - size of the border of the foreground, default=0=no border
  41.  
  42.  
  43. Colours tables below are defined into braces :
  44. {position in the gradient (0 to 1), colour in hexadecimal, alpha (0 to 1)}
  45. example for a single colour table :
  46. {{0,0xFFAA00,1}} position parameter doesn't matter
  47. example for a two-colours table :
  48. {{0,0xFFAA00,1},{1,0x00AA00,1}} or {{0.5,0xFFAA00,1},{1,0x00AA00,1}}
  49. example for a three-colours table :
  50. {{0,0xFFAA00,1},{0.5,0xFF0000,1},{1,0x00AA00,1}}
  51.  
  52. bg_colour   - colour table for background,
  53.               default = {{0,0x000000,.5},{1,0xFFFFFF,.5}}
  54. fg_colour   - colour table for foreground,
  55.               default = {{0,0x00FFFF,1},{1,0x0000FF,1}}
  56. bg_bd_colour- colour table for background border,
  57.               default = {{1,0xFFFFFF,1}}             
  58. fg_bd_colour- colour table for foreground border,
  59.               default = {{1,0xFFFF00,1}}             
  60.  
  61. bg_orientation, bg_bd_orientation, fg_orientation, fg_bd_orientation,
  62.             - "orientation" defines the starting point of the gradient,
  63.               default="nn"
  64.               there are 8 available starting points :
  65.               "nw","nn","ne","ee","se","ss","sw","ww"
  66.               (n for north, w for west ...)
  67.               theses 8 points are the 4 corners + the 4 middles of graph
  68.               so a gradient "nn" will go from "nn" to "ss"
  69.               a gradient "nw" will go from "nw" to "se"
  70.  
  71. draw_me     - if set to false, graph is not drawn (default = true)
  72.               it can be used with a conky string, if the string returns 1, the graph is drawn :
  73.               example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
  74.              
  75. v1.0 (31/10/2010) original release
  76. v1.1 (07/01/2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
  77.                   text is parsed inside the function, not in the array of settings
  78.  
  79. --      This program is free software; you can redistribute it and/or modify
  80. --      it under the terms of the GNU General Public License as published by
  81. --      the Free Software Foundation version 3 (GPLv3)
  82. --    
  83. --      This program is distributed in the hope that it will be useful,
  84. --      but WITHOUT ANY WARRANTY; without even the implied warranty of
  85. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  86. --      GNU General Public License for more details.
  87. --    
  88. --      You should have received a copy of the GNU General Public License
  89. --      along with this program; if not, write to the Free Software
  90. --      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  91. --      MA 02110-1301, USA.    
  92.  
  93. ]]
  94.  
  95. require 'cairo'
  96.  
  97. function set_settings()
  98.     graph_settings={
  99.         {
  100.             name="cpu",
  101.             arg="cpu1",
  102.             max=100,
  103.             width=300,
  104.             height=110,
  105.             y=160,
  106.             x=25,
  107.             nb_values=100,
  108.             bg_colour={{0,0x000000,0}},
  109.             fg_bd_colour = { {0,0xe6194b,1}, },
  110.             foreground=false,
  111.             fg_bd_size=0.7,
  112.         },
  113.         {
  114.             name="cpu",
  115.             arg="cpu2",
  116.             max=100,
  117.             width=300,
  118.             height=110,
  119.             y=160,
  120.             x=25,
  121.             nb_values=100,
  122.             bg_colour={{0,0x000000,0}},
  123.             fg_bd_colour = { {0,0xf58231,1}, },
  124.             foreground=false,
  125.             fg_bd_size=0.7,
  126.         },
  127.         {
  128.             name="cpu",
  129.             arg="cpu3",
  130.             max=100,
  131.             width=300,
  132.             height=110,
  133.             y=160,
  134.             x=25,
  135.             nb_values=100,
  136.             bg_colour={{0,0x000000,0}},
  137.             fg_bd_colour = { {0,0xffe119,1}, },
  138.             foreground=false,
  139.             fg_bd_size=0.7,
  140.         },
  141.         {
  142.             name="cpu",
  143.             arg="cpu4",
  144.             max=100,
  145.             width=300,
  146.             height=110,
  147.             y=160,
  148.             x=25,
  149.             nb_values=100,
  150.             bg_colour={{0,0x000000,0}},
  151.             fg_bd_colour = { {0,0xbfef45,1}, },
  152.             foreground=false,
  153.             fg_bd_size=0.7,
  154.         },
  155.         {
  156.             name="cpu",
  157.             arg="cpu5",
  158.             max=100,
  159.             width=300,
  160.             height=110,
  161.             y=160,
  162.             x=25,
  163.             nb_values=100,
  164.             bg_colour={{0,0x000000,0}},
  165.             fg_bd_colour = { {0,0x3cb44b,1}, },
  166.             foreground=false,
  167.             fg_bd_size=0.7,
  168.         },
  169.         {
  170.             name="cpu",
  171.             arg="cpu6",
  172.             max=100,
  173.             width=300,
  174.             height=110,
  175.             y=160,
  176.             x=25,
  177.             nb_values=100,
  178.             bg_colour={{0,0x000000,0}},
  179.             fg_bd_colour = { {0,0x42d4f4,1}, },
  180.             foreground=false,
  181.             fg_bd_size=0.7,
  182.         },
  183.         {
  184.             name="cpu",
  185.             arg="cpu7",
  186.             max=100,
  187.             width=300,
  188.             height=110,
  189.             y=160,
  190.             x=25,
  191.             nb_values=100,
  192.             bg_colour={{0,0x000000,0}},
  193.             fg_bd_colour = { {0,0x4363d8,1}, },
  194.             foreground=false,
  195.             fg_bd_size=0.7,
  196.         },
  197.         {
  198.             name="cpu",
  199.             arg="cpu8",
  200.             max=100,
  201.             width=300,
  202.             height=110,
  203.             y=160,
  204.             x=25,
  205.             nb_values=100,
  206.             bg_colour={{0,0x000000,0}},
  207.             fg_bd_colour = { {0,0x911eb4,1}, },
  208.             foreground=false,
  209.             fg_bd_size=0.7,
  210.         },
  211.         {
  212.             name="cpu",
  213.             arg="cpu9",
  214.             max=100,
  215.             width=300,
  216.             height=110,
  217.             y=160,
  218.             x=25,
  219.             nb_values=100,
  220.             bg_colour={{0,0x000000,0}},
  221.             fg_bd_colour = { {0,0xf032e6,1}, },
  222.             foreground=false,
  223.             fg_bd_size=0.7,
  224.         },
  225.         {
  226.             name="cpu",
  227.             arg="cpu10",
  228.             max=100,
  229.             width=300,
  230.             height=110,
  231.             y=160,
  232.             x=25,
  233.             nb_values=100,
  234.             bg_colour={{0,0x000000,0}},
  235.             fg_bd_colour = { {0,0xfabebe,1}, },
  236.             foreground=false,
  237.             fg_bd_size=0.7,
  238.         },
  239.         {
  240.             name="cpu",
  241.             arg="cpu11",
  242.             max=100,
  243.             width=300,
  244.             height=110,
  245.             y=160,
  246.             x=25,
  247.             nb_values=100,
  248.             bg_colour={{0,0x000000,0}},
  249.             fg_bd_colour = { {0,0xffd8b1,1}, },
  250.             foreground=false,
  251.             fg_bd_size=0.7,
  252.         },
  253.         {
  254.             name="cpu",
  255.             arg="cpu12",
  256.             max=100,
  257.             width=300,
  258.             height=110,
  259.             y=160,
  260.             x=25,
  261.             nb_values=100,
  262.             bg_colour={{0,0x000000,0}},
  263.             fg_bd_colour = { {0,0xfffac8,1}, },
  264.             foreground=false,
  265.             fg_bd_size=0.7,
  266.             bg_bd_size=0.5,
  267.         },
  268.         {
  269.             name="memperc",
  270.             arg="",
  271.             max=100,
  272.             width=300,
  273.             height=110,
  274.             y=345,
  275.             x=25,
  276.             nb_values=100,
  277.             bg_colour={{0,0x000000,0}},
  278.             fg_bd_colour = { {0,0xab1852,1}, },
  279.             foreground=false,
  280.             fg_bd_size=0.7,
  281.         },
  282.         {
  283.             name="swapperc",
  284.             arg="",
  285.             max=100,
  286.             width=300,
  287.             height=110,
  288.             y=345,
  289.             x=25,
  290.             nb_values=100,
  291.             bg_colour={{0,0x000000,0}},
  292.             fg_bd_colour = { {0,0x49a835,1}, },
  293.             foreground=false,
  294.             fg_bd_size=0.7,
  295.             bg_bd_size=0.5,
  296.         },
  297.         {
  298.             name="diskio_read",
  299.             arg="/dev/nvme0n1",
  300.             max=100,
  301.             width=85,
  302.             height=110,
  303.             y=505,
  304.             x=25,
  305.             nb_values=100,
  306.             bg_colour={{0,0x000000,0}},
  307.             fg_bd_colour = { {0,0x49a835,1}, },
  308.             foreground=false,
  309.             fg_bd_size=0.7,
  310.             bg_bd_size=0.5,
  311.         },
  312.         {
  313.             name="time",
  314.             arg="%S",
  315.             max=100,
  316.             width=85,
  317.             height=110,
  318.             y=505,
  319.             x=25,
  320.             nb_values=100,
  321.             bg_colour={{0,0x000000,0}},
  322.             fg_bd_colour = { {0,0x4fa835,1}, },
  323.             foreground=false,
  324.             fg_bd_size=0.7,
  325.         },
  326.     }
  327. end
  328.  
  329.  
  330. function check_settings(t)
  331.     --tables are check only when conky start
  332.     if t.name==nil and t.arg==nil then
  333.         print ("No input values ... use parameters 'name'" ..
  334.             " with 'arg' or only parameter 'arg' ")
  335.         return 1
  336.     end
  337.  
  338.     if t.max==nil then
  339.         print ("No maximum value defined, use 'max'")
  340.         print ("for name=" .. t.name .. " with arg=" .. t.arg)
  341.         return 1
  342.     end
  343.     if t.name==nil then t.name="" end
  344.     if t.arg==nil then t.arg="" end
  345.     return 0
  346. end
  347.  
  348. function conky_main_graph()
  349.  
  350.     if conky_window == nil then return end
  351.        
  352.     local w=conky_window.width
  353.     local h=conky_window.height
  354.     local cs=cairo_xlib_surface_create(conky_window.display,
  355.             conky_window.drawable, conky_window.visual, w, h)
  356.     cr=cairo_create(cs)
  357.  
  358.     updates=tonumber(conky_parse('${updates}'))
  359.     --start drawing after "updates_gap" updates
  360.     --prevent segmentation error for cpu
  361.     updates_gap=5
  362.     if updates==1 then    
  363.         set_settings()
  364.        
  365.         flagOK=0
  366.         for i in pairs(graph_settings) do
  367.             if graph_settings[i].width==nil then graph_settings[i].width=100 end
  368.             if graph_settings[i].nb_values==nil then  
  369.                 graph_settings[i].nb_values= graph_settings[i].width
  370.             end
  371.             --create an empty table to store values
  372.             graph_settings[i]["values"]={}
  373.             --beginning point
  374.             graph_settings[i].beg = graph_settings[i].nb_values
  375.             --graph_settings[i].beg = 0
  376.             for j =1, graph_settings[i].nb_values do
  377.                 graph_settings[i].values[j]=0
  378.             end
  379.             graph_settings[i].flag_init=true
  380.             flagOK=flagOK + check_settings(graph_settings[i])
  381.  
  382.         end
  383.     end
  384.  
  385.     if flagOK>0 then
  386.         --abort script if error in one of the tables
  387.         print ("ERROR : Check the graph_setting table")
  388.         return
  389.     end
  390.  
  391.     --drawing process
  392.     if updates > updates_gap then
  393.         for i in pairs(graph_settings) do
  394.             if graph_settings[i].draw_me==true then graph_settings[i].draw_me = nil end
  395.             if (graph_settings[i].draw_me==nil or conky_parse(tostring(graph_settings[i].draw_me)) == "1") then
  396.                 local nb_values=graph_settings[i].nb_values
  397.                 graph_settings[i].automax=0
  398.                 for j =1, nb_values do
  399.                     if graph_settings[i].values[j+1]==nil then
  400.                         graph_settings[i].values[j+1]=0
  401.                     end
  402.                
  403.                     graph_settings[i].values[j]=graph_settings[i].values[j+1]
  404.                     if j==nb_values then
  405.                         --store value
  406.                         if graph_settings[i].name=="" then
  407.                             value=graph_settings[i].arg
  408.                         else
  409.                             value=tonumber(conky_parse('${' ..
  410.                                 graph_settings[i].name .. " " ..
  411.                                 graph_settings[i].arg ..'}'))
  412.                         end
  413.                         graph_settings[i].values[nb_values]=value
  414.                     end
  415.                     graph_settings[i].automax=math.max(graph_settings[i].automax,
  416.                                                        graph_settings[i].values[j])
  417.                     --should stop weird glitches at beginning when no values reported yet for upspeed or diskio
  418.                     if graph_settings[i].automax == 0 then graph_settings[i].automax = 1 end
  419.                 end
  420.                 draw_graph(graph_settings[i])
  421.             end
  422.         end
  423.     end
  424.  
  425.     cairo_destroy(cr)
  426.     cairo_surface_destroy(cs)
  427.     updates=nil
  428.     updates_gap=nil
  429. end
  430.  
  431.  
  432. function draw_graph(t)
  433.     --drawing function
  434.  
  435.     local function rgb_to_r_g_b(colour)
  436.         return ((colour[2] / 0x10000) % 0x100) / 255., ((colour[2] / 0x100) % 0x100) / 255., (colour[2] % 0x100) / 255., colour[3]
  437.     end
  438.  
  439.     local function linear_orientation(o,w,h)
  440.         --set gradient for bg and bg border
  441.         local p
  442.         if o=="nn" then
  443.             p={w/2,h,w/2,0}
  444.         elseif o=="ne" then
  445.             p={w,h,0,0}
  446.         elseif o=="ww" then
  447.             p={0,h/2,w,h/2}
  448.         elseif o=="se" then
  449.             p={w,0,0,h}
  450.         elseif o=="ss" then
  451.             p={w/2,0,w/2,h}
  452.         elseif o=="ee" then
  453.             p={w,h/2,0,h/2}    
  454.         elseif o=="sw" then
  455.             p={0,0,w,h}
  456.         elseif o=="nw" then
  457.             p={0,h,w,0}
  458.         end
  459.         return p
  460.     end
  461.  
  462.     local function linear_orientation_inv(o,w,h)
  463.         --set gradient for fg and fg border
  464.         local p
  465.         if o=="ss" then
  466.             p={w/2,h,w/2,0}
  467.         elseif o=="sw" then
  468.             p={w,h,0,0}
  469.         elseif o=="ee" then
  470.             p={0,h/2,w,h/2}
  471.         elseif o=="nw" then
  472.             p={w,0,0,h}
  473.         elseif o=="nn" then
  474.             p={w/2,0,w/2,h}
  475.         elseif o=="ww" then
  476.             p={w,h/2,0,h/2}    
  477.         elseif o=="ne" then
  478.             p={0,0,w,h}
  479.         elseif o=="se" then
  480.             p={0,h,w,0}
  481.         end
  482.         return p
  483.     end
  484.  
  485.  
  486.     --set default values
  487.    
  488.     --cancel drawing if not needed
  489.     if t.draw_me~=nil and conky_parse(tostring(t.draw_me)) ~= "1" then
  490.         return
  491.     end
  492.    
  493.  
  494.    
  495.     if t.height==nil    then t.height=20 end
  496.     --checked in previous part : width and nb_values
  497.        
  498.     if t.background==nil    then t.background=true end
  499.     if t.bg_bd_size==nil    then t.bg_bd_size=0 end
  500.     if t.x==nil             then t.x=t.bg_bd_size end
  501.     if t.y==nil             then t.y=conky_window.height -t.bg_bd_size end
  502.     if t.bg_colour==nil     then t.bg_colour={{0,0x000000,.5},{1,0xFFFFFF,.5}} end
  503.     if t.bg_bd_colour==nil  then t.bg_bd_colour={{1,0xFFFFFF,1}} end
  504.    
  505.     if t.foreground==nil    then t.foreground=true end
  506.     if t.fg_colour==nil     then t.fg_colour={{0,0x00FFFF,1},{1,0x0000FF,1}} end
  507.    
  508.     if t.fg_bd_size==nil    then t.fg_bd_size=0 end
  509.     if t.fg_bd_colour==nil  then t.fg_bd_colour={{1,0xFFFF00,1}} end
  510.    
  511.     if t.autoscale==nil     then t.autoscale=false end
  512.     if t.inverse==nil       then t.inverse=false end
  513.     if t.angle==nil         then t.angle=0 end
  514.    
  515.     if t.bg_bd_orientation==nil then t.bg_bd_orientation="nn" end
  516.     if t.bg_orientation==nil then t.bg_orientation="nn" end
  517.     if t.fg_bd_orientation==nil then t.fg_bd_orientation="nn" end
  518.     if t.fg_orientation==nil then t.fg_orientation="nn" end
  519.  
  520.     --check colours tables
  521.     for i=1, #t.fg_colour do    
  522.         if #t.fg_colour[i]~=3 then
  523.             print ("error in fg_colour table")
  524.             t.fg_colour[i]={1,0x0000FF,1}
  525.         end
  526.     end
  527.    
  528.     for i=1, #t.fg_bd_colour do    
  529.         if #t.fg_bd_colour[i]~=3 then
  530.             print ("error in fg_bd_colour table")
  531.             t.fg_bd_colour[i]={1,0x00FF00,1}
  532.         end
  533.     end
  534.    
  535.     for i=1, #t.bg_colour do    
  536.         if #t.bg_colour[i]~=3 then
  537.             print ("error in background color table")
  538.             t.bg_colour[i]={1,0xFFFFFF,0.5}
  539.         end
  540.     end    
  541.  
  542.     for i=1, #t.bg_bd_colour do    
  543.         if #t.bg_bd_colour[i]~=3 then
  544.             print ("error in background border color table")
  545.             t.bg_bd_colour[i]={1,0xFFFFFF,1}
  546.         end
  547.     end    
  548.  
  549.     --calculate skew parameters if needed
  550.     if t.flag_init then
  551.         if t.skew_x == nil then
  552.             t.skew_x=0
  553.         else
  554.             t.skew_x = math.pi*t.skew_x/180
  555.         end
  556.         if t.skew_y == nil then
  557.             t.skew_y=0
  558.         else
  559.             t.skew_y = math.pi*t.skew_y/180
  560.         end
  561.         t.flag_init=false
  562.     end
  563.  
  564.     cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
  565.     cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND)
  566.  
  567.     local matrix0 = cairo_matrix_t:create()
  568.     tolua.takeownership(matrix0)
  569.     cairo_save(cr)
  570.     cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
  571.     cairo_transform(cr,matrix0)
  572.    
  573.     local ratio=t.width/t.nb_values
  574.  
  575.     cairo_translate(cr,t.x,t.y)
  576.     cairo_rotate(cr,t.angle*math.pi/180)
  577.     cairo_scale(cr,1,-1)
  578.  
  579.     --background
  580.     if t.background then
  581.         local pts=linear_orientation(t.bg_orientation,t.width,t.height)
  582.         local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
  583.         for i=1, #t.bg_colour do
  584.             --print ("i",i,t.colour[i][1], rgb_to_r_g_b(t.colour[i]))
  585.             cairo_pattern_add_color_stop_rgba (pat, t.bg_colour[i][1], rgb_to_r_g_b(t.bg_colour[i]))
  586.         end
  587.         cairo_set_source (cr, pat)
  588.         cairo_rectangle(cr,0,0,t.width,t.height)   
  589.         cairo_fill(cr) 
  590.         cairo_pattern_destroy(pat)
  591.     end
  592.    
  593.     --autoscale
  594.     cairo_save(cr)
  595.     if t.autoscale then
  596.         t.max= t.automax*1.1
  597.     end
  598.    
  599.     local scale_x = t.width/(t.nb_values-1)
  600.     local scale_y = t.height/t.max
  601.    
  602.     --define first point of the graph
  603.     if updates-updates_gap <t.nb_values then
  604.         t.beg = t.beg - 1
  605.         --next line prevent segmentation error when conky window is redraw
  606.         --quicly when another window "fly" over it
  607.         if t.beg<0 then t.beg=0 end
  608.     else
  609.         t.beg=0
  610.     end
  611.     if t.inverse then cairo_scale(cr,-1,1)
  612.     cairo_translate(cr,-t.width,0) end
  613.  
  614.     --graph foreground
  615.     if t.foreground then
  616.         local pts_fg=linear_orientation_inv(t.fg_orientation,t.width,t.height)
  617.         local pat = cairo_pattern_create_linear (pts_fg[1],pts_fg[2],pts_fg[3],pts_fg[4])
  618.         for i=1,#t.fg_colour,1 do
  619.             cairo_pattern_add_color_stop_rgba (pat, 1-t.fg_colour[i][1], rgb_to_r_g_b(t.fg_colour[i]))
  620.         end
  621.         cairo_set_source (cr, pat)
  622.  
  623.         cairo_move_to(cr,t.beg*scale_x,0)
  624.         cairo_line_to(cr,t.beg*scale_x,t.values[t.beg+1]*scale_y)
  625.         for i=t.beg, t.nb_values-1 do
  626.             cairo_line_to(cr,i*scale_x,t.values[i+1]*scale_y)      
  627.         end
  628.         cairo_line_to(cr,(t.nb_values-1)*scale_x,0)
  629.         cairo_close_path(cr)
  630.         cairo_fill(cr)
  631.         cairo_pattern_destroy(pat)
  632.     end
  633.  
  634.     --graph_border
  635.     if t.fg_bd_size>0 then
  636.         local pts=linear_orientation_inv(t.fg_bd_orientation,t.width,t.height)
  637.         local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
  638.         for i=1,#t.fg_bd_colour,1 do
  639.             cairo_pattern_add_color_stop_rgba (pat, 1-t.fg_bd_colour[i][1], rgb_to_r_g_b(t.fg_bd_colour[i]))
  640.         end
  641.         cairo_set_source (cr, pat)
  642.         cairo_move_to(cr,t.beg*scale_x,t.values[t.beg+1]*scale_y)
  643.         for i=t.beg, t.nb_values-1 do
  644.             cairo_line_to(cr,i*scale_x,t.values[i+1]*scale_y)      
  645.         end
  646.         cairo_set_line_width(cr,t.fg_bd_size)
  647.         cairo_stroke(cr)
  648.         cairo_pattern_destroy(pat)
  649.     end
  650.     cairo_restore(cr)
  651.  
  652.     --background border
  653.     if t.bg_bd_size>0 then
  654.         local pts=linear_orientation(t.bg_bd_orientation,t.width,t.height)
  655.         local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
  656.         for i=1, #t.bg_bd_colour do
  657.             --print ("i",i,t.colour[i][1], rgb_to_r_g_b(t.colour[i]))
  658.             cairo_pattern_add_color_stop_rgba (pat, t.bg_bd_colour[i][1], rgb_to_r_g_b(t.bg_bd_colour[i]))
  659.         end
  660.         cairo_set_source (cr, pat)
  661.         cairo_rectangle(cr,0,0,t.width,t.height)   
  662.         cairo_set_line_width(cr,t.bg_bd_size)
  663.         cairo_stroke(cr)
  664.         cairo_pattern_destroy(pat) 
  665.     end
  666.  
  667.     cairo_restore(cr)
  668.  
  669. end
  670.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement