<commit_before>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

CLASS({
  package: 'foam.demos',
  name: 'ClockView',

  extends: 'foam.graphics.Circle',

  traits: [ 'com.google.misc.Colors' ],

  requires: [
    'foam.graphics.Circle',
    'foam.ui.IntFieldView'
  ],

  properties: [
    {
      model_: 'BooleanProperty',
      name: 'drawTicks',
    },
    {
      model_: 'FloatProperty',
      name: 'r',
      label: 'Radius',
      defaultValue: 100
    },
    {
      name: 'color',
      type: 'String',
      factory: function() { return this.BLUE; }
    },
    {
      name: 'minuteHand',
      type: 'Hand',
      factory: function() {
        return this.Hand.create({r:this.r-6, width:5, color: this.GREEN});
      }
    },
    {
      name: 'hourHand',
      type: 'Hand',
      factory: function() {
        return this.Hand.create({r:this.r-15, width:7, color: this.YELLOW});
      }
    },
    {
      name: 'secondHand',
      type: 'Hand',
      factory: function() {
        return this.Hand.create({r:this.r-6, width:3, color: this.RED});
      }
    }
  ],

  methods: {
    init: function() {
      this.SUPER();

      this.border = this.BLUE;
      this.borderWidth = 5;
      this.color = 'white';
      
      this.addChild(this.hourHand);
      this.addChild(this.minuteHand);
      this.addChild(this.secondHand);
    },

    paintSelf: function() {
      this.SUPER();

      var date = new Date();

      this.secondHand.a = Math.PI/2 - Math.PI*2 * date.getSeconds() / 60 ;
      this.minuteHand.a = Math.PI/2 - Math.PI*2 * date.getMinutes() / 60 ;
      this.hourHand.a   = Math.PI/2 - Math.PI*2 * (date.getHours() % 12) / 12 + this.minuteHand.a / 12;

      var c = this.canvas;
      
      if ( ! this.drawTicks ) return;

      for ( var i = 0 ; i < 12 ; i++ ) {
        var a = Math.PI*2/12*i;
        var l = i % 3 ? 6 : 10;
        var w = i % 3 ? 2 : 3;
        c.beginPath();
        c.moveTo((this.r-l)*Math.cos(a),-(this.r-l)*Math.sin(a));
        c.lineTo((this.r)*Math.cos(a),-(this.r)*Math.sin(a));
        c.closePath();<commit_msg>Fix for ClockView not setting border color correctly.<commit_after>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

CLASS({
  package: 'foam.demos',
  name: 'ClockView',

  extends: 'foam.graphics.Circle',

  traits: [ 'com.google.misc.Colors' ],

  requires: [
    'foam.graphics.Circle',
    'foam.ui.IntFieldView'
  ],

  properties: [
    {
      model_: 'BooleanProperty',
      name: 'drawTicks',
    },
    {
      model_: 'FloatProperty',
      name: 'r',
      label: 'Radius',
      defaultValue: 100
    },
    {
      name: 'color',
      type: 'String',
      factory: function() { return this.BLUE; }
    },
    {
      name: 'minuteHand',
      type: 'Hand',
      factory: function() {
        return this.Hand.create({r:this.r-6, width:5, color: this.GREEN});
      }
    },
    {
      name: 'hourHand',
      type: 'Hand',
      factory: function() {
        return this.Hand.create({r:this.r-15, width:7, color: this.YELLOW});
      }
    },
    {
      name: 'secondHand',
      type: 'Hand',
      factory: function() {
        return this.Hand.create({r:this.r-6, width:3, color: this.RED});
      }
    }
  ],

  methods: {
    init: function() {
      this.SUPER();

      this.border = this.color;
      this.borderWidth = 5;
      this.color = 'white';
      
      this.addChild(this.hourHand);
      this.addChild(this.minuteHand);
      this.addChild(this.secondHand);
    },

    paintSelf: function() {
      this.SUPER();

      var date = new Date();

      this.secondHand.a = Math.PI/2 - Math.PI*2 * date.getSeconds() / 60 ;
      this.minuteHand.a = Math.PI/2 - Math.PI*2 * date.getMinutes() / 60 ;
      this.hourHand.a   = Math.PI/2 - Math.PI*2 * (date.getHours() % 12) / 12 + this.minuteHand.a / 12;

      var c = this.canvas;
      
      if ( ! this.drawTicks ) return;

      for ( var i = 0 ; i < 12 ; i++ ) {
        var a = Math.PI*2/12*i;
        var l = i % 3 ? 6 : 10;
        var w = i % 3 ? 2 : 3;
        c.beginPath();
        c.moveTo((this.r-l)*Math.cos(a),-(this.r-l)*Math.sin(a));
        c.lineTo((this.r)*Math.cos(a),-(this.r)*Math.sin(a));
        c.closePath();
{'fraction_non_alphanumeric': 0.15371716042481834, 'fraction_numerical': 0.017887087758524316, 'mean_word_length': 2.1857566765578635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798025', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1783, 'n_words': 452}