|
| 1 | +import { Line, Rectangle, Svg, Text } from "cx/svg"; |
| 2 | +import { ColorMap, Legend, PieChart, PieSlice } from "cx/charts"; |
| 3 | +import { Controller, KeySelection, Repeater } from "cx/ui"; |
| 4 | +import { HtmlElement } from "cx/widgets"; |
| 5 | + |
| 6 | +/* |
| 7 | + Issue was brought by this commit: |
| 8 | + |
| 9 | + Message: Use parent stores to prevent store change floods |
| 10 | + Link: https://github.com/codaxy/cxjs/commit/2fc6e5555df5f7d589ade27f4dd6d534d7bd0a72 |
| 11 | +
|
| 12 | + Before this, when pie slice active bind is used, it was true by default. |
| 13 | + After it, only the first pie slice active bind is initialized to true. |
| 14 | +*/ |
| 15 | + |
| 16 | +class PageController extends Controller { |
| 17 | + init() { |
| 18 | + super.init(); |
| 19 | + var value = 100; |
| 20 | + this.store.set( |
| 21 | + "$page.points", |
| 22 | + Array.from({ length: 7 }, (_, i) => ({ |
| 23 | + id: i, |
| 24 | + name: "Item " + (i + 1), |
| 25 | + value: (value = value + (Math.random() - 0.5) * 30) |
| 26 | + })) |
| 27 | + ); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +export default ( |
| 32 | + <cx> |
| 33 | + <div class="widgets" controller={PageController}> |
| 34 | + <Legend /> |
| 35 | + <div> |
| 36 | + <Svg style="width:600px; height:400px;"> |
| 37 | + <ColorMap /> |
| 38 | + <PieChart angle={360}> |
| 39 | + <Repeater records-bind="$page.points"> |
| 40 | + <PieSlice |
| 41 | + value-bind="$record.value" |
| 42 | + active-bind="$record.active" |
| 43 | + colorMap="pie" |
| 44 | + r={80} |
| 45 | + r0={20} |
| 46 | + offset={1} |
| 47 | + br={5} |
| 48 | + tooltip={{ |
| 49 | + text: { |
| 50 | + tpl: "Item {$index}: {$record.value:n;2}" |
| 51 | + }, |
| 52 | + trackMouse: true, |
| 53 | + globalMouseTracking: true, |
| 54 | + destroyDelay: 50, |
| 55 | + createDelay: 0, |
| 56 | + animate: false |
| 57 | + }} |
| 58 | + innerPointRadius={80} |
| 59 | + outerPointRadius={90} |
| 60 | + name-bind="$record.name" |
| 61 | + selection={{ |
| 62 | + type: KeySelection, |
| 63 | + bind: "$page.selection", |
| 64 | + records: { bind: "$page.points" }, |
| 65 | + record: { bind: "$record" }, |
| 66 | + index: { bind: "$index" }, |
| 67 | + keyField: "id" |
| 68 | + }} |
| 69 | + > |
| 70 | + <Line style="stroke:gray" /> |
| 71 | + <Rectangle |
| 72 | + anchors="1 1 1 1" |
| 73 | + offset="-10 20 10 -20" |
| 74 | + style="fill:white" |
| 75 | + > |
| 76 | + <Text tpl="{$record.value:n;1}" dy="0.4em" ta="middle" /> |
| 77 | + </Rectangle> |
| 78 | + </PieSlice> |
| 79 | + </Repeater> |
| 80 | + </PieChart> |
| 81 | + </Svg> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + import {HtmlElement} from "cx/widgets"; |
| 85 | + </cx> |
| 86 | +); |
0 commit comments