mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-11 08:52:58 +00:00
Add click handling functionality to horizontal bar charts and hover effect for each bar
This commit is contained in:
parent
b6347971fc
commit
e58c40ec40
@ -30,6 +30,12 @@ export default class DatasetHealthContainer extends Component {
|
|||||||
// Do something in the future
|
// Do something in the future
|
||||||
});
|
});
|
||||||
|
|
||||||
|
actions = {
|
||||||
|
onFilterSelect(): void {
|
||||||
|
// Change filter so that table can only show a certain category or severity
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Mock data for testing demo purposes, to be deleted once we have actual data and further development
|
// Mock data for testing demo purposes, to be deleted once we have actual data and further development
|
||||||
testSeries = [{ name: 'Test1', value: 10 }, { name: 'Test2', value: 5 }, { name: 'Test3', value: 3 }];
|
testSeries = [{ name: 'Test1', value: 10 }, { name: 'Test2', value: 5 }, { name: 'Test3', value: 3 }];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
import Component from '@ember/component';
|
||||||
|
|
||||||
|
export default class DatasetsHealthMetricsCharts extends Component.extend({
|
||||||
|
// anything which *must* be merged to prototype here
|
||||||
|
}) {
|
||||||
|
// normal class body definition here
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ import Component from '@ember/component';
|
|||||||
import { IChartDatum } from 'wherehows-web/typings/app/visualization/charts';
|
import { IChartDatum } from 'wherehows-web/typings/app/visualization/charts';
|
||||||
import { computed, get, set, setProperties } from '@ember/object';
|
import { computed, get, set, setProperties } from '@ember/object';
|
||||||
import ComputedProperty from '@ember/object/computed';
|
import ComputedProperty from '@ember/object/computed';
|
||||||
|
import { noop } from 'wherehows-web/utils/helpers/functions';
|
||||||
|
|
||||||
interface IBarSeriesDatum extends IChartDatum {
|
interface IBarSeriesDatum extends IChartDatum {
|
||||||
yOffset: number;
|
yOffset: number;
|
||||||
@ -155,13 +156,22 @@ export default class HorizontalBarChart extends Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expected to be optionally passed in from the containing component, this function handles the action to
|
||||||
|
* be taken if a user selects an individual bar from the chart.
|
||||||
|
* @param {string} name - the "category" or "tag" that goes with each legend label
|
||||||
|
* @param {number} value - the value associated with each series datum
|
||||||
|
*/
|
||||||
|
onBarSelect: (name: string, value: number) => void;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
// Applying passed in properties or setting to default values
|
// Applying passed in properties or setting to default values
|
||||||
setProperties(this, {
|
setProperties(this, {
|
||||||
labelTagProperty: this.labelTagProperty || 'name',
|
labelTagProperty: this.labelTagProperty || 'name',
|
||||||
labelAppendTag: this.labelAppendTag || '',
|
labelAppendTag: this.labelAppendTag || '',
|
||||||
labelAppendValue: this.labelAppendValue || ''
|
labelAppendValue: this.labelAppendValue || '',
|
||||||
|
onBarSelect: this.onBarSelect || noop
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,4 +22,12 @@
|
|||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__bar {
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
transform: scale(1.02, 1);
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
Coming Soon!
|
<h3>Metadata Health</h3>
|
||||||
|
|
||||||
<div style="width: 50%">
|
<div style="width: 50%">
|
||||||
{{visualization/charts/horizontal-bar-chart
|
{{visualization/charts/horizontal-bar-chart
|
||||||
title="Test Chart"
|
title="test Chart"
|
||||||
series=testSeries
|
series=testSeries
|
||||||
labelAppendValue="%"}}
|
labelAppendValue="%"
|
||||||
|
onBarSelect=(action "onFilterSelect")}}
|
||||||
</div>
|
</div>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
{{yield}}
|
||||||
@ -3,7 +3,9 @@
|
|||||||
<g class="highcharts-series-group">
|
<g class="highcharts-series-group">
|
||||||
<g class="highcharts-series highcharts-series-0 highcharts-bar-series highcharts-tracker highcharts-series-hover">
|
<g class="highcharts-series highcharts-series-0 highcharts-bar-series highcharts-tracker highcharts-series-hover">
|
||||||
{{#each seriesData as |datum index|}}
|
{{#each seriesData as |datum index|}}
|
||||||
<rect x="0" y="{{datum.yOffset}}" height="16" width="{{datum.barLength}}" class="highcharts-color-{{index}}" rx="2px" ry="2px"></rect>
|
<rect x="0" y="{{datum.yOffset}}" height="16" width="{{datum.barLength}}" class="highcharts-color-{{index}} viz-bar-chart__bar" rx="2px" ry="2px"
|
||||||
|
{{action onBarSelect (get datum labelTagProperty) datum.value}}>
|
||||||
|
</rect>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</g>
|
</g>
|
||||||
<g class="highcharts-data-labels highcharts-series-0 highcharts-bar-series highcharts-color-0 highcharts-tracker">
|
<g class="highcharts-data-labels highcharts-series-0 highcharts-bar-series highcharts-color-0 highcharts-tracker">
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupRenderingTest } from 'ember-qunit';
|
||||||
|
import { render } from '@ember/test-helpers';
|
||||||
|
import hbs from 'htmlbars-inline-precompile';
|
||||||
|
|
||||||
|
module('Integration | Component | datasets/health/metrics-charts', function(hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
|
test('it renders', async function(assert) {
|
||||||
|
// Set any properties with this.set('myProperty', 'value');
|
||||||
|
// Handle any actions with this.set('myAction', function(val) { ... });
|
||||||
|
|
||||||
|
await render(hbs`{{datasets/health/metrics-charts}}`);
|
||||||
|
|
||||||
|
assert.equal(this.element.textContent.trim(), '');
|
||||||
|
|
||||||
|
// Template block usage:
|
||||||
|
await render(hbs`
|
||||||
|
{{#datasets/health/metrics-charts}}
|
||||||
|
template block text
|
||||||
|
{{/datasets/health/metrics-charts}}
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(this.element.textContent.trim(), 'template block text');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user