mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 01:10:08 +00:00
增加PolarChart极坐标图表
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
/******************************************/
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -165,7 +166,7 @@ namespace XCharts
|
||||
/// </summary>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom)
|
||||
internal static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
|
||||
{
|
||||
if (axis.type == Axis.AxisType.Value || axis.type == Axis.AxisType.Log)
|
||||
{
|
||||
@@ -190,7 +191,7 @@ namespace XCharts
|
||||
/// <param name="coordinateWidth"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
/// <returns></returns>
|
||||
internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom)
|
||||
internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null)
|
||||
{
|
||||
int num = GetScaleNumber(axis, coordinateWidth, dataZoom) - 1;
|
||||
if (num <= 0) num = 1;
|
||||
@@ -285,5 +286,49 @@ namespace XCharts
|
||||
else if (axis.IsValue() && axis.runtimeMinValue == 0 && axis.runtimeMaxValue == 0) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
internal static void AdjustCircleLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
{
|
||||
var txtWidth = txt.preferredWidth;
|
||||
var sizeDelta = new Vector2(txtWidth, txt.preferredHeight);
|
||||
txt.GetComponent<RectTransform>().sizeDelta = sizeDelta;
|
||||
var diff = pos.x - cenPos.x;
|
||||
if (diff < -1f) //left
|
||||
{
|
||||
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
|
||||
}
|
||||
else if (diff > 1f) //right
|
||||
{
|
||||
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x, y);
|
||||
}
|
||||
txt.transform.localPosition = pos + offset;
|
||||
}
|
||||
|
||||
internal static void AdjustRadiusAxisLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
|
||||
{
|
||||
var txtWidth = txt.preferredWidth;
|
||||
var sizeDelta = new Vector2(txtWidth, txt.preferredHeight);
|
||||
txt.GetComponent<RectTransform>().sizeDelta = sizeDelta;
|
||||
var diff = pos.y - cenPos.y;
|
||||
if (diff > 20f) //left
|
||||
{
|
||||
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
|
||||
}
|
||||
else if (diff < -20f) //right
|
||||
{
|
||||
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
|
||||
pos = new Vector3(pos.x, y);
|
||||
}
|
||||
txt.transform.localPosition = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Runtime/Internal/Helper/PolarHelper.cs
Normal file
34
Runtime/Internal/Helper/PolarHelper.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class PolarHelper
|
||||
{
|
||||
internal static void UpdatePolarCenter(Polar polar, Vector3 chartPosition, float chartWidth, float chartHeight)
|
||||
{
|
||||
if (polar.center.Length < 2) return;
|
||||
var centerX = polar.center[0] <= 1 ? chartWidth * polar.center[0] : polar.center[0];
|
||||
var centerY = polar.center[1] <= 1 ? chartHeight * polar.center[1] : polar.center[1];
|
||||
polar.runtimeCenterPos = chartPosition + new Vector3(centerX, centerY);
|
||||
if (polar.radius <= 0)
|
||||
{
|
||||
polar.runtimeRadius = 0;
|
||||
}
|
||||
else if (polar.radius <= 1)
|
||||
{
|
||||
polar.runtimeRadius = Mathf.Min(chartWidth, chartHeight) * polar.radius;
|
||||
}
|
||||
else
|
||||
{
|
||||
polar.runtimeRadius = polar.radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Helper/PolarHelper.cs.meta
Normal file
11
Runtime/Internal/Helper/PolarHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64e494d13836f430ea7f4fe3e2a716b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -286,8 +286,16 @@ namespace XCharts
|
||||
if (value < min) min = value;
|
||||
}
|
||||
}
|
||||
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
|
||||
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
|
||||
if (ceilRate < 0)
|
||||
{
|
||||
serie.runtimeDataMin = min;
|
||||
serie.runtimeDataMax = max;
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
|
||||
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetAllMinMaxData(Serie serie, int ceilRate = 0, DataZoom dataZoom = null)
|
||||
|
||||
@@ -181,6 +181,48 @@ namespace XCharts
|
||||
tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
|
||||
public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tooltip.formatter))
|
||||
{
|
||||
var sb = ChartHelper.sb;
|
||||
sb.Length = 0;
|
||||
sb.Append(tooltip.runtimeAngle).Append("\n");
|
||||
foreach (var serie in series.list)
|
||||
{
|
||||
if (serie.show && IsSelectedSerie(tooltip, serie.index))
|
||||
{
|
||||
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
|
||||
for (int i = 0; i < dataIndexList.Count; i++)
|
||||
{
|
||||
var dataIndex = dataIndexList[i];
|
||||
var serieData = serie.GetSerieData(dataIndex);
|
||||
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
|
||||
float xValue, yValue;
|
||||
serie.GetXYData(dataIndex, null, out xValue, out yValue);
|
||||
|
||||
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
|
||||
if (!string.IsNullOrEmpty(serie.name))
|
||||
sb.Append(serie.name).Append(": ");
|
||||
sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
|
||||
if (i != dataIndexList.Count - 1)
|
||||
{
|
||||
sb.Append("\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n");
|
||||
}
|
||||
}
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
string content = tooltip.formatter;
|
||||
FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, themeInfo, null, null);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
|
||||
string category = null, DataZoom dataZoom = null, bool isCartesian = false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user