| Line | |
|---|
| 1 | // @authro nowelium |
|---|
| 2 | GoogleChart := Object clone do( |
|---|
| 3 | Query := Map clone do( |
|---|
| 4 | addParameter := method(key, value, |
|---|
| 5 | atPut(key, value) |
|---|
| 6 | ) |
|---|
| 7 | |
|---|
| 8 | asQueryParams := method( |
|---|
| 9 | buf := Sequence clone asBuffer |
|---|
| 10 | self foreach(key, value, |
|---|
| 11 | buf appendSeq(key) |
|---|
| 12 | buf appendSeq("=") |
|---|
| 13 | buf appendSeq(value) |
|---|
| 14 | buf appendSeq("&") |
|---|
| 15 | ) |
|---|
| 16 | buf asString |
|---|
| 17 | ) |
|---|
| 18 | ) |
|---|
| 19 | |
|---|
| 20 | init := method( |
|---|
| 21 | self query := Query clone |
|---|
| 22 | ) |
|---|
| 23 | |
|---|
| 24 | URL := Object clone do( |
|---|
| 25 | url := "http://chart.apis.google.com/chart?" |
|---|
| 26 | query := nil |
|---|
| 27 | withQuery := method( |
|---|
| 28 | buf := Sequence clone asBuffer |
|---|
| 29 | buf appendSeq(url) |
|---|
| 30 | args := call message argsEvaluatedIn(call target) |
|---|
| 31 | args foreach(chart, |
|---|
| 32 | buf appendSeq(chart query asQueryParams) |
|---|
| 33 | ) |
|---|
| 34 | query = buf asString |
|---|
| 35 | self |
|---|
| 36 | ) |
|---|
| 37 | asHTML := method( |
|---|
| 38 | "<img src=\"" .. query asMutable replaceSeq("&", "&") .. "\" />" |
|---|
| 39 | ) |
|---|
| 40 | ) |
|---|
| 41 | ) |
|---|