All Projects → markau → Angular Svg Timer

markau / Angular Svg Timer

An SVG-based timer button in AngularJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Angular Svg Timer

Visualizer
UI-Router state visualizer and transition visualizer
Stars: ✭ 205 (+1763.64%)
Mutual labels:  svg, angularjs
Onthefly
🔗 Generate TinySVG, HTML and CSS on the fly
Stars: ✭ 37 (+236.36%)
Mutual labels:  svg, angularjs
Mean Angular5 Passport Authentication
Securing MEAN Stack (Angular 5) Web Application using Passport Authentication
Stars: ✭ 24 (+118.18%)
Mutual labels:  angularjs
Firebase Demo
Stars: ✭ 9 (-18.18%)
Mutual labels:  angularjs
Md Form Validator
Simplify the usage of ngMessages with the angular material design
Stars: ✭ 8 (-27.27%)
Mutual labels:  angularjs
React Circle
Renders a svg circle + progress, it just works 💘
Stars: ✭ 925 (+8309.09%)
Mutual labels:  svg
Squib
A Ruby DSL for prototyping card games.
Stars: ✭ 850 (+7627.27%)
Mutual labels:  svg
Rails Api And Angularjs
Integration between rails and angularjs which includes rspec tests.
Stars: ✭ 22 (+100%)
Mutual labels:  angularjs
Gi
Native Go (golang) Graphical Interface system (2D and 3D), built on GoKi tree framework
Stars: ✭ 864 (+7754.55%)
Mutual labels:  svg
Angular Loading Feedback
Angular directive to indicate loads in app
Stars: ✭ 8 (-27.27%)
Mutual labels:  angularjs
Materializecss Autocomplete
Small material design autocomplete library for materializecss
Stars: ✭ 9 (-18.18%)
Mutual labels:  angularjs
Jocs.github.io
💯Jocs 的个人博客,所有的文章都在 issues 里面
Stars: ✭ 840 (+7536.36%)
Mutual labels:  angularjs
Ngfilereader
This is file reader component on angular.
Stars: ✭ 25 (+127.27%)
Mutual labels:  angularjs
Chart.xkcd
Chart.xkcd is a chart library that plots “sketchy”, “cartoony” or “hand-drawn” styled charts.
Stars: ✭ 6,982 (+63372.73%)
Mutual labels:  svg
Ng Gentelella
An AngularJS admin interface based on the Gentelella bootstrap template markup.
Stars: ✭ 24 (+118.18%)
Mutual labels:  angularjs
Ng Suggest
AngularJS module to provide Typeahead via OpenSearch Suggestions
Stars: ✭ 9 (-18.18%)
Mutual labels:  angularjs
Snowflake
❄️ SVG in Swift
Stars: ✭ 924 (+8300%)
Mutual labels:  svg
Create Content Loader
✏️ Tool to create your own react-content-loader easily.
Stars: ✭ 937 (+8418.18%)
Mutual labels:  svg
React Planner
✏️ A React Component for plans design. Draw a 2D floorplan and navigate it in 3D mode.
Stars: ✭ 846 (+7590.91%)
Mutual labels:  svg
Angular Typed
the angularjs typing tool module, that helps you with typing animation
Stars: ✭ 11 (+0%)
Mutual labels:  angularjs

angular-svg-timer

Build Status

An Angular directive to provide a self-contained, SVG-based timer button with visual feedback of elapsed time:

Timer screenshots

The SVG is based on this fiddle. Extending this into an Angular directive allows additional features, including the start/stop button (works with touch) and communication between the directive and the view so that timer events can be handled.

Demo

See the demo page for a working example.

Usage

  1. Install with bower:

    bower install angular-svg-timer

  2. Include the scripts in your main index.html file:

    <script src="bower_components/moment/moment.js"></script>
    <script src="bower_components/angular-moment/angular-moment.js"></script>
    <script src="bower_components/angular-svg-timer/timer.js"></script>
    
  3. Register the module dependency in your main app.js file, e.g.:

    var App = angular.module('App', ['markau.timer']);

Quick start

The minimal declaration is:

<markau-timer time="20" />

Options

The directive uses an isolate scope with 2-way binding on provided attributes, so the view can remain aware of changes in timer state.

The directive exposes the following attributes:

  • Time: countdown time (in milliseconds). Required.
  • Status:
    • notstarted
    • running
    • complete
    • <something else> (based on events below)
  • Events: an array of objects in the form { 'time': '<event>' }. This is intended to allow the timer to check for <event> milestones and update the status accordingly. The one event supported so far is { 'time': 'half' }; when the countdown is half way through, the status attribute changes from 'running' to 'halftime'. Other useful events may include 1/4 and 3/4 time, '10 seconds remaining' etc.

Example

Instantiate scope variables:

$scope.time = 20;
$scope.status = 'notstarted';
$scope.events: [{ 'time': 'half' }];

Bind the scope variables to attributes on the element:

<markau-timer time="time" status="status" events="events" />

Add a placeholder to show the current value of the scope variable:

<h2>Timer status: {{status}}</h2>

More advanced use cases involve a $watch on the $scope.status variable, or use of ng-class to show different content depending on the status. The demo page shows this in action.

Style

The directive uses an html template which exposes the svg-container and svg-timer-text classes. You can change the style on the countdown text by overriding the class:

.svg-timer-text {
    fill: #262626; /* 'fill' is the svg version of 'color' */
    font-size: 42px;
}

Size

Being an SVG, the timer scales to fill the containing DOM element (effectively, width: 100%). Place it inside a width-constrained block element to control the size of the timer.

A note on precision

Counting setTimeout() intervals is an unreliable method of measuring time in JavaScript; a 1000ms interval is not necessarily 1000ms, up to 200-300ms, depending on the load on the client device (intervals can be blocked).

This directive follows an approach of comparing the elapsed time of each setTimeout() interval against Date.now(), in order to calculate and adjust for any drift. This use of system time ensures reliable results across devices.

Compatability

This has been tested on Android 4.2 and iOS 6 / 7 in a Phonegap project, in addition to a variety of modern desktop browsers.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].