@quartic/bokehjs
Version:
Interactive, novel data visualization
71 lines (61 loc) • 2.04 kB
text/coffeescript
import {Model} from "../../model"
import * as p from "core/properties"
import {logger} from "core/logging"
import {uniq} from "core/util/array"
import {ColumnDataSource} from "../../models/sources/column_data_source"
export class LegendItem extends Model
type: "LegendItem"
_check_data_sources_on_renderers: () ->
field =
if field?
if .length < 1
return false
source = [0].data_source
if source?
for r in
if r.data_source != source
return false
return true
_check_field_label_on_data_source: () ->
field =
if field?
if .length < 1
return false
source = [0].data_source
if source? and field not in source.columns()
return false
return true
initialize: (attrs, options) ->
super(attrs, options)
# Validate data_sources match
data_source_validation =
if not data_source_validation
logger.error("Non matching data sources on legend item renderers")
# Validate label in data_source
field_validation =
if not field_validation
logger.error("Bad column name on label: #{@label}")
{
label: [ p.StringSpec, null ]
renderers: [ p.Array, [] ]
}
get_field_from_label_prop: () =>
if ? and .field?
return .field
get_labels_list_from_label_prop: () =>
# Always return a list of the labels
if ? and .value?
return [.value]
field =
if field?
if [0] and [0].data_source?
source = [0].data_source
else
return ["No source found"]
if source instanceof ColumnDataSource
data = source.get_column(field)
if data?
return uniq(data)
else
return ["Invalid field"]
return []