/*******************************************************************************
 * Caleydo - Visualization for Molecular Biology - http://caleydo.org
 * Copyright (c) The Caleydo Team. All rights reserved.
 * Licensed under the new BSD license, available at http://caleydo.org/license
 *******************************************************************************/
package org.caleydo.view.domino.internal.data;

import java.util.Collection;

import org.caleydo.core.data.collection.EDataClass;
import org.caleydo.core.data.collection.EDimension;
import org.caleydo.core.data.datadomain.DataSupportDefinitions;
import org.caleydo.core.data.perspective.table.TablePerspective;
import org.caleydo.core.data.perspective.variable.Perspective;
import org.caleydo.core.view.opengl.layout2.manage.GLElementFactoryContext.Builder;
import org.caleydo.view.domino.api.model.typed.TypedGroupSet;
import org.caleydo.view.domino.api.model.typed.TypedList;

/**
 * @author Samuel Gratzl
 *
 */
public class Numerical1DDataDomainValues extends A1DDataDomainValues implements INumerical1DContainer {
	private final TypedGroupSet groups;
	private final boolean isInteger;
	private final Numerical1DMixin mixin;

	public Numerical1DDataDomainValues(TablePerspective data, EDimension main) {
		super(data, main);
		Perspective p = main.select(data.getDimensionPerspective(), data.getRecordPerspective());
		this.groups = Numerical1DMixin.extractGroups(p, this);
		this.isInteger = DataSupportDefinitions.dataClass(EDataClass.NATURAL_NUMBER).apply(data);

		this.mixin = new Numerical1DMixin(this, groups);
	}

	@Override
	public String getExtensionID() {
		return "numerical.1d";
	}

	@Override
	protected TypedGroupSet getGroups() {
		return groups;
	}

	@Override
	public Collection<String> getDefaultVisualization() {
		return mixin.getDefaultVisualization();
	}

	@Override
	public boolean apply(String input) {
		return super.apply(input) && !"distribution.pie".equals(input);
	}


	@Override
	protected void fill(Builder b, TypedList data) {
		super.fill(b, data);
		mixin.fill(b, data);
	}


	@Override
	public Float getRaw(int id) {
		Object r = super.getRaw(id);
		if (r instanceof Float)
			return ((Float)r);
		if (r instanceof Integer && isInteger) {
			Integer i = (Integer) r;
			if (i.intValue() == Integer.MIN_VALUE)
				return Float.NaN;
			return i.floatValue();
		}
		if (r instanceof Number)
			return ((Number) r).floatValue();
		return Float.NaN;
	}
}

@@ -727,32 +727,74 @@
 le.Perspective;%0A
+import org.caleydo.core.util.color.Color;%0A
 import org.caley
@@ -2113,24 +2113,489 @@
  data);%0A%09%7D%0A%0A
+%09@Override%0A%09public Color apply(Integer recordID, Integer dimensionID) %7B%0A%09%09if (isInvalid(recordID) %7C%7C isInvalid(dimensionID))%0A%09%09%09return Color.NOT_A_NUMBER_COLOR;%0A%09%09float vs = getNormalized(dimensionID, recordID);%0A%09%09if (Float.isNaN(vs))%0A%09%09%09return Color.NOT_A_NUMBER_COLOR;%0A%09%09return new Color(1 - vs);%0A%09%09// // get value%0A%09%09// float%5B%5D color = d.getTable().getColor(dimensionID, recordID);%0A%09%09// // to a color%0A%09%09// return new Color(color%5B0%5D, color%5B1%5D, color%5B2%5D, 1.0f);%0A%09%7D%0A
 %0A%09@Override%0A

fix #106: invert color map for 1d numerical