<commit_before>﻿// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.R.Components.Plots.ViewModel;

namespace Microsoft.R.Components.Plots.Implementation.View {
    public partial class RPlotManagerControl : UserControl {
        // Anything below 200 pixels at fixed 96dpi is impractical, and prone to rendering errors
        private const int MinPixelWidth = 200;
        private const int MinPixelHeight = 200;

        public IRPlotManagerViewModel Model => DataContext as IRPlotManagerViewModel;

        public RPlotManagerControl() {
            InitializeComponent();
        }

        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) {
            var unadjustedPixelSize = WpfUnitsConversion.ToPixels(Content as Visual, e.NewSize);

            // If the window gets below a certain minimum size, plot to the minimum size
            int pixelWidth = Math.Max((int)unadjustedPixelSize.Width, MinPixelWidth);
            int pixelHeight = Math.Max((int)unadjustedPixelSize.Height, MinPixelHeight);
            int resolution = WpfUnitsConversion.GetResolution(Content as Visual);

            Model.ResizePlotAfterDelay(pixelWidth, pixelHeight, resolution);
        }

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
            var image = (FrameworkElement)sender;
            var pos = e.GetPosition(image);
            var pixelSize = WpfUnitsConversion.ToPixels(image as Visual, pos);

            Model.ClickPlot((int)pixelSize.X, (int)pixelSize.Y);
        }
    }
}<commit_msg>Check for null view model.<commit_after>﻿// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.R.Components.Plots.ViewModel;

namespace Microsoft.R.Components.Plots.Implementation.View {
    public partial class RPlotManagerControl : UserControl {
        // Anything below 200 pixels at fixed 96dpi is impractical, and prone to rendering errors
        private const int MinPixelWidth = 200;
        private const int MinPixelHeight = 200;

        public IRPlotManagerViewModel Model => DataContext as IRPlotManagerViewModel;

        public RPlotManagerControl() {
            InitializeComponent();
        }

        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) {
            var unadjustedPixelSize = WpfUnitsConversion.ToPixels(Content as Visual, e.NewSize);

            // If the window gets below a certain minimum size, plot to the minimum size
            int pixelWidth = Math.Max((int)unadjustedPixelSize.Width, MinPixelWidth);
            int pixelHeight = Math.Max((int)unadjustedPixelSize.Height, MinPixelHeight);
            int resolution = WpfUnitsConversion.GetResolution(Content as Visual);

            Model?.ResizePlotAfterDelay(pixelWidth, pixelHeight, resolution);
        }

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
            var image = (FrameworkElement)sender;
            var pos = e.GetPosition(image);
            var pixelSize = WpfUnitsConversion.ToPixels(image as Visual, pos);

            Model?.ClickPlot((int)pixelSize.X, (int)pixelSize.Y);
        }
    }
}
{'fraction_non_alphanumeric': 0.07437102571191595, 'fraction_numerical': 0.006082388719933647, 'mean_word_length': 3.1875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '832085', 'n_tokens_mistral': 945, 'n_tokens_neox': 887, 'n_words': 276}