示例#1
0
    public AxisMap GetNextUnusedAxisMap(AxisMap currentAxisMap)
    {
        int currentAxisMapIndex = axisMaps.IndexOf(currentAxisMap);

        if (currentAxisMapIndex != -1)
        {
            int axisMapIndexToCheck = currentAxisMapIndex;

            axisMapIndexToCheck = currentAxisMapIndex == axisMaps.Count - 1 ? 0 : axisMapIndexToCheck + 1;
            while (axisMapIndexToCheck != currentAxisMapIndex)
            {
                AxisMap axisMapToCheck = axisMaps [axisMapIndexToCheck];
                if (!axisMapToCheck.isInUse)
                {
                    currentAxisMap.isInUse = false;
                    axisMapToCheck.isInUse = true;
                    return(axisMapToCheck);
                }
                else
                {
                    axisMapIndexToCheck++;
                }
            }
        }

        return(currentAxisMap);
    }
示例#2
0
        private IEnumerable <AxisGridLine> CreateAlphaGridLines(AxisMap map, List <string> values, double lower, double upper)
        {
            var lowerString = map.SortOrder == SortOrder.Ascending
                ? (string)map.MapInverse(lower)
                : (string)map.MapInverse(upper);

            var upperString = map.SortOrder == SortOrder.Ascending
                ? (string)map.MapInverse(upper)
                : (string)map.MapInverse(lower);

            var lowerChar = IsFirstCharacterValid(lowerString)
                ? lowerString[0]
                : StartChar;

            var upperChar = IsFirstCharacterValid(upperString)
                ? upperString[0]
                : EndChar;

            for (var c = lowerChar; c <= upperChar; c++)
            {
                var first = values.Where(p => p != string.Empty)
                            .FirstOrDefault(p => p[0].ToString().ToUpper() == c.ToString().ToUpper());

                if (first != null)
                {
                    yield return(CreateAxisGridLine(map.Map(first).GetValueOrDefault(), c.ToString().ToUpper()));
                }
            }
        }
示例#3
0
        public IEnumerable <AxisGridLine> Create(Type type, AxisMap map, IEnumerable <object> values, double lower, double upper)
        {
            if (type == typeof(Boolean))
            {
                return(_booleanFactory.Create(map, lower, upper));
            }

            if (type == typeof(DateTime))
            {
                return(_dateTimeFactory.Create(map, lower, upper));
            }

            if (type == typeof(Double))
            {
                return(_floatFactory.Create(map, lower, upper));
            }

            if (type == typeof(Int32))
            {
                return(_integerFactory.Create(map, lower, upper));
            }

            if (type == typeof(String))
            {
                return(_stringFactory.Create(map, values.ToList(), lower, upper));
            }

            return(new List <AxisGridLine>());
        }
