Class: ODDB::View::Ajax::DDDChart

Inherits:
HtmlGrid::Component show all
Includes:
PartSize
Defined in:
src/view/ajax/ddd_chart.rb

Constant Summary

HTTP_HEADERS =
{
  'Content-Type'  =>  'image/png',
}
MAX_LEN =
50

Instance Method Summary (collapse)

Methods included from PartSize

#comparable_size, #part_size

Methods inherited from HtmlGrid::Component

#additional_javascripts, #dynamic_html

Instance Method Details

- (Object) init



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'src/view/ajax/ddd_chart.rb', line 239

def init
  @labels = {}
  @data = []
  @original_index = 0
  img_name = @session.user_input(:for)
  ikskey = img_name[/^\d{8}/]
  original = @session.package_by_ikskey ikskey
  my_factor = (original.generic_group_factor || 1).to_f
  oseq = original.sequence
  @model.each_with_index do |pac, idx|
    ddd_price = pac.ddd_price
    @data.push ddd_price
    base = pac.name_base
    size = comparable_size(pac)
    fullname = u sprintf("%s, %s", base, size)
    name = fullname.length > MAX_LEN ? fullname[0, MAX_LEN - 1] + "…" : fullname
    label = sprintf "%s: CHF %4.2f", name, ddd_price
    pac_factor = (pac.generic_group_factor || 1).to_f / my_factor
    if pac == original
      @original_index = idx
      @title = @lookandfeel.lookup(:ddd_chart_title, fullname)
    elsif pac_factor == 2 || pac.sequence.comparable?(oseq, 2)
      label = sprintf "2 x %s: CHF %4.2f", name, ddd_price
    elsif pac_factor == 0.5 || pac.sequence.comparable?(oseq, 0.5)
      label = sprintf "1/2 x %s: CHF %4.2f", name, ddd_price
    end
    @labels.store idx, label
  end
  super
end

- (Object) to_html(cgi)



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'src/view/ajax/ddd_chart.rb', line 269

def to_html(cgi)
  factor = (@session.user_input(:factor) || 1).to_f
  height = (60 + @data.size * 20) * factor
  width = 750 * factor
  gr = SideBar.new "#{width}x#{height}"

  gr.title = @title

  gr.hide_legend = true
  gr.marker_font_size = 15
  gr.title_font_size = 16
  gr.sort = false
  gr.margins = 4
  gr.left_margin = 0

  gr.theme = {
    :colors => ['#ccff99'],
    :marker_color => '#dddddd',
    :font_color => 'black',      
    :background_colors => "white",
    :custom_colors => { @original_index => '#2ba476' },
    :source => @lookandfeel.lookup(:ddd_chart_source),
    :source_font_size => 12
  }

  gr.data "Data", @data

  labels = {}
  gr.labels = @labels
  gr.maximum_value = (@data.max * 2).to_f.ceil / 2.0
  gr.minimum_value = 0

  gr.to_blob
end