import hbs from 'htmlbars-inline-precompile'; import EmberObject, { computed } from '@ember/object'; import { on } from '@ember/object/evented'; import DelayedTruth from '../utils/delayed-truth'; export default { title: 'Charts/Distribution Bar', }; export let Standard = () => { return { template: hbs`
Distribution Bar
{{#if delayedTruth.complete}} {{/if}}

The distribution bar chart proportionally show data in a single bar. It includes a tooltip out of the box, assumes the size of the container element, and is designed to be styled with CSS.

`, context: { delayedTruth: DelayedTruth.create(), distributionBarData: [ { label: 'one', value: 10 }, { label: 'two', value: 20 }, { label: 'three', value: 30 }, ], }, }; }; export let WithClasses = () => { return { template: hbs`
Distribution Bar with classes
{{#if delayedTruth.complete}} {{/if}}

If a datum provides a className property, it will be assigned to the corresponding rect element, allowing for custom colorization.

`, context: { delayedTruth: DelayedTruth.create(), distributionBarDataWithClasses: [ { label: 'Queued', value: 10, className: 'queued' }, { label: 'Complete', value: 20, className: 'complete' }, { label: 'Failed', value: 30, className: 'failed' }, ], }, }; }; export let Flexibility = () => { return { template: hbs`
Distribution Bar flexibility
{{#if delayedTruth.complete}} {{/if}}
{{#if delayedTruth.complete}} {{/if}}

Distribution bar assumes the dimensions of the container.

`, context: { delayedTruth: DelayedTruth.create(), distributionBarData: [ { label: 'one', value: 10 }, { label: 'two', value: 20 }, { label: 'three', value: 30 }, ], }, }; }; export let LiveUpdating = () => { return { template: hbs`
Live-updating Distribution Bar

Distribution bar animates with data changes.

`, context: { controller: EmberObject.extend({ timerTicks: 0, startTimer: on('init', function () { this.set( 'timer', setInterval(() => { this.incrementProperty('timerTicks'); }, 500) ); }), willDestroy() { clearInterval(this.timer); }, distributionBarDataRotating: computed('timerTicks', function () { return [ { label: 'one', value: Math.round(Math.random() * 50) }, { label: 'two', value: Math.round(Math.random() * 50) }, { label: 'three', value: Math.round(Math.random() * 50) }, ]; }), }).create(), }, }; }; export let SingleBar = () => { return { template: hbs`
Distribution Bar with single bar
{{#if delayedTruth.complete}} {{/if}}
`, context: { delayedTruth: DelayedTruth.create(), distributionBarDatum: [{ label: 'one', value: 10 }], }, }; }; export let Jumbo = () => { return { template: hbs`
Jumbo Distribution Bar
{{#if delayedTruth.complete}}
    {{#each chart.data as |datum index|}}
  1. {{datum.value}} {{datum.label}}
  2. {{/each}}
{{/if}}

A variation of the Distribution Bar component for when the distribution bar is the central component of the page. It's a larger format that requires no interaction to see the data labels and values.

`, context: { delayedTruth: DelayedTruth.create(), distributionBarData: [ { label: 'one', value: 10 }, { label: 'two', value: 20 }, { label: 'three', value: 0 }, { label: 'four', value: 35 }, ], }, }; };