示例#4
0
        public void LoadFrom(XmlNode xn)
        {
            MappedType = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["type"].Value, true);
            Source     = (SourceType)Enum.Parse(typeof(SourceType), xn.Attributes["source"].Value, true);
            UUID       = xn.Attributes["uuid"] != null?Guid.Parse(xn.Attributes["uuid"].Value) : Guid.NewGuid();

            if (Source == SourceType.RawInput)
            {
                VendorID    = int.Parse(xn.Attributes["vid"].Value, NumberStyles.HexNumber);
                ProductID   = int.Parse(xn.Attributes["pid"].Value, NumberStyles.HexNumber);
                ReportHash  = uint.Parse(xn.Attributes["rpt_hash"].Value);
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.XInput)
            {
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.MUNIA)
            {
                DevicePath = xn.Attributes["devicepath"].Value;
            }
            else if (Source == SourceType.Arduino)
            {
                string port = xn.Attributes["arduino_port"].Value;
                ArduinoPort = SerialPortInfo.GetPorts().FirstOrDefault(spi => spi.Name == port) ?? new SerialPortInfo {
                    Name = port
                };
                ArduinoSource = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["arduino_type"].Value, true);
            }

            foreach (XmlNode n in xn["buttons"].ChildNodes)
            {
                var btn = new ButtonMap();
                btn.LoadFrom(n);
                ButtonMaps.Add(btn);
            }

            foreach (XmlNode n in xn["axes"].ChildNodes)
            {
                var axis = new AxisMap();
                axis.LoadFrom(n);
                AxisMaps.Add(axis);
            }

            foreach (XmlNode n in xn["buttons_to_axis"].ChildNodes)
            {
                var button = new ButtonToAxisMap();
                button.LoadFrom(n);
                ButtonToAxisMaps.Add(button);
            }

            foreach (XmlNode n in xn["axis_to_buttons"].ChildNodes)
            {
                var axis = new AxisToButtonMap();
                axis.LoadFrom(n);
                AxisToButtonMaps.Add(axis);
            }
        }
        private AxisGridLine CreateAxisGridLine(AxisMap map, double value)
        {
            var line = new AxisGridLine()
            {
                Position  = GetPosition(map, value),
                LabelName = GetLabelName(value)
            };

            return(line);
        }
示例#6
0
        public IEnumerable <AxisGridLine> CreateFourHours(AxisMap map, DateTime lower, DateTime upper)
        {
            var startTime = lower.Date;

            var endTime = upper;

            for (var date = startTime; date <= endTime; date = date.AddHours(4))
            {
                yield return(CreateAxisGridLine(map, date));
            }
        }
        public IEnumerable <AxisGridLine> CreateQuarters(AxisMap map, DateTime lower, DateTime upper)
        {
            var startDate = GetFirstDayOfQuarter(lower);

            var endDate = GetFirstDayOfQuarter(upper).AddMonths(4);

            for (var date = startDate; date <= endDate; date = date.AddMonths(3))
            {
                yield return(CreateAxisGridLine(map, date));
            }
        }
        public IEnumerable <AxisGridLine> CreateDays(AxisMap map, DateTime lower, DateTime upper)
        {
            var startDate = new DateTime(lower.Year, lower.Month, lower.Day);

            var endDate = new DateTime(upper.Year, upper.Month, upper.Day);//.AddDays(1);

            for (var date = startDate; date <= endDate; date = date.AddDays(1))
            {
                yield return(CreateAxisGridLine(map, date));
            }
        }
        public IEnumerable <AxisGridLine> CreateWeeks(AxisMap map, DateTime lower, DateTime upper)
        {
            var startDate = GetFirstDayOfWeek(lower).Date;

            var endDate = GetFirstDayOfWeek(upper).AddDays(7).Date;

            for (var date = startDate; date <= endDate; date = date.AddDays(7))
            {
                yield return(CreateAxisGridLine(map, date));
            }
        }
示例#10
0
        public IEnumerable <AxisGridLine> Create(AxisMap map, List <object> values, double lower, double upper)
        {
            var count = values
                        .Select(map.Map)
                        .Count(p => p >= lower &&
                               p <= upper);

            return((count <= AlphaGroupMin)
                ? CreateValueGridLines(map, values, lower, upper)
                : CreateAlphaGridLines(map, values.Cast <string>().ToList(), lower, upper));
        }
        private static AxisGridLine CreateAxisLine(AxisMap map, bool value)
        {
            var location = map.Map(value);

            var line = new AxisGridLine()
            {
                LabelName = value.ToString(),
                Position  = location ?? 0d
            };

            return(line);
        }
示例#12
0
        // TODO: This is duplicated across multiple classes... must refactor
        private AxisGridLine CreateAxisGridLine(AxisMap map, DateTime value, string label)
        {
            var position = map.Map(value);

            var line = new AxisGridLine()
            {
                LabelName = label,
                Position  = position.GetValueOrDefault()
            };

            return(line);
        }
