작업 조건 분석 기능 개발

This commit is contained in:
정영민
2025-03-10 16:42:23 +09:00
parent 840638c6e3
commit f2029fd8c9
2988 changed files with 569938 additions and 2342 deletions

View File

@@ -0,0 +1,651 @@
#define Graph_And_Chart_PRO
#define CandleChart
using ChartAndGraph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.Events;
namespace ChartAndGraph
{
[ExecuteInEditMode]
public abstract class CandleChart : ScrollableAxisChart
{
/// <summary>
/// a candle chart event
/// </summary>
[Serializable]
public class CandleEvent : UnityEvent<CandleEventArgs>
{
}
[SerializeField]
[Tooltip("The height ratio of the chart")]
protected float heightRatio = 300;
[SerializeField]
[Tooltip("The width ratio of the chart")]
protected float widthRatio = 600;
protected override float TotalHeightLink
{
get
{
return heightRatio;
}
}
protected override float TotalWidthLink
{
get
{
return widthRatio;
}
}
/// <summary>
/// occures when a point is clicked
/// </summary>
public CandleEvent CandleClicked = new CandleEvent();
/// <summary>
/// occurs when a point is hovered
/// </summary>
public CandleEvent CandleHovered = new CandleEvent();
/// <summary>
/// occurs when no candle is hovered any longer
/// </summary>
public UnityEvent NonHovered = new UnityEvent();
public enum CandleThicknessMode
{
/// <summary>
/// the candle size is detemined only by the candle duration paramenter
/// </summary>
Fill,
/// <summary>
/// the candle is of constant size , regardless of the view size
/// </summary>
Constant,
/// <summary>
/// the candle size is fixed , but proportional to the view size
/// </summary>
Proportional
}
/// <summary>
/// format a candle value to the parameter strings
/// </summary>
/// <param name="candleVal"></param>
/// <param name="fractionDigits"></param>
/// <param name="open"></param>
/// <param name="high"></param>
/// <param name="low"></param>
/// <param name="close"></param>
public void FormatCandleValue(CandleChartData.CandleValue candleVal, int fractionDigits, out string open, out string high, out string low, out string close)
{
open = StringFromAxisFormat(new DoubleVector3(candleVal.Start,candleVal.Open,0.0), mVerticalAxis,false);
close = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Close, 0.0), mVerticalAxis, false);
high = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.High, 0.0), mVerticalAxis, false);
low = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Low, 0.0), mVerticalAxis, false);
}
/// <summary>
/// format a candle value to the parameter strings
/// </summary>
/// <param name="candleVal"></param>
/// <param name="fractionDigits"></param>
/// <param name="start"></param>
/// <param name="duration"></param>
public void FormatCandleValue(CandleChartData.CandleValue candleVal, int fractionDigits, out string start, out string duration)
{
start = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mHorizontalAxis, true);
duration = StringFromAxisFormat(new DoubleVector3(candleVal.Duration, candleVal.Open, 0.0), mHorizontalAxis, true);
}
/// <summary>
/// format a candle value to the parameter strings
/// </summary>
/// <param name="candleVal"></param>
/// <param name="fractionDigits"></param>
/// <param name="open"></param>
/// <param name="high"></param>
/// <param name="low"></param>
/// <param name="close"></param>
/// <param name="start"></param>
/// <param name="duration"></param>
public void FormatCandleValue(CandleChartData.CandleValue candleVal, int fractionDigits, out string open, out string high, out string low, out string close, out string start, out string duration)
{
FormatCandleValue(candleVal, fractionDigits, out open, out high, out low, out close);
FormatCandleValue(candleVal, fractionDigits, out start, out duration);
}
public class CandleEventArgs
{
int mType;
public CandleEventArgs(int index, int type, Rect selectionRect, Vector3 position, CandleChartData.CandleValue value, string category)
{
mType = type;
Position = position;
SelectionRect = selectionRect;
CandleValue = value;
Category = category;
}
/// <summary>
/// true if this event is triggered for the high portion of the candle
/// </summary>
public bool IsHighEvent { get { return mType == 0; } }
/// <summary>
/// true if this event is triggered for the low portion of the candle
/// </summary>
public bool IsLowEvent { get { return mType == 2; } }
/// <summary>
/// true if this event is triggerd for the body portion of the candle (open/close)
/// </summary>
public bool IsBodyEvent { get { return mType == 1; } }
/// <summary>
/// the rect on the canvas that represents the selected object
/// </summary>
public Rect SelectionRect { get; private set; }
/// <summary>
/// mouse position
/// </summary>
public Vector3 Position { get; private set; }
/// <summary>
/// the index of the candle in the data
/// </summary>
public int Index { get; private set; }
/// <summary>
/// the value of the candle
/// </summary>
public CandleChartData.CandleValue CandleValue { get; private set; }
/// <summary>
/// the category of the candle
/// </summary>
public string Category { get; private set; }
}
[SerializeField]
[Tooltip("Thickness mode for the candle chart")]
protected CandleThicknessMode thicknessMode = CandleThicknessMode.Constant;
/// <summary>
/// Thickness mode for the candle chart
/// </summary>
public CandleThicknessMode ThicknessMode
{
get { return thicknessMode; }
set
{
thicknessMode = value;
Invalidate();
}
}
protected override IChartData DataLink
{
get
{
return Data;
}
}
[SerializeField]
[Tooltip("Thickness contant for the candle chart , it's meaning depends on the thickness mode")]
protected float thicknessConstant = 10f;
/// <summary>
/// Thickness contant for the candle chart , it's meaning depends on the thickness mode\
/// Fill - multiply the duration size of the candle by a constant , should be between 0f to 1f
/// Constant - the pixel size of the candle
/// Proportional - constant size of the candle in seconds
/// </summary>
public float ThicknessConstant
{
get { return thicknessConstant; }
set
{
thicknessConstant = value;
Invalidate();
}
}
protected override float GetScrollingRange(int axis)
{
float min = (float)((IInternalCandleData)Data).GetMinValue(axis, false);
float max = (float)((IInternalCandleData)Data).GetMaxValue(axis, false);
return max - min;
}
[SerializeField]
[Tooltip("format with the following labels: <?start> , <?duration>,<?open>,<?high>,<?low>,<?close>")]
private string itemFormat = "O:<?open>,H:<?high>,L:<?low>,C:<?close>";
/// <summary>
/// format with the following labels:
/// <?start>
/// <?duration>
/// <?open>
/// <?close>
/// <?high>
/// <?low>
/// </summary>
public string ItemFormat
{
get { return itemFormat; }
set
{
itemFormat = value;
Invalidate();
}
}
[SerializeField]
[Tooltip("Used when using hoverItem component, and the mouse is hovering over the body of the candle,format with the following labels: <?start> , <?duration>,<?open>,<?high>,<?low>,<?close>")]
private string bodyFormat = "O:<?open>,C:<?close>";
/// <summary>
/// format with the following labels:
/// <?start>
/// <?duration>
/// <?open>
/// <?close>
/// <?high>
/// <?low>
/// </summary>
public string BodyFormat
{
get { return bodyFormat; }
set
{
bodyFormat = value;
Invalidate();
}
}
[SerializeField]
[Tooltip("Used when using hoverItem component, and the mouse is hovering over the high line of the candle,format with the following labels: <?start> , <?duration>,<?open>,<?high>,<?low>,<?close>")]
private string highFormat = "H:<?high>";
public string HighFormat
{
get { return highFormat; }
set
{
highFormat = value;
Invalidate();
}
}
[SerializeField]
[Tooltip("Used when using hoverItem component, and the mouse is hovering over the low line of the candle,format with the following labels: <?start> , <?duration>,<?open>,<?high>,<?low>,<?close>")]
private string lowFormat = "L:<?low>";
public string LowFormat
{
get { return lowFormat; }
set
{
lowFormat = value;
Invalidate();
}
}
/// <summary>
/// the candle chart data
/// </summary>
[HideInInspector]
[SerializeField]
protected CandleChartData Data = new CandleChartData();
/// <summary>
/// Holds the candle chart data. including values and categories
/// </summary>
public CandleChartData DataSource { get { return Data; } }
protected override void Start()
{
base.Start();
if (ChartCommon.IsInEditMode == false)
{
HookEvents();
}
Invalidate();
}
protected override void OnValidate()
{
base.OnValidate();
if (ChartCommon.IsInEditMode == false)
{
HookEvents();
}
Data.RestoreDataValues();
Invalidate();
}
/// <summary>
/// hooks data source events.
/// </summary>
protected void HookEvents()
{
((IInternalCandleData)Data).InternalDataChanged -= CandleChart_InternalDataChanged;
((IInternalCandleData)Data).InternalDataChanged += CandleChart_InternalDataChanged;
((IInternalCandleData)Data).InternalViewPortionChanged -= CandleChart_InternalViewPortionChanged;
((IInternalCandleData)Data).InternalViewPortionChanged += CandleChart_InternalViewPortionChanged;
((IInternalCandleData)Data).InternalRealTimeDataChanged -= CandleChart_InternalRealTimeDataChanged;
((IInternalCandleData)Data).InternalRealTimeDataChanged += CandleChart_InternalRealTimeDataChanged;
}
private void CandleChart_InternalViewPortionChanged(object sender, EventArgs e)
{
InvalidateRealtime();
}
private void CandleChart_InternalRealTimeDataChanged(int index,string str)
{
InvalidateRealtime();
}
private void CandleChart_InternalDataChanged(object sender, EventArgs e)
{
Invalidate();
}
protected override void OnLabelSettingChanged()
{
base.OnLabelSettingChanged();
Invalidate();
}
protected override void OnAxisValuesChanged()
{
base.OnAxisValuesChanged();
Invalidate();
}
protected override void OnLabelSettingsSet()
{
base.OnLabelSettingsSet();
Invalidate();
}
protected override LegenedData LegendInfo
{
get
{
LegenedData data = new LegenedData();
if (Data == null)
return data;
foreach (var cat in ((IInternalCandleData)Data).Categories)
{
for (int i = 0; i < 2; i++)
{
LegenedData.LegenedItem item = new LegenedData.LegenedItem();
CandleChartData.CandleSettings settings = cat.UpCandle;
if (i == 0)
{
item.Name = cat.Name + " Increasing";
}
else
{
item.Name = cat.Name + " Decreasing";
settings = cat.DownCandle;
}
if (settings.Fill != null)
item.Material = settings.Fill;
else
{
if (settings.Outline != null)
item.Material = settings.Outline;
else
item.Material = settings.Line;
}
data.AddLegenedItem(item);
}
}
return data;
}
}
protected override bool SupportsCategoryLabels
{
get
{
return true;
}
}
protected override bool SupportsGroupLables
{
get
{
return false;
}
}
protected override bool SupportsItemLabels
{
get
{
return true;
}
}
protected override bool HasValues(AxisBase axis)
{
if (axis == mVerticalAxis || axis == mHorizontalAxis) // has both horizontal and vertical axis
return true;
return false;
}
protected override double MaxValue(AxisBase axis)
{
if (axis == null)
return 0.0;
if (axis == mHorizontalAxis)
return ((IInternalCandleData)Data).GetMaxValue(0, false);
if (axis == mVerticalAxis)
return ((IInternalCandleData)Data).GetMaxValue(1, false);
return 0.0;
}
protected override double MinValue(AxisBase axis)
{
if (axis == null)
return 0.0;
if (axis == mHorizontalAxis)
return ((IInternalCandleData)Data).GetMinValue(0, false);
if (axis == mVerticalAxis)
return ((IInternalCandleData)Data).GetMinValue(1, false);
return 0.0;
}
void Deflate(ref double start, ref double duration, double amount)
{
double center = start + duration * 0.5;
duration *= amount;
start = center - duration * 0.5;
}
CandleChartData.CandleValue NormalizeCandle(CandleChartData.CandleValue candle, DoubleVector3 min, DoubleVector3 range)
{
CandleChartData.CandleValue res = new CandleChartData.CandleValue();
res.Open = ChartCommon.normalizeInRangeY(candle.Open, min, range);
res.Close = ChartCommon.normalizeInRangeY(candle.Close, min, range);
res.High = ChartCommon.normalizeInRangeY(candle.High, min, range);
res.Low = ChartCommon.normalizeInRangeY(candle.Low, min, range);
double duration = candle.Duration;
double start = candle.Start;
if (ThicknessMode == CandleThicknessMode.Fill)
Deflate(ref start, ref duration, ThicknessConstant);
else if (thicknessMode == CandleThicknessMode.Proportional)
Deflate(ref start, ref duration, ThicknessConstant / duration);
double candleEnd = start + duration;
candleEnd = ChartCommon.normalizeInRangeX(candleEnd, min, range);
res.Start = ChartCommon.normalizeInRangeX(start, min, range);
res.Duration = candleEnd - res.Start;
return res;
}
public CandleChartData.CandleValue InterpolateCandleInRect(CandleChartData.CandleValue candle, Rect viewRect)
{
CandleChartData.CandleValue res = new CandleChartData.CandleValue();
res.Open = ChartCommon.interpolateInRectY(viewRect, candle.Open);
res.Close = ChartCommon.interpolateInRectY(viewRect, candle.Close);
res.High = ChartCommon.interpolateInRectY(viewRect, candle.High);
res.Low = ChartCommon.interpolateInRectY(viewRect, candle.Low);
if (res.High < res.Low)
{
double tmp = res.High;
res.High = res.Low;
res.Low = tmp;
tmp = res.Open;
res.Open = res.Close;
res.Close = tmp;
}
double candleEnd = candle.Start + candle.Duration;
candleEnd = ChartCommon.interpolateInRectX(viewRect, candleEnd);
double start = ChartCommon.interpolateInRectX(viewRect, candle.Start);
double duration = candleEnd - start;
if (start > candleEnd)
{
double tmp = start;
start = candleEnd;
candleEnd = tmp;
}
if (ThicknessMode == CandleThicknessMode.Constant)
{
Deflate(ref start, ref duration, ThicknessConstant / duration);
}
res.Start = start;
res.Duration = duration;
return res;
}
StringBuilder mTmpBuilder = new StringBuilder();
protected string FormatItemWithFormat(string format, string open, string close, string high, string low, string start, string duration)
{
FormatItemWithFormat(mTmpBuilder, format, open, close, high, low, start, duration);
return mTmpBuilder.ToString();
}
public string FormatItem(string open, string close, string high, string low, string start, string duration)
{
return FormatItemWithFormat(itemFormat, open, close, high, low, start, duration);
}
public string FormatLow(string open, string close, string high, string low, string start, string duration)
{
return FormatItemWithFormat(lowFormat, open, close, high, low, start, duration);
}
public string FormatHigh(string open, string close, string high, string low, string start, string duration)
{
return FormatItemWithFormat(highFormat, open, close, high, low, start, duration);
}
public string FormatBody(string open, string close, string high, string low, string start, string duration)
{
return FormatItemWithFormat(bodyFormat, open, close, high, low, start, duration);
}
protected void FormatItem(StringBuilder builder, string open, string close, string high, string low, string start, string duration)
{
FormatItemWithFormat(builder, itemFormat, open, close, high, low, start, duration);
}
protected void FormatItemWithFormat(StringBuilder builder, string format, string open, string close, string high, string low, string start, string duration)
{
builder.Length = 0;
builder.Append(format);
builder.Replace("<?open>", open).Replace("<?close>", close).Replace("<?high>", high).Replace("<?low>", low).Replace("<?start>", start).Replace("<?duration>", duration);
}
protected void TransformCandles(IList<CandleChartData.CandleValue> candles, List<CandleChartData.CandleValue> output, Rect viewRect, DoubleVector3 min, DoubleVector3 max)
{
DoubleVector3 range = max - min;
if (Math.Abs(range.x) <= 0.0001f || Math.Abs(range.y) < 0.0001f)
return;
output.Clear();
for (int i = 0; i < candles.Count; i++)
{
CandleChartData.CandleValue candle = candles[i];
candle = InterpolateCandleInRect(NormalizeCandle(candle, min, range), viewRect);
output.Add(candle);
}
}
protected int ClipCandles(IList<CandleChartData.CandleValue> candles, List<CandleChartData.CandleValue> result)
{
result.Clear();
double minX, minY, maxX, maxY, xScroll, yScroll, xSize, ySize, xOut;
GetScrollParams(out minX, out minY, out maxX, out maxY, out xScroll, out yScroll, out xSize, out ySize, out xOut);
double direction = 1.0;
if (minX > maxX)
direction = -1.0;
bool prevOut = true;
int refrenceIndex = 0;
for (int i = 0; i < candles.Count; i++)
{
CandleChartData.CandleValue candle = candles[i];
double candleEnd = candle.Duration + candle.Start;
if (candleEnd* direction >= xScroll* direction && candle.Start* direction <= xOut* direction) // if the candle is within range
{
if (prevOut)
{
refrenceIndex = i;
prevOut = false;
}
result.Add(candle);
}
}
return refrenceIndex;
}
protected override void OnNonHoverted()
{
base.OnNonHoverted();
if (NonHovered != null)
NonHovered.Invoke();
}
protected override void OnItemSelected(object userData)
{
base.OnItemSelected(userData);
CandleEventArgs args = userData as CandleEventArgs;
if (CandleClicked != null)
CandleClicked.Invoke(args);
}
protected override void OnItemHoverted(object userData)
{
base.OnItemHoverted(userData);
CandleEventArgs args = userData as CandleEventArgs;
if (CandleHovered != null)
CandleHovered.Invoke(args);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8205d387a1db4a04c85ed37decb56caf
timeCreated: 1491152606
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,657 @@
#define Graph_And_Chart_PRO
using ChartAndGraph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
[Serializable]
public class CandleChartData : ScrollableChartData, IInternalCandleData
{
[Serializable]
public struct CandleValue
{
public CandleValue(double open, double high, double low, double close, DateTime start, TimeSpan duration)
{
Open = open;
High = high;
Low = low;
Close = close;
Start = ChartDateUtility.DateToValue(start);
Duration = ChartDateUtility.TimeSpanToValue(duration);
}
public CandleValue(double open, double high, double low, double close, double start, double duration)
{
Open = open;
High = high;
Low = low;
Close = close;
Start = start;
Duration = duration;
}
public double Open;
public double High;
public double Low;
public double Close;
public double Start;
public double Duration;
public bool isUp
{
get { return Close > Open; }
}
public double End
{
get { return Start + Duration; }
}
public DoubleVector2 MidPoint
{
get { return new DoubleVector2(Start + (Duration * 0.5), (Open + Close) * 0.5); }
}
public double Max
{
get
{
return Math.Max(Open, Close);
}
}
public double LowBound
{
get
{
return Math.Min(Math.Min(High, Low), Math.Min(Open, Close));
}
}
public double HighBound
{
get
{
return Math.Max(Math.Max(High, Low), Math.Max(Open, Close));
}
}
public double Min
{
get
{
return Math.Min(Open, Close);
}
}
}
[Serializable]
public class CandleSettings
{
public double LineThickness = 2.0;
public double CandleThicknessMultiplier = 1.0;
public double OutlineThickness = 0.0;
public ChartItemEffect CandleHoverPrefab;
public Material Outline;
public Material Line;
public Material Fill;
public GameObject CandlePrefab;
}
[Serializable]
public class CategoryData : BaseScrollableCategoryData
{
public List<CandleValue> Data = new List<CandleValue>();
public CandleSettings UpCandle = new CandleSettings();
public CandleSettings DownCandle = new CandleSettings();
public double Depth = 0f;
}
class CandleComparer : IComparer<CandleValue>
{
public int Compare(CandleValue x, CandleValue y)
{
if (x.Open < y.Open)
return -1;
if (x.Open > y.Open)
return 1;
return 0;
}
}
[Serializable]
class SerializedCategory
{
public string Name;
[HideInInspector]
public CandleValue[] Data;
[HideInInspector]
public double? MaxX, MaxY, MinX, MinY;
public CandleSettings UpCandle = new CandleSettings();
public CandleSettings DownCandle = new CandleSettings();
public double Depth = 0f;
}
CandleComparer mComparer = new CandleComparer();
[SerializeField]
SerializedCategory[] mSerializedData = new SerializedCategory[0];
event EventHandler IInternalCandleData.InternalViewPortionChanged
{
add
{
ViewPortionChanged += value;
}
remove
{
ViewPortionChanged -= value;
}
}
event EventHandler IInternalCandleData.InternalDataChanged
{
add
{
DataChanged += value;
}
remove
{
DataChanged -= value;
}
}
/// <summary>
/// rename a category. throws and exception on error
/// </summary>
/// <param name="prevName"></param>
/// <param name="newName"></param>
public void RenameCategory(string prevName, string newName)
{
if (prevName == newName)
return;
if (mData.ContainsKey(newName))
throw new ArgumentException(String.Format("A category named {0} already exists", newName));
CategoryData cat = (CategoryData)mData[prevName];
mData.Remove(prevName);
cat.Name = newName;
mData.Add(newName, cat);
RaiseDataChanged();
}
/// <summary>
/// Adds a new category to the candle chart.
/// </summary>
/// <param name="category"></param>
/// <param name="material"></param>
/// <param name="innerFill"></param>
public void AddCategory(string category, CandleSettings up, CandleSettings down, double depth)
{
AddCategory3DCandle(category, up, down, 0f);
}
/// <summary>
/// add category to the candle chart
/// </summary>
/// <param name="category"></param>
/// <param name="up"></param>
/// <param name="down"></param>
/// <param name="depth"></param>
public void AddCategory3DCandle(string category, CandleSettings up, CandleSettings down, double depth)
{
if (mData.ContainsKey(category))
throw new ArgumentException(String.Format("A category named {0} already exists", category));
CategoryData data = new CategoryData();
mData.Add(category, data);
data.Name = category;
data.DownCandle = down;
data.UpCandle = up;
data.Depth = depth;
RaiseDataChanged();
}
/// <summary>
/// removed a category from the DataSource. returnes true on success , or false if the category does not exist
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
public bool RemoveCategory(string category)
{
return mData.Remove(category);
}
public void SetDownCandle(string category, CandleSettings down)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return;
}
CategoryData data = (CategoryData)mData[category];
data.DownCandle = down;
RaiseDataChanged();
}
public void SetUpCandle(string category, CandleSettings up)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return;
}
CategoryData data = (CategoryData)mData[category];
data.UpCandle = up;
RaiseDataChanged();
}
/// <summary>
/// sets the depth for a 3d graph category
/// </summary>
/// <param name="category"></param>
/// <param name="depth"></param>
public void Set3DCategoryDepth(string category, double depth)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return;
}
if (depth < 0)
depth = 0f;
CategoryData data = (CategoryData)mData[category];
data.Depth = depth;
RaiseDataChanged();
}
/// <summary>
/// clears all the data for the selected category
/// </summary>
/// <param name="category"></param>
public void ClearCategory(string category)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return;
}
mData[category].MaxX = null;
mData[category].MaxY = null;
mData[category].MinX = null;
mData[category].MinY = null;
((CategoryData)mData[category]).Data.Clear();
RaiseDataChanged();
}
/// <summary>
/// gets the candle at the specified index for a given category
/// </summary>
/// <param name="category"></param>
/// <param name="index"></param>
/// <returns></returns>
public int GetCandleCount(string category)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return 0;
}
CategoryData data = (CategoryData)mData[category];
return data.Data.Count;
}
/// <summary>
/// gets the candle at the specified index for a given category
/// </summary>
/// <param name="category"></param>
/// <param name="index"></param>
/// <returns></returns>
public CandleValue GetCandle(string category, int index)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return new CandleValue();
}
CategoryData data = (CategoryData)mData[category];
return data.Data[index];
}
/// <summary>
/// returns the total amount of candles in the given category
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
public int GetTotalCandlesInCategory(string category)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return 0;
}
CategoryData data = (CategoryData)mData[category];
return data.Data.Count;
}
/// <summary>
/// use this to modify candles in realtime.
/// </summary>
/// <param name="category"></param>
/// <param name="candle"></param>
public void ModifyCandleInCategory(string category, int candleIndex, double open, double high, double low, double close)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return;
}
CategoryData data = (CategoryData)mData[category];
List<CandleValue> candles = data.Data;
if (candleIndex == -1)
candleIndex = data.Data.Count - 1;
if (candleIndex < 0 || candleIndex >= candles.Count)
{
Debug.LogWarning("Candle index is out of range, call is ignored");
return;
}
double candleMax = Math.Max(Math.Max(open, close), Math.Max(high, low));
double candleMin = Math.Min(Math.Min(open, close), Math.Min(high, low));
if (data.MaxY.HasValue == false || data.MaxY.Value < candleMax)
data.MaxY = candleMax;
if (data.MinY.HasValue == false || data.MinY.Value > candleMin)
data.MinY = candleMin;
CandleValue candle = data.Data[candleIndex];
candle.Open = open;
candle.Close = close;
candle.High = high;
candle.Low = low;
data.Data[candleIndex] = candle;
RaiseRealtimeDataChanged(candleIndex, category);
}
/// <summary>
/// removes a candle from a category
/// </summary>
/// <param name="category"></param>
/// <param name="index"></param>
public void RemoveCandleInCategory(string category, int candleIndex)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return;
}
CategoryData data = (CategoryData)mData[category];
List<CandleValue> candles = data.Data;
if (candleIndex < 0 || candleIndex >= candles.Count)
{
Debug.LogWarning("Candle index is out of range, call is ignored");
return;
}
data.Data.RemoveAt(candleIndex);
RaiseRealtimeDataChanged(candleIndex, category);
}
/// <summary>
/// use this to modify candles in realtime. this overload modifies the last candle and can be used for realtime candle data stream
/// </summary>
/// <param name="category"></param>
/// <param name="candle"></param>
public void ModifyLastCandleInCategory(string category, double open, double high, double low, double close)
{
ModifyCandleInCategory(category, -1, open, high, low, close);
}
class Slider : BaseSlider
{
public string category;
public double from;
public int index;
public double to;
public double current;
public double y;
private CandleChartData mParent;
public Slider(CandleChartData parent)
{
mParent = parent;
}
public override DoubleVector2 Max
{
get
{
return new DoubleVector2(current, y);
}
}
public override DoubleVector2 Min
{
get
{
return new DoubleVector2(current, y);
}
}
public override string Category { get { return category; } }
public override int MinIndex
{
get { return index; }
}
public override bool Update()
{
BaseScrollableCategoryData baseData;
if (mParent.mData.TryGetValue(category, out baseData) == false)
return true;
double time = Time.time;
time -= StartTime;
if (Duration <= 0.0001f)
time = 1f;
else
{
time /= Duration;
Math.Max(0.0, Math.Min(time, 1.0));
}
current = from * (1.0 - time) + to * time;
if (time >= 1f)
{
mParent.ModifyMinMax(baseData, new DoubleVector3(current, y, 0.0));
return true;
}
return false;
}
}
/// <summary>
/// adds a point to the category. The points are sorted by their x value automatically
/// </summary>
/// <param name="category"></param>
/// <param name="point"></param>
public void AddCandleToCategory(string category, CandleValue candle, float autoScrollSlideTime = 0f)
{
if (mData.ContainsKey(category) == false)
{
Debug.LogWarning("Invalid category name. Make sure the category is present in the chart");
return;
}
CategoryData data = (CategoryData)mData[category];
List<CandleValue> candles = data.Data;
double start = candle.Start;
double end = candle.Start + candle.Duration;
double candleMax = Math.Max(Math.Max(candle.Open, candle.Close), Math.Max(candle.High, candle.Low));
double candleMin = Math.Min(Math.Min(candle.Open, candle.Close), Math.Min(candle.High, candle.Low));
if (autoScrollSlideTime <= 0f)
{
if (data.MaxX.HasValue == false || data.MaxX.Value < end)
data.MaxX = end;
}
if (data.MinX.HasValue == false || data.MinX.Value > start)
data.MinX = start;
if (data.MaxY.HasValue == false || data.MaxY.Value < candleMax)
data.MaxY = candleMax;
if (data.MinY.HasValue == false || data.MinY.Value > candleMin)
data.MinY = candleMin;
if (candles.Count > 0)
{
if (candles[candles.Count - 1].Start < candle.Start)
{
if (autoScrollSlideTime > 0f)
{
Slider s = new Slider(this);
s.category = category;
s.from = candles[candles.Count - 1].End;
s.to = end;
s.StartTime = Time.time;
s.Duration = autoScrollSlideTime;
s.y = (candleMax + candleMin) * 0.5;
s.index = candles.Count - 1;
mSliders.Add(s);
}
candles.Add(candle);
RaiseRealtimeDataChanged(candles.Count-1, category);
return;
}
}
int search = candles.BinarySearch(candle, mComparer);
if (search < 0)
search = ~search;
candles.Insert(search, candle);
RaiseRealtimeDataChanged(search, category);
}
double IInternalCandleData.GetMaxValue(int axis, bool dataValue)
{
return GetMaxValue(axis, dataValue);
}
double IInternalCandleData.GetMinValue(int axis, bool dataValue)
{
return GetMinValue(axis, dataValue);
}
public override void OnAfterDeserialize()
{
if (mSerializedData == null)
return;
mData.Clear();
mSuspendEvents = true;
for (int i = 0; i < mSerializedData.Length; i++)
{
SerializedCategory cat = mSerializedData[i];
if (cat.Depth < 0)
cat.Depth = 0f;
string name = cat.Name;
AddCategory3DCandle(name, cat.UpCandle, cat.DownCandle, cat.Depth);
CategoryData data = (CategoryData)mData[name];
data.Data.AddRange(cat.Data);
data.MaxX = cat.MaxX;
data.MaxY = cat.MaxY;
data.MinX = cat.MinX;
data.MinY = cat.MinY;
}
mSuspendEvents = false;
}
public override void OnBeforeSerialize()
{
List<SerializedCategory> serialized = new List<SerializedCategory>();
foreach (KeyValuePair<string, CategoryData> pair in mData.Select(x => new KeyValuePair<string, CategoryData>(x.Key, (CategoryData)x.Value)))
{
SerializedCategory cat = new SerializedCategory();
cat.Name = pair.Key;
cat.MaxX = pair.Value.MaxX;
cat.MinX = pair.Value.MinX;
cat.MaxY = pair.Value.MaxY;
cat.MinY = pair.Value.MinY;
cat.UpCandle = pair.Value.UpCandle;
cat.DownCandle = pair.Value.DownCandle;
cat.Depth = pair.Value.Depth;
cat.Data = pair.Value.Data.ToArray();
if (cat.Depth < 0)
cat.Depth = 0f;
serialized.Add(cat);
}
mSerializedData = serialized.ToArray();
}
public override BaseScrollableCategoryData GetDefaultCategory()
{
throw new NotImplementedException();
}
protected override void InnerClearCategory(string category)
{
throw new NotImplementedException();
}
protected override void AppendDatum(string category, MixedSeriesGenericValue value)
{
throw new NotImplementedException();
}
protected override void AppendDatum(string category, IList<MixedSeriesGenericValue> value)
{
throw new NotImplementedException();
}
protected override bool AddCategory(string category, BaseScrollableCategoryData data)
{
throw new NotImplementedException();
}
int IInternalCandleData.TotalCategories
{
get { return mData.Count; }
}
event Action<int,string> IInternalCandleData.InternalRealTimeDataChanged
{
add
{
RealtimeDataChanged += value;
}
remove
{
RealtimeDataChanged -= value;
}
}
IEnumerable<CategoryData> IInternalCandleData.Categories
{
get
{
return mData.Values.Select(x => (CategoryData)x);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e8db3da49553a7d449f2082158192d56
timeCreated: 1491152608
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,138 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
class CanvasCandle : MonoBehaviour, ICandleCreator
{
List<CandleChartData.CandleValue> mEmptyCandle = new List<CandleChartData.CandleValue>();
HashSet<CanvasCandleGraphic> mOccupied = new HashSet<CanvasCandleGraphic>();
CanvasCandleGraphic mCandle, mLine;
CanvasCandleGraphic mOutline;
/// <summary>
/// The selected index is hovered about the specified point
/// </summary>
public event EventHandlingGraphic.GraphicEvent Hover;
/// <summary>
/// The selected index is clicked about the specified point
/// </summary>
public event EventHandlingGraphic.GraphicEvent Click;
/// <summary>
/// The currently hovered and selected objects are no longer selected or hovered.
/// </summary>
public event Action Leave;
private CanvasCandleGraphic CreateCandleGraphic()
{
GameObject obj = ChartCommon.CreateCanvasChartItem();
var rend = obj.AddComponent<CanvasRenderer>();
rend.cullTransparentMesh = false;
CanvasCandleGraphic graphic = obj.AddComponent<CanvasCandleGraphic>();
graphic.maskable = true;
RectTransform rect = obj.GetComponent<RectTransform>();
rect.SetParent(transform, false);
rect.anchoredPosition = Vector3.zero;
rect.localRotation = Quaternion.identity;
rect.localScale = new Vector3(1f, 1f, 1f);
HookEventsForGraphic(graphic);
return graphic;
}
void HookEventsForGraphic(CanvasCandleGraphic graphic)
{
graphic.Hover += (index, type, data, position) => { Candle_Hover(graphic, index, type, data, position); };
graphic.Click += (index, type, data, position) => { Candle_Click(graphic, index, type, data, position); }; ;
graphic.Leave += () => { Candle_Leave(graphic); };
}
public void Clear()
{
ChartCommon.SafeDestroy(mCandle);
ChartCommon.SafeDestroy(mLine);
ChartCommon.SafeDestroy(mOutline);
}
public void SetRefrenceIndex(int index)
{
if (mCandle != null)
mCandle.SetRefrenceIndex(index);
if (mLine != null)
mCandle.SetRefrenceIndex(index);
if (mOutline != null)
mOutline.SetRefrenceIndex(index);
}
public void Generate(CandleChart parent, Rect viewRect, IList<CandleChartData.CandleValue> value, CandleChartData.CandleSettings settings)
{
if (parent.IsCanvas == false)
{
Debug.LogWarning("prefab is meant to be used with canvas candle chart only");
return;
}
if (mCandle == null)
mCandle = CreateCandleGraphic();
if (settings.Fill == null || settings.CandleThicknessMultiplier < 0.0001f)
mCandle.SetCandle(0, mEmptyCandle, settings);
else
mCandle.SetCandle(0, value, settings);
mCandle.HoverTransform(transform);
mCandle.SetViewRect(viewRect, new Rect());
mCandle.SetHoverPrefab(settings.CandleHoverPrefab);
mCandle.material = settings.Fill;
if (mLine == null)
mLine = CreateCandleGraphic();
if (settings.Line == null || settings.LineThickness < 0.0001f)
mLine.SetCandle(1, mEmptyCandle, settings);
else
mLine.SetCandle(1, value, settings);
mLine.HoverTransform(transform);
mLine.SetHoverPrefab(settings.CandleHoverPrefab);
mLine.material = settings.Line;
mLine.SetViewRect(viewRect, new Rect());
if (mOutline == null)
mOutline = CreateCandleGraphic();
mOutline.material = settings.Outline;
mOutline.SetViewRect(viewRect, new Rect());
if (settings.Outline == null || settings.OutlineThickness < 0.0001f)
mOutline.SetCandle(2, mEmptyCandle, settings);
else
mOutline.SetCandle(2, value, settings);
}
private void Candle_Leave(CanvasCandleGraphic graphic)
{
if (mOccupied.Remove(graphic))
{
if (mOccupied.Count == 0)
{
if (Leave != null)
Leave();
}
}
}
private void Candle_Click(CanvasCandleGraphic graphic, int index, int type, object data, Vector2 position)
{
mOccupied.Add(graphic);
position = graphic.transform.TransformPoint(position);
if (Click != null)
Click(index, type, data, position);
}
private void Candle_Hover(CanvasCandleGraphic graphic, int index, int type, object data, Vector2 position)
{
mOccupied.Add(graphic);
position = graphic.transform.TransformPoint(position);
if (Hover != null)
Hover(index, type, data, position);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 663704866ea20c443b89affc7c7efb2f
timeCreated: 1491395378
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,548 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
class CanvasCandleChart : CandleChart
{
List<CandleChartData.CandleValue> mClipped = new List<CandleChartData.CandleValue>();
List<CandleChartData.CandleValue> mTransformed = new List<CandleChartData.CandleValue>();
List<CandleChartData.CandleValue> mCurrentSeries = new List<CandleChartData.CandleValue>();
int mTmpCurrentIndex = 0;
List<int> mUpToIndex = new List<int>();
List<int> mDownToIndex = new List<int>();
Dictionary<string, CategoryObject> mCategoryObjects = new Dictionary<string, CategoryObject>();
StringBuilder mRealtimeStringBuilder = new StringBuilder();
HashSet<string> mOccupiedCateogies = new HashSet<string>();
List<int> mTmpToRemove = new List<int>();
private bool SupressRealtimeGeneration = false;
[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 float TotalDepthLink
{
get
{
return 0f;
}
}
public override bool SupportRealtimeGeneration
{
get
{
return true;
}
}
public override bool IsCanvas
{
get
{
return true;
}
}
class CategoryObject
{
public CanvasChartMesh mItemLabels;
public CanvasCandle mUp;
public CanvasCandle mDown;
public Dictionary<int, string> mCahced = new Dictionary<int, string>();
public HashSet<CanvasCandle> mOccupiedCandles = new HashSet<CanvasCandle>();
private CanvasCandleChart mParent;
/// <summary>
/// The selected index is hovered about the specified point
/// </summary>
public event EventHandlingGraphic.GraphicEvent Hover;
/// <summary>
/// The selected index is clicked about the specified point
/// </summary>
public event EventHandlingGraphic.GraphicEvent Click;
/// <summary>
/// The currently hovered and selected objects are no longer selected or hovered.
/// </summary>
public event Action Leave;
public CategoryObject(CanvasCandleChart parent)
{
mParent = parent;
}
public void HookEvents()
{
HookEvents(mUp, true);
HookEvents(mDown, false);
}
void HookEvents(CanvasCandle candle, bool isUp)
{
if (candle == null)
return;
candle.Leave += () => mLeave(candle);
candle.Hover += (index, type, data, position) => { mHover(candle, mParent.MapIndex(index, isUp), type, data, position); };
candle.Click += (index, type, data, position) => { mClick(candle, mParent.MapIndex(index, isUp), type, data, position); };
}
private void mClick(CanvasCandle candle, int index, int type, object data, Vector2 position)
{
mOccupiedCandles.Add(candle);
if (Click != null)
Click(index, type, data, position);
}
private void mHover(CanvasCandle candle, int index, int type, object data, Vector2 position)
{
mOccupiedCandles.Add(candle);
if (Hover != null)
Hover(index, type, data, position);
}
private void mLeave(CanvasCandle candle)
{
if (mOccupiedCandles.Remove(candle))
{
if (mOccupiedCandles.Count == 0)
{
if (Leave != null)
Leave();
}
}
}
}
protected override bool ShouldFitCanvas { get { return true; } }
protected override FitType FitAspectCanvas
{
get
{
return FitType.Aspect;
}
}
private CanvasCandle CreateDataObject(CandleChartData.CategoryData data, GameObject rectMask)
{
GameObject obj = new GameObject("Candles", typeof(RectTransform));
ChartCommon.HideObject(obj, hideHierarchy);
obj.AddComponent<ChartItem>();
RectTransform t = obj.GetComponent<RectTransform>();
obj.AddComponent<CanvasRenderer>();
CanvasCandle candles = obj.AddComponent<CanvasCandle>();
t.SetParent(rectMask.transform, false);
t.localScale = new Vector3(1f, 1f, 1f);
t.anchorMin = new Vector2(0f, 0f);
t.anchorMax = new Vector2(1f, 1f);
t.sizeDelta = new Vector2(0f, 0f);
t.anchorMin = new Vector2(0f, 0f);
t.anchorMax = new Vector2(0f, 0f);
t.anchoredPosition = Vector3.zero;
return candles;
}
protected override double GetCategoryDepth(string category)
{
return 0.0;
}
public override void GenerateRealtime()
{
if (SupressRealtimeGeneration)
return;
base.GenerateRealtime();
double minX = ((IInternalCandleData)Data).GetMinValue(0, false);
double minY = ((IInternalCandleData)Data).GetMinValue(1, false);
double maxX = ((IInternalCandleData)Data).GetMaxValue(0, false);
double maxY = ((IInternalCandleData)Data).GetMaxValue(1, false);
double xScroll = GetScrollOffset(0);
double yScroll = GetScrollOffset(1);
double xSize = maxX - minX;
double ySize = maxY - minY;
double xOut = minX + xScroll + xSize;
double yOut = minY + yScroll + ySize;
DoubleVector3 min = new DoubleVector3(xScroll + minX, yScroll + minY);
DoubleVector3 max = new DoubleVector3(xOut, yOut);
Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio);
ClearBillboardCategories();
bool edit = false;
foreach (CandleChartData.CategoryData data in ((IInternalCandleData)Data).Categories)
{
CategoryObject obj = null;
if (mCategoryObjects.TryGetValue(data.Name, out obj) == false)
continue;
mClipped.Clear();
mTransformed.Clear();
int refrenceIndex = ClipCandles(data.Data, mClipped);
TransformCandles(mClipped, mTransformed, viewRect, min, max);
if (data.Data.Count == 0 && ChartCommon.IsInEditMode)
{
edit = true;
}
mTmpToRemove.Clear();
int range = refrenceIndex + mClipped.Count;
foreach (int key in obj.mCahced.Keys)
{
if (key < refrenceIndex || key > range)
mTmpToRemove.Add(key);
}
for (int i = 0; i < mTmpToRemove.Count; i++)
obj.mCahced.Remove(mTmpToRemove[i]);
obj.mCahced.Remove(data.Data.Count - 1); // never store the last point cache , it might be intepolating by the realtime feature
if (data.Data.Count == 0)
continue;
GenerateItemLabels(true, obj, data, viewRect, refrenceIndex, edit);
if (obj.mUp != null)
{
FillCurrentSeries(true, refrenceIndex);
obj.mUp.Generate(this, viewRect, mCurrentSeries, data.UpCandle);
}
if (obj.mDown != null)
{
FillCurrentSeries(false, refrenceIndex);
obj.mDown.Generate(this, viewRect, mCurrentSeries, data.DownCandle);
}
}
}
protected override void ClearChart()
{
base.ClearChart();
ClearBillboard();
mActiveTexts.Clear();
mCategoryObjects.Clear();
}
void GenerateItemLabels(bool realTime, CategoryObject categoryObj, CandleChartData.CategoryData data, Rect viewRect, int refrenceIndex, bool edit)
{
if (mItemLabels != null && mItemLabels.isActiveAndEnabled)
{
CanvasChartMesh m = null;
if (realTime)
{
m = categoryObj.mItemLabels;
if (m == null)
return;
m.Clear();
}
else
{
m = new CanvasChartMesh(true);
m.RecycleText = true;
categoryObj.mItemLabels = m;
}
Rect textRect = viewRect;
textRect.xMin -= 1f;
textRect.yMin -= 1f;
textRect.xMax += 1f;
textRect.yMax += 1f;
for (int i = 0; i < mTransformed.Count; i++)
{
Vector2 pointValue = mTransformed[i].MidPoint.ToVector2();
if (textRect.Contains(pointValue) == false)
continue;
CandleChartData.CandleValue candleVal = mTransformed[i];
int candleIndex = i + refrenceIndex;
if (edit == false)
candleVal = data.Data[i + refrenceIndex];
Vector3 labelPos = ((Vector3)pointValue) + new Vector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth);
if (mItemLabels.Alignment == ChartLabelAlignment.Base)
labelPos.y -= (float)mTransformed[i].MidPoint.y;
string toSet;
if (realTime == false || categoryObj.mCahced.TryGetValue(candleIndex, out toSet) == false)
{
string Open = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mVerticalAxis, false);
string Close = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Close, 0.0), mVerticalAxis, false);
string High = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.High, 0.0), mVerticalAxis, false);
string Low = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Low, 0.0), mVerticalAxis, false);
string Start = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mHorizontalAxis, true);
string Duration = StringFromAxisFormat(new DoubleVector3(candleVal.Duration, candleVal.Open, 0.0), mHorizontalAxis, true);
FormatItem(mRealtimeStringBuilder, Open, Close, High, Low, Start, Duration);
toSet = mItemLabels.TextFormat.Format(mRealtimeStringBuilder.ToString(), data.Name, "");
categoryObj.mCahced[candleIndex] = toSet;
}
labelPos -= new Vector3(CanvasFitOffset.x * TotalWidth, CanvasFitOffset.y * TotalHeight, 0f);
BillboardText billboard = m.AddText(this, mItemLabels.TextPrefab, transform, mItemLabels.FontSize, mItemLabels.FontSharpness, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null);
TextController.AddText(billboard);
AddBillboardText(data.Name, i + refrenceIndex, billboard);
}
if (realTime)
{
m.DestoryRecycled();
if (m.TextObjects != null)
{
foreach (BillboardText text in m.TextObjects)
{
((IInternalUse)this).InternalTextController.AddText(text);
}
}
}
}
}
bool UpPredicate(CandleChartData.CandleValue x)
{
if (x.isUp)
mUpToIndex.Add(mTmpCurrentIndex);
mTmpCurrentIndex++;
return x.isUp;
}
bool DownPredicate(CandleChartData.CandleValue x)
{
if (x.isUp == false)
mDownToIndex.Add(mTmpCurrentIndex);
mTmpCurrentIndex++;
return !x.isUp;
}
void FillCurrentSeries(bool isUp, int refrenceIndex)
{
mTmpCurrentIndex = refrenceIndex;
mCurrentSeries.Clear();
if (isUp)
{
mUpToIndex.Clear();
mCurrentSeries.AddRange(mTransformed.Where(UpPredicate));
}
else
{
mDownToIndex.Clear();
mCurrentSeries.AddRange(mTransformed.Where(DownPredicate));
}
}
int MapIndex(int index, bool isUp)
{
if (isUp)
{
if (mUpToIndex.Count <= index)
return index;
return mUpToIndex[index];
}
if (mDownToIndex.Count <= index)
return index;
return mDownToIndex[index];
}
public override void InternalGenerateChart()
{
if (gameObject.activeInHierarchy == false)
return;
base.InternalGenerateChart();
if (FitToContainer)
{
RectTransform trans = GetComponent<RectTransform>();
widthRatio = trans.rect.width;
heightRatio = trans.rect.height;
}
ClearChart();
if (Data == null)
return;
GenerateAxis(true);
double minX = ((IInternalCandleData)Data).GetMinValue(0, false);
double minY = ((IInternalCandleData)Data).GetMinValue(1, false);
double maxX = ((IInternalCandleData)Data).GetMaxValue(0, false);
double maxY = ((IInternalCandleData)Data).GetMaxValue(1, false);
double xScroll = GetScrollOffset(0);
double yScroll = GetScrollOffset(1);
double xSize = maxX - minX;
double ySize = maxY - minY;
double xOut = minX + xScroll + xSize;
double yOut = minY + yScroll + ySize;
DoubleVector3 min = new DoubleVector3(xScroll + minX, yScroll + minY);
DoubleVector3 max = new DoubleVector3(xOut, yOut);
Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio);
int total = ((IInternalCandleData)Data).TotalCategories + 1;
bool edit = false;
ClearBillboard();
mActiveTexts.Clear();
int index = 0;
GameObject mask = CreateRectMask(viewRect);
foreach (CandleChartData.CategoryData data in ((IInternalCandleData)Data).Categories)
{
mClipped.Clear();
mTransformed.Clear();
int refrenceIndex = ClipCandles(data.Data, mClipped);
TransformCandles(mClipped, mTransformed, viewRect, min, max);
if (data.Data.Count == 0 && ChartCommon.IsInEditMode)
{
int tmpIndex = total - 1 - index;
float low = (((float)tmpIndex) / (float)total);
float high = (((float)tmpIndex + 1) / (float)total);
float y1 = Mathf.Lerp(high, low, 0.6f);
float y2 = Mathf.Lerp(high, low, 0.3f);
mTransformed.Clear();
mTransformed.Add(InterpolateCandleInRect(new CandleChartData.CandleValue(y1, high, low, y2, 0.1, 0.1), viewRect));
mTransformed.Add(InterpolateCandleInRect(new CandleChartData.CandleValue(y1, low, high, y2, 0.5, 0.2), viewRect));
edit = true;
index++;
}
CategoryObject categoryObj = new CategoryObject(this);
CanvasCandle up = CreateDataObject(data, mask);
CanvasCandle down = CreateDataObject(data, mask);
FillCurrentSeries(true, refrenceIndex);
up.Generate(this, viewRect, mCurrentSeries, data.UpCandle);
FillCurrentSeries(false, refrenceIndex);
down.Generate(this, viewRect, mCurrentSeries, data.DownCandle);
string catName = data.Name;
categoryObj.mUp = up;
categoryObj.mDown = down;
categoryObj.HookEvents();
GenerateItemLabels(false, categoryObj, data, viewRect, refrenceIndex, edit);
categoryObj.Hover += (idx, t, d, pos) => { Category_Hover(catName, idx, t, d, pos); };
categoryObj.Click += (idx, t, d, pos) => { Category_Click(catName, idx, t, d, pos); };
categoryObj.Leave += () => { Category_Leave(catName); };
mCategoryObjects[catName] = categoryObj;
}
}
void Category_Hover(string category, int index, int type, object data, Vector2 position)
{
CandleChartData.CandleValue candle = Data.GetCandle(category, index);
Dictionary<int, BillboardText> catgoryTexts;
BillboardText b;
if (mTexts.TryGetValue(category, out catgoryTexts))
{
if (catgoryTexts.TryGetValue(index, out b))
SelectActiveText(b);
}
Rect selection = new Rect();
if (data != null && data is Rect)
selection = (Rect)data;
OnItemHoverted(new CandleEventArgs(index, type, selection, position, candle, category));
}
/// <summary>
/// handles click of the category
/// </summary>
/// <param name="category"></param>
/// <param name="index"></param>
/// <param name="type"></param>
/// <param name="data"></param>
/// <param name="position"></param>
void Category_Click(string category, int index, int type, object data, Vector2 position)
{
CandleChartData.CandleValue candle = Data.GetCandle(category, index);
Dictionary<int, BillboardText> catgoryTexts;
BillboardText b;
if (mTexts.TryGetValue(category, out catgoryTexts))
{
if (catgoryTexts.TryGetValue(index, out b))
SelectActiveText(b);
}
Rect selection = new Rect();
if (data != null && data is Rect)
selection = (Rect)data;
OnItemSelected(new CandleEventArgs(index, type, selection, position, candle, category));
}
void Category_Leave(string cat)
{
TriggerActiveTextsOut();
OnItemLeave(new CandleEventArgs(0, 0, new Rect(), new Vector3(), new CandleChartData.CandleValue(), cat),"none");
}
protected override void OnItemHoverted(object userData)
{
base.OnItemHoverted(userData);
var args = userData as CandleEventArgs;
mOccupiedCateogies.Add(args.Category);
}
protected override void OnItemSelected(object userData)
{
base.OnItemSelected(userData);
var args = userData as CandleEventArgs;
mOccupiedCateogies.Add(args.Category);
}
protected override void OnItemLeave(object userData,string type)
{
//base.OnItemLeave(userData);
CandleEventArgs args = userData as CandleEventArgs;
if (args == null)
return;
string category = args.Category;
mOccupiedCateogies.Remove(category);
mOccupiedCateogies.RemoveWhere(x => !Data.HasCategory(x));
if (mOccupiedCateogies.Count == 0)
{
if (NonHovered != null)
NonHovered.Invoke();
}
}
internal override void SetAsMixedSeries()
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 25a10981261111f4bbc2ed5f2cd476f7
timeCreated: 1501868716
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,514 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
namespace ChartAndGraph
{
class CanvasCandleGraphic : EventHandlingGraphic
{
CandleChartData.CandleSettings mCandleSettings;
List<CandleChartData.CandleValue> mCandles = new List<CandleChartData.CandleValue>();
int mPart;
UIVertex[] mTmpVerts = new UIVertex[4];
Vector2 mMin, mMax;
protected override Vector2 Min
{
get
{
return mMin;
}
}
protected override Vector2 Max
{
get
{
return mMax;
}
}
protected Rect RectFromIndex(int index, int type, Rect Default)
{
if (index >= mCandles.Count)
return Default;
CandleChartData.CandleValue candle = mCandles[index];
float max = (float)candle.Max;
float min = (float)candle.Min;
float start = (float)candle.Start;
float end = (float)(candle.Start + candle.Duration);
float mid = (start + end) * 0.5f;
if (type == 0)
return ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, max, (float)candle.High);
if (type == 2)
return ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, (float)candle.Low, min);
return ChartCommon.RectFromCenter(mid, (float)(mCandleSettings.CandleThicknessMultiplier * candle.Duration), min, max);
}
protected override void SetUpHoverObject(ChartItemEffect hover, int index, int type, object selectionData)
{
Rect selectionRect = (Rect)selectionData;
selectionRect = RectFromIndex(index, type, selectionRect);
hover.ItemData = selectionRect;
SetupHoverObjectToRect(hover, index, type, selectionRect);
}
protected void PickLine(Vector3 mouse, out int pickedIndex, out int pickedType, out object selectionData)
{
pickedIndex = -1;
pickedType = -1;
selectionData = null;
for (int i = 0; i < mCandles.Count; i++)
{
CandleChartData.CandleValue candle = mCandles[i];
float max = (float)candle.Max;
float min = (float)candle.Min;
float start = (float)candle.Start;
float end = (float)(candle.Start + candle.Duration);
float mid = (start + end) * 0.5f;
Rect high = ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, max, (float)candle.High);
Rect low = ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, (float)candle.Low, min);
if (high.Contains(mouse))
{
selectionData = high;
pickedType = 0;
pickedIndex = i;
return;
}
if (low.Contains(mouse))
{
selectionData = low;
pickedType = 2;
pickedIndex = i;
return;
}
}
}
protected void PickBody(Vector3 mouse, out int pickedIndex, out int pickedType, out object selectionData)
{
pickedIndex = -1;
pickedType = -1;
selectionData = null;
for (int i = 0; i < mCandles.Count; i++)
{
CandleChartData.CandleValue candle = mCandles[i];
float max = (float)candle.Max;
float min = (float)candle.Min;
float start = (float)candle.Start;
float end = (float)(candle.Start + candle.Duration);
float mid = (start + end) * 0.5f;
Rect Body = ChartCommon.RectFromCenter(mid, (float)(mCandleSettings.CandleThicknessMultiplier * candle.Duration), min, max);
if (Body.Contains(mouse))
{
selectionData = Body;
pickedType = 1;
pickedIndex = i;
return;
}
}
}
protected override void Pick(Vector3 mouse, out int pickedIndex, out int pickedType, out object selectionData)
{
if (mPart == 0)
PickBody(mouse, out pickedIndex, out pickedType, out selectionData);
else
PickLine(mouse, out pickedIndex, out pickedType, out selectionData);
if (pickedIndex >= 0)
pickedIndex += refrenceIndex;
}
protected override float MouseInThreshold
{
get
{
return Sensitivity;
}
}
public void ClearCandles()
{
mCandles = null;
SetAllDirty();
Rebuild(CanvasUpdate.PreRender);
}
public void SetCandle(int part, IList<CandleChartData.CandleValue> candles, CandleChartData.CandleSettings settings)
{
mPart = part;
mCandles.Clear();
mCandles.AddRange(candles);
mCandleSettings = settings;
double minX = double.PositiveInfinity;
double minY = double.PositiveInfinity;
double maxX = double.NegativeInfinity;
double maxY = double.NegativeInfinity;
for (int i = 0; i < mCandles.Count; i++)
{
var candle = mCandles[i];
minY = Math.Min(candle.LowBound, minY);
maxY = Math.Max(candle.HighBound, maxY);
minX = Math.Min(minX, candle.Start);
maxX = Math.Max(maxX, candle.Start + candle.Duration);
}
mMin = new Vector2((float)minX, (float)minY);
mMax = new Vector2((float)maxX, (float)maxY);
SetAllDirty();
Rebuild(CanvasUpdate.PreRender);
SetUpAllHoverObjects();
}
IEnumerable<UIVertex> getOutline()
{
UIVertex v = new UIVertex();
if (mCandles == null)
yield break;
float outlineThickness = (float)mCandleSettings.OutlineThickness * 0.5f;
for (int i = 0; i < mCandles.Count; i++)
{
CandleChartData.CandleValue candle = mCandles[i];
float max = (float)Math.Max(candle.Open, candle.Close);
float min = (float)Math.Min(candle.Open, candle.Close);
float start = (float)candle.Start;
float end = (float)(candle.Start + candle.Duration);
float mid = (start + end) * 0.5f;
float thickness = (float)(mCandleSettings.CandleThicknessMultiplier * candle.Duration * 0.5);
if (min == max)
{
min -= 2f;
max += 2f;
}
//long and dirty part the defines all the verices of the candle outline
//outline of the body
v.position = new Vector3(mid - thickness - outlineThickness, max, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid - thickness + outlineThickness, max, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - thickness - outlineThickness, min, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid - thickness + outlineThickness, min, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the body
v.position = new Vector3(mid + thickness - outlineThickness, max, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + thickness + outlineThickness, max, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid + thickness - outlineThickness, min, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid + thickness + outlineThickness, min, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the high line
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.High, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.High, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, max, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, max, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the high line
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.High, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.High, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, max, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, max, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the low line
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, min, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, min, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.Low, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.Low, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the low line
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, min, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, min, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.Low, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.Low, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the low line connection with body
v.position = new Vector3(mid - thickness - outlineThickness, min + outlineThickness, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, min + outlineThickness, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - thickness - outlineThickness, min - outlineThickness, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, min - outlineThickness, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the low line connection with body
v.position = new Vector3(mid + thickness + outlineThickness, min + outlineThickness, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, min + outlineThickness, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid + thickness + outlineThickness, min - outlineThickness, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, min - outlineThickness, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the high line connection with body
v.position = new Vector3(mid - thickness - outlineThickness, max - outlineThickness, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, max - outlineThickness, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - thickness - outlineThickness, max + outlineThickness, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, max + outlineThickness, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
//outline of the high line connection with body
v.position = new Vector3(mid + thickness + outlineThickness, max - outlineThickness, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, max - outlineThickness, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid + thickness + outlineThickness, max + outlineThickness, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, max + outlineThickness, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
}
}
IEnumerable<UIVertex> getCandle()
{
UIVertex v = new UIVertex();
if (mCandles == null)
yield break;
for (int i = 0; i < mCandles.Count; i++)
{
CandleChartData.CandleValue candle = mCandles[i];
float max = (float)Math.Max(candle.Open, candle.Close);
float min = (float)Math.Min(candle.Open, candle.Close);
float start = (float)candle.Start;
float end = (float)(candle.Start + candle.Duration);
float mid = (start + end) * 0.5f;
float thickness = (float)(mCandleSettings.CandleThicknessMultiplier * candle.Duration * 0.5);
if (min == max)
{
min -= 2f;
max += 2f;
}
v.position = new Vector3(mid - thickness, max, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + thickness, max, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - thickness, min, 0f);
v.uv0 = new Vector2(-0f, 1f);
yield return v;
v.position = new Vector3(mid + thickness, min, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
}
}
IEnumerable<UIVertex> getLine()
{
UIVertex v = new UIVertex();
if (mCandles == null)
yield break;
for (int i = 0; i < mCandles.Count; i++)
{
CandleChartData.CandleValue candle = mCandles[i];
float max = (float)Math.Max(candle.Open, candle.Close);
float min = (float)Math.Min(candle.Open, candle.Close);
float start = (float)candle.Start;
float end = (float)(candle.Start + candle.Duration);
float mid = (start + end) * 0.5f;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, (float)candle.High, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, (float)candle.High, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, max, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, max, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, min, 0f);
v.uv0 = new Vector2(0f, 0f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, min, 0f);
v.uv0 = new Vector2(1f, 0f);
yield return v;
v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, (float)candle.Low, 0f);
v.uv0 = new Vector2(0f, 1f);
yield return v;
v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, (float)candle.Low, 0f);
v.uv0 = new Vector2(1f, 1f);
yield return v;
}
}
IEnumerable<UIVertex> getVerices()
{
if (mCandles == null)
return new UIVertex[0];
if (mPart == 0)
return getCandle();
else if (mPart == 1)
return getLine();
return getOutline();
}
#if (!UNITY_5_2_0) && (!UNITY_5_2_1)
protected override void OnPopulateMesh(VertexHelper vh)
{
base.OnPopulateMesh(vh);
vh.Clear();
int vPos = 0;
foreach (UIVertex v in getVerices())
{
mTmpVerts[vPos++] = v;
if (vPos == 4)
{
UIVertex tmp = mTmpVerts[2];
mTmpVerts[2] = mTmpVerts[3];
mTmpVerts[3] = tmp;
vPos = 0;
vh.AddUIVertexQuad(mTmpVerts);
}
}
}
#endif
#pragma warning disable 0672
#if !UNITY_2017_1_OR_NEWER
protected override void OnPopulateMesh(Mesh m)
{
WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1);
int vPos = 0;
foreach (UIVertex v in getVerices())
{
mTmpVerts[vPos++] = v;
if (vPos == 4)
{
vPos = 0;
mesh.AddQuad(mTmpVerts[0], mTmpVerts[1], mTmpVerts[2], mTmpVerts[3]);
}
}
mesh.ApplyToMesh(m);
}
#endif
#pragma warning restore 0672
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 05af876f1131be94d999a98f574aa820
timeCreated: 1491155958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ChartAndGraph
{
interface ICandleCreator
{
void Generate(CandleChart parent, Rect viewRect, IList<CandleChartData.CandleValue> value, CandleChartData.CandleSettings settings);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dc37318de0ced4249a4f86d43c9799cc
timeCreated: 1491395378
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
#define Graph_And_Chart_PRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ChartAndGraph
{
interface IInternalCandleData
{
/// <summary>
///
/// </summary>
/// <param name="axis">0 for horizontal 1 for vertical</param>
/// <returns></returns>
double GetMinValue(int axis, bool dataValue);
double GetMaxValue(int axis, bool dataValue);
void OnBeforeSerialize();
void OnAfterDeserialize();
event EventHandler InternalDataChanged;
event EventHandler InternalViewPortionChanged;
event Action<int,string> InternalRealTimeDataChanged;
int TotalCategories { get; }
IEnumerable<CandleChartData.CategoryData> Categories { get; }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: aebb79a10b5864b48b9f8b096c53d48a
timeCreated: 1501601469
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,101 @@
#define Graph_And_Chart_PRO
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using UnityEngine;
//namespace ChartAndGraph
//{
// class WorldSpaceCandle : MonoBehaviour, ICandleCreator
// {
// public GameObject Prefab = null;
// GameObjectPool<ChartItem> mPooledCandles = new GameObjectPool<ChartItem>();
// List<ChartItem> mCandles = new List<ChartItem>();
// class CandleObject
// {
// public GameObject upper;
// public GameObject lower;
// public GameObject body;
// }
// GameObject CreatePrefab(Transform parent,float centerX, float fromY, float width, float toY)
// {
// GameObject obj = GameObject.Instantiate(Prefab);
// ChartCommon.EnsureComponent<ChartItem>(obj);
// obj.transform.SetParent((parent == null) ? transform : parent, true);
// float centerY = (fromY + toY) * 0.5f;
// float height = Mathf.Abs(fromY - toY);
// obj.transform.position = new Vector3(centerX, centerY, 0f);
// obj.transform.rotation = Quaternion.identity;
// obj.transform.localScale = new Vector3(width * 2f, height, 1f);
// return obj;
// }
// ChartItem CreateCandle(CandleChartData.CandleValue candle, CandleChartData.CandleSettings settings)
// {
// float max = (float)candle.Max;
// float min = (float)candle.Min;
// float midX = (float)(candle.Start + (candle.Duration * 0.5));
// // float midY = (max + min) * 0.5f;
// GameObject candleGameobj = ChartCommon.CreateChartItem();
// candleGameobj.transform.SetParent(transform);
// candleGameobj.transform.position = new Vector3(midX, 0f, 0f);
// CandleObject candleObj = new CandleObject();
// candleObj.upper = CreatePrefab(candleGameobj.transform,0f, (float)candle.High, (float)settings.LineThickness, max);
// candleObj.lower = CreatePrefab(candleGameobj.transform,0f, (float)candle.Low, (float)settings.LineThickness, min);
// candleObj.body = CreatePrefab(candleGameobj.transform,0f, min, (float)settings.CandleThicknessMultiplier, max);
// SetMaterial(candleObj.upper, settings.Line);
// SetMaterial(candleObj.lower, settings.Line);
// SetMaterial(candleObj.body, settings.Fill);
// ChartItem t = candleGameobj.GetComponent<ChartItem>();
// t.TagData = candleObj;
// return t;
// }
// void ClearCandles()
// {
// for(int i=0; i<mCandles.Count; i++)
// {
// if (mCandles[i] != null)
// {
// ChartCommon.SafeDestroy(mCandles[i].gameObject);
// }
// }
// mCandles.Clear();
// mPooledCandles.DestoryAll();
// }
// void SetMaterial(GameObject obj, Material mat)
// {
// Renderer rend = obj.GetComponent<Renderer>();
// if (rend != null)
// rend.material = mat;
// }
// public void Generate(CandleChart parent,Rect viewRect, IList<CandleChartData.CandleValue> value, CandleChartData.CandleSettings settings)
// {
// if ((parent is ICanvas))
// {
// Debug.LogWarning("prefab is meant not meant to be used with canvas candle chart");
// return;
// }
// ClearCandles();
// for (int i=0; i<value.Count; i++)
// {
// ChartItem candle = CreateCandle(value[i], settings);
// mCandles.Add(candle);
// }
// }
// }
//}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 595feb9c9d841b044b53baa40a298e08
timeCreated: 1491403646
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: