<commit_before>// Copyright (c) 2015, the uix project authors. Please see the AUTHORS file for
// details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library uix.example.canvas.main;

import 'dart:math' as math;
import 'dart:html' as html;
import 'package:uix/uix.dart';

$Canvas() => new Canvas();
class Canvas extends Component {
  final tag = 'canvas';
  html.CanvasRenderingContext2D ctx;
  int width = -1;
  int height = -1;
  html.Point p = const html.Point(0, 0);

  init() {
    ctx = (element as html.CanvasElement).context2D;
    element.onMouseMove.listen(_handleMove);

    addSubscription(html.window.onResize.listen(_handleResize));
  }

  void _handleMove(html.MouseEvent e) {
    p = e.client - element.offset.topLeft;
    invalidate();
  }

  void _handleResize(html.Event e) {
    width = -1;
    height = -1;
    invalidate();
  }

  updateView() async {
    if (width == -1) {
      await scheduler.currentFrame.read();
      width = element.client.width;
      height = element.client.height;
      element.setAttribute('width', width.toString());
      element.setAttribute('height', height.toString());
      await scheduler.currentFrame.write();
    }
    ctx.globalCompositeOperation = 'source-over';
    ctx.fillStyle = 'rgba(0, 0, 0, 1)';
    ctx.fillRect(0, 0, width, height);

    ctx.globalCompositeOperation = 'lighter';<commit_msg>Fix Canvas example<commit_after>// Copyright (c) 2015, the uix project authors. Please see the AUTHORS file for
// details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library uix.example.canvas.main;

import 'dart:math' as math;
import 'dart:html' as html;
import 'package:uix/uix.dart';

$Canvas() => new Canvas();
class Canvas extends Component {
  final tag = 'canvas';
  html.CanvasRenderingContext2D ctx;
  int width = -1;
  int height = -1;
  html.Point p = const html.Point(0, 0);

  init() {
    ctx = (element as html.CanvasElement).context2D;
    element.onMouseMove.listen(_handleMove);

    addSubscription(html.window.onResize.listen(_handleResize));
  }

  void _handleMove(html.MouseEvent e) {
    p = e.offset;
    invalidate();
  }

  void _handleResize(html.Event e) {
    width = -1;
    height = -1;
    invalidate();
  }

  updateView() async {
    if (width == -1) {
      await scheduler.currentFrame.read();
      width = element.client.width;
      height = element.client.height;
      await scheduler.currentFrame.write();
      element.setAttribute('width', width.toString());
      element.setAttribute('height', height.toString());
    }
    ctx.globalCompositeOperation = 'source-over';
    ctx.fillStyle = 'rgba(0, 0, 0, 1)';
    ctx.fillRect(0, 0, width, height);

    ctx.globalCompositeOperation = 'lighter';
{'fraction_non_alphanumeric': 0.13154221912072575, 'fraction_numerical': 0.013258897418004187, 'mean_word_length': 3.357142857142857, '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': '4086626', 'n_tokens_mistral': 929, 'n_tokens_neox': 916, 'n_words': 248}