示例#13
0
        // TODO: This is duplicated across multiple classes... must refactor
        private static AxisGridLine CreateAxisGridLine(AxisMap map, DateTime value)
        {
            var position = map.Map(value);

            var line = new AxisGridLine()
            {
                LabelName = value.ToLongTimeString(),
                Position  = position.GetValueOrDefault()
            };

            return(line);
        }
示例#14
0
        // Creates one axismap per column in the data set.
        private void CreateAxisMaps()
        {
            _axisMaps = new List <AxisMap>();

            for (int i = 0; i < _input.GetData().GetAxisLength(Axis.X); i++)
            {
                AxisMap axisMap = new AxisMap();
                axisMap.Input = _input;
                axisMap.Index = i;
                axisMap.DoMapping();
                _axisMaps.Add(axisMap);
            }
        }
示例#15
0
        public IEnumerable <AxisGridLine> CreateTenSeconds(AxisMap map, DateTime lower, DateTime upper)
        {
            var startTime = lower.Date
                            .AddHours(lower.Hour)
                            .AddMinutes(lower.Minute);

            var endTime = upper;

            for (var date = startTime; date <= endTime; date = date.AddSeconds(10))
            {
                yield return(CreateAxisGridLine(map, date));
            }
        }
        public IEnumerable <AxisGridLine> Create(AxisMap map, DateTime lower, DateTime upper, int step)
        {
            var startYear = GetFirstYearOfGroup(lower, step);

            var endYear = GetFirstYearOfGroup(upper, step);

            if (step == 1000)
            {
                endYear += 1000;
            }

            for (var year = startYear; year <= endYear; year += step)
            {
                yield return(CreateAxisGridLine(map, GetDateFromYear(year)));
            }
        }
        public IEnumerable <AxisGridLine> Create(AxisMap map, double lower, double upper)
        {
            var lowerFloat = map.SortOrder == SortOrder.Ascending
                ? (double)map.MapInverse(lower) / 2
                : (double)map.MapInverse(upper) / 2;

            var upperFloat = map.SortOrder == SortOrder.Ascending
                ? (double)map.MapInverse(upper) / 2
                : (double)map.MapInverse(lower) / 2;

            if (lowerFloat <= double.MinValue / 2)
            {
                yield return(CreateAxisGridLine(map, double.MinValue));
            }

            if (upperFloat >= double.MaxValue / 2)
            {
                yield return(CreateAxisGridLine(map, double.MaxValue));
            }

            var width = (double)upperFloat - lowerFloat;
            var step  = 0d;
            var start = double.MinValue;

            for (var i = 0.0000000001; i < double.MaxValue; i *= 10)
            {
                double i2 = i / 2;

                if (width >= i2 && width < i2 * 20)
                {
                    step  = i2;
                    start = lowerFloat - (lowerFloat % i2);
                    break;
                }
            }

            if (step == 0d)
            {
                yield break;
            }

            for (var i = start; i <= upperFloat; i += step)
            {
                yield return(CreateAxisGridLine(map, i * 2));
            }
        }
示例#18
0
        private IEnumerable <AxisGridLine> CreateValueGridLines(AxisMap map, List <object> values, double lower, double upper)
        {
            if (map.SortOrder == SortOrder.Descending)
            {
                values.Reverse();
            }

            foreach (var value in values)
            {
                var location = map.Map(value).GetValueOrDefault();

                if (location >= lower && location <= upper)
                {
                    yield return(CreateAxisGridLine(location, value.ToString()));
                }
            }
        }
        public IEnumerable <AxisGridLine> Create(AxisMap map, double lower, double upper)
        {
            var lowerInt = map.SortOrder == SortOrder.Ascending
                ? (int)map.MapInverse(lower)
                : (int)map.MapInverse(upper);

            var upperInt = map.SortOrder == SortOrder.Ascending
                ? (int)map.MapInverse(upper)
                : (int)map.MapInverse(lower);

            var width = (double)upperInt - lowerInt;

            if (lowerInt == int.MinValue)
            {
                yield return(CreateAxisGridLine(map, lowerInt));
            }

            if (upperInt == int.MaxValue)
            {
                yield return(CreateAxisGridLine(map, upperInt));
            }

            var step  = 0d;
            var start = 0d;

            for (var i = 1d; i < int.MaxValue; i *= 10)
            {
                if (width >= i && width < i * 15)
                {
                    step  = i;
                    start = (int)(lowerInt - (lowerInt % i));
                    break;
                }
            }

            if (step == 0d)
            {
                yield break;
            }

            for (var i = start; i <= upperInt; i += step)
            {
                yield return(CreateAxisGridLine(map, (int)i));
            }
        }
