1
0
Fork 0
mirror of synced 2024-07-07 07:15:43 +12:00

Latest Donut and Legend Updates

This commit is contained in:
cmack 2020-08-05 16:57:54 +01:00
parent 5d4193bfd3
commit 8c1d7bc971
5 changed files with 106 additions and 80 deletions

View file

@ -27,7 +27,7 @@
height: 20px; height: 20px;
/* background-color: #5e17e9; */ /* background-color: #5e17e9; */
background-color: var(--grey-2); background-color: var(--grey-2);
transform: translateY(-50%); /* transform: translateY(-50%); */
cursor: pointer; cursor: pointer;
transition: 0.2s ease transform, 0.2s ease background-color, transition: 0.2s ease transform, 0.2s ease background-color,
0.2s ease box-shadow; 0.2s ease box-shadow;

View file

@ -498,13 +498,7 @@ export default {
control: ModelSelect, control: ModelSelect,
}, },
{ {
label: "Fix Highlight Slice", label: "Keep Last Hover",
key: "hasFixedHighlightedSlice",
valueKey: "checked",
control: Checkbox,
},
{
label: "Hover highlight",
key: "hasLastHoverSliceHighlighted", key: "hasLastHoverSliceHighlighted",
valueKey: "checked", valueKey: "checked",
control: Checkbox, control: Checkbox,
@ -516,7 +510,7 @@ export default {
control: Checkbox, control: Checkbox,
}, },
{ {
label: "Has Hover", label: "Hover Highlight",
key: "hasHoverAnimation", key: "hasHoverAnimation",
valueKey: "checked", valueKey: "checked",
control: Checkbox, control: Checkbox,
@ -559,6 +553,28 @@ export default {
valueKey: "checked", valueKey: "checked",
control: Checkbox, control: Checkbox,
}, },
{
label: "Show Legend",
key: "useLegend",
valueKey: "checked",
control: Checkbox,
},
{
label: "Horizontal Legend",
key: "horizontalLegend",
valueKey: "checked",
control: Checkbox,
},
{
label: "Legend Width",
key: "legendWidth",
control: Input,
},
{
label: "Legend Height",
key: "legendHeight",
control: Input,
},
], ],
}, },
}, },

View file

@ -291,8 +291,11 @@
"externalRadius": "number", "externalRadius": "number",
"internalRadius": "number", "internalRadius": "number",
"radiusHoverOffset": "number", "radiusHoverOffset": "number",
"percentageFormat": "string",
"useLegend": "bool", "useLegend": "bool",
"percentageFormat": "string" "horizontalLegend": "bool",
"legendWidth": "number",
"legendHeight": "number"
} }
}, },
"sparkline": { "sparkline": {

View file

@ -17,14 +17,15 @@
let chartElement = null let chartElement = null
let chartContainer = null let chartContainer = null
let chartSvgWidth = 0
let chartSvg = null
export let _bb export let _bb
export let model export let model
let store = _bb.store let store = _bb.store
export let customMouseOver = null
export let customMouseMove = null export let customMouseMove = null
export let customMouseOut = null
export let customClick = null export let customClick = null
export let orderingFunction = null export let orderingFunction = null
@ -46,6 +47,10 @@
export let internalRadius = 25 export let internalRadius = 25
export let isAnimated = true export let isAnimated = true
export let radiusHoverOffset = 0 export let radiusHoverOffset = 0
export let useLegend = true
export let horizontalLegend = false
export let legendWidth = null
export let legendHeight = null
async function fetchData() { async function fetchData() {
const FETCH_RECORDS_URL = `/api/views/all_${model}` const FETCH_RECORDS_URL = `/api/views/all_${model}`
@ -79,6 +84,8 @@
}) })
function bindChartUIProps() { function bindChartUIProps() {
chart.percentageFormat(".0f")
if (notNull(color)) { if (notNull(color)) {
chart.colorSchema(getColorSchema(color)) chart.colorSchema(getColorSchema(color))
} }
@ -127,6 +134,8 @@
if (notNull(orderingFunction)) { if (notNull(orderingFunction)) {
chart.orderingFunction(orderingFunction) chart.orderingFunction(orderingFunction)
} }
chartContainer.datum(_data).call(chart)
chartSvg = document.querySelector(`.${chartClass} .britechart`)
} }
function bindChartEvents() { function bindChartEvents() {
@ -142,22 +151,33 @@
legendChart.clearHighlight() legendChart.clearHighlight()
}) })
chart.on("customMouseOver", function(data) { chart.on("customMouseOver", function(data) {
console.log("DATA", data.data)
legendChart.highlight(data.data.id) legendChart.highlight(data.data.id)
}) })
} }
} }
$: if (!width && chartSvg) {
width = chartSvg.clientWidth
chart.width(width)
chartContainer.datum(_data).call(chart)
}
$: _data = model ? $store[model] : data $: _data = model ? $store[model] : data
$: colorSchema = getColorSchema(color) $: colorSchema = getColorSchema(color)
</script> </script>
<div bind:this={chartElement} class={chartClass} /> <div>
<Legend <div bind:this={chartElement} class={chartClass} />
{#if useLegend}
<Legend
bind:legend={legendChart} bind:legend={legendChart}
{colorSchema} {colorSchema}
useLegend useLegend
isHorizontal={horizontalLegend}
width={legendWidth || width}
height={legendHeight}
{chartClass} {chartClass}
{width}
data={_data} /> data={_data} />
{/if}
</div>

View file

@ -4,7 +4,6 @@
import { select } from "d3-selection" import { select } from "d3-selection"
import { onMount } from "svelte" import { onMount } from "svelte"
export let chartClass = ""
export let useLegend = true export let useLegend = true
export let data = [] export let data = []
export let width = null export let width = null
@ -23,20 +22,13 @@
let legendContainer = null let legendContainer = null
let legendElement = null let legendElement = null
let chartSvgWidth = 0 $: {
let chartSvg = null if (legendElement) {
legendContainer = select(legendElement)
legend.numberFormat(".0f")
onMount(() => {
if (chartClass) {
chartSvg = document.querySelector(`.${chartClass} .britechart`)
}
})
function bindChartUIProps() {
if (width) { if (width) {
legend.width(width) legend.width(width)
} else if (chartSvg) {
legend.width(chartSvg.clientWidth)
} }
if (notNull(height)) { if (notNull(height)) {
@ -55,10 +47,6 @@
legend.highlightByEntryId(highlightByEntryId) legend.highlightByEntryId(highlightByEntryId)
} }
if (notNull(isHorizontal)) {
legend.isHorizontal(isHorizontal)
}
if (notNull(margin)) { if (notNull(margin)) {
legend.margin(margin) legend.margin(margin)
} }
@ -78,16 +66,15 @@
if (notNull(unit)) { if (notNull(unit)) {
legend.unit(unit) legend.unit(unit)
} }
}
$: {
if (legendElement) {
legendContainer = select(legendElement)
bindChartUIProps()
legendContainer.datum(data).call(legend) legendContainer.datum(data).call(legend)
} }
} }
$: if (notNull(isHorizontal)) {
debugger
legend.isHorizontal(isHorizontal)
}
const legendClass = `legend-container` const legendClass = `legend-container`
</script> </script>