Esempio n. 1
0
        private void RenderItemLabelsDiscrete(VisualPayload payload, List <ICriterionMetaSelector> criteria)
        {
            var sizePeriod = SizePeriod.GetLastKeyValue(payload.Data);

            const float shiftRatio = 0.50f; // 0.50 means 'centered'    todo: make this a setting (mutable field)

            // Determine how many labels to create, based on the maximum 'index' (coordinate) of the axis in question
            var entries = AxisIndexVariable.GetEntries(payload.Data);

            var maxVar = -1;

            foreach (var e in entries)
            {
                maxVar = Mathf.Max(maxVar, AxisIndexVariable.GetValue(e));
            }
            if (maxVar == -1)
            {
                return;
            }
            maxVar += 1;

            //var numLabels =
            //    //!entries.Any() ? 0 :
            //    entries.Max( e => AxisIndexVariable.GetValue( e ) ) + 1;

            RenderItemLabelsInternal(payload, maxVar, sizePeriod, shiftRatio, true, criteria);
        }
Esempio n. 2
0
        private void RenderItemLabelsInternal(VisualPayload payload, int numLabels, float sizePeriod, float shiftRatio, bool discrete, List <ICriterionMetaSelector> criteria)
        {
            var startingOffset  = StartingOffset.GetLastKeyValue(payload.Data);
            var axisOrientation = AxisOrientation.GetLastKeyValue(payload.Data);

            var startX = startingOffset.x + (sizePeriod * shiftRatio * axisOrientation.x);
            var startY = startingOffset.y + (sizePeriod * shiftRatio * axisOrientation.y);
            var startZ = startingOffset.z + (sizePeriod * shiftRatio * axisOrientation.z);

            var localOffset    = new Vector3(startX, startY, startZ);
            var localOffsetAdd = new Vector3(sizePeriod * axisOrientation.x, sizePeriod * axisOrientation.y, sizePeriod * axisOrientation.z);

            var currentContinuousValue   = MinimumValue;
            var continuousValueIncrement = 0.0f;

            if (numLabels > 1)
            {
                continuousValueIncrement = (MaximumValue - MinimumValue) / (float)(numLabels - 1);
            }

            var maxSize = 0.0f;
            List <LabelBehaviour> labelsCreated = new List <LabelBehaviour>();



            for (var labelIndex = 0; labelIndex < numLabels; labelIndex++)
            {
                var    text     = String.Empty;
                object rowIndex = 0;

                if (discrete)
                {
                    var entries = AxisIndexVariable.GetEntries(payload.Data);

                    // Mind you, this is super inefficient.
                    foreach (var entry in entries)
                    {
                        if (labelIndex == AxisIndexVariable.GetValue(entry))
                        {
                            text     = ItemText.GetValue(entry);
                            rowIndex = AxisIndexVariable.GetValue(entry);
                            break;
                        }
                    }
                }
                else
                {
                    text     = currentContinuousValue.ToString("F2");
                    rowIndex = (float)currentContinuousValue;
                    currentContinuousValue += continuousValueIncrement;
                }

                var axisElementObj = LabelSystemFactory.InstantiateAxisElementLabel();

                var labelComponent = axisElementObj.GetComponent <AxisElementLabel>();

                LabelSystem.CreateLabel(text, localOffset, ItemLabelOrientation.GetLastKeyValue(payload.Data), labelComponent);

                labelComponent.SetCriteria(criteria, rowIndex);


                labelsCreated.Add(labelComponent);
                maxSize = Math.Max(maxSize, LabelSystem.GetDesiredLabelLength(labelComponent));

                localOffset += localOffsetAdd;
            }

            foreach (var label in labelsCreated)
            {
                LabelSystem.SetLabelLength(label, maxSize);
            }
        }
Esempio n. 3
0
        public void Render(VisualPayload payload, IMetaSelectable selectable)
        {
            RenderAxisLabel(payload);   // Optional 'Axis title'

            // Labels along an axis:
            var mode = AxisMode.GetLastKeyValue(payload.Data);

            if (mode == AxialLabelAxisMode.Discrete)
            {
                // create equality criteria
                var normalSelector = PayloadSelectorFactory.InstantiateCriterionEqualsSelect(selectable);
                normalSelector.SelectionMode.OperationToPerform = SelectionOperation.SelectOnly;
                normalSelector.CriterionField = (mut) => AxisIndexVariable.GetValue(mut);
                normalSelector.ArrityLevels   = AxisIndexVariable.NumberOfIntermediates;

                var toggleSelector = PayloadSelectorFactory.InstantiateCriterionEqualsSelect(selectable);
                toggleSelector.SelectionMode.OperationToPerform = SelectionOperation.ToggleFullySelected;
                toggleSelector.RequiredModifiers = new InputModifiers()
                {
                    Control = true
                };
                toggleSelector.CriterionField = (mut) => AxisIndexVariable.GetValue(mut);
                toggleSelector.ArrityLevels   = AxisIndexVariable.NumberOfIntermediates;

                normalSelector.FieldLastKey = AxisIndexVariable.AbsoluteKey;
                toggleSelector.FieldLastKey = AxisIndexVariable.AbsoluteKey;

                var discreteCriterionSelectors = new List <ICriterionMetaSelector>()
                {
                    normalSelector, toggleSelector
                };

                RenderItemLabelsDiscrete(payload, discreteCriterionSelectors);
            }
            else if (mode == AxialLabelAxisMode.Continuous)
            {
                // create range criteria
                var normalRangeSelector = PayloadSelectorFactory.InstantiateCriterionRangeSelect(selectable);
                normalRangeSelector.SelectionMode.OperationToPerform = SelectionOperation.SelectOnly;
                normalRangeSelector.CriterionField = (mut) => ComparisonValue.GetValue(mut);
                normalRangeSelector.ArrityLevels   = ComparisonValue.NumberOfIntermediates;

                var toggleRangeSelector = PayloadSelectorFactory.InstantiateCriterionRangeSelect(selectable);
                toggleRangeSelector.SelectionMode.OperationToPerform = SelectionOperation.ToggleFullySelected;
                toggleRangeSelector.RequiredModifiers = new InputModifiers()
                {
                    Control = true
                };
                toggleRangeSelector.CriterionField = (mut) => ComparisonValue.GetValue(mut);
                toggleRangeSelector.ArrityLevels   = ComparisonValue.NumberOfIntermediates;

                normalRangeSelector.FieldLastKey = ComparisonValue.AbsoluteKey;
                toggleRangeSelector.FieldLastKey = ComparisonValue.AbsoluteKey;

                var continuousCriterionSelectors = new List <ICriterionMetaSelector>()
                {
                    normalRangeSelector, toggleRangeSelector
                };

                RenderItemLabelsContinuous(payload, continuousCriterionSelectors);
            }
        }