/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

package demo.chart3d;

import ilog.views.chart.IlvChart;
import ilog.views.chart.IlvScale;
import ilog.views.chart.data.IlvDataSet;
import ilog.views.chart.data.IlvDataSetPoint;
import ilog.views.chart.renderer.IlvSingleChartRenderer;
import ilog.views.chart.servlet.IlvChartHitmap;
import ilog.views.chart.servlet.IlvChartHitmapAccumulator;
import ilog.views.chart.servlet.IlvDefaultChartHitmapDefinition;
import ilog.views.chart.servlet.IlvDefaultChartToolTip;
import ilog.views.chart.servlet.IlvIMapAttributes;
import ilog.views.util.hitmap.IlvHitmapConstants;
import ilog.views.util.hitmap.IlvHitmapInfoGenerator;

/**
 * The customized hitmap info definition for 3D chart view.
 * 
 * @since JViews 8.7
 */
public class HitmapDefinition3D extends IlvDefaultChartHitmapDefinition {

  /**
   * A tooltip class that allows access to the data set and to the index of the
   * data point in the data set.
   */
  static class DataPointToolTip extends IlvDefaultChartToolTip {
    private final IlvDataSet dataSet;
    private final int idx;

    DataPointToolTip(IlvDataSet dataSet, int idx) {
      super("Data value", dataSet, idx);
      this.dataSet = dataSet;
      this.idx = idx;
    }

    public IlvDataSet getDataSet() {
      return this.dataSet;
    }

    public int getIdx() {
      return this.idx;
    }
  }

  Override
  public void drawIntoHitmap(IlvChart chart, IlvScale scale, IlvChartHitmapAccumulator accumulator) {
    // do not draw scale hitmap for chart 3D demo.
    // super.drawIntoHitmap(chart, scale, accumulator);
  }

  Override
  public IlvIMapAttributes getAttributes(IlvChart chart, IlvSingleChartRenderer renderer, IlvDataSetPoint dp) {
    return new DataPointToolTip(dp.getDataSet(), dp.getIndex());
  }

  Override
  public String getToolTipAsHTML(IlvIMapAttributes attributes) {
    DataPointToolTip tooltip = (DataPointToolTip) attributes;
    StringBuffer buffer = new StringBuffer();
    buffer.append("{");
    buffer.append("'title':");
    buffer.append("'Value").append(tooltip.getIdx()).append("'");
    buffer.append(",");
    buffer.append("'value':");
    buffer.append("'" + tooltip.getALT() + "'");
    buffer.append("}");
    return buffer.toString();
  }

  Override
  public IlvHitmapInfoGenerator createHitmapInfoGenerator(String infoType, IlvChartHitmap hitmap) {

    if (infoType.equals(IlvHitmapConstants.CURSOR_TYPE)) {
      return new MyCursorInfoGenerator(hitmap);
    } else {
      return super.createHitmapInfoGenerator(infoType, hitmap);
    }
  }
}