#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.EventSystems;
namespace ChartAndGraph
{
public class CanvasBarChart : BarChart, ICanvas
{
///
/// The seperation between the axis and the chart bars.
///
[SerializeField]
private bool fitToContainer = false;
public bool FitToContainer
{
get { return fitToContainer; }
set
{
fitToContainer = value;
OnPropertyUpdated();
}
}
[SerializeField]
private ChartMagin fitMargin;
public ChartMagin FitMargin
{
get { return fitMargin; }
set
{
fitMargin = value;
OnPropertyUpdated();
}
}
protected override ChartMagin MarginLink
{
get
{
return fitMargin;
}
}
[SerializeField]
///
/// prefab for the bar elements of the chart. must be the size of one unit with a pivot at the middle bottom
///
[Tooltip("Prefab for the bar elements of the chart. must be the size of one unit with a pivot at the middle bottom")]
private CanvasRenderer barPrefab;
///
/// prefab for the bar elements of the chart. must be the size of one unit with a pivot at the middle bottom
///
public CanvasRenderer BarPrefab
{
get { return barPrefab; }
set
{
barPrefab = value;
OnPropertyUpdated();
}
}
public override bool IsCanvas
{
get
{
return true;
}
}
///
/// The seperation between the axis and the chart bars.
///
[SerializeField]
[Tooltip("The seperation between the axis and the chart bars")]
private float axisSeperation = 20f;
protected override float TotalDepthLink
{
get
{
return 0.0f;
}
}
///
/// The seperation between the axis and the chart bars.
///
public float AxisSeperation
{
get { return axisSeperation; }
set
{
axisSeperation = value;
OnPropertyUpdated();
}
}
///
/// seperation between bar of the same group
///
[SerializeField]
[Tooltip("seperation between bar of the same group")]
private float barSeperation = 45f;
///
/// seperation between bars of the same group.
///
public float BarSeperation
{
get { return barSeperation; }
set
{
barSeperation = value;
OnPropertyUpdated();
}
}
///
/// seperation between bar groups
///
[SerializeField]
[Tooltip("seperation between bar groups")]
private float groupSeperation = 220f;
///
/// The seperation between bar groups.
///
public float GroupSeperation
{
get { return groupSeperation; }
set
{
groupSeperation = value;
OnPropertyUpdated();
}
}
public override bool SupportRealtimeGeneration
{
get
{
return false;
}
}
///
/// the width of each bar in the chart
///
[SerializeField]
[Tooltip("the width of each bar in the chart")]
private float barSize = 20f;
///
/// the width of each bar in the chart
///
public float BarSize
{
get { return barSize; }
set
{
barSize = value;
OnPropertyUpdated();
}
}
protected override ChartOrientedSize AxisSeperationLink
{
get
{
return new ChartOrientedSize(AxisSeperation);
}
}
protected override ChartOrientedSize BarSeperationLink
{
get
{
return new ChartOrientedSize(BarSeperation);
}
}
protected override ChartOrientedSize GroupSeperationLink
{
get
{
return new ChartOrientedSize(GroupSeperation);
}
}
protected override ChartOrientedSize BarSizeLink
{
get
{
return new ChartOrientedSize(BarSize);
}
}
protected override void SetBarSize(GameObject bar, Vector3 size,float elevation)
{
RectTransform rect = bar.GetComponent();
if (rect != null)
{
float ySize = size.y;
float yAnchor = 0f;
if (ySize < 0)
{
ySize = -ySize;
yAnchor = 1;
}
rect.pivot = new Vector2(0.5f, yAnchor);
rect.sizeDelta = new Vector2(size.x, ySize);
Vector2 v = rect.localPosition;
v.y = elevation;
rect.localPosition = v;
}
else
base.SetBarSize(bar, size,elevation);
}
protected override void Update()
{
base.Update();
}
//protected override Vector3 CanvasFitOffset
//{
// get
// {
// return new Vector3();
// }
//}
///
///
///
///
[SerializeField]
[Tooltip("")]
private FitOrientation barFitDirection = FitOrientation.Normal;
///
/// the width of each bar in the chart
///
/// the width of each bar in the chart
///
///
///
[SerializeField]
[Tooltip("")]
private FitAlign barFitAlign = FitAlign.CenterXCenterY;
///
/// the width of each bar in the chart
/// ();
if (FitToContainer)
{
if (barFitDirection == FitOrientation.Normal)
{
float width = MessureWidth();
heightRatio = width * (trans.rect.size.y / trans.rect.size.x);
}
else
{
float width = MessureWidth();
heightRatio = width * (trans.rect.size.x / trans.rect.size.y);
}
}
base.InternalGenerateChart();
//if (TextController != null && TextController.gameObject)
// TextController.gameObject.transform.SetAsLastSibling();
//float widthScale = trans.rect.size.x / TotalWidth;
//float heightScale = trans.rect.size.y / HeightRatio;
//GameObject fixPosition = new GameObject();
//ChartCommon.HideObject(fixPosition, hideHierarchy);
//fixPosition.AddComponent();
//fixPosition.transform.position = transform.position;
//while (gameObject.transform.childCount > 0)
// transform.GetChild(0).SetParent(fixPosition.transform, false);
//fixPosition.transform.SetParent(transform, false);
//fixPosition.transform.localScale = new Vector3(1f, 1f, 1f);
//float uniformScale = Math.Min(widthScale, heightScale);
//fixPosition.transform.localScale = new Vector3(uniformScale, uniformScale, uniformScale);
//fixPosition.transform.localPosition = new Vector3(-TotalWidth * uniformScale * 0.5f, -HeightRatio * uniformScale * 0.5f, 0f);
}
protected override GameObject BarPrefabLink
{
get
{
if (BarPrefab == null)
return null;
return BarPrefab.gameObject;
}
}
}
}