3 Luci statistics - diagram color helper class
4 (c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
16 module("luci.statistics.rrdtool.colors", package.seeall)
21 Instance = luci.util.class()
23 function Instance.from_string( self, s )
25 tonumber(s:sub(1,2), 16),
26 tonumber(s:sub(3,4), 16),
27 tonumber(s:sub(5,6), 16)
31 function Instance.to_string( self, c )
40 function Instance.random( self )
41 local r = math.random(255)
42 local g = math.random(255)
46 if ( r + g ) < 255 then
52 local b = min + math.floor( math.random() * ( max - min ) )
57 function Instance.faded( self, fg, opts )
59 opts.background = opts.background or { 255, 255, 255 }
60 opts.alpha = opts.alpha or 0.25
62 if type(opts.background) == "string" then
63 opts.background = _string_to_color(opts.background)
66 local bg = opts.background
69 ( opts.alpha * fg[1] ) + ( ( 1.0 - opts.alpha ) * bg[1] ),
70 ( opts.alpha * fg[2] ) + ( ( 1.0 - opts.alpha ) * bg[2] ),
71 ( opts.alpha * fg[3] ) + ( ( 1.0 - opts.alpha ) * bg[3] )