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)
22 Instance = luci.util.class()
24 function Instance.from_string( self, s )
26 luci.bits.Hex2Dec(s:sub(1,2)),
27 luci.bits.Hex2Dec(s:sub(3,4)),
28 luci.bits.Hex2Dec(s:sub(5,6))
32 function Instance.to_string( self, c )
41 function Instance.random( self )
42 local r = math.random(255)
43 local g = math.random(255)
47 if ( r + g ) < 255 then
53 local b = min + math.floor( math.random() * ( max - min ) )
58 function Instance.faded( self, fg, opts )
60 opts.background = opts.background or { 255, 255, 255 }
61 opts.alpha = opts.alpha or 0.25
63 if type(opts.background) == "string" then
64 opts.background = _string_to_color(opts.background)
67 local bg = opts.background
70 ( opts.alpha * fg[1] ) + ( ( 1.0 - opts.alpha ) * bg[1] ),
71 ( opts.alpha * fg[2] ) + ( ( 1.0 - opts.alpha ) * bg[2] ),
72 ( opts.alpha * fg[3] ) + ( ( 1.0 - opts.alpha ) * bg[3] )