示例#20
0
    /// <summary>
    /// Adds the player with axis map.
    /// </summary>
    /// <returns>The player id.</returns>
    /// <param name="axisMapToUse">Axis map to use.</param>
    private Player AddPlayerWithAxisMap(AxisMap axisMapToUse)
    {
        GameObject playerObject;

        if (uLink.Network.peerType == uLink.NetworkPeerType.Disconnected)
        {
            if (_playerCreationPoint)
            {
                playerObject = (GameObject)Instantiate(playerPrefab, _playerCreationPoint.transform.position, _playerCreationPoint.transform.rotation);
            }
            else
            {
                playerObject = (GameObject)Instantiate(playerPrefab, transform.position, transform.rotation);
            }
        }
        else
        {
            if (_playerCreationPoint)
            {
                playerObject = (GameObject)uLink.Network.Instantiate(playerPrefab, _playerCreationPoint.transform.position, _playerCreationPoint.transform.rotation, 0);
            }
            else
            {
                playerObject = (GameObject)uLink.Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
            }
        }

        if (playerObject != null)
        {
            Player player = playerObject.GetComponent <Player>();
            player.transform.parent = transform;
            player.SetId(players.Count);
            player.AxisMap = axisMapToUse;
            players.Add(player);
            OnResetPlayer(player);
            return(player);
        }

        return(null);
    }
        public void SetUp()
        {
            _values = new List <object>();
            _column = new ColumnBuilder()
                      .WithDataType(typeof(object))
                      .WithValues(_values)
                      .Build();
            _layout = new ScatterPlotLayoutBuilder()
                      .WithYAxisColumn(_column)
                      .Build();
            _scatterPlot = new ScatterPlotBuilder()
                           .WithLayout(_layout)
                           .Build();
            _viewExtent   = new Rect();
            _axisMap      = new FakeAxisMap();
            _values       = new List <object>();
            _axisGridLine = new AxisGridLine();
            _axisLines    = new List <AxisGridLine> {
                _axisGridLine
            };

            _mockViewRepository = new Mock <IViewRepository>();
            _mockViewRepository.Setup(p => p.Get <ScatterPlot>())
            .Returns(_scatterPlot);

            _mockMapFactory = new Mock <IMapFactory>();
            _mockMapFactory.Setup(p => p.CreateAxisMap(_column, 0d, 1d, SortOrder.Ascending))
            .Returns(_axisMap);

            _mockFactory = new Mock <IGridLineFactory>();
            _mockFactory.Setup(p => p.Create(typeof(object), _axisMap, _values, _viewExtent.Left, _viewExtent.Right))
            .Returns(_axisLines);

            _handler = new GetYAxisGridLinesQueryHandler(
                _mockViewRepository.Object,
                _mockMapFactory.Object,
                _mockFactory.Object);
        }
 private double GetPosition(AxisMap map, double value)
 {
     return(map.Map(value).GetValueOrDefault());
 }
示例#23
0
 private void OnAddPlayerWithAxisMap(AxisMap axisMapToUse)
 {
     AddPlayerWithAxisMap(axisMapToUse);
 }