Esempio n. 1
0
 private void OnEquationFormatRequested(object sender, MathRichEditBoxFormatRequest e)
 {
     if (!string.IsNullOrEmpty(e.OriginalText))
     {
         e.FormattedText = GraphingControl.FormatMathML(e.OriginalText);
     }
 }
Esempio n. 2
0
        private void GraphMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
        {
            var dataPackage = new DataPackage();

            dataPackage.RequestedOperation = DataPackageOperation.Copy;

            var bitmapStream = GraphingControl.GetGraphBitmapStream();

            dataPackage.SetBitmap(bitmapStream);
            Clipboard.SetContent(dataPackage);
        }
Esempio n. 3
0
 private void OnEquationKeyGraphFeaturesRequested(object sender, EquationViewModel equationViewModel)
 {
     ViewModel.SetSelectedEquation(equationViewModel);
     if (equationViewModel != null)
     {
         var keyGraphFeatureInfo = GraphingControl.AnalyzeEquation(equationViewModel.GraphEquation);
         equationViewModel.PopulateKeyGraphFeatures(keyGraphFeatureInfo);
         IsKeyGraphFeaturesVisible = true;
         equationViewModel.GraphEquation.IsSelected = true;
     }
 }
Esempio n. 4
0
        private void OnEquationsVectorChanged(IObservableVector <EquationViewModel> sender, IVectorChangedEventArgs e)
        {
            // If an item is already added to the graph, changing it should automatically trigger a graph update
            if (e.CollectionChange == CollectionChange.ItemChanged)
            {
                return;
            }

            // Do not plot the graph if we are removing an empty equation, just remove it
            if (e.CollectionChange == CollectionChange.ItemRemoved)
            {
                var itemToRemove = GraphingControl.Equations[(int)e.Index];

                if (string.IsNullOrEmpty(itemToRemove.Expression))
                {
                    GraphingControl.Equations.RemoveAt((int)e.Index);

                    if (GraphingControl.Equations.Count == 1 && string.IsNullOrEmpty(GraphingControl.Equations[0].Expression))
                    {
                        IsManualAdjustment = false;
                    }

                    return;
                }
            }

            // Do not plot the graph if we are adding an empty equation, just add it
            if (e.CollectionChange == CollectionChange.ItemInserted)
            {
                var itemToAdd = sender[(int)e.Index];

                if (string.IsNullOrEmpty(itemToAdd.Expression))
                {
                    GraphingControl.Equations.Add(itemToAdd.GraphEquation);

                    return;
                }
            }

            // We are either adding or removing a valid equation, or resetting the collection. We will need to plot the graph
            GraphingControl.Equations.Clear();

            foreach (var equationViewModel in ViewModel.Equations)
            {
                GraphingControl.Equations.Add(equationViewModel.GraphEquation);
            }

            GraphingControl.PlotGraph(false);
        }
Esempio n. 5
0
        private void OnTracePointChanged(double xPointValue, double yPointValue)
        {
            double xAxisMin, xAxisMax, yAxisMin, yAxisMax;

            GraphingControl.GetDisplayRanges(out xAxisMin, out xAxisMax, out yAxisMin, out yAxisMax);

            TraceValue.Text = "(" + xPointValue.ToString("R") + ", " + yPointValue.ToString("N15") + ")";

            var peer = FrameworkElementAutomationPeer.FromElement(TraceValue);

            if (peer != null)
            {
                peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
            }

            PositionGraphPopup();
        }
Esempio n. 6
0
        private void GraphViewButton_Click(object sender, RoutedEventArgs e)
        {
            var    narratorNotifier = new NarratorNotifier();
            string announcementText;

            if (IsManualAdjustment)
            {
                announcementText = AppResourceProvider.GetInstance().GetResourceString("GraphViewManualAdjustmentAnnouncement");
            }
            else
            {
                announcementText  = AppResourceProvider.GetInstance().GetResourceString("GraphViewAutomaticBestFitAnnouncement");
                announcementText += AppResourceProvider.GetInstance().GetResourceString("GridResetAnnouncement");
                GraphingControl.ResetGrid();
            }

            var announcement = CalculatorAnnouncement.GetGraphViewBestFitChangedAnnouncement(announcementText);

            narratorNotifier.Announce(announcement);

            CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogGraphButtonClicked(
                GraphButton.GraphView, IsManualAdjustment ? GraphButtonValue.ManualAdjustment : GraphButtonValue.AutomaticBestFit);
        }
Esempio n. 7
0
        private void UpdateGraphAutomationName()
        {
            int    numEquations = 0;
            double xAxisMin, xAxisMax, yAxisMin, yAxisMax;

            // Only count equations that are graphed
            foreach (var equation in ViewModel.Equations)
            {
                if (equation.GraphEquation.IsValidated)
                {
                    numEquations++;
                }
            }

            GraphingControl.GetDisplayRanges(out xAxisMin, out xAxisMax, out yAxisMin, out yAxisMax);

            GraphControlAutomationName = LocalizationStringUtil.GetLocalizedString(
                AppResourceProvider.GetInstance().GetResourceString("graphAutomationName"),
                xAxisMin.ToString(),
                xAxisMax.ToString(),
                yAxisMin.ToString(),
                yAxisMax.ToString(),
                numEquations.ToString());
        }
Esempio n. 8
0
        // When share is invoked (by the user or programmatically) the event handler we registered will be called to populate the data package with the
        // data to be shared. We will request the current graph image from the grapher as a stream that will pass to the share request.
        private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            var resourceLoader = ResourceLoader.GetForCurrentView();

            try
            {
                string rawHtml;
                string equationHtml;

                rawHtml = "<p><img src='graph.png' width='600' alt='" + resourceLoader.GetString("GraphImageAltText") + "'></p>";

                var  equations    = ViewModel.Equations;
                bool hasEquations = false;

                if (equations.Count > 0)
                {
                    equationHtml = "<span style=\"color: rgb(68, 114, 196); font-style: bold; font-size : 13pt;\">"
                                   + resourceLoader.GetString("EquationsShareHeader") + "</span>"
                                   + "<table cellpadding=\"0\" cellspacing=\"0\" >";

                    foreach (var equation in equations)
                    {
                        var expression = equation.Expression;
                        if (string.IsNullOrEmpty(expression))
                        {
                            continue;
                        }

                        var color = equation.LineColor;
                        hasEquations = true;

                        expression = GraphingControl.ConvertToLinear(expression);

                        string equationColorHtml;
                        equationColorHtml = "color:rgb(" + color.R.ToString() + "," + color.G.ToString() + "," + color.B.ToString() + ");";

                        equationHtml += "<tr style=\"margin: 0pt 0pt 0pt 0pt; padding: 0pt 0pt 0pt 0pt; \"><td><span style=\"font-size: 22pt; line-height: 0;"
                                        + equationColorHtml + "\">&#x25A0;</span></td><td><div style=\"margin: 4pt 0pt 0pt 6pt;\">"
                                        + Utilities.EscapeHtmlSpecialCharacters(expression) + "</div></td>";
                    }
                    equationHtml += "</table>";

                    if (hasEquations)
                    {
                        rawHtml += equationHtml;
                    }
                }

                var variables = ViewModel.Variables;

                if (variables.Count > 0)
                {
                    var localizedSeperator = LocalizationSettings.GetInstance().GetListSeparatorWinRT() + " ";

                    rawHtml += "<br><span style=\"color: rgb(68, 114, 196); font-style: bold; font-size: 13pt;\">"
                               + resourceLoader.GetString("VariablesShareHeader")
                               + "</span><br><div style=\"margin: 4pt 0pt 0pt 0pt;\">";

                    for (int i = 0; i < variables.Count; i++)
                    {
                        var name  = variables[i].Name;
                        var value = variables[i].Value;

                        rawHtml += name + "=";
                        var formattedValue = value.ToString();
                        rawHtml += formattedValue;

                        if (variables.Count - 1 != i)
                        {
                            rawHtml += localizedSeperator;
                        }
                    }

                    rawHtml += "</div>";
                }

                rawHtml += "<br><br>";

                // Shortcut to the request data
                var requestData = args.Request.Data;

                DataPackage dataPackage = new DataPackage();
                var         html        = HtmlFormatHelper.CreateHtmlFormat(rawHtml);

                requestData.Properties.Title = resourceLoader.GetString("ShareActionTitle");

                requestData.SetHtmlFormat(html);

                var bitmapStream = GraphingControl.GetGraphBitmapStream();

                requestData.ResourceMap.Add("graph.png", bitmapStream);
                requestData.SetBitmap(bitmapStream);

                // Set the thumbnail image (in case the share target can't handle HTML)
                requestData.Properties.Thumbnail = bitmapStream;
            }
            catch (Exception ex)
            {
                ShowShareError();
                CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogPlatformExceptionInfo(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ex.HResult);
            }
        }
Esempio n. 9
0
 private void OnZoomOutCommand(object parameter)
 {
     GraphingControl.ZoomFromCenter(zoomOutScale);
     CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogGraphButtonClicked(GraphButton.ZoomOut, GraphButtonValue.None);
 }
Esempio n. 10
0
 private void OnVariableChanged(object sender, VariableChangedEventArgs args)
 {
     GraphingControl.SetVariable(args.variableName, args.newValue);
 }