Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3879914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:46:58+00:00 2026-05-19T22:46:58+00:00

I would like to create visualizations using Protovis, but writing in CoffeeScript rather than

  • 0

I would like to create visualizations using Protovis, but writing in CoffeeScript rather than JavaScript (partly for the (x)->x function notation but other reasons as well)

Is this possible? What <script> tag would I use and is there any special order of script tags that are necessary?

Thanks.

Edit: I’d like to avoid a manual compilation step if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:46:59+00:00Added an answer on May 19, 2026 at 10:46 pm

    To clarify the question a little: Protovis code is written using a special tag,

    <script type="text/javascript+protovis">
    

    after the Protovis library has been included. However, this code must be inlined with the HTML. The browser doesn’t recognize the text/javascript+protovis type, so it simply ignores the tag; Protovis finds it and reads in the text the tag contains, without attempting to load any file linked by src.

    Why does Protovis do this? Because it runs a regex-based parser through the code to convert JavaScript 1.8 code to JavaScript 1.6 code; that way, you can use cutting-edge JavaScript features, and your code will still run in older browsers. Very cool.

    While you could certainly write CoffeeScript code, compile it, and then paste it in, that would make for a very tedious build process. The good news is that it’s unlikely (impossible?) that you’ll get code out of the CoffeeScript compiler that uses anything beyond JS 1.6 features; most of those features are baked, in some form, into CoffeeScript itself. For instance, array comprehensions, and an abbreviated syntax for anonymous functions. That means you can just use

    <script type="text/javascript" src="myProtovisCode.js"></script>
    

    for your compiled CoffeeScript code (or text/coffeescript with the coffee-script.js library, for development).

    The real trick is translating the Protovis examples, with their unfamiliar JS 1.8 syntax, into CoffeeScript. For instance,

    cell.add(pv.Dot)
        .def("x", function(k0, k1) pv.Scale.linear(flowers, function(d) d[k0]).range(0, s))
        .def("y", function(k0, k1) pv.Scale.linear(flowers, function(d) d[k1]).range(0, s))
    

    uses the abbreviated JS 1.8 anonymous function syntax, where function(x) x * x is shorthand for function(x) { return x * x; }. Of course, this translates easily to CoffeeScript:

    cell.add(pv.Dot)
        .def("x", (k0, k1) -> pv.Scale.linear(flowers, (d) -> d[k0]).range(0, s))
        .def("y", (k0, k1) -> pv.Scale.linear(flowers, (d) -> d[k1]).range(0, s))
    

    For further reference, check out New in JavaScript 1.8 over at Mozilla’s docs (Firefox being the only browser that natively supports JS 1.8 at present).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create an automatic Flowchart-like visualization to simple Java Logic, for
I would like to create a regex which validates a name of a person.
I would like to create a form that changes dynamically. I have a form
I would like to create a button in my game for the user. The
I would like to create trigger in MS SQL Server that would be call
I would like to create a textbox which accepts text in english only and
I would like to create a custom project template in visual studio 2010/2008 and
How to pass database name into stored procedure? I tried something like create procedure
I have a matrix in R that represents the joint probability mass function (pmf)
I have a table in a Rails application which (in schema.rb) looks like: create_